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

make BeforeHookCreation resources progressing until recreated, fixes #10077 #10579

Closed
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
26 changes: 25 additions & 1 deletion controller/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package controller

import (
"github.com/argoproj/gitops-engine/pkg/health"
"github.com/argoproj/gitops-engine/pkg/sync/common"
hookutil "github.com/argoproj/gitops-engine/pkg/sync/hook"
"github.com/argoproj/gitops-engine/pkg/sync/ignore"
kubeutil "github.com/argoproj/gitops-engine/pkg/utils/kube"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/argoproj/argo-cd/v2/pkg/apis/application"
Expand All @@ -21,7 +23,12 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
continue
}

if res.Live != nil && (hookutil.IsHook(res.Live) || ignore.Ignore(res.Live)) {
if res.Live != nil && ignore.Ignore(res.Live) {
continue
}

requiresRecreation := isPendingRecreation(res.Live, app)
if res.Live != nil && hookutil.IsHook(res.Live) && !requiresRecreation {
continue
}

Expand All @@ -31,6 +38,8 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
gvk := schema.GroupVersionKind{Group: res.Group, Version: res.Version, Kind: res.Kind}
if res.Live == nil {
healthStatus = &health.HealthStatus{Status: health.HealthStatusMissing}
} else if requiresRecreation {
healthStatus = &health.HealthStatus{Status: health.HealthStatusProgressing}
} else {
// App the manages itself should not affect own health
if isSelfReferencedApp(app, kubeutil.GetObjectRef(res.Live)) {
Expand Down Expand Up @@ -71,3 +80,18 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
}
return &appHealth, savedErr
}

func isPendingRecreation(resource *unstructured.Unstructured, app *appv1.Application) bool {
if resource != nil && hookutil.IsHook(resource) {
for _, policy := range hookutil.DeletePolicies(resource) {
if policy != common.HookDeletePolicyBeforeHookCreation {
continue
}
if app.Status.OperationState == nil {
continue
}
app.Status.OperationState.StartedAt.After(resource.GetCreationTimestamp().Time)
}
}
return false
}