Skip to content

Commit a62eefd

Browse files
Merge pull request #8204 from bryan-cox/migrate-self-azure-e2e
CNTRLPLANE-3222: Migrate self-managed Azure e2e tests to v2 Ginkgo framework
2 parents 7ac2953 + dfa0ec5 commit a62eefd

9 files changed

Lines changed: 596 additions & 213 deletions

File tree

test/e2e/create_cluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestCreateCluster(t *testing.T) {
129129

130130
if globalOpts.Platform == hyperv1.AzurePlatform || globalOpts.Platform == hyperv1.AWSPlatform {
131131
// ensure Ingress Operator configuration is properly applied
132-
e2eutil.EnsureIngressOperatorConfiguration(t, ctx, mgtClient, guestClient, hostedCluster)
132+
e2eutil.EnsureIngressOperatorConfiguration(t, ctx, guestClient, hostedCluster)
133133
}
134134

135135
e2eutil.EnsureAWSCCMWithCustomizations(t, ctx, &e2eutil.AWSCCMTestConfig{

test/e2e/util/azure.go

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,86 +17,93 @@ import (
1717
crclient "sigs.k8s.io/controller-runtime/pkg/client"
1818
)
1919

20-
func EnsureAzureWorkloadIdentityWebhookMutation(t *testing.T, ctx context.Context, guestClient crclient.Client) {
21-
t.Run("EnsureAzureWorkloadIdentityWebhookMutation", func(t *testing.T) {
22-
AtLeast(t, Version422)
23-
g := NewWithT(t)
20+
func ValidateAzureWorkloadIdentityWebhookMutation(t testing.TB, ctx context.Context, guestClient crclient.Client) {
21+
g := NewWithT(t)
2422

25-
nsName := fmt.Sprintf("azure-wi-e2e-%d", time.Now().UnixNano())
26-
testNamespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: nsName}}
27-
g.Expect(guestClient.Create(ctx, testNamespace)).To(Succeed(), "failed to create test namespace")
23+
nsName := fmt.Sprintf("azure-wi-e2e-%d", time.Now().UnixNano())
24+
testNamespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: nsName}}
25+
g.Expect(guestClient.Create(ctx, testNamespace)).To(Succeed(), "failed to create test namespace")
26+
defer func() {
27+
_ = guestClient.Delete(context.Background(), testNamespace)
28+
}()
2829

29-
serviceAccount := &corev1.ServiceAccount{
30-
ObjectMeta: metav1.ObjectMeta{
31-
Name: "azure-wi-test-sa",
32-
Namespace: nsName,
33-
Annotations: map[string]string{
34-
"azure.workload.identity/client-id": "00000000-0000-0000-0000-000000000000",
35-
},
30+
serviceAccount := &corev1.ServiceAccount{
31+
ObjectMeta: metav1.ObjectMeta{
32+
Name: "azure-wi-test-sa",
33+
Namespace: nsName,
34+
Annotations: map[string]string{
35+
"azure.workload.identity/client-id": "00000000-0000-0000-0000-000000000000",
3636
},
37-
}
38-
g.Expect(guestClient.Create(ctx, serviceAccount)).To(Succeed(), "failed to create test service account")
37+
},
38+
}
39+
g.Expect(guestClient.Create(ctx, serviceAccount)).To(Succeed(), "failed to create test service account")
3940

40-
pod := &corev1.Pod{
41-
ObjectMeta: metav1.ObjectMeta{
42-
Name: "azure-wi-webhook-test-pod",
43-
Namespace: nsName,
44-
Labels: map[string]string{
45-
"azure.workload.identity/use": "true",
46-
},
41+
pod := &corev1.Pod{
42+
ObjectMeta: metav1.ObjectMeta{
43+
Name: "azure-wi-webhook-test-pod",
44+
Namespace: nsName,
45+
Labels: map[string]string{
46+
"azure.workload.identity/use": "true",
4747
},
48-
Spec: corev1.PodSpec{
49-
ServiceAccountName: serviceAccount.Name,
50-
SecurityContext: &corev1.PodSecurityContext{
51-
RunAsNonRoot: ptr.To(true),
52-
SeccompProfile: &corev1.SeccompProfile{
53-
Type: corev1.SeccompProfileTypeRuntimeDefault,
54-
},
48+
},
49+
Spec: corev1.PodSpec{
50+
ServiceAccountName: serviceAccount.Name,
51+
SecurityContext: &corev1.PodSecurityContext{
52+
RunAsNonRoot: ptr.To(true),
53+
SeccompProfile: &corev1.SeccompProfile{
54+
Type: corev1.SeccompProfileTypeRuntimeDefault,
5555
},
56-
Containers: []corev1.Container{
57-
{
58-
Name: "app",
59-
Image: "registry.k8s.io/pause:3.10",
60-
Command: []string{"/pause"},
61-
SecurityContext: &corev1.SecurityContext{
62-
AllowPrivilegeEscalation: ptr.To(false),
63-
Capabilities: &corev1.Capabilities{
64-
Drop: []corev1.Capability{"ALL"},
65-
},
56+
},
57+
Containers: []corev1.Container{
58+
{
59+
Name: "app",
60+
Image: "registry.k8s.io/pause:3.10",
61+
Command: []string{"/pause"},
62+
SecurityContext: &corev1.SecurityContext{
63+
AllowPrivilegeEscalation: ptr.To(false),
64+
Capabilities: &corev1.Capabilities{
65+
Drop: []corev1.Capability{"ALL"},
6666
},
6767
},
6868
},
69-
RestartPolicy: corev1.RestartPolicyNever,
7069
},
71-
}
72-
g.Expect(guestClient.Create(ctx, pod)).To(Succeed(), "failed to create pod for webhook mutation test")
70+
RestartPolicy: corev1.RestartPolicyNever,
71+
},
72+
}
73+
g.Expect(guestClient.Create(ctx, pod)).To(Succeed(), "failed to create pod for webhook mutation test")
7374

74-
EventuallyObject(
75-
t,
76-
ctx,
77-
"Azure workload identity webhook to mutate test pod",
78-
func(ctx context.Context) (*corev1.Pod, error) {
79-
mutatedPod := &corev1.Pod{}
80-
err := guestClient.Get(ctx, types.NamespacedName{Name: pod.Name, Namespace: pod.Namespace}, mutatedPod)
81-
return mutatedPod, err
75+
EventuallyObject(
76+
t,
77+
ctx,
78+
"Azure workload identity webhook to mutate test pod",
79+
func(ctx context.Context) (*corev1.Pod, error) {
80+
mutatedPod := &corev1.Pod{}
81+
err := guestClient.Get(ctx, types.NamespacedName{Name: pod.Name, Namespace: pod.Namespace}, mutatedPod)
82+
return mutatedPod, err
83+
},
84+
[]Predicate[*corev1.Pod]{
85+
func(mutatedPod *corev1.Pod) (bool, string, error) {
86+
if hasProjectedTokenVolume(mutatedPod.Spec.Volumes) {
87+
return true, "", nil
88+
}
89+
return false, "expected projected service account token volume to be injected", nil
8290
},
83-
[]Predicate[*corev1.Pod]{
84-
func(mutatedPod *corev1.Pod) (bool, string, error) {
85-
if hasProjectedTokenVolume(mutatedPod.Spec.Volumes) {
86-
return true, "", nil
87-
}
88-
return false, "expected projected service account token volume to be injected", nil
89-
},
90-
func(mutatedPod *corev1.Pod) (bool, string, error) {
91-
if hasAzureFederatedTokenEnv(mutatedPod.Spec.Containers) {
92-
return true, "", nil
93-
}
94-
return false, "expected AZURE_FEDERATED_TOKEN_FILE env var in pod containers", nil
95-
},
91+
func(mutatedPod *corev1.Pod) (bool, string, error) {
92+
if hasAzureFederatedTokenEnv(mutatedPod.Spec.Containers) {
93+
return true, "", nil
94+
}
95+
return false, "expected AZURE_FEDERATED_TOKEN_FILE env var in pod containers", nil
9696
},
97-
WithTimeout(3*time.Minute),
98-
WithInterval(5*time.Second),
99-
)
97+
},
98+
WithTimeout(3*time.Minute),
99+
WithInterval(5*time.Second),
100+
)
101+
}
102+
103+
func EnsureAzureWorkloadIdentityWebhookMutation(t *testing.T, ctx context.Context, guestClient crclient.Client) {
104+
t.Run("EnsureAzureWorkloadIdentityWebhookMutation", func(t *testing.T) {
105+
AtLeast(t, Version422)
106+
ValidateAzureWorkloadIdentityWebhookMutation(t, ctx, guestClient)
100107
})
101108
}
102109

test/e2e/util/eventually.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func WithFilteredConditionDump(matchers ...Condition) EventuallyOption {
8282
}
8383

8484
// EventuallyObject polls until the predicate is fulfilled on the object.
85-
func EventuallyObject[T client.Object](t *testing.T, ctx context.Context, objective string, getter func(context.Context) (T, error), predicates []Predicate[T], options ...EventuallyOption) {
85+
func EventuallyObject[T client.Object](t testing.TB, ctx context.Context, objective string, getter func(context.Context) (T, error), predicates []Predicate[T], options ...EventuallyOption) {
8686
t.Helper()
8787
opts := defaultOptions()
8888
for _, option := range options {
@@ -209,7 +209,7 @@ func summarizePredicteResults(results []predicateResult) bool {
209209
return done
210210
}
211211

212-
func printStatus[T client.Object](t *testing.T, lastTimestamp time.Time, object T, done bool, reasons []string) {
212+
func printStatus[T client.Object](t testing.TB, lastTimestamp time.Time, object T, done bool, reasons []string) {
213213
if len(reasons) == 0 {
214214
return
215215
}
@@ -236,7 +236,7 @@ type predicateResult struct {
236236
}
237237

238238
// EventuallyObjects polls until the predicate is fulfilled on each of a set of objects.
239-
func EventuallyObjects[T client.Object](t *testing.T, ctx context.Context, objective string, getter func(context.Context) ([]T, error), groupPredicates []Predicate[[]T], predicates []Predicate[T], options ...EventuallyOption) {
239+
func EventuallyObjects[T client.Object](t testing.TB, ctx context.Context, objective string, getter func(context.Context) ([]T, error), groupPredicates []Predicate[[]T], predicates []Predicate[T], options ...EventuallyOption) {
240240
t.Helper()
241241
opts := defaultOptions()
242242
for _, option := range options {
@@ -376,7 +376,7 @@ type predicateReasons struct {
376376
reasons []string
377377
}
378378

379-
func printCollectionStatus[T client.Object](t *testing.T, lastTimestamp time.Time, done bool, reasons map[types.NamespacedName]predicateReasons) {
379+
func printCollectionStatus[T client.Object](t testing.TB, lastTimestamp time.Time, done bool, reasons map[types.NamespacedName]predicateReasons) {
380380
prefix := ""
381381
if !done {
382382
prefix = "in"
@@ -522,7 +522,7 @@ func adaptConditions(in []metav1.Condition) []Condition {
522522
}
523523

524524
// EventuallyNotFound polls until the object is not found (deleted).
525-
func EventuallyNotFound[T client.Object](t *testing.T, ctx context.Context, c client.Client, obj T, options ...EventuallyOption) {
525+
func EventuallyNotFound[T client.Object](t testing.TB, ctx context.Context, c client.Client, obj T, options ...EventuallyOption) {
526526
t.Helper()
527527
opts := defaultOptions()
528528
for _, option := range options {

0 commit comments

Comments
 (0)