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

Refactor pausing #211

Merged
merged 16 commits into from
Oct 22, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,8 @@ spec:
- type
type: object
type: array
controllerPause:
type: boolean
currentPodHash:
type: string
currentStepHash:
Expand All @@ -2689,6 +2691,19 @@ spec:
type: integer
observedGeneration:
type: string
pauseConditions:
items:
properties:
reason:
type: string
startTime:
format: date-time
type: string
required:
- reason
- startTime
type: object
type: array
pauseStartTime:
format: date-time
type: string
Expand Down
15 changes: 15 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10354,6 +10354,8 @@ spec:
- type
type: object
type: array
controllerPause:
type: boolean
currentPodHash:
type: string
currentStepHash:
Expand All @@ -10363,6 +10365,19 @@ spec:
type: integer
observedGeneration:
type: string
pauseConditions:
items:
properties:
reason:
type: string
startTime:
format: date-time
type: string
required:
- reason
- startTime
type: object
type: array
pauseStartTime:
format: date-time
type: string
Expand Down
15 changes: 15 additions & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10354,6 +10354,8 @@ spec:
- type
type: object
type: array
controllerPause:
type: boolean
currentPodHash:
type: string
currentStepHash:
Expand All @@ -10363,6 +10365,19 @@ spec:
type: integer
observedGeneration:
type: string
pauseConditions:
items:
properties:
reason:
type: string
startTime:
format: date-time
type: string
required:
- reason
- startTime
type: object
type: array
pauseStartTime:
format: date-time
type: string
Expand Down
49 changes: 48 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.

22 changes: 22 additions & 0 deletions pkg/apis/rollouts/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,30 @@ type RolloutPause struct {
Duration *int32 `json:"duration,omitempty"`
}

// PauseReason reasons that the rollout can pause
type PauseReason string

const (
// PauseReasonInconclusiveAnalysis pauses rollout when rollout has an inconclusive analysis run
PauseReasonInconclusiveAnalysis PauseReason = "InconclusiveAnalysisRun"
// PauseReasonCanaryPauseStep pause rollout for canary pause step
PauseReasonCanaryPauseStep PauseReason = "CanaryPauseStep"
// PauseReasonBlueGreenPause pause rollout before promoting rollout
PauseReasonBlueGreenPause PauseReason = "BlueGreenPause"
)

// PauseCondition the reason for a pause and when it started
type PauseCondition struct {
Reason PauseReason `json:"reason"`
StartTime metav1.Time `json:"startTime"`
}

// RolloutStatus is the status for a Rollout resource
type RolloutStatus struct {
// PauseConditions indicates why the rollout is currently paused
PauseConditions []PauseCondition `json:"pauseConditions,omitempty"`
//ControllerPause indicates the controller has paused the rollout
ControllerPause bool `json:"controllerPause,omitempty"`
// CurrentPodHash the hash of the current pod template
// +optional
CurrentPodHash string `json:"currentPodHash,omitempty"`
Expand Down
24 changes: 24 additions & 0 deletions 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.

10 changes: 9 additions & 1 deletion pkg/kubectl-argo-rollouts/cmd/resume/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const (
# Resume a rollout
%[1]s resume guestbook
`
unpausePatch = `{
"spec": {
"paused": false
},
"status: {
"pauseConditions": null
}
}`
)

// NewCmdResume returns a new instance of an `rollouts resume` command
Expand All @@ -29,7 +37,7 @@ func NewCmdResume(o *options.ArgoRolloutsOptions) *cobra.Command {
}
rolloutIf := o.RolloutsClientset().ArgoprojV1alpha1().Rollouts(o.Namespace())
for _, name := range args {
ro, err := rolloutIf.Patch(name, types.MergePatchType, []byte(`{"spec":{"paused":false}}`))
ro, err := rolloutIf.Patch(name, types.MergePatchType, []byte(unpausePatch))
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/kubectl-argo-rollouts/cmd/resume/resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func TestResumeCmdSuccess(t *testing.T) {
Spec: v1alpha1.RolloutSpec{
Paused: true,
},
Status: v1alpha1.RolloutStatus{
PauseConditions: []v1alpha1.PauseCondition{{
Reason: v1alpha1.PauseReasonCanaryPauseStep,
}},
ControllerPause: true,
},
}

tf, o := options.NewFakeArgoRolloutsOptions(&ro)
Expand All @@ -46,7 +52,8 @@ func TestResumeCmdSuccess(t *testing.T) {
fakeClient.ReactionChain = nil
fakeClient.AddReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
if patchAction, ok := action.(kubetesting.PatchAction); ok {
if string(patchAction.GetPatch()) == `{"spec":{"paused":false}}` {
if string(patchAction.GetPatch()) == unpausePatch {
ro.Status.PauseConditions = nil
ro.Spec.Paused = false
}
}
Expand All @@ -59,7 +66,9 @@ func TestResumeCmdSuccess(t *testing.T) {
err := cmd.Execute()
assert.Nil(t, err)

assert.Nil(t, ro.Status.PauseConditions)
assert.False(t, ro.Spec.Paused)
assert.True(t, ro.Status.ControllerPause)
stdout := o.Out.(*bytes.Buffer).String()
stderr := o.ErrOut.(*bytes.Buffer).String()
assert.Equal(t, stdout, "rollout 'guestbook' resumed\n")
Expand Down
6 changes: 5 additions & 1 deletion rollout/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *RolloutController) getAnalysisRunsForRollout(rollout *v1alpha1.Rollout)
func (c *RolloutController) reconcileAnalysisRuns(roCtx *canaryContext) error {
rollout := roCtx.Rollout()
otherArs := roCtx.OtherAnalysisRuns()
if rollout.Spec.Paused {
if len(rollout.Status.PauseConditions) > 0 {
return nil
}
newCurrentAnalysisRuns := []*v1alpha1.AnalysisRun{}
Expand Down Expand Up @@ -147,6 +147,10 @@ func (c *RolloutController) reconcileStepBasedAnalysisRun(roCtx *canaryContext)
return currentAr, err
}

if currentAr.Status != nil && currentAr.Status.Status == v1alpha1.AnalysisStatusInconclusive {
roCtx.PauseContext().AddPauseCondition(v1alpha1.PauseReasonInconclusiveAnalysis)
}

return currentAr, nil
}

Expand Down
11 changes: 6 additions & 5 deletions rollout/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,20 +542,21 @@ func TestPausedStepAfterInconclusiveAnalysisRun(t *testing.T) {
patch := f.getPatchedRollout(patchIndex)
now := metav1.Now().UTC().Format(time.RFC3339)
expectedPatch := `{
"spec":{
"paused": true
},
"status": {
"conditions": %s,
"canary": {
"currentStepAnalysisRun": null
},
"pauseStartTime": "%s"
"pauseConditions": [{
"reason": "%s",
"startTime": "%s"
}],
"controllerPause": true
}
}`
condition := generateConditionsPatch(true, conditions.ReplicaSetUpdatedReason, r2, false)

assert.Equal(t, calculatePatch(r2, fmt.Sprintf(expectedPatch, condition, now)), patch)
assert.Equal(t, calculatePatch(r2, fmt.Sprintf(expectedPatch, condition, v1alpha1.PauseReasonInconclusiveAnalysis, now)), patch)
}

func TestErrorConditionAfterErrorAnalysisRun(t *testing.T) {
Expand Down
Loading