Skip to content
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
10 changes: 10 additions & 0 deletions internal/controller/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/yaml"

argooperator "github.com/argoproj-labs/argocd-operator/api/v1beta1"
argoapi "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
Expand Down Expand Up @@ -192,6 +193,15 @@ return health_status`,
})
}

if customChecksYAML := patternsOperatorConfig.getStringValue("gitops.customHealthChecks"); customChecksYAML != "" {
var customChecks []argooperator.ResourceHealthCheck
if err := yaml.Unmarshal([]byte(customChecksYAML), &customChecks); err != nil {
log.Printf("Failed to parse gitops.customHealthChecks: %v", err)
} else {
resourceHealthChecks = append(resourceHealthChecks, customChecks...)
}
}

trueBool := true
initVolumes := []v1.Volume{
{
Expand Down
50 changes: 50 additions & 0 deletions internal/controller/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,56 @@ var _ = Describe("newArgoCD", func() {
Expect(argo.Spec.ResourceHealthChecks[1].Kind).To(Equal("Application"))
})

It("should append custom health checks from gitops.customHealthChecks", func() {
customYAML := `- group: apps
kind: Deployment
check: |
hs = {}
hs.status = "Healthy"
return hs
- group: batch
kind: Job
check: |
hs = {}
hs.status = "Progressing"
return hs`
argo = newArgoCD("test-argo", "test-ns", PatternsOperatorConfig{"gitops.customHealthChecks": customYAML})
Expect(argo.Spec.ResourceHealthChecks).To(HaveLen(3))
Expect(argo.Spec.ResourceHealthChecks[0].Group).To(Equal("operators.coreos.com"))
Expect(argo.Spec.ResourceHealthChecks[1].Group).To(Equal("apps"))
Expect(argo.Spec.ResourceHealthChecks[1].Kind).To(Equal("Deployment"))
Expect(argo.Spec.ResourceHealthChecks[2].Group).To(Equal("batch"))
Expect(argo.Spec.ResourceHealthChecks[2].Kind).To(Equal("Job"))
})

It("should append custom health checks alongside Application health check when both are enabled", func() {
customYAML := `- group: apps
kind: Deployment
check: |
hs = {}
hs.status = "Healthy"
return hs`
argo = newArgoCD("test-argo", "test-ns", PatternsOperatorConfig{
"gitops.applicationHealthCheckEnabled": "true",
"gitops.customHealthChecks": customYAML,
})
Expect(argo.Spec.ResourceHealthChecks).To(HaveLen(3))
Expect(argo.Spec.ResourceHealthChecks[0].Group).To(Equal("operators.coreos.com"))
Expect(argo.Spec.ResourceHealthChecks[1].Group).To(Equal("argoproj.io"))
Expect(argo.Spec.ResourceHealthChecks[2].Group).To(Equal("apps"))
})

It("should handle invalid YAML in gitops.customHealthChecks gracefully", func() {
argo = newArgoCD("test-argo", "test-ns", PatternsOperatorConfig{"gitops.customHealthChecks": "not: valid: yaml: list"})
Expect(argo.Spec.ResourceHealthChecks).To(HaveLen(1))
Expect(argo.Spec.ResourceHealthChecks[0].Group).To(Equal("operators.coreos.com"))
})

It("should not add custom health checks when gitops.customHealthChecks is empty", func() {
argo = newArgoCD("test-argo", "test-ns", PatternsOperatorConfig{"gitops.customHealthChecks": ""})
Expect(argo.Spec.ResourceHealthChecks).To(HaveLen(1))
})

})

var _ = Describe("commonSyncPolicy", func() {
Expand Down
1 change: 1 addition & 0 deletions internal/controller/patterns_operator_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var DefaultPatternsOperatorConfig = PatternsOperatorConfig{
"gitops.csv": GitOpsDefaultCSV,
"gitops.additionalArgoAdmins": "",
"gitops.applicationHealthCheckEnabled": "false",
"gitops.customHealthChecks": "",
"gitea.chartName": GiteaChartName,
"gitea.helmRepoUrl": GiteaHelmRepoUrl,
"gitea.chartVersion": GiteaDefaultChartVersion,
Expand Down