Skip to content

Commit bdd9b7f

Browse files
Merge pull request #2497 from metal3-io-bot/cherry-pick-2380-to-release-1.9
🌱 E2E: Ensure cert-manager webhook is available
2 parents 46b6593 + f0edbc5 commit bdd9b7f

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ releasenotes
4040
# goland
4141
.idea
4242

43+
# zed
44+
.zed*
45+
4346
# Common editor / temporary files
4447
*~
4548
*.tmp

test/e2e/data/cert-manager-test.yaml

+28
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

+36
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"
@@ -197,6 +198,41 @@ func preInitFunc(clusterProxy framework.ClusterProxy, bmoRelease string, ironicR
197198
Deployment: deployment,
198199
}, e2eConfig.GetIntervals(specName, "wait-deployment")...)
199200
}
201+
// Create an issuer and certificate to ensure that cert-manager is ready.
202+
certManagerTest, err := os.ReadFile("data/cert-manager-test.yaml")
203+
Expect(err).ToNot(HaveOccurred(), "Unable to read cert-manager test YAML file")
204+
Eventually(func() error {
205+
return clusterProxy.CreateOrUpdate(ctx, certManagerTest)
206+
}, e2eConfig.GetIntervals(specName, "wait-deployment")...).Should(Succeed())
207+
// Wait for and check that the certificate becomes ready.
208+
certKey := client.ObjectKey{
209+
Name: "my-selfsigned-cert",
210+
Namespace: "test",
211+
}
212+
testCert := new(unstructured.Unstructured)
213+
testCert.SetAPIVersion("cert-manager.io/v1")
214+
testCert.SetKind("Certificate")
215+
Eventually(func() error {
216+
if err := clusterProxy.GetClient().Get(ctx, certKey, testCert); err != nil {
217+
return err
218+
}
219+
conditions, found, err := unstructured.NestedSlice(testCert.Object, "status", "conditions")
220+
if err != nil {
221+
return err
222+
}
223+
if !found {
224+
return fmt.Errorf("certificate doesn't have status.conditions (yet)")
225+
}
226+
// There is only one condition (Ready) on certificates.
227+
condType := conditions[0].(map[string]any)["type"]
228+
condStatus := conditions[0].(map[string]any)["status"]
229+
if condType == "Ready" && condStatus == "True" {
230+
return nil
231+
}
232+
return fmt.Errorf("certificate is not ready, type: %s, status: %s, message: %s", condType, condStatus, conditions[0].(map[string]any)["message"])
233+
}, e2eConfig.GetIntervals(specName, "wait-deployment")...).Should(Succeed())
234+
// Delete test namespace
235+
Expect(clusterProxy.GetClientSet().CoreV1().Namespaces().Delete(ctx, "test", metav1.DeleteOptions{})).To(Succeed())
200236
}
201237

202238
By("Fetch manifest for bootstrap cluster")

0 commit comments

Comments
 (0)