Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Avoid NPE while dereferencing statefulset status
Browse files Browse the repository at this point in the history
Unlike other analogous types, the StatefulSet status has a *int64
pointer field for `ObservedGeneration`. Whatever the reason for this,
it means we need to check that it's not nil before dereferencing it.
  • Loading branch information
squaremo committed May 4, 2018
1 parent 5704727 commit 52a7688
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cluster/kubernetes/resourcekinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func (dk *statefulSetKind) getPodControllers(c *Cluster, namespace string) ([]po
func makeStatefulSetPodController(statefulSet *apiapps.StatefulSet) podController {
var status string
objectMeta, statefulSetStatus := statefulSet.ObjectMeta, statefulSet.Status
if *statefulSetStatus.ObservedGeneration >= objectMeta.Generation {
// The type of ObservedGeneration is *int64, unlike other controllers.
if statefulSetStatus.ObservedGeneration != nil && *statefulSetStatus.ObservedGeneration >= objectMeta.Generation {
// the definition has been updated; now let's see about the replicas
updated, wanted := statefulSetStatus.UpdatedReplicas, *statefulSet.Spec.Replicas
if updated == wanted {
Expand Down

0 comments on commit 52a7688

Please sign in to comment.