Skip to content

Commit

Permalink
Clean up max surge and unavailable
Browse files Browse the repository at this point in the history
- add missing omitempty flags
- change defaults to deployment defaults
- fix flaky test
  • Loading branch information
dthomson25 committed Feb 20, 2019
1 parent 177247e commit c8d7de4
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
4 changes: 0 additions & 4 deletions controller/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,6 @@ func TestSyncRolloutWaitIncrementStepIndex(t *testing.T) {
f.expectPatchRolloutAction(r2)
f.run(getKey(r2, t))

key := fmt.Sprintf("%s/%s", r2.Namespace, r2.Name)
//When the controller starts, it will enqueue the rollout so we expect the rollout to enqueue at least once.
assert.Equal(t, 1, f.enqueuedObjects[key])

patchBytes := filterInformerActions(f.client.Actions())[0].(core.PatchAction).GetPatch()
assert.Equal(t, expectedPatch, string(patchBytes))
}
8 changes: 5 additions & 3 deletions examples/example-rollout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Rollout
metadata:
name: example-rollout
spec:
replicas: 1
replicas: 5
selector:
matchLabels:
app: guestbook
Expand All @@ -24,5 +24,7 @@ spec:
type: CanaryUpdate
canary:
steps:
- pause: true
- pause: true
- setWeight: 20
- wait: 20
- setWeight: 40
- pause: {}
1 change: 1 addition & 0 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ spec:
description: StableRS indicates the last replicaset that walked
through all the canary steps or was the only replicaset
type: string
waitStartTime: {}
collisionCount:
description: Count of hash collisions for the Rollout. The Rollout controller
uses this field as a collision avoidance mechanism when it needs to
Expand Down
1 change: 1 addition & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ spec:
description: StableRS indicates the last replicaset that walked
through all the canary steps or was the only replicaset
type: string
waitStartTime: {}
collisionCount:
description: Count of hash collisions for the Rollout. The Rollout controller
uses this field as a collision avoidance mechanism when it needs to
Expand Down
1 change: 1 addition & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ spec:
description: StableRS indicates the last replicaset that walked
through all the canary steps or was the only replicaset
type: string
waitStartTime: {}
collisionCount:
description: Count of hash collisions for the Rollout. The Rollout controller
uses this field as a collision avoidance mechanism when it needs to
Expand Down
9 changes: 8 additions & 1 deletion pkg/apis/rollouts/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/rollouts/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type CanaryStrategy struct {
// that at least 70% of original number of pods are available at all times
// during the update.
// +optional
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable"`
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`

// MaxSurge The maximum number of pods that can be scheduled above the original number of
// pods.
Expand All @@ -111,7 +111,7 @@ type CanaryStrategy struct {
// new RC can be scaled up further, ensuring that total number of pods running
// at any time during the update is atmost 130% of original pods.
// +optional
MaxSurge *intstr.IntOrString `json:"maxSurge"`
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
}

// CanaryStep defines a step of a canary deployment.
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions utils/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const (
// DefaultRevisionHistoryLimit default number of revisions to keep if .Spec.RevisionHistoryLimit is nil
DefaultRevisionHistoryLimit = int32(10)
// DefaultMaxSurge default number for the max number of additional pods that can be brought up during a rollout
DefaultMaxSurge = 1
DefaultMaxSurge = "25"
// DefaultMaxUnavailable default number for the max number of unavailable pods during a rollout
DefaultMaxUnavailable = 1
DefaultMaxUnavailable = 0
)

// GetRolloutReplicasOrDefault returns the specified number of replicas in a rollout or the default number
Expand All @@ -37,7 +37,7 @@ func GetMaxSurgeOrDefault(rollout *v1alpha1.Rollout) *intstr.IntOrString {
if rollout.Spec.Strategy.CanaryStrategy != nil && rollout.Spec.Strategy.CanaryStrategy.MaxSurge != nil {
return rollout.Spec.Strategy.CanaryStrategy.MaxSurge
}
defaultValue := intstr.FromInt(DefaultMaxSurge)
defaultValue := intstr.FromString(DefaultMaxSurge)
return &defaultValue
}

Expand Down
2 changes: 1 addition & 1 deletion utils/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestGetMaxSurgeOrDefault(t *testing.T) {

assert.Equal(t, maxSurge, *GetMaxSurgeOrDefault(rolloutNonDefaultValue))
rolloutDefaultValue := &v1alpha1.Rollout{}
assert.Equal(t, intstr.FromInt(DefaultMaxSurge), *GetMaxSurgeOrDefault(rolloutDefaultValue))
assert.Equal(t, intstr.FromString(DefaultMaxSurge), *GetMaxSurgeOrDefault(rolloutDefaultValue))
}

func TestGetMaxUnavailableOrDefault(t *testing.T) {
Expand Down

0 comments on commit c8d7de4

Please sign in to comment.