Skip to content

Commit 5cf7436

Browse files
committed
fix(repo-server): Fix SystemCATrust for RHEL 9
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 811c2f1 commit 5cf7436

2 files changed

Lines changed: 55 additions & 33 deletions

File tree

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/sequential/1-120_repo_server_system_ca_trust.go

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ import (
2222
"crypto/x509"
2323
"encoding/pem"
2424
"fmt"
25+
"io"
26+
"net/http"
2527
"regexp"
2628
"strings"
2729

2830
"github.com/onsi/gomega/gcustom"
2931
matcher "github.com/onsi/gomega/types"
32+
"gopkg.in/yaml.v3"
3033
"k8s.io/apimachinery/pkg/util/rand"
3134
"k8s.io/client-go/util/retry"
3235
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
@@ -56,9 +59,8 @@ import (
5659

5760
var (
5861
// 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+
image = fetchArgoCDComponentImage()
63+
imageVersion = "main"
6264

6365
trustedHelmAppSource = &appv1alpha1.ApplicationSource{
6466
RepoURL: "https://stefanprodan.github.io/podinfo",
@@ -76,6 +78,8 @@ var (
7678

7779
k8sClient client.Client
7880
ctx context.Context
81+
ns *corev1.Namespace
82+
cleanupNs func()
7983

8084
clusterSupportsClusterTrustBundles bool
8185
)
@@ -90,25 +94,16 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
9094
ctx = context.Background()
9195

9296
clusterSupportsClusterTrustBundles = detectClusterTrustBundleSupport(k8sClient, ctx)
93-
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-
}
10397
})
10498

10599
AfterEach(func() {
100+
fixture.OutputDebugOnFail(ns)
101+
cleanupNs()
106102
purgeCtbs()
107103
})
108104

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

113108
By("creating Argo CD instance with missing Secret")
114109
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -130,8 +125,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
130125
Skip("Cluster does not support ClusterTrustBundles")
131126
}
132127

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

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

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

177170
cmCert := createCmFromCert(ns, getCACert("github.com"))
178171
Expect(k8sClient.Create(ctx, cmCert)).To(Succeed())
@@ -220,8 +213,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
220213
})
221214

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

226218
By("creating Argo CD instance with empty system trust")
227219
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -253,8 +245,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
253245
})
254246

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

259250
By("creating Argo CD instance with empty system trust")
260251
argoCD := argoCDSpec(ns, argov1beta1api.ArgoCDRepoSpec{
@@ -268,8 +259,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
268259
})
269260

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

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

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

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

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

419407
// Use random label value not to collide with leftover CTBs fom other tests
420408
labelVal := rand.String(5)
@@ -804,7 +792,9 @@ func getTrustedCertCount(rsPod *corev1.Pod) int {
804792
command := []string{
805793
"kubectl", "-n", rsPod.Namespace, "exec",
806794
"-c", "argocd-repo-server", rsPod.Name, "--",
807-
"cat", caBundlePath,
795+
"bash", "-c",
796+
// Ubuntu or RHEL location
797+
"cat /etc/ssl/certs/ca-certificates.crt || cat /etc/ssl/certs/ca-bundle.crt",
808798
}
809799

810800
var out string
@@ -909,3 +899,35 @@ func purgeCtbs() {
909899
Expect(k8sClient.DeleteAllOf(ctx, &certificatesv1beta1.ClusterTrustBundle{}, expr)).To(Succeed())
910900
}
911901
}
902+
903+
// fetchArgoCDComponentImage pulls image url to discover its current location
904+
func fetchArgoCDComponentImage() string {
905+
resp, err := http.Get("https://raw.githubusercontent.com/rh-gitops-midstream/release/refs/heads/main/config.yaml")
906+
Expect(err).ToNot(HaveOccurred(), "failed to fetch config.yaml")
907+
defer resp.Body.Close()
908+
909+
Expect(resp.StatusCode).To(Equal(http.StatusOK), "failed to fetch config.yaml")
910+
911+
body, err := io.ReadAll(resp.Body)
912+
Expect(err).ToNot(HaveOccurred(), "failed to read config.yaml")
913+
914+
var config struct {
915+
KonfluxImages []struct {
916+
Name string `yaml:"name"`
917+
BuildRef string `yaml:"buildRef"`
918+
} `yaml:"konfluxImages"`
919+
}
920+
921+
err = yaml.Unmarshal(body, &config)
922+
Expect(err).ToNot(HaveOccurred(), "failed to parse config.yaml")
923+
924+
for _, img := range config.KonfluxImages {
925+
if img.Name == "argocd" {
926+
Expect(img.BuildRef).ToNot(BeEmpty(), "buildRef for argocd is empty")
927+
return img.BuildRef
928+
}
929+
}
930+
931+
Fail("argocd image not found in konfluxImages")
932+
return ""
933+
}

0 commit comments

Comments
 (0)