Skip to content

Commit 49ead7f

Browse files
Merge pull request #547 from mbaldessari/ourown-gitops
Make the operator use its own vp-gitops ns+argo instance on greenfield deployments
2 parents 8ba5c02 + f4788fd commit 49ead7f

9 files changed

Lines changed: 343 additions & 106 deletions

File tree

config/rbac/role.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ rules:
7575
verbs:
7676
- get
7777
- list
78+
- apiGroups:
79+
- console.openshift.io
80+
resources:
81+
- consolelinks
82+
verbs:
83+
- create
84+
- delete
85+
- get
86+
- list
87+
- patch
88+
- update
7889
- apiGroups:
7990
- gitops.hybrid-cloud-patterns.io
8091
resources:

internal/controller/argo.go

Lines changed: 87 additions & 2 deletions
Large diffs are not rendered by default.

internal/controller/argo_test.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var _ = Describe("Argo Pattern", func() {
105105
argoApp = &argoapi.Application{
106106
ObjectMeta: metav1.ObjectMeta{
107107
Name: applicationName(pattern),
108-
Namespace: "openshift-gitops",
108+
Namespace: getClusterWideArgoNamespace(),
109109
Labels: map[string]string{
110110
"validatedpatterns.io/pattern": pattern.Name,
111111
},
@@ -118,8 +118,13 @@ var _ = Describe("Argo Pattern", func() {
118118
},
119119
Project: "default",
120120
SyncPolicy: &argoapi.SyncPolicy{
121-
Automated: &argoapi.SyncPolicyAutomated{},
121+
Automated: &argoapi.SyncPolicyAutomated{
122+
SelfHeal: true,
123+
},
122124
SyncOptions: []string{},
125+
Retry: &argoapi.RetryStrategy{
126+
Limit: 20,
127+
},
123128
},
124129
},
125130
}
@@ -450,6 +455,10 @@ var _ = Describe("Argo Pattern", func() {
450455
Name: "global.gitOpsSubNamespace",
451456
Value: GitOpsDefaultSubscriptionNamespace,
452457
},
458+
argoapi.HelmParameter{
459+
Name: "global.vpArgoNamespace",
460+
Value: getClusterWideArgoNamespace(),
461+
},
453462
argoapi.HelmParameter{
454463
Name: "global.multiSourceTargetRevision",
455464
Value: "0.0.*",
@@ -488,6 +497,10 @@ var _ = Describe("Argo Pattern", func() {
488497
Name: "global.gitOpsSubNamespace",
489498
Value: GitOpsDefaultSubscriptionNamespace,
490499
},
500+
argoapi.HelmParameter{
501+
Name: "global.vpArgoNamespace",
502+
Value: getClusterWideArgoNamespace(),
503+
},
491504
argoapi.HelmParameter{
492505
Name: "global.multiSourceTargetRevision",
493506
Value: "0.0.*",
@@ -525,6 +538,10 @@ var _ = Describe("Argo Pattern", func() {
525538
Name: "global.gitOpsSubNamespace",
526539
Value: GitOpsDefaultSubscriptionNamespace,
527540
},
541+
argoapi.HelmParameter{
542+
Name: "global.vpArgoNamespace",
543+
Value: getClusterWideArgoNamespace(),
544+
},
528545
argoapi.HelmParameter{
529546
Name: "global.multiSourceTargetRevision",
530547
Value: "0.0.*",
@@ -625,14 +642,14 @@ var _ = Describe("Argo Pattern", func() {
625642
})
626643
It("should return false and log the appropriate message", func() {
627644
automatedSyncPolicyChanged := automatedSyncPolicy.DeepCopy()
628-
automatedSyncPolicyChanged.SelfHeal = true
645+
automatedSyncPolicyChanged.SelfHeal = false
629646
logBuffer := new(bytes.Buffer)
630647
log.SetOutput(logBuffer)
631648
defer log.SetOutput(os.Stderr)
632649

633650
result := compareAutomatedSyncPolicy(automatedSyncPolicy, automatedSyncPolicyChanged)
634651
Expect(result).To(BeFalse())
635-
Expect(logBuffer.String()).To(ContainSubstring("SyncPolicy SelfHeal changed true -> false"))
652+
Expect(logBuffer.String()).To(ContainSubstring("SyncPolicy SelfHeal changed false -> true"))
636653
})
637654
It("compareAutomatedSyncPolicy() function with nil arg1", func() {
638655
Expect(compareAutomatedSyncPolicy(automatedSyncPolicy, nil)).To(BeFalse())
@@ -1479,6 +1496,9 @@ var _ = Describe("CommonSyncPolicy", func() {
14791496
Expect(policy).ToNot(BeNil())
14801497
Expect(policy.Automated).ToNot(BeNil())
14811498
Expect(policy.Automated.Prune).To(BeFalse())
1499+
Expect(policy.Automated.SelfHeal).To(BeTrue())
1500+
Expect(policy.Retry).ToNot(BeNil())
1501+
Expect(policy.Retry.Limit).To(Equal(int64(20)))
14821502
})
14831503
})
14841504

@@ -1954,16 +1974,16 @@ var _ = Describe("removeApplication", func() {
19541974
app := &argoapi.Application{
19551975
ObjectMeta: metav1.ObjectMeta{
19561976
Name: "test-app",
1957-
Namespace: "openshift-gitops",
1977+
Namespace: getClusterWideArgoNamespace(),
19581978
},
19591979
}
19601980
argoClient := argoclient.NewSimpleClientset(app)
19611981

1962-
err := removeApplication(argoClient, "test-app", "openshift-gitops")
1982+
err := removeApplication(argoClient, "test-app", getClusterWideArgoNamespace())
19631983
Expect(err).ToNot(HaveOccurred())
19641984

19651985
// Verify the application is gone
1966-
_, err = argoClient.ArgoprojV1alpha1().Applications("openshift-gitops").Get(
1986+
_, err = argoClient.ArgoprojV1alpha1().Applications(getClusterWideArgoNamespace()).Get(
19671987
context.Background(), "test-app", metav1.GetOptions{})
19681988
Expect(err).To(HaveOccurred())
19691989
Expect(kerrors.IsNotFound(err)).To(BeTrue())
@@ -1973,7 +1993,7 @@ var _ = Describe("removeApplication", func() {
19731993
Context("when the application does not exist", func() {
19741994
It("should return an error", func() {
19751995
argoClient := argoclient.NewSimpleClientset()
1976-
err := removeApplication(argoClient, "nonexistent", "openshift-gitops")
1996+
err := removeApplication(argoClient, "nonexistent", getClusterWideArgoNamespace())
19771997
Expect(err).To(HaveOccurred())
19781998
})
19791999
})
@@ -2151,6 +2171,9 @@ var _ = Describe("commonSyncPolicy", func() {
21512171
Expect(policy).ToNot(BeNil())
21522172
Expect(policy.Automated).ToNot(BeNil())
21532173
Expect(policy.Automated.Prune).To(BeFalse())
2174+
Expect(policy.Automated.SelfHeal).To(BeTrue())
2175+
Expect(policy.Retry).ToNot(BeNil())
2176+
Expect(policy.Retry.Limit).To(Equal(int64(20)))
21542177
})
21552178

21562179
It("should return nil sync policy when manual sync is enabled", func() {
@@ -2188,7 +2211,7 @@ var _ = Describe("syncApplication", func() {
21882211
app := &argoapi.Application{
21892212
ObjectMeta: metav1.ObjectMeta{
21902213
Name: "test-app",
2191-
Namespace: "openshift-gitops",
2214+
Namespace: getClusterWideArgoNamespace(),
21922215
},
21932216
}
21942217
argoFakeClient := argoclient.NewSimpleClientset(app)
@@ -2205,7 +2228,7 @@ var _ = Describe("syncApplication", func() {
22052228
app := &argoapi.Application{
22062229
ObjectMeta: metav1.ObjectMeta{
22072230
Name: "test-app",
2208-
Namespace: "openshift-gitops",
2231+
Namespace: getClusterWideArgoNamespace(),
22092232
},
22102233
}
22112234
argoFakeClient := argoclient.NewSimpleClientset(app)
@@ -2222,7 +2245,7 @@ var _ = Describe("syncApplication", func() {
22222245
app := &argoapi.Application{
22232246
ObjectMeta: metav1.ObjectMeta{
22242247
Name: "test-app",
2225-
Namespace: "openshift-gitops",
2248+
Namespace: getClusterWideArgoNamespace(),
22262249
},
22272250
Operation: &argoapi.Operation{
22282251
Sync: &argoapi.SyncOperation{
@@ -2245,15 +2268,15 @@ var _ = Describe("getChildApplications", func() {
22452268
parentApp := &argoapi.Application{
22462269
ObjectMeta: metav1.ObjectMeta{
22472270
Name: "parent-app",
2248-
Namespace: "openshift-gitops",
2271+
Namespace: getClusterWideArgoNamespace(),
22492272
},
22502273
}
22512274
childApp := &argoapi.Application{
22522275
ObjectMeta: metav1.ObjectMeta{
22532276
Name: "child-app",
2254-
Namespace: "openshift-gitops",
2277+
Namespace: getClusterWideArgoNamespace(),
22552278
Annotations: map[string]string{
2256-
"argocd.argoproj.io/tracking-id": "parent-app:argoproj.io/Application:openshift-gitops/child-app",
2279+
"argocd.argoproj.io/tracking-id": fmt.Sprintf("parent-app:argoproj.io/Application:%s/child-app", getClusterWideArgoNamespace()),
22572280
},
22582281
},
22592282
}
@@ -2271,7 +2294,7 @@ var _ = Describe("getChildApplications", func() {
22712294
parentApp := &argoapi.Application{
22722295
ObjectMeta: metav1.ObjectMeta{
22732296
Name: "parent-app",
2274-
Namespace: "openshift-gitops",
2297+
Namespace: getClusterWideArgoNamespace(),
22752298
},
22762299
}
22772300
argoFakeClient := argoclient.NewSimpleClientset(parentApp)

internal/controller/defaults.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ const (
3333
// Default Operator Config Map Name
3434
OperatorConfigMap = "patterns-operator-config"
3535
// Default Application Namespace
36-
ApplicationNamespace = "openshift-gitops"
36+
ApplicationNamespace = "vp-gitops"
3737
// ClusterWide Argo Name
38-
ClusterWideArgoName = "openshift-gitops"
38+
ClusterWideArgoName = "vp-gitops"
39+
// Legacy Application Namespace (used by the default gitops-operator instance)
40+
LegacyApplicationNamespace = "openshift-gitops"
41+
// Legacy ClusterWide Argo Name
42+
LegacyClusterWideArgoName = "openshift-gitops"
3943
)
4044

4145
// GitOps Subscription

0 commit comments

Comments
 (0)