Skip to content

Commit

Permalink
added 'appsv1.DeploymentReplicaFailure' condition (#878)
Browse files Browse the repository at this point in the history
* modified ReplicaFailure logic

Signed-off-by: jignyasamishra <[email protected]>

* made changes in the unit tests

Signed-off-by: jignyasamishra <[email protected]>

* made changes in the unit tests

Signed-off-by: jignyasamishra <[email protected]>

---------

Signed-off-by: jignyasamishra <[email protected]>
  • Loading branch information
jignyasamishra authored Jan 13, 2024
1 parent f2c0e1a commit 2f0080a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/kapp/resourcesmisc/apps_v1_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (s AppsV1Deployment) IsDoneApplying() DoneApplyState {
"Deployment is not progressing: %s (message: %s)", cond.Reason, cond.Message)}
}

case "FailedDelete":
case appsv1.DeploymentReplicaFailure:
if cond.Status == corev1.ConditionTrue {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Deployment failed to delete pods: %s (message: %s)", cond.Reason, cond.Message)}
return DoneApplyState{Done: false, Successful: false, Message: fmt.Sprintf(
"Deployment has encountered replica failure: %s (message: %s)", cond.Reason, cond.Message)}
}
}
}
Expand Down
54 changes: 54 additions & 0 deletions pkg/kapp/resourcesmisc/apps_v1_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,60 @@ status:
require.Equal(t, expectedState, state, "Found incorrect state")
}

func TestAppsV1DeploymentReplicaFailure(t *testing.T) {

depYAML := `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
generation: 1
status:
observedGeneration: 1
conditions:
- type: Progressing
status: "False"
reason: "ProgressDeadlineExceeded"
message: "Progress deadline exceeded"
`

deployment := buildDep(depYAML, t)
state := deployment.IsDoneApplying()

expectedState := ctlresm.DoneApplyState{
Done: true,
Successful: false,
Message: "Deployment is not progressing: ProgressDeadlineExceeded (message: Progress deadline exceeded)",
}

require.Equal(t, expectedState, state, "Found incorrect state")

depYAML = `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
generation: 1
status:
observedGeneration: 1
conditions:
- type: ReplicaFailure
status: "True"
reason: "FailedCreate"
message: "Failed to create pods"
`
deployment = buildDep(depYAML, t)
state = deployment.IsDoneApplying()

expectedState = ctlresm.DoneApplyState{
Done: false,
Successful: false,
Message: "Deployment has encountered replica failure: FailedCreate (message: Failed to create pods)",
}

require.Equal(t, expectedState, state, "Found incorrect state")
}

func buildDep(resourcesBs string, t *testing.T) *ctlresm.AppsV1Deployment {
newResources, err := ctlres.NewFileResource(ctlres.NewBytesSource([]byte(resourcesBs))).Resources()
require.NoErrorf(t, err, "Expected resources to parse")
Expand Down

0 comments on commit 2f0080a

Please sign in to comment.