Skip to content

Commit 0e8774a

Browse files
grzpiotrowskialebedev87
authored andcommitted
OCPBUGS-60009: Add aws lb controller CredentialsRequest in the e2e tests setup (#201)
This commit fixes OCPBUGS-60009. https://issues.redhat.com/browse/OCPBUGS-60009 AWS Load Balancer Controller CredentialsRequest is now created in the setup of the aws-load-balancer-operator e2e tests, eliminating the race condition where the target namespace for the request did not exist yet when the credentials request was created as part of the CI pre-install steps.
1 parent ffa66d5 commit 0e8774a

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

hack/controller/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ This `CrendetialsRequest` is a compact ("minified") version of the source IAM po
2020
This allows it to be created by both the Cloud Credential Operator and `ccoctl`.
2121
Currently, this `CrendetialsRequest` is used in two places:
2222
- by the operator [to ensure `CredentialsRequest` CR](https://github.com/openshift/aws-load-balancer-operator/blob/a846cc27dc0f08adbf404714d308ded7f2cddebe/pkg/controllers/awsloadbalancercontroller/credentials_request.go#L145) during `AWSLoadBalancerController` reconciliation
23-
- by [the aws-load-balancer pre-install CI step](https://github.com/openshift/release/blob/d797eff6740de41ee2793866f358b246e2b52ae4/ci-operator/step-registry/aws-load-balancer/pre-install/aws-load-balancer-pre-install-commands.sh#L14) to create a secret for [some e2e test cases](https://github.com/openshift/aws-load-balancer-operator/blob/a846cc27dc0f08adbf404714d308ded7f2cddebe/test/e2e/operator_test.go#L324).
23+
- by the operator e2e tests to create a secret for [some e2e test cases](https://github.com/openshift/aws-load-balancer-operator/blob/a846cc27dc0f08adbf404714d308ded7f2cddebe/test/e2e/operator_test.go#L324).
2424

2525
**Note**: this `CredentialsRequest` has broader permissions than the source IAM policy!

test/e2e/operator_test.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242

4343
albo "github.com/openshift/aws-load-balancer-operator/api/v1"
4444
albov1alpha1 "github.com/openshift/aws-load-balancer-operator/api/v1alpha1"
45+
"github.com/openshift/aws-load-balancer-operator/pkg/controllers/awsloadbalancercontroller"
4546
)
4647

4748
const (
@@ -58,9 +59,6 @@ const (
5859
// controllerRoleARNVarName contains IAM role ARN to be used by the controller on a ROSA/STS cluster.
5960
controllerRoleARNVarName = "ALBO_E2E_CONTROLLER_ROLE_ARN"
6061

61-
// controllerSecretName is the name of the controller's cloud credential secret provisioned by the CI.
62-
controllerSecretName = "aws-load-balancer-controller-cluster"
63-
6462
// awsLoadBalancerControllerContainerName is the name of the AWS load balancer controller's container.
6563
awsLoadBalancerControllerContainerName = "controller"
6664
)
@@ -85,6 +83,10 @@ var (
8583
Name: "aws-load-balancer-operator-e2e",
8684
Namespace: operatorNamespace,
8785
}
86+
controllerSecretName = types.NamespacedName{
87+
Name: "aws-load-balancer-controller-cluster",
88+
Namespace: operatorNamespace,
89+
}
8890
controllerRoleARN string
8991
)
9092

@@ -134,6 +136,10 @@ func TestMain(m *testing.M) {
134136
fmt.Printf("failed to create credentialsrequest for e2e: %s\n", err)
135137
os.Exit(1)
136138
}
139+
if err := ensureControllerCredentialsRequest(controllerSecretName); err != nil {
140+
fmt.Printf("failed to create credentialsrequest for controller: %s\n", err)
141+
os.Exit(1)
142+
}
137143
cfg, err = awsConfigWithCredentials(context.TODO(), kubeClient, infra.Status.PlatformStatus.AWS.Region, e2eSecretName)
138144
if err != nil {
139145
fmt.Printf("failed to load aws config %v\n", err)
@@ -256,7 +262,7 @@ func TestAWSLoadBalancerControllersV1Alpha1(t *testing.T) {
256262

257263
// The additional resource tags and the credentials secret are added to ALBC
258264
// because they changed in v1.
259-
alb := newALBCBuilder().withResourceTags(map[string]string{"testtag": "testval"}).withCredSecret(controllerSecretName).buildv1alpha1()
265+
alb := newALBCBuilder().withResourceTags(map[string]string{"testtag": "testval"}).withCredSecret(controllerSecretName.Name).buildv1alpha1()
260266
if err := kubeClient.Create(context.TODO(), alb); err != nil {
261267
t.Fatalf("failed to create aws load balancer controller: %v", err)
262268
}
@@ -334,7 +340,7 @@ func TestAWSLoadBalancerControllerWithCredentialsSecret(t *testing.T) {
334340
}()
335341

336342
t.Log("Creating aws load balancer controller instance with credentials secret")
337-
alb := newALBCBuilder().withCredSecret(controllerSecretName).build()
343+
alb := newALBCBuilder().withCredSecret(controllerSecretName.Name).build()
338344
if err := kubeClient.Create(context.TODO(), alb); err != nil {
339345
t.Fatalf("failed to create aws load balancer controller: %v", err)
340346
}
@@ -1425,6 +1431,38 @@ func ensureCredentialsRequest(secret types.NamespacedName) error {
14251431
return nil
14261432
}
14271433

1434+
// ensureControllerCredentialsRequest creates CredentialsRequest to provision a secret with the cloud credentials
1435+
// required by the controller in some of the e2e tests.
1436+
func ensureControllerCredentialsRequest(secret types.NamespacedName) error {
1437+
providerSpec, err := cco.Codec.EncodeProviderSpec(&cco.AWSProviderSpec{
1438+
StatementEntries: awsloadbalancercontroller.GetIAMPolicyMinify().Statement,
1439+
})
1440+
if err != nil {
1441+
return err
1442+
}
1443+
1444+
cr := cco.CredentialsRequest{
1445+
ObjectMeta: v1.ObjectMeta{
1446+
Name: "aws-load-balancer-controller",
1447+
Namespace: "openshift-cloud-credential-operator",
1448+
},
1449+
Spec: cco.CredentialsRequestSpec{
1450+
SecretRef: corev1.ObjectReference{
1451+
Name: secret.Name,
1452+
Namespace: secret.Namespace,
1453+
},
1454+
ServiceAccountNames: []string{"aws-load-balancer-controller-cluster"},
1455+
ProviderSpec: providerSpec,
1456+
},
1457+
}
1458+
1459+
if err = kubeClient.Create(context.Background(), &cr); err != nil && !errors.IsAlreadyExists(err) {
1460+
return err
1461+
}
1462+
1463+
return nil
1464+
}
1465+
14281466
func createTestWorkload(t *testing.T, namespace string) *corev1.Service {
14291467
t.Helper()
14301468
return createTestWorkloadWithCustomize(t, namespace, nil)

0 commit comments

Comments
 (0)