@@ -44,9 +44,43 @@ import (
4444
4545// Which ArgoCD objects we're creating
4646const (
47- ArgoCDGroup = "argoproj.io"
48- ArgoCDVersion = "v1beta1"
49- ArgoCDResource = "argocds"
47+ ArgoCDGroup = "argoproj.io"
48+ ArgoCDVersion = "v1beta1"
49+ ArgoCDResource = "argocds"
50+ ArgoCDKind = "ArgoCD"
51+ ArgoCDAPIVersion = ArgoCDGroup + "/" + ArgoCDVersion
52+
53+ ApplicationKind = "Application"
54+
55+ DefaultProject = "default"
56+ InClusterDestination = "in-cluster"
57+ PatternRef = "patternref"
58+ SyncOptionForce = "Force=true"
59+ )
60+
61+ // Unstructured map keys
62+ const (
63+ FieldAPIVersion = "apiVersion"
64+ FieldKind = "kind"
65+ FieldMetadata = "metadata"
66+ FieldName = "name"
67+ )
68+
69+ // Volume/ConfigMap names for CA bundle handling
70+ const (
71+ KubeRootCACM = "kube-root-ca.crt"
72+ CaBundlesVol = "ca-bundles"
73+ )
74+
75+ // Helm parameter names
76+ const (
77+ ParamMultiSourceSupport = "global.multiSourceSupport"
78+ ParamMultiSourceRepoUrl = "global.multiSourceRepoUrl"
79+ ParamExperimentalCapabilities = "global.experimentalCapabilities"
80+ ParamGitOpsSubNamespace = "global.gitOpsSubNamespace"
81+ ParamVpArgoNamespace = "global.vpArgoNamespace"
82+ ParamMultiSourceTargetRevision = "global.multiSourceTargetRevision"
83+ ParamDeletePattern = "global.deletePattern"
5084)
5185
5286// ConsoleLink constants
@@ -62,7 +96,7 @@ func newArgoCD(name, namespace string, patternsOperatorConfig PatternsOperatorCo
6296 "g, cluster-admins, role:admin" ,
6397 "g, admin, role:admin" ,
6498 }
65- for argoAdmin := range strings .SplitSeq (patternsOperatorConfig .getStringValue ("gitops.additionalArgoAdmins" ), "," ) {
99+ for argoAdmin := range strings .SplitSeq (patternsOperatorConfig .getStringValue (configKeyAdditionalAdmins ), "," ) {
66100 argoAdmin = strings .TrimSpace (argoAdmin )
67101 if argoAdmin != "" {
68102 argoPolicies = append (argoPolicies , "g, " + argoAdmin + ", role:admin" )
@@ -160,12 +194,12 @@ health_status.message = "An install plan for a subscription is pending installat
160194return health_status` ,
161195 },
162196 }
163- if patternsOperatorConfig .getBoolValue ("gitops.applicationHealthCheckEnabled" ) {
197+ if patternsOperatorConfig .getBoolValue (configKeyHealthCheck ) {
164198 // As of ArgoCD 1.8 the Application health check was dropped (see https://github.com/argoproj/argo-cd/issues/3781),
165199 // but in app-of-apps pattern this is needed in order to implement children apps dependencies via sync-waves
166200 resourceHealthChecks = append (resourceHealthChecks , argooperator.ResourceHealthCheck {
167- Group : "argoproj.io" ,
168- Kind : "Application" ,
201+ Group : ArgoCDGroup ,
202+ Kind : ApplicationKind ,
169203 Check : `local health_status = {}
170204health_status.status = "Progressing"
171205health_status.message = ""
@@ -199,32 +233,32 @@ return health_status`,
199233 VolumeSource : v1.VolumeSource {
200234 ConfigMap : & v1.ConfigMapVolumeSource {
201235 LocalObjectReference : v1.LocalObjectReference {
202- Name : "kube-root-ca.crt" ,
236+ Name : KubeRootCACM ,
203237 },
204238 },
205239 },
206240 },
207241 {
208- Name : "trusted-ca-bundle" ,
242+ Name : trustedBundleCM ,
209243 VolumeSource : v1.VolumeSource {
210244 ConfigMap : & v1.ConfigMapVolumeSource {
211245 LocalObjectReference : v1.LocalObjectReference {
212- Name : "trusted-ca-bundle" ,
246+ Name : trustedBundleCM ,
213247 },
214248 Optional : & trueBool ,
215249 },
216250 },
217251 },
218252 {
219- Name : "ca-bundles" ,
253+ Name : CaBundlesVol ,
220254 VolumeSource : v1.VolumeSource {
221255 EmptyDir : & v1.EmptyDirVolumeSource {},
222256 },
223257 },
224258 }
225259 initVolumeMounts := []v1.VolumeMount {
226260 {
227- Name : "ca-bundles" ,
261+ Name : CaBundlesVol ,
228262 MountPath : "/etc/pki/tls/certs" ,
229263 },
230264 }
@@ -239,11 +273,11 @@ return health_status`,
239273 MountPath : "/var/run/kube-root-ca" , // ca.crt field
240274 },
241275 {
242- Name : "trusted-ca-bundle" ,
276+ Name : trustedBundleCM ,
243277 MountPath : "/var/run/trusted-ca" , // ca-bundle.crt field
244278 },
245279 {
246- Name : "ca-bundles" ,
280+ Name : CaBundlesVol ,
247281 MountPath : "/tmp/ca-bundles" ,
248282 },
249283 },
@@ -257,8 +291,8 @@ return health_status`,
257291
258292 s := argooperator.ArgoCD {
259293 TypeMeta : metav1.TypeMeta {
260- Kind : "ArgoCD" ,
261- APIVersion : "argoproj.io/v1beta1" ,
294+ Kind : ArgoCDKind ,
295+ APIVersion : ArgoCDAPIVersion ,
262296 },
263297 ObjectMeta : metav1.ObjectMeta {
264298 Name : name ,
@@ -512,10 +546,10 @@ func createOrUpdateConsoleLink(client dynamic.Interface, argoName, argoNamespace
512546
513547 consoleLinkObj := & unstructured.Unstructured {
514548 Object : map [string ]any {
515- "apiVersion" : ConsoleLinkGroup + "/" + ConsoleLinkVersion ,
516- "kind" : "ConsoleLink" ,
517- "metadata" : map [string ]any {
518- "name" : linkName ,
549+ FieldAPIVersion : ConsoleLinkGroup + "/" + ConsoleLinkVersion ,
550+ FieldKind : "ConsoleLink" ,
551+ FieldMetadata : map [string ]any {
552+ FieldName : linkName ,
519553 },
520554 "spec" : map [string ]any {
521555 "applicationMenu" : map [string ]any {
@@ -617,28 +651,28 @@ func newApplicationParameters(p *api.Pattern) []argoapi.HelmParameter {
617651 Value : strconv .FormatBool (p .Spec .GitConfig .TokenSecret != "" ),
618652 },
619653 {
620- Name : "global.multiSourceSupport" ,
654+ Name : ParamMultiSourceSupport ,
621655 Value : strconv .FormatBool (* p .Spec .MultiSourceConfig .Enabled ),
622656 },
623657 {
624- Name : "global.multiSourceRepoUrl" ,
658+ Name : ParamMultiSourceRepoUrl ,
625659 Value : p .Spec .MultiSourceConfig .HelmRepoUrl ,
626660 },
627661
628662 {
629- Name : "global.experimentalCapabilities" ,
663+ Name : ParamExperimentalCapabilities ,
630664 Value : p .Spec .ExperimentalCapabilities ,
631665 },
632666 }
633667 _ , gitOpsSubNamespace := DetectGitOpsSubscription ()
634668 parameters = append (parameters , argoapi.HelmParameter {
635- Name : "global.gitOpsSubNamespace" ,
669+ Name : ParamGitOpsSubNamespace ,
636670 Value : gitOpsSubNamespace ,
637671 }, argoapi.HelmParameter {
638- Name : "global.vpArgoNamespace" ,
672+ Name : ParamVpArgoNamespace ,
639673 Value : getClusterWideArgoNamespace (),
640674 }, argoapi.HelmParameter {
641- Name : "global.multiSourceTargetRevision" ,
675+ Name : ParamMultiSourceTargetRevision ,
642676 Value : getClusterGroupChartVersion (p ),
643677 })
644678 for _ , extra := range p .Spec .ExtraParameters {
@@ -665,7 +699,7 @@ func newApplicationParameters(p *api.Pattern) []argoapi.HelmParameter {
665699 deletePatternValue = "DeleteChildApps"
666700 }
667701 parameters = append (parameters , argoapi.HelmParameter {
668- Name : "global.deletePattern" ,
702+ Name : ParamDeletePattern ,
669703 Value : string (deletePatternValue ),
670704 ForceString : true ,
671705 })
@@ -810,12 +844,12 @@ func commonSyncPolicy(p *api.Pattern) *argoapi.SyncPolicy {
810844func commonApplicationSpec (p * api.Pattern , sources []argoapi.ApplicationSource ) * argoapi.ApplicationSpec {
811845 spec := & argoapi.ApplicationSpec {
812846 Destination : argoapi.ApplicationDestination {
813- Name : "in-cluster" ,
847+ Name : InClusterDestination ,
814848 Namespace : p .Namespace ,
815849 },
816850 // Project is a reference to the project this application belongs to.
817851 // The empty string means that application belongs to the 'default' project.
818- Project : "default" ,
852+ Project : DefaultProject ,
819853
820854 // IgnoreDifferences is a list of resources and their fields which should be ignored during comparison
821855 // IgnoreDifferences []ResourceIgnoreDifferences `json:"ignoreDifferences,omitempty" protobuf:"bytes,5,name=ignoreDifferences"`
@@ -912,7 +946,7 @@ func newMultiSourceApplication(p *api.Pattern) *argoapi.Application {
912946 valuesSource := & argoapi.ApplicationSource {
913947 RepoURL : p .Spec .GitConfig .TargetRepo ,
914948 TargetRevision : p .Spec .GitConfig .TargetRevision ,
915- Ref : "patternref" ,
949+ Ref : PatternRef ,
916950 }
917951 sources = append (sources , * valuesSource )
918952
@@ -987,10 +1021,10 @@ func newArgoGiteaApplication(p *api.Pattern, patternsOperatorConfig PatternsOper
9871021 }
9881022 spec := & argoapi.ApplicationSpec {
9891023 Destination : argoapi.ApplicationDestination {
990- Name : "in-cluster" ,
1024+ Name : InClusterDestination ,
9911025 Namespace : GiteaNamespace ,
9921026 },
993- Project : "default" ,
1027+ Project : DefaultProject ,
9941028 Source : & argoapi.ApplicationSource {
9951029 RepoURL : patternsOperatorConfig .getStringValue ("gitea.helmRepoUrl" ),
9961030 TargetRevision : patternsOperatorConfig .getStringValue ("gitea.chartVersion" ),
@@ -1299,14 +1333,14 @@ func updateHelmParameter(goal api.PatternParameter, actual []argoapi.HelmParamet
12991333// syncApplication syncs the application with prune and force options if such a sync is not already in progress.
13001334// Returns nil if a sync is already in progress, error otherwise
13011335func syncApplication (client argoclient.Interface , app * argoapi.Application , withPrune bool ) error {
1302- if app .Operation != nil && app .Operation .Sync != nil && app .Operation .Sync .Prune == withPrune && slices .Contains (app .Operation .Sync .SyncOptions , "Force=true" ) {
1336+ if app .Operation != nil && app .Operation .Sync != nil && app .Operation .Sync .Prune == withPrune && slices .Contains (app .Operation .Sync .SyncOptions , SyncOptionForce ) {
13031337 return nil
13041338 }
13051339
13061340 app .Operation = & argoapi.Operation {
13071341 Sync : & argoapi.SyncOperation {
13081342 Prune : withPrune ,
1309- SyncOptions : []string {"Force=true" },
1343+ SyncOptions : []string {SyncOptionForce },
13101344 },
13111345 }
13121346
0 commit comments