Skip to content

Commit

Permalink
[e2e] drop sshSetup in favor of ensureTestRunnerRBAC
Browse files Browse the repository at this point in the history
This changes aggregates the RBAC resources required by the test runner job
in the proposed function ensureTestRunnerRBAC() to avoid duplication of
intended functionality.

(cherry picked from commit a2a6f6b)
  • Loading branch information
jrvaldes committed Nov 6, 2023
1 parent 48f08a8 commit a367e19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
28 changes: 10 additions & 18 deletions test/e2e/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (tc *testContext) ensureTestRunnerSA() error {

// ensureTestRunnerRole ensures the proper Role exists, a requirement for SSHing into a Windows node
// noop if the Role already exists.
func (tc *testContext) ensureTestRunnerRole() error {
func (tc *testContext) ensureTestRunnerRole(ctx context.Context) error {
role := rbac.Role{
TypeMeta: meta.TypeMeta{},
ObjectMeta: meta.ObjectMeta{Name: tc.workloadNamespace},
Expand All @@ -325,7 +325,7 @@ func (tc *testContext) ensureTestRunnerRole() error {
},
},
}
_, err := tc.client.K8s.RbacV1().Roles(tc.workloadNamespace).Create(context.TODO(), &role, meta.CreateOptions{})
_, err := tc.client.K8s.RbacV1().Roles(tc.workloadNamespace).Create(ctx, &role, meta.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("unable to create role: %w", err)
}
Expand Down Expand Up @@ -358,7 +358,7 @@ func (tc *testContext) ensureTestRunnerClusterRole(ctx context.Context) error {

// ensureTestRunnerRoleBinding ensures the proper RoleBinding exists, a requirement for SSHing into a Windows node
// noop if the RoleBinding already exists.
func (tc *testContext) ensureTestRunnerRoleBinding() error {
func (tc *testContext) ensureTestRunnerRoleBinding(ctx context.Context) error {
rb := rbac.RoleBinding{
TypeMeta: meta.TypeMeta{},
ObjectMeta: meta.ObjectMeta{Name: tc.workloadNamespace},
Expand All @@ -374,7 +374,7 @@ func (tc *testContext) ensureTestRunnerRoleBinding() error {
Name: tc.workloadNamespace,
},
}
_, err := tc.client.K8s.RbacV1().RoleBindings(tc.workloadNamespace).Create(context.TODO(), &rb, meta.CreateOptions{})
_, err := tc.client.K8s.RbacV1().RoleBindings(tc.workloadNamespace).Create(ctx, &rb, meta.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("unable to create role: %w", err)
}
Expand Down Expand Up @@ -407,20 +407,6 @@ func (tc *testContext) ensureTestRunnerClusterRoleBinding(ctx context.Context) e
return nil
}

// sshSetup creates all the Kubernetes resources required to SSH into a Windows node
func (tc *testContext) sshSetup() error {
if err := tc.ensureTestRunnerSA(); err != nil {
return fmt.Errorf("error ensuring SA created: %w", err)
}
if err := tc.ensureTestRunnerRole(); err != nil {
return fmt.Errorf("error ensuring Role created: %w", err)
}
if err := tc.ensureTestRunnerRoleBinding(); err != nil {
return fmt.Errorf("error ensuring RoleBinding created: %w", err)
}
return nil
}

// ensureTestRunnerRBAC creates the RBAC resources required for the test runner service account
func (tc *testContext) ensureTestRunnerRBAC() error {
ctx := context.TODO()
Expand All @@ -433,6 +419,12 @@ func (tc *testContext) ensureTestRunnerRBAC() error {
if err := tc.ensureTestRunnerClusterRoleBinding(ctx); err != nil {
return fmt.Errorf("error ensuring RoleBinding created: %w", err)
}
if err := tc.ensureTestRunnerRole(ctx); err != nil {
return fmt.Errorf("error ensuring Role created: %w", err)
}
if err := tc.ensureTestRunnerRoleBinding(ctx); err != nil {
return fmt.Errorf("error ensuring RoleBinding created: %w", err)
}
return nil
}

Expand Down
1 change: 0 additions & 1 deletion test/e2e/wmco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestWMCO(t *testing.T) {
// Create the namespace test resources can be deployed in, as well as required resources within said namespace.
require.NoError(t, tc.ensureNamespace(tc.workloadNamespace, tc.workloadNamespaceLabels), "error creating test namespace")
require.NoError(t, tc.ensureTestRunnerRBAC(), "error creating test runner RBAC")
require.NoError(t, tc.sshSetup(), "unable to setup SSH requirements")

// When the upgrade test is run from CI, the namespace that gets created does not have the required monitoring
// label, so we ensure that it gets applied and the WMCO deployment is restarted.
Expand Down

0 comments on commit a367e19

Please sign in to comment.