Skip to content

Commit

Permalink
Support for matching observedGeneration for status.Condition level (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaritanushree authored Apr 25, 2022
1 parent f4500f9 commit bfa3235
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
9 changes: 5 additions & 4 deletions pkg/kapp/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ type WaitRule struct {
}

type WaitRuleConditionMatcher struct {
Type string
Status string
Failure bool
Success bool
Type string
Status string
Failure bool
Success bool
SupportsObservedGeneration bool
}

type RebaseRule struct {
Expand Down
22 changes: 18 additions & 4 deletions pkg/kapp/resourcesmisc/custom_waiting_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ type customWaitingResourceStruct struct {
}

type customWaitingResourceCondition struct {
Type string
Status string
Reason string
Message string
Type string
Status string
Reason string
Message string
ObservedGeneration int64
}

func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {
Expand All @@ -54,10 +55,15 @@ func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {
"Waiting for generation %d to be observed", obj.Metadata.Generation)}
}

hasConditionWaitingForGeneration := false
// Check on failure conditions first
for _, condMatcher := range s.waitRule.ConditionMatchers {
for _, cond := range obj.Status.Conditions {
if cond.Type == condMatcher.Type && cond.Status == condMatcher.Status {
if condMatcher.SupportsObservedGeneration && obj.Metadata.Generation != cond.ObservedGeneration {
hasConditionWaitingForGeneration = true
continue
}
if condMatcher.Failure {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Encountered failure condition %s == %s: %s (message: %s)",
Expand All @@ -71,6 +77,10 @@ func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {
for _, condMatcher := range s.waitRule.ConditionMatchers {
for _, cond := range obj.Status.Conditions {
if cond.Type == condMatcher.Type && cond.Status == condMatcher.Status {
if condMatcher.SupportsObservedGeneration && obj.Metadata.Generation != cond.ObservedGeneration {
hasConditionWaitingForGeneration = true
continue
}
if condMatcher.Success {
return DoneApplyState{Done: true, Successful: true, Message: fmt.Sprintf(
"Encountered successful condition %s == %s: %s (message: %s)",
Expand All @@ -80,5 +90,9 @@ func (s CustomWaitingResource) IsDoneApplying() DoneApplyState {
}
}

if hasConditionWaitingForGeneration {
return DoneApplyState{Done: false, Message: fmt.Sprintf(
"Waiting for generation %d to be observed by status condition(s)", obj.Metadata.Generation)}
}
return DoneApplyState{Done: false, Message: "No failing or successful conditions found"}
}

0 comments on commit bfa3235

Please sign in to comment.