apps: replace intstr.FromInt with intstr.FromInt32
This touches cases where FromInt() is used on numeric constants, or values which are already int32s, or int variables which are defined close by and can be changed to int32s with little impact. Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
committed by
Stephen Kitt
parent
f871d5fabe
commit
5bfe738af2
@@ -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)),
|
||||
|
||||
@@ -40,14 +40,14 @@ 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,
|
||||
@@ -55,7 +55,7 @@ func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
|
||||
},
|
||||
{
|
||||
deploymentReplicas: 10,
|
||||
maxSurge: intstr.FromInt(2),
|
||||
maxSurge: intstr.FromInt32(2),
|
||||
oldReplicas: 5,
|
||||
newReplicas: 0,
|
||||
scaleExpected: true,
|
||||
@@ -63,7 +63,7 @@ func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
|
||||
},
|
||||
{
|
||||
deploymentReplicas: 10,
|
||||
maxSurge: intstr.FromInt(2),
|
||||
maxSurge: intstr.FromInt32(2),
|
||||
oldReplicas: 10,
|
||||
newReplicas: 2,
|
||||
scaleExpected: false,
|
||||
@@ -71,7 +71,7 @@ func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
|
||||
{
|
||||
// Should scale down.
|
||||
deploymentReplicas: 10,
|
||||
maxSurge: intstr.FromInt(2),
|
||||
maxSurge: intstr.FromInt32(2),
|
||||
oldReplicas: 2,
|
||||
newReplicas: 11,
|
||||
scaleExpected: true,
|
||||
@@ -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{
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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{
|
||||
@@ -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{}
|
||||
|
||||
@@ -294,7 +294,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
|
||||
}{
|
||||
{
|
||||
deploymentReplicas: 10,
|
||||
maxUnavailable: intstr.FromInt(0),
|
||||
maxUnavailable: intstr.FromInt32(0),
|
||||
readyPods: 10,
|
||||
oldReplicas: 10,
|
||||
scaleExpected: true,
|
||||
@@ -302,7 +302,7 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
|
||||
},
|
||||
{
|
||||
deploymentReplicas: 10,
|
||||
maxUnavailable: intstr.FromInt(2),
|
||||
maxUnavailable: intstr.FromInt32(2),
|
||||
readyPods: 10,
|
||||
oldReplicas: 10,
|
||||
scaleExpected: true,
|
||||
@@ -310,21 +310,21 @@ func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing
|
||||
},
|
||||
{
|
||||
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,
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
},
|
||||
{
|
||||
@@ -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,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user