Skip to content

Commit b7d0243

Browse files
Merge pull request #2380 from Nordix/lentzi90/cert-manager-flake
🌱 E2E: Ensure cert-manager webhook is available
2 parents a8a5369 + b9c917d commit b7d0243

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ out
3939
# goland
4040
.idea
4141

42+
# zed
43+
.zed*
44+
4245
# Common editor / temporary files
4346
*~
4447
*.tmp
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: test
5+
---
6+
apiVersion: cert-manager.io/v1
7+
kind: Issuer
8+
metadata:
9+
name: selfsigned-issuer
10+
namespace: test
11+
spec:
12+
selfSigned: {}
13+
---
14+
apiVersion: cert-manager.io/v1
15+
kind: Certificate
16+
metadata:
17+
name: my-selfsigned-cert
18+
namespace: test
19+
spec:
20+
commonName: my-selfsigned-cert
21+
secretName: root-secret
22+
privateKey:
23+
algorithm: ECDSA
24+
size: 256
25+
issuerRef:
26+
name: selfsigned-issuer
27+
kind: Issuer
28+
group: cert-manager.io

test/e2e/upgrade_clusterctl_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
. "github.com/onsi/ginkgo/v2"
1212
. "github.com/onsi/gomega"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1415
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
1516
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"
1617
framework "sigs.k8s.io/cluster-api/test/framework"
@@ -205,6 +206,41 @@ func preInitFunc(clusterProxy framework.ClusterProxy, bmoRelease string, ironicR
205206
Deployment: deployment,
206207
}, e2eConfig.GetIntervals(specName, "wait-deployment")...)
207208
}
209+
// Create an issuer and certificate to ensure that cert-manager is ready.
210+
certManagerTest, err := os.ReadFile("data/cert-manager-test.yaml")
211+
Expect(err).ToNot(HaveOccurred(), "Unable to read cert-manager test YAML file")
212+
Eventually(func() error {
213+
return clusterProxy.CreateOrUpdate(ctx, certManagerTest)
214+
}, e2eConfig.GetIntervals(specName, "wait-deployment")...).Should(Succeed())
215+
// Wait for and check that the certificate becomes ready.
216+
certKey := client.ObjectKey{
217+
Name: "my-selfsigned-cert",
218+
Namespace: "test",
219+
}
220+
testCert := new(unstructured.Unstructured)
221+
testCert.SetAPIVersion("cert-manager.io/v1")
222+
testCert.SetKind("Certificate")
223+
Eventually(func() error {
224+
if err := clusterProxy.GetClient().Get(ctx, certKey, testCert); err != nil {
225+
return err
226+
}
227+
conditions, found, err := unstructured.NestedSlice(testCert.Object, "status", "conditions")
228+
if err != nil {
229+
return err
230+
}
231+
if !found {
232+
return fmt.Errorf("certificate doesn't have status.conditions (yet)")
233+
}
234+
// There is only one condition (Ready) on certificates.
235+
condType := conditions[0].(map[string]any)["type"]
236+
condStatus := conditions[0].(map[string]any)["status"]
237+
if condType == "Ready" && condStatus == "True" {
238+
return nil
239+
}
240+
return fmt.Errorf("certificate is not ready, type: %s, status: %s, message: %s", condType, condStatus, conditions[0].(map[string]any)["message"])
241+
}, e2eConfig.GetIntervals(specName, "wait-deployment")...).Should(Succeed())
242+
// Delete test namespace
243+
Expect(clusterProxy.GetClientSet().CoreV1().Namespaces().Delete(ctx, "test", metav1.DeleteOptions{})).To(Succeed())
208244
}
209245

210246
By("Fetch manifest for bootstrap cluster")

0 commit comments

Comments
 (0)