Skip to content

Commit

Permalink
Merge pull request #101875 from ravisantoshgudimetla/fix-nil-check
Browse files Browse the repository at this point in the history
Fix nil check
  • Loading branch information
k8s-ci-robot committed May 11, 2021
2 parents 2112bdd + 6f35e1a commit c7be779
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
50 changes: 27 additions & 23 deletions pkg/controller/daemon/daemon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,33 +847,37 @@ func TestDaemonSetPodCreateExpectationsError(t *testing.T) {
}

func TestSimpleDaemonSetUpdatesStatusAfterLaunchingPods(t *testing.T) {
for _, strategy := range updateStrategies() {
ds := newDaemonSet("foo")
ds.Spec.UpdateStrategy = *strategy
manager, podControl, clientset, err := newTestController(ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
}
dsMaxSurgeFeatureFlags := []bool{false, true}
for _, isEnabled := range dsMaxSurgeFeatureFlags {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DaemonSetUpdateSurge, isEnabled)()
for _, strategy := range updateStrategies() {
ds := newDaemonSet("foo")
ds.Spec.UpdateStrategy = *strategy
manager, podControl, clientset, err := newTestController(ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
}

var updated *apps.DaemonSet
clientset.PrependReactor("update", "daemonsets", func(action core.Action) (handled bool, ret runtime.Object, err error) {
if action.GetSubresource() != "status" {
var updated *apps.DaemonSet
clientset.PrependReactor("update", "daemonsets", func(action core.Action) (handled bool, ret runtime.Object, err error) {
if action.GetSubresource() != "status" {
return false, nil, nil
}
if u, ok := action.(core.UpdateAction); ok {
updated = u.GetObject().(*apps.DaemonSet)
}
return false, nil, nil
}
if u, ok := action.(core.UpdateAction); ok {
updated = u.GetObject().(*apps.DaemonSet)
}
return false, nil, nil
})
})

manager.dsStore.Add(ds)
addNodes(manager.nodeStore, 0, 5, nil)
expectSyncDaemonSets(t, manager, ds, podControl, 5, 0, 0)
manager.dsStore.Add(ds)
addNodes(manager.nodeStore, 0, 5, nil)
expectSyncDaemonSets(t, manager, ds, podControl, 5, 0, 0)

// Make sure the single sync() updated Status already for the change made
// during the manage() phase.
if got, want := updated.Status.CurrentNumberScheduled, int32(5); got != want {
t.Errorf("Status.CurrentNumberScheduled = %v, want %v", got, want)
// Make sure the single sync() updated Status already for the change made
// during the manage() phase.
if got, want := updated.Status.CurrentNumberScheduled, int32(5); got != want {
t.Errorf("Status.CurrentNumberScheduled = %v, want %v", got, want)
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/daemon/util/daemonset_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func SurgeCount(ds *apps.DaemonSet, numberToSchedule int) (int, error) {
if r == nil {
return 0, nil
}
// If surge is not requested, we should default to 0.
if r.MaxSurge == nil {
return 0, nil
}
return intstrutil.GetScaledValueFromIntOrPercent(r.MaxSurge, numberToSchedule, true)
}

Expand Down

0 comments on commit c7be779

Please sign in to comment.