Skip to content

Commit df9b542

Browse files
Merge pull request #29698 from chiragkyal/hypershift-default-cert
OCPBUGS-55214: Fix default cert issuer name for HyperShift in `RouteExternalCertificate` test case
2 parents b503d7c + ec3d027 commit df9b542

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

test/extended/router/external_certificate.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ const (
3939
// helloOpenShiftResponse is the HTTP response from hello-openshift example pod.
4040
// https://github.com/kubernetes/kubernetes/blob/88dfcb225d41326113990e87b11137641c121a32/test/images/agnhost/netexec/netexec.go#L266-L269
4141
helloOpenShiftResponse = "NOW:"
42-
// defaultCertificateCN is the CommonName of router default certificate.
43-
defaultCertificateCN = "ingress-operator"
42+
// selfManagedDefaultCertificateCN is the CommonName of router default certificate for SelfManaged cluster profile.
43+
selfManagedDefaultCertificateCN = "ingress-operator"
44+
// hypershiftDefaultCertificateCN is the CommonName of router default certificate for HyperShift cluster profile.
45+
hypershiftDefaultCertificateCN = "root-ca"
4446
)
4547

4648
var _ = g.Describe("[sig-network][OCPFeatureGate:RouteExternalCertificate][Feature:Router][apigroup:route.openshift.io]", func() {
@@ -459,7 +461,7 @@ var _ = g.Describe("[sig-network][OCPFeatureGate:RouteExternalCertificate][Featu
459461
err = waitForRouterOKResponseExec(oc.Namespace(), execPod.Name, routerURL, hostName, changeTimeoutSeconds)
460462
o.Expect(err).NotTo(o.HaveOccurred())
461463
} else {
462-
resp, err := verifyRouteServesDefaultCert(hostName)
464+
resp, err := verifyRouteServesDefaultCert(oc, hostName)
463465
o.Expect(err).NotTo(o.HaveOccurred())
464466
o.Expect(resp).Should(o.ContainSubstring(helloOpenShiftResponse))
465467
}
@@ -624,7 +626,18 @@ func httpsGetCallWithExecPod(oc *exutil.CLI, url string, rootCertPEM []byte) (st
624626
}
625627

626628
// verifyRouteServesDefaultCert checks that the given hostname serves the default certificate.
627-
func verifyRouteServesDefaultCert(hostname string) (string, error) {
629+
func verifyRouteServesDefaultCert(oc *exutil.CLI, hostname string) (string, error) {
630+
defaultCertificateCN := selfManagedDefaultCertificateCN
631+
632+
// change the expected defaultCertificateCN if it's a HyperShift cluster.
633+
isHypershift, err := exutil.IsHypershift(context.Background(), oc.AdminConfigClient())
634+
if err != nil {
635+
return "", fmt.Errorf("failed to verify HyperShift cluster: %w", err)
636+
}
637+
if isHypershift {
638+
defaultCertificateCN = hypershiftDefaultCertificateCN
639+
}
640+
628641
client := &http.Client{
629642
Transport: &http.Transport{
630643
TLSClientConfig: &tls.Config{
@@ -635,7 +648,7 @@ func verifyRouteServesDefaultCert(hostname string) (string, error) {
635648
url := fmt.Sprintf("https://%s", hostname)
636649

637650
var body string
638-
err := wait.PollUntilContextTimeout(context.Background(), time.Second, changeTimeoutSeconds*time.Second, false, func(ctx context.Context) (bool, error) {
651+
err = wait.PollUntilContextTimeout(context.Background(), time.Second, changeTimeoutSeconds*time.Second, false, func(ctx context.Context) (bool, error) {
639652
var err error
640653
var resp *http.Response
641654
resp, body, err = sendHttpRequestWithRetry(url, client)
@@ -646,7 +659,7 @@ func verifyRouteServesDefaultCert(hostname string) (string, error) {
646659
// check that the route is serving the default certificate.
647660
for _, cert := range resp.TLS.PeerCertificates {
648661
if !strings.Contains(cert.Issuer.CommonName, defaultCertificateCN) {
649-
e2e.Logf("Unexpected Issuer CommonName: %v, retrying...", cert.Issuer.CommonName)
662+
e2e.Logf("Unexpected Issuer CommonName: expected %v, but got %v, retrying...", defaultCertificateCN, cert.Issuer.CommonName)
650663
return false, nil
651664
}
652665
}

0 commit comments

Comments
 (0)