@@ -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 ,
@@ -509,10 +543,10 @@ func createOrUpdateConsoleLink(client dynamic.Interface, argoName, argoNamespace
509543
510544 consoleLinkObj := & unstructured.Unstructured {
511545 Object : map [string ]any {
512- "apiVersion" : ConsoleLinkGroup + "/" + ConsoleLinkVersion ,
513- "kind" : "ConsoleLink" ,
514- "metadata" : map [string ]any {
515- "name" : linkName ,
546+ FieldAPIVersion : ConsoleLinkGroup + "/" + ConsoleLinkVersion ,
547+ FieldKind : "ConsoleLink" ,
548+ FieldMetadata : map [string ]any {
549+ FieldName : linkName ,
516550 },
517551 "spec" : map [string ]any {
518552 "applicationMenu" : map [string ]any {
@@ -614,28 +648,28 @@ func newApplicationParameters(p *api.Pattern) []argoapi.HelmParameter {
614648 Value : strconv .FormatBool (p .Spec .GitConfig .TokenSecret != "" ),
615649 },
616650 {
617- Name : "global.multiSourceSupport" ,
651+ Name : ParamMultiSourceSupport ,
618652 Value : strconv .FormatBool (* p .Spec .MultiSourceConfig .Enabled ),
619653 },
620654 {
621- Name : "global.multiSourceRepoUrl" ,
655+ Name : ParamMultiSourceRepoUrl ,
622656 Value : p .Spec .MultiSourceConfig .HelmRepoUrl ,
623657 },
624658
625659 {
626- Name : "global.experimentalCapabilities" ,
660+ Name : ParamExperimentalCapabilities ,
627661 Value : p .Spec .ExperimentalCapabilities ,
628662 },
629663 }
630664 _ , gitOpsSubNamespace := DetectGitOpsSubscription ()
631665 parameters = append (parameters , argoapi.HelmParameter {
632- Name : "global.gitOpsSubNamespace" ,
666+ Name : ParamGitOpsSubNamespace ,
633667 Value : gitOpsSubNamespace ,
634668 }, argoapi.HelmParameter {
635- Name : "global.vpArgoNamespace" ,
669+ Name : ParamVpArgoNamespace ,
636670 Value : getClusterWideArgoNamespace (),
637671 }, argoapi.HelmParameter {
638- Name : "global.multiSourceTargetRevision" ,
672+ Name : ParamMultiSourceTargetRevision ,
639673 Value : getClusterGroupChartVersion (p ),
640674 })
641675 for _ , extra := range p .Spec .ExtraParameters {
@@ -662,7 +696,7 @@ func newApplicationParameters(p *api.Pattern) []argoapi.HelmParameter {
662696 deletePatternValue = "DeleteChildApps"
663697 }
664698 parameters = append (parameters , argoapi.HelmParameter {
665- Name : "global.deletePattern" ,
699+ Name : ParamDeletePattern ,
666700 Value : string (deletePatternValue ),
667701 ForceString : true ,
668702 })
@@ -807,12 +841,12 @@ func commonSyncPolicy(p *api.Pattern) *argoapi.SyncPolicy {
807841func commonApplicationSpec (p * api.Pattern , sources []argoapi.ApplicationSource ) * argoapi.ApplicationSpec {
808842 spec := & argoapi.ApplicationSpec {
809843 Destination : argoapi.ApplicationDestination {
810- Name : "in-cluster" ,
844+ Name : InClusterDestination ,
811845 Namespace : p .Namespace ,
812846 },
813847 // Project is a reference to the project this application belongs to.
814848 // The empty string means that application belongs to the 'default' project.
815- Project : "default" ,
849+ Project : DefaultProject ,
816850
817851 // IgnoreDifferences is a list of resources and their fields which should be ignored during comparison
818852 // IgnoreDifferences []ResourceIgnoreDifferences `json:"ignoreDifferences,omitempty" protobuf:"bytes,5,name=ignoreDifferences"`
@@ -909,7 +943,7 @@ func newMultiSourceApplication(p *api.Pattern) *argoapi.Application {
909943 valuesSource := & argoapi.ApplicationSource {
910944 RepoURL : p .Spec .GitConfig .TargetRepo ,
911945 TargetRevision : p .Spec .GitConfig .TargetRevision ,
912- Ref : "patternref" ,
946+ Ref : PatternRef ,
913947 }
914948 sources = append (sources , * valuesSource )
915949
@@ -984,10 +1018,10 @@ func newArgoGiteaApplication(p *api.Pattern, patternsOperatorConfig PatternsOper
9841018 }
9851019 spec := & argoapi.ApplicationSpec {
9861020 Destination : argoapi.ApplicationDestination {
987- Name : "in-cluster" ,
1021+ Name : InClusterDestination ,
9881022 Namespace : GiteaNamespace ,
9891023 },
990- Project : "default" ,
1024+ Project : DefaultProject ,
9911025 Source : & argoapi.ApplicationSource {
9921026 RepoURL : patternsOperatorConfig .getStringValue ("gitea.helmRepoUrl" ),
9931027 TargetRevision : patternsOperatorConfig .getStringValue ("gitea.chartVersion" ),
@@ -1296,14 +1330,14 @@ func updateHelmParameter(goal api.PatternParameter, actual []argoapi.HelmParamet
12961330// syncApplication syncs the application with prune and force options if such a sync is not already in progress.
12971331// Returns nil if a sync is already in progress, error otherwise
12981332func syncApplication (client argoclient.Interface , app * argoapi.Application , withPrune bool ) error {
1299- if app .Operation != nil && app .Operation .Sync != nil && app .Operation .Sync .Prune == withPrune && slices .Contains (app .Operation .Sync .SyncOptions , "Force=true" ) {
1333+ if app .Operation != nil && app .Operation .Sync != nil && app .Operation .Sync .Prune == withPrune && slices .Contains (app .Operation .Sync .SyncOptions , SyncOptionForce ) {
13001334 return nil
13011335 }
13021336
13031337 app .Operation = & argoapi.Operation {
13041338 Sync : & argoapi.SyncOperation {
13051339 Prune : withPrune ,
1306- SyncOptions : []string {"Force=true" },
1340+ SyncOptions : []string {SyncOptionForce },
13071341 },
13081342 }
13091343
0 commit comments