Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apps: use new intstr functions #117624

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/controller/daemon/daemon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func newDaemonSet(name string) *apps.DaemonSet {
}

func newRollingUpdateStrategy() *apps.DaemonSetUpdateStrategy {
one := intstr.FromInt(1)
one := intstr.FromInt32(1)
return &apps.DaemonSetUpdateStrategy{
Type: apps.RollingUpdateDaemonSetStrategyType,
RollingUpdate: &apps.RollingUpdateDaemonSet{MaxUnavailable: &one},
Expand Down Expand Up @@ -3217,7 +3217,7 @@ func getQueuedKeys(queue workqueue.RateLimitingInterface) []string {
func TestSurgeDealsWithExistingPods(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ds := newDaemonSet("foo")
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(1))
manager, podControl, _, err := newTestController(ctx, ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
Expand All @@ -3234,7 +3234,7 @@ func TestSurgeDealsWithExistingPods(t *testing.T) {
func TestSurgePreservesReadyOldPods(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ds := newDaemonSet("foo")
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(1))
manager, podControl, _, err := newTestController(ctx, ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
Expand Down Expand Up @@ -3274,7 +3274,7 @@ func TestSurgePreservesReadyOldPods(t *testing.T) {
func TestSurgeCreatesNewPodWhenAtMaxSurgeAndOldPodDeleted(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ds := newDaemonSet("foo")
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(1))
manager, podControl, _, err := newTestController(ctx, ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
Expand Down Expand Up @@ -3321,7 +3321,7 @@ func TestSurgeCreatesNewPodWhenAtMaxSurgeAndOldPodDeleted(t *testing.T) {
func TestSurgeDeletesUnreadyOldPods(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ds := newDaemonSet("foo")
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(1))
manager, podControl, _, err := newTestController(ctx, ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
Expand Down Expand Up @@ -3362,7 +3362,7 @@ func TestSurgePreservesOldReadyWithUnsatisfiedMinReady(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ds := newDaemonSet("foo")
ds.Spec.MinReadySeconds = 15
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(1))
manager, podControl, _, err := newTestController(ctx, ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
Expand Down Expand Up @@ -3407,7 +3407,7 @@ func TestSurgeDeletesOldReadyWithUnsatisfiedMinReady(t *testing.T) {
_, ctx := ktesting.NewTestContext(t)
ds := newDaemonSet("foo")
ds.Spec.MinReadySeconds = 15
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(1))
manager, podControl, _, err := newTestController(ctx, ds)
if err != nil {
t.Fatalf("error creating DaemonSets controller: %v", err)
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/daemon/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func TestDaemonSetUpdatesNoTemplateChanged(t *testing.T) {
}

func newUpdateSurge(value intstr.IntOrString) apps.DaemonSetUpdateStrategy {
zero := intstr.FromInt(0)
zero := intstr.FromInt32(0)
return apps.DaemonSetUpdateStrategy{
Type: apps.RollingUpdateDaemonSetStrategyType,
RollingUpdate: &apps.RollingUpdateDaemonSet{
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestGetUnavailableNumbers(t *testing.T) {
},
ds: func() *apps.DaemonSet {
ds := newDaemonSet("x")
ds.Spec.UpdateStrategy = newUpdateUnavailable(intstr.FromInt(0))
ds.Spec.UpdateStrategy = newUpdateUnavailable(intstr.FromInt32(0))
return ds
}(),
nodeToPods: make(map[string][]*v1.Pod),
Expand All @@ -418,7 +418,7 @@ func TestGetUnavailableNumbers(t *testing.T) {
},
ds: func() *apps.DaemonSet {
ds := newDaemonSet("x")
ds.Spec.UpdateStrategy = newUpdateUnavailable(intstr.FromInt(1))
ds.Spec.UpdateStrategy = newUpdateUnavailable(intstr.FromInt32(1))
return ds
}(),
nodeToPods: func() map[string][]*v1.Pod {
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestGetUnavailableNumbers(t *testing.T) {
},
ds: func() *apps.DaemonSet {
ds := newDaemonSet("x")
ds.Spec.UpdateStrategy = newUpdateUnavailable(intstr.FromInt(0))
ds.Spec.UpdateStrategy = newUpdateUnavailable(intstr.FromInt32(0))
return ds
}(),
nodeToPods: func() map[string][]*v1.Pod {
Expand All @@ -471,7 +471,7 @@ func TestGetUnavailableNumbers(t *testing.T) {
},
ds: func() *apps.DaemonSet {
ds := newDaemonSet("x")
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt(0))
ds.Spec.UpdateStrategy = newUpdateSurge(intstr.FromInt32(0))
return ds
}(),
nodeToPods: func() map[string][]*v1.Pod {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/deployment/deployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func newDeployment(name string, replicas int, revisionHistoryLimit *int32, maxSu
Strategy: apps.DeploymentStrategy{
Type: apps.RollingUpdateDeploymentStrategyType,
RollingUpdate: &apps.RollingUpdateDeployment{
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromInt(0); return &i }(),
MaxSurge: func() *intstr.IntOrString { i := intstr.FromInt(0); return &i }(),
MaxUnavailable: func() *intstr.IntOrString { i := intstr.FromInt32(0); return &i }(),
MaxSurge: func() *intstr.IntOrString { i := intstr.FromInt32(0); return &i }(),
},
},
Replicas: pointer.Int32(int32(replicas)),
Expand Down
40 changes: 20 additions & 20 deletions pkg/controller/deployment/rolling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,38 @@ func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
{
// Should not scale up.
deploymentReplicas: 10,
maxSurge: intstr.FromInt(0),
maxSurge: intstr.FromInt32(0),
oldReplicas: 10,
newReplicas: 0,
scaleExpected: false,
},
{
deploymentReplicas: 10,
maxSurge: intstr.FromInt(2),
maxSurge: intstr.FromInt32(2),
oldReplicas: 10,
newReplicas: 0,
scaleExpected: true,
expectedNewReplicas: 2,
},
{
deploymentReplicas: 10,
maxSurge: intstr.FromInt(2),
maxSurge: intstr.FromInt32(2),
oldReplicas: 5,
newReplicas: 0,
scaleExpected: true,
expectedNewReplicas: 7,
},
{
deploymentReplicas: 10,
maxSurge: intstr.FromInt(2),
maxSurge: intstr.FromInt32(2),
oldReplicas: 10,
newReplicas: 2,
scaleExpected: false,
},
{
// Should scale down.
deploymentReplicas: 10,
maxSurge: intstr.FromInt(2),
maxSurge: intstr.FromInt32(2),
oldReplicas: 2,
newReplicas: 11,
scaleExpected: true,
Expand All @@ -85,7 +85,7 @@ func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
newRS := rs("foo-v2", test.newReplicas, nil, noTimestamp)
oldRS := rs("foo-v2", test.oldReplicas, nil, noTimestamp)
allRSs := []*apps.ReplicaSet{newRS, oldRS}
maxUnavailable := intstr.FromInt(0)
maxUnavailable := intstr.FromInt32(0)
deployment := newDeployment("foo", test.deploymentReplicas, nil, &test.maxSurge, &maxUnavailable, map[string]string{"foo": "bar"})
fake := fake.Clientset{}
controller := &DeploymentController{
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
}{
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(0),
maxUnavailable: intstr.FromInt32(0),
oldReplicas: 10,
newReplicas: 0,
readyPodsFromOldRS: 10,
Expand All @@ -144,7 +144,7 @@ func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
oldReplicas: 10,
newReplicas: 0,
readyPodsFromOldRS: 10,
Expand All @@ -154,7 +154,7 @@ func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
},
{ // expect unhealthy replicas from old replica sets been cleaned up
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
oldReplicas: 10,
newReplicas: 0,
readyPodsFromOldRS: 8,
Expand All @@ -164,7 +164,7 @@ func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
},
{ // expect 1 unhealthy replica from old replica sets been cleaned up, and 1 ready pod been scaled down
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
oldReplicas: 10,
newReplicas: 0,
readyPodsFromOldRS: 9,
Expand All @@ -174,7 +174,7 @@ func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
},
{ // the unavailable pods from the newRS would not make us scale down old RSs in a further step
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
oldReplicas: 8,
newReplicas: 2,
readyPodsFromOldRS: 8,
Expand All @@ -194,7 +194,7 @@ func TestDeploymentController_reconcileOldReplicaSets(t *testing.T) {
oldRS.Status.AvailableReplicas = int32(test.readyPodsFromOldRS)
oldRSs := []*apps.ReplicaSet{oldRS}
allRSs := []*apps.ReplicaSet{oldRS, newRS}
maxSurge := intstr.FromInt(0)
maxSurge := intstr.FromInt32(0)
deployment := newDeployment("foo", test.deploymentReplicas, nil, &maxSurge, &test.maxUnavailable, newSelector)
fakeClientset := fake.Clientset{}
controller := &DeploymentController{
Expand Down Expand Up @@ -261,8 +261,8 @@ func TestDeploymentController_cleanupUnhealthyReplicas(t *testing.T) {
oldRS := rs("foo-v2", test.oldReplicas, nil, noTimestamp)
oldRS.Status.AvailableReplicas = int32(test.readyPods)
oldRSs := []*apps.ReplicaSet{oldRS}
maxSurge := intstr.FromInt(2)
maxUnavailable := intstr.FromInt(2)
maxSurge := intstr.FromInt32(2)
maxUnavailable := intstr.FromInt32(2)
deployment := newDeployment("foo", 10, nil, &maxSurge, &maxUnavailable, nil)
fakeClientset := fake.Clientset{}

Expand Down Expand Up @@ -294,37 +294,37 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
}{
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(0),
maxUnavailable: intstr.FromInt32(0),
readyPods: 10,
oldReplicas: 10,
scaleExpected: true,
expectedOldReplicas: 9,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
readyPods: 10,
oldReplicas: 10,
scaleExpected: true,
expectedOldReplicas: 8,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
readyPods: 8,
oldReplicas: 10,
scaleExpected: false,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
readyPods: 10,
oldReplicas: 0,
scaleExpected: false,
},
{
deploymentReplicas: 10,
maxUnavailable: intstr.FromInt(2),
maxUnavailable: intstr.FromInt32(2),
readyPods: 1,
oldReplicas: 10,
scaleExpected: false,
Expand All @@ -338,7 +338,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
oldRS.Status.AvailableReplicas = int32(test.readyPods)
allRSs := []*apps.ReplicaSet{oldRS}
oldRSs := []*apps.ReplicaSet{oldRS}
maxSurge := intstr.FromInt(0)
maxSurge := intstr.FromInt32(0)
deployment := newDeployment("foo", test.deploymentReplicas, nil, &maxSurge, &test.maxUnavailable, map[string]string{"foo": "bar"})
fakeClientset := fake.Clientset{}
controller := &DeploymentController{
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/deployment/util/deployment_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,11 @@ func WaitForObservedDeployment(getDeploymentFunc func() (*apps.Deployment, error
// 2 desired, max unavailable 0%, surge 1% - should scale new(+1), then old(-1), then new(+1), then old(-1)
// 1 desired, max unavailable 0%, surge 1% - should scale new(+1), then old(-1)
func ResolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired int32) (int32, int32, error) {
surge, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxSurge, intstrutil.FromInt(0)), int(desired), true)
surge, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxSurge, intstrutil.FromInt32(0)), int(desired), true)
if err != nil {
return 0, 0, err
}
unavailable, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxUnavailable, intstrutil.FromInt(0)), int(desired), false)
unavailable, err := intstrutil.GetScaledValueFromIntOrPercent(intstrutil.ValueOrDefault(maxUnavailable, intstrutil.FromInt32(0)), int(desired), false)
if err != nil {
return 0, 0, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/deployment/util/deployment_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,22 +975,22 @@ func TestMaxUnavailable(t *testing.T) {
}{
{
name: "maxUnavailable less than replicas",
deployment: deployment(10, intstr.FromInt(5)),
deployment: deployment(10, intstr.FromInt32(5)),
expected: int32(5),
},
{
name: "maxUnavailable equal replicas",
deployment: deployment(10, intstr.FromInt(10)),
deployment: deployment(10, intstr.FromInt32(10)),
expected: int32(10),
},
{
name: "maxUnavailable greater than replicas",
deployment: deployment(5, intstr.FromInt(10)),
deployment: deployment(5, intstr.FromInt32(10)),
expected: int32(5),
},
{
name: "maxUnavailable with replicas is 0",
deployment: deployment(0, intstr.FromInt(10)),
deployment: deployment(0, intstr.FromInt32(10)),
expected: int32(0),
},
{
Expand Down Expand Up @@ -1277,22 +1277,22 @@ func TestMinAvailable(t *testing.T) {
}{
{
name: "replicas greater than maxUnavailable",
deployment: deployment(10, intstr.FromInt(5)),
deployment: deployment(10, intstr.FromInt32(5)),
expected: 5,
},
{
name: "replicas equal maxUnavailable",
deployment: deployment(10, intstr.FromInt(10)),
deployment: deployment(10, intstr.FromInt32(10)),
expected: 0,
},
{
name: "replicas less than maxUnavailable",
deployment: deployment(5, intstr.FromInt(10)),
deployment: deployment(5, intstr.FromInt32(10)),
expected: 0,
},
{
name: "replicas is 0",
deployment: deployment(0, intstr.FromInt(10)),
deployment: deployment(0, intstr.FromInt32(10)),
expected: 0,
},
{
Expand Down