Skip to content

Commit 71974fd

Browse files
authored
fix(repo-server): Fix SystemCATrust for RHEL 9 (#1123)
The hardcoded image url caused the tests to pass despite the desired image have changed. Signed-off-by: Oliver Gondža <ogondza@gmail.com>
1 parent dd74960 commit 71974fd

File tree

7 files changed

+73
-60
lines changed

7 files changed

+73
-60
lines changed

controllers/argocd/openshift/openshift.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ func ReconcilerHook(cr *argoapp.ArgoCD, v interface{}, hint string) error {
6363
case cr.Name + "-repo-server":
6464

6565
prodImage := o.Spec.Template.Spec.Containers[0].Image
66-
usingReleasedImages := strings.Contains(prodImage, "registry.redhat.io/openshift-gitops-1/argocd-rhel")
67-
if cr.Spec.Repo.SystemCATrust != nil && usingReleasedImages {
66+
if cr.Spec.Repo.SystemCATrust != nil {
6867
updateSystemCATrustBuilding(cr, o, prodImage, logv)
6968
}
7069
}
@@ -154,7 +153,8 @@ done
154153
echo "User defined trusted CA files:"
155154
ls /etc/pki/ca-trust/source/anchors/
156155
157-
update-ca-trust
156+
# Specifying the explicit location to turn on the container-aware behavior
157+
update-ca-trust extract --output /etc/pki/ca-trust/extracted
158158
159159
echo "Trusted anchors:"
160160
trust list

test/openshift/e2e/ginkgo/fixture/clusterserviceversion/fixture.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package clusterserviceversion
22

33
import (
44
"context"
5+
"strings"
56

67
. "github.com/onsi/gomega"
78
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -27,5 +28,16 @@ func Update(obj *olmv1alpha1.ClusterServiceVersion, modify func(*olmv1alpha1.Clu
2728
return k8sClient.Update(context.Background(), obj)
2829
})
2930
Expect(err).ToNot(HaveOccurred())
31+
}
3032

33+
func Get(ctx context.Context, k8sClient client.Client) *olmv1alpha1.ClusterServiceVersion {
34+
var csvList olmv1alpha1.ClusterServiceVersionList
35+
Expect(k8sClient.List(ctx, &csvList, client.InNamespace("openshift-gitops-operator"))).To(Succeed())
36+
for idx := range csvList.Items {
37+
idxCSV := csvList.Items[idx]
38+
if strings.Contains(idxCSV.Name, "gitops-operator") {
39+
return &idxCSV
40+
}
41+
}
42+
return nil
3143
}

test/openshift/e2e/ginkgo/fixture/utils/fixtureUtils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"os"
55

6+
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
67
"k8s.io/apimachinery/pkg/runtime"
78
"k8s.io/client-go/rest"
89
"k8s.io/client-go/tools/clientcmd"
@@ -146,6 +147,10 @@ func getKubeClient(config *rest.Config) (client.Client, *runtime.Scheme, error)
146147
return nil, nil, err
147148
}
148149

150+
if err := certificatesv1beta1.AddToScheme(scheme); err != nil {
151+
return nil, nil, err
152+
}
153+
149154
k8sClient, err := client.New(config, client.Options{Scheme: scheme})
150155
if err != nil {
151156
return nil, nil, err

test/openshift/e2e/ginkgo/sequential/1-085_validate_dynamic_plugin_installation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
. "github.com/onsi/gomega"
99
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1010
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
11-
clusterserviceversionFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterserviceversion"
11+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterserviceversion"
1212
deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
1313
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
1414
osFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/os"
@@ -86,7 +86,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
8686

8787
By("adding DYNAMIC_PLUGIN_START_OCP_VERSION to CSV operator Deployment env var list")
8888

89-
clusterserviceversionFixture.Update(csv, func(csv *olmv1alpha1.ClusterServiceVersion) {
89+
clusterserviceversion.Update(csv, func(csv *olmv1alpha1.ClusterServiceVersion) {
9090

9191
envList := csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Env
9292
envList = append(envList, corev1.EnvVar{Name: "DYNAMIC_PLUGIN_START_OCP_VERSION", Value: ocVersion})

test/openshift/e2e/ginkgo/sequential/1-115_validate_imagepullpolicy_console_plugin_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
gitopsoperatorv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
2626
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
2727
argocdFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd"
28+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterserviceversion"
2829
gitopsserviceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/gitopsservice"
2930
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
3031
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
@@ -67,7 +68,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
6768
Eventually(argoCD).Should(k8sFixture.ExistByName())
6869
Eventually(argoCD).Should(argocdFixture.BeAvailable())
6970

70-
csv := getCSV(ctx, k8sClient)
71+
csv := clusterserviceversion.Get(ctx, k8sClient)
7172
Expect(csv).ToNot(BeNil())
7273
defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }()
7374

@@ -207,7 +208,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
207208
Eventually(argoCD).Should(k8sFixture.ExistByName())
208209
Eventually(argoCD).Should(argocdFixture.BeAvailable())
209210

210-
csv := getCSV(ctx, k8sClient)
211+
csv := clusterserviceversion.Get(ctx, k8sClient)
211212
Expect(csv).ToNot(BeNil())
212213
defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }()
213214

@@ -264,7 +265,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
264265
// return
265266
// }
266267

267-
// csv := getCSV(ctx, k8sClient)
268+
// csv := clusterserviceversion.Get(ctx, k8sClient)
268269
// Expect(csv).ToNot(BeNil())
269270
// defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }()
270271

test/openshift/e2e/ginkgo/sequential/1-120_repo_server_system_ca_trust.go

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/onsi/gomega/gcustom"
2929
matcher "github.com/onsi/gomega/types"
30+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterserviceversion"
3031
"k8s.io/apimachinery/pkg/util/rand"
3132
"k8s.io/client-go/util/retry"
3233
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
@@ -51,15 +52,10 @@ import (
5152
argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1"
5253
"github.com/argoproj-labs/argocd-operator/tests/ginkgo/fixture"
5354
argocdFixture "github.com/argoproj-labs/argocd-operator/tests/ginkgo/fixture/argocd"
54-
fixtureUtils "github.com/argoproj-labs/argocd-operator/tests/ginkgo/fixture/utils"
55+
fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
5556
)
5657

5758
var (
58-
// The differences between the upstream image using Ubuntu, and the downstream one using rhel.
59-
image = "" // argocd-operator default
60-
imageVersion = "" // argocd-operator default
61-
caBundlePath = "/etc/ssl/certs/ca-certificates.crt"
62-
6359
trustedHelmAppSource = &appv1alpha1.ApplicationSource{
6460
RepoURL: "https://stefanprodan.github.io/podinfo",
6561
Chart: "podinfo",
@@ -74,14 +70,17 @@ var (
7470
Helm: &appv1alpha1.ApplicationSourceHelm{Values: "service:\n type: ClusterIP"},
7571
}
7672

77-
k8sClient client.Client
78-
ctx context.Context
73+
k8sClient client.Client
74+
ctx context.Context
75+
ns *corev1.Namespace
76+
cleanupNs func()
77+
image string
78+
imageVersion string
7979

8080
clusterSupportsClusterTrustBundles bool
8181
)
8282

8383
var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
84-
8584
Context("1-120_repo_server_system_ca_trust", func() {
8685
BeforeEach(func() {
8786
fixture.EnsureSequentialCleanSlate()
@@ -91,24 +90,18 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
9190

9291
clusterSupportsClusterTrustBundles = detectClusterTrustBundleSupport(k8sClient, ctx)
9392

94-
if fixture.EnvLocalRun() {
95-
Skip("skipping test as LOCAL_RUN env is set.")
96-
}
97-
98-
if !fixture.EnvNonOLM() {
99-
image = "registry.redhat.io/openshift-gitops-1/argocd-rhel8"
100-
imageVersion = "sha256:8a0544c14823492165550d83a6d8ba79dd632b46144d3fdcb543793726111d76"
101-
caBundlePath = "/etc/ssl/certs/ca-bundle.crt"
102-
}
93+
// The differences between the upstream image using Ubuntu, and the downstream one using rhel.
94+
image, imageVersion = getArgoCDComponentImageAndVersion()
10395
})
10496

10597
AfterEach(func() {
98+
fixture.OutputDebugOnFail(ns)
99+
cleanupNs()
106100
purgeCtbs()
107101
})
108102

109103
It("ensures that missing Secret aborts startup", func() {
110-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
111-
defer cleanupFunc()
104+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
112105

113106
By("creating Argo CD instance with missing Secret")
114107
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -130,8 +123,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
130123
Skip("Cluster does not support ClusterTrustBundles")
131124
}
132125

133-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
134-
defer cleanupFunc()
126+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
135127

136128
// Create a bundle with 2 CA certs in it. Ubuntu's update-ca-certificates issues a warning, but apparently it works
137129
// It is desirable to test with multiple certs in one bundle because OpenShift permits it
@@ -171,8 +163,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
171163
})
172164

173165
It("ensures that CMs and Secrets are trusted in repo-server and plugins", func() {
174-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
175-
defer cleanupFunc()
166+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
176167

177168
cmCert := createCmFromCert(ns, getCACert("github.com"))
178169
Expect(k8sClient.Create(ctx, cmCert)).To(Succeed())
@@ -220,8 +211,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
220211
})
221212

222213
It("ensures that 0 trusted certs with DropImageCertificates trusts nothing", func() {
223-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
224-
defer cleanupFunc()
214+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
225215

226216
By("creating Argo CD instance with empty system trust")
227217
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -253,8 +243,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
253243
})
254244

255245
It("ensures that empty trust keeps image certs in place", func() {
256-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
257-
defer cleanupFunc()
246+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
258247

259248
By("creating Argo CD instance with empty system trust")
260249
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -268,8 +257,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
268257
})
269258

270259
It("ensures that Secrets and ConfigMaps get reconciled", func() {
271-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
272-
defer cleanupFunc()
260+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
273261

274262
By("creating Argo CD instance with empty system trust, but full of anticipation")
275263
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -360,8 +348,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
360348
Skip("Cluster does not support ClusterTrustBundles")
361349
}
362350

363-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
364-
defer cleanupFunc()
351+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
365352

366353
combinedCtb := createCtbFromCerts(getCACert("github.com"), getCACert("github.io"))
367354
_ = k8sClient.Delete(ctx, combinedCtb) // Exists only in case of previous failures, must be deleted before argo starts!
@@ -413,8 +400,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
413400
Skip("Cluster does not support ClusterTrustBundles")
414401
}
415402

416-
ns, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
417-
defer cleanupFunc()
403+
ns, cleanupNs = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
418404

419405
// Use random label value not to collide with leftover CTBs fom other tests
420406
labelVal := rand.String(5)
@@ -804,7 +790,9 @@ func getTrustedCertCount(rsPod *corev1.Pod) int {
804790
command := []string{
805791
"kubectl", "-n", rsPod.Namespace, "exec",
806792
"-c", "argocd-repo-server", rsPod.Name, "--",
807-
"cat", caBundlePath,
793+
"bash", "-c",
794+
// Ubuntu or RHEL location
795+
"cat /etc/ssl/certs/ca-certificates.crt || cat /etc/ssl/certs/ca-bundle.crt",
808796
}
809797

810798
var out string
@@ -909,3 +897,22 @@ func purgeCtbs() {
909897
Expect(k8sClient.DeleteAllOf(ctx, &certificatesv1beta1.ClusterTrustBundle{}, expr)).To(Succeed())
910898
}
911899
}
900+
901+
// getArgoCDComponentImageAndVersion ensures rhel based image is used for testing this.
902+
// If this is installed as a full-blown operator, use its images.
903+
// If not, inject bleeding-edge pre-release rhel-based images.
904+
func getArgoCDComponentImageAndVersion() (string, string) {
905+
csv := clusterserviceversion.Get(ctx, k8sClient)
906+
if csv != nil {
907+
for _, image := range csv.Spec.RelatedImages {
908+
if image.Name == "argocd_image" {
909+
By("Detected operator image " + image.Image + ". Using it")
910+
return "", ""
911+
}
912+
}
913+
}
914+
915+
defImage := "quay.io/redhat-user-workloads/rh-openshift-gitops-tenant/argocd-rhel9"
916+
By("Injecting rhel image " + defImage)
917+
return defImage, "main"
918+
}

test/openshift/e2e/ginkgo/sequential/1-121-valiate_resource_constraints_gitopsservice_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1010
gitopsoperatorv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
1111
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
12-
clusterserviceversionFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterserviceversion"
12+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterserviceversion"
1313
deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
1414
gitopsserviceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/gitopsservice"
1515
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
@@ -24,18 +24,6 @@ import (
2424

2525
// --- Helper Functions ---
2626

27-
func getCSV(ctx context.Context, k8sClient client.Client) *olmv1alpha1.ClusterServiceVersion {
28-
var csvList olmv1alpha1.ClusterServiceVersionList
29-
Expect(k8sClient.List(ctx, &csvList, client.InNamespace("openshift-gitops-operator"))).To(Succeed())
30-
for idx := range csvList.Items {
31-
idxCSV := csvList.Items[idx]
32-
if strings.Contains(idxCSV.Name, "gitops-operator") {
33-
return &idxCSV
34-
}
35-
}
36-
return nil
37-
}
38-
3927
func getOCPVersion() string {
4028
output, err := osFixture.ExecCommand("oc", "version")
4129
Expect(err).ToNot(HaveOccurred())
@@ -48,7 +36,7 @@ func getOCPVersion() string {
4836
}
4937

5038
func addDynamicPluginEnv(csv *olmv1alpha1.ClusterServiceVersion, ocVersion string) {
51-
clusterserviceversionFixture.Update(csv, func(csv *olmv1alpha1.ClusterServiceVersion) {
39+
clusterserviceversion.Update(csv, func(csv *olmv1alpha1.ClusterServiceVersion) {
5240
envList := csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Env
5341
envList = append(envList, corev1.EnvVar{Name: "DYNAMIC_PLUGIN_START_OCP_VERSION", Value: ocVersion})
5442
csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Env = envList
@@ -86,7 +74,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
8674
})
8775

8876
It("validates that GitOpsService can take in custom resource constraints", func() {
89-
csv := getCSV(ctx, k8sClient)
77+
csv := clusterserviceversion.Get(ctx, k8sClient)
9078
Expect(csv).ToNot(BeNil())
9179
defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }()
9280

@@ -167,7 +155,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
167155
})
168156

169157
It("validates that GitOpsService can update resource constraints", func() {
170-
csv := getCSV(ctx, k8sClient)
158+
csv := clusterserviceversion.Get(ctx, k8sClient)
171159
Expect(csv).ToNot(BeNil())
172160
defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }()
173161

@@ -238,7 +226,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
238226
})
239227

240228
It("validates gitops plugin and backend can have different resource constraints", func() {
241-
csv := getCSV(ctx, k8sClient)
229+
csv := clusterserviceversion.Get(ctx, k8sClient)
242230
Expect(csv).ToNot(BeNil())
243231
defer func() { Expect(fixture.RemoveDynamicPluginFromCSV(ctx, k8sClient)).To(Succeed()) }()
244232

0 commit comments

Comments
 (0)