Files
zeekay 06ba4a5dd2 gitops-engine: drop Argo wording from prose and test fixtures
Reworded comments ("Argo CD"/"ArgoCD"/"Argo hook" -> "Hanzo CD"/"our
own hook") across cache, sync/hook, and utils/kube, plus one inert
sample pod name in a diff test fixture. Fixed agent/README.md's
kubectl-apply install URLs, which still pulled manifests from
raw.githubusercontent.com/argoproj/gitops-engine instead of this
repo. Left agent/manifests' argoproj/gitops-agent:latest image (no
ghcr.io/hanzoai equivalent has been built), the health-check testdata
fixtures (captured real cluster state, inert to the code under test),
the LICENSE's required upstream copyright notice, and every kept
github.com/argoproj/* issue citation untouched. pkg/diff/testdata/ was
not touched at all, per instruction.
2026-09-05 01:22:24 -07:00

59 lines
1.4 KiB
Go

package hook
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/hanzoai/cd/gitops-engine/pkg/sync/common"
helmhook "github.com/hanzoai/cd/gitops-engine/pkg/sync/hook/helm"
resourceutil "github.com/hanzoai/cd/gitops-engine/pkg/sync/resource"
)
const (
// HookFinalizer is the finalizer added to hooks to ensure they are deleted only after the sync phase is completed.
HookFinalizer = "cd.hanzo.ai/hook-finalizer"
)
func HasHookFinalizer(obj *unstructured.Unstructured) bool {
finalizers := obj.GetFinalizers()
for _, finalizer := range finalizers {
if finalizer == HookFinalizer {
return true
}
}
return false
}
func IsHook(obj *unstructured.Unstructured) bool {
_, ok := obj.GetAnnotations()[common.AnnotationKeyHook]
if ok {
return !Skip(obj)
}
return helmhook.IsHook(obj)
}
func Skip(obj *unstructured.Unstructured) bool {
for _, hookType := range Types(obj) {
if hookType == common.HookTypeSkip {
return len(Types(obj)) == 1
}
}
return false
}
func Types(obj *unstructured.Unstructured) []common.HookType {
var types []common.HookType
for _, text := range resourceutil.GetAnnotationCSVs(obj, common.AnnotationKeyHook) {
t, ok := common.NewHookType(text)
if ok {
types = append(types, t)
}
}
// we ignore Helm hooks if we have our own hook
if len(types) == 0 {
for _, t := range helmhook.Types(obj) {
types = append(types, t.HookType())
}
}
return types
}