Skip to content

Commit 36f5814

Browse files
authored
Merge pull request #250 from alebedev87/release-1.2-konflux-container
Cherry pick fixes for e2e tests
2 parents 12e007c + b9b5d29 commit 36f5814

2 files changed

Lines changed: 45 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: 44 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
}
@@ -717,6 +723,7 @@ func TestAWSLoadBalancerControllerWithWAFv2(t *testing.T) {
717723
}
718724

719725
func TestAWSLoadBalancerControllerWithWAFRegional(t *testing.T) {
726+
t.Skip("Skipping this test for now as creation of WAF Classic ACLs is deprecated (OCPBUGS-57320)")
720727
t.Log("Getting WAFRegional WebACL")
721728
var webACLID string
722729
if !stsModeRequested() {
@@ -1425,6 +1432,38 @@ func ensureCredentialsRequest(secret types.NamespacedName) error {
14251432
return nil
14261433
}
14271434

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

0 commit comments

Comments
 (0)