Skip to content

Commit 6d572dc

Browse files
committed
arg nit: ctx before client
1 parent 7032528 commit 6d572dc

File tree

6 files changed

+104
-106
lines changed

6 files changed

+104
-106
lines changed

controllers/operator/appdbreplicaset_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ func (r *ReconcileAppDbReplicaSet) tryConfigureMonitoringInOpsManager(ctx contex
16671667
AutoPEMKeyFilePath: agentCertPath,
16681668
CAFilePath: util.CAFilePathInContainer,
16691669
}
1670-
err = authentication.Configure(r.client, ctx, types.NamespacedName{Namespace: opsManager.Namespace, Name: opsManager.Name}, conn, opts, false, log)
1670+
err = authentication.Configure(ctx, r.client, types.NamespacedName{Namespace: opsManager.Namespace, Name: opsManager.Name}, conn, opts, false, log)
16711671
if err != nil {
16721672
log.Errorf("Could not set Automation Authentication options in Ops/Cloud Manager for the Application Database. "+
16731673
"Application Database is always configured with authentication enabled, but this will not be "+

controllers/operator/authentication/authentication.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type UserOptions struct {
8686

8787
// Configure will configure all the specified authentication Mechanisms. We need to ensure we wait for
8888
// the agents to reach ready state after each operation as prematurely updating the automation config can cause the agents to get stuck.
89-
func Configure(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, isRecovering bool, log *zap.SugaredLogger) error {
89+
func Configure(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, isRecovering bool, log *zap.SugaredLogger) error {
9090
log.Infow("ensuring correct deployment mechanisms", "ProcessNames", opts.ProcessNames, "Mechanisms", opts.Mechanisms)
9191

9292
// In case we're recovering, we can push all changes at once, because the mechanism is triggered after 20min by default.
@@ -117,7 +117,7 @@ func Configure(client kubernetesClient.Client, ctx context.Context, mdbNamespace
117117

118118
// once we have made sure that the deployment authentication mechanism array contains the desired auth mechanism
119119
// we can then configure the agent authentication.
120-
if err := enableAgentAuthentication(client, ctx, mdbNamespacedName, conn, opts, log); err != nil {
120+
if err := enableAgentAuthentication(ctx, client, mdbNamespacedName, conn, opts, log); err != nil {
121121
return xerrors.Errorf("error enabling agent authentication: %w", err)
122122
}
123123
if err := waitForReadyStateIfNeeded(); err != nil {
@@ -262,7 +262,7 @@ func removeUnsupportedAgentMechanisms(conn om.Connection, opts Options, log *zap
262262

263263
// enableAgentAuthentication determines which agent authentication mechanism should be configured
264264
// and enables it in Ops Manager
265-
func enableAgentAuthentication(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error {
265+
func enableAgentAuthentication(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error {
266266
ac, err := conn.ReadAutomationConfig()
267267
if err != nil {
268268
return xerrors.Errorf("error reading automation config: %w", err)
@@ -271,7 +271,7 @@ func enableAgentAuthentication(client kubernetesClient.Client, ctx context.Conte
271271
// we then configure the agent authentication for that type
272272
mechanism := convertToMechanismOrPanic(opts.AgentMechanism, ac)
273273

274-
if err := ensureAgentAuthenticationIsConfigured(client, ctx, mdbNamespacedName, conn, opts, ac, mechanism, log); err != nil {
274+
if err := ensureAgentAuthenticationIsConfigured(ctx, client, mdbNamespacedName, conn, opts, ac, mechanism, log); err != nil {
275275
return xerrors.Errorf("error ensuring agent authentication is configured: %w", err)
276276
}
277277

@@ -369,7 +369,7 @@ func addOrRemoveAgentClientCertificate(conn om.Connection, opts Options, log *za
369369
}
370370

371371
// ensureAgentAuthenticationIsConfigured will configure the agent authentication settings based on the desiredAgentAuthMechanism
372-
func ensureAgentAuthenticationIsConfigured(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, ac *om.AutomationConfig, mechanism Mechanism, log *zap.SugaredLogger) error {
372+
func ensureAgentAuthenticationIsConfigured(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, ac *om.AutomationConfig, mechanism Mechanism, log *zap.SugaredLogger) error {
373373
if mechanism.IsAgentAuthenticationConfigured(ac, opts) {
374374
log.Infof("Agent authentication mechanism %s is already configured", mechanism.GetName())
375375
return nil

controllers/operator/authentication/configure_authentication_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestConfigureScramSha256(t *testing.T) {
3434
AgentMechanism: "SCRAM",
3535
}
3636

37-
if err := Configure(kubeClient, ctx, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
37+
if err := Configure(ctx, kubeClient, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
3838
t.Fatal(err)
3939
}
4040

@@ -66,7 +66,7 @@ func TestConfigureX509(t *testing.T) {
6666
},
6767
}
6868

69-
if err := Configure(kubeClient, ctx, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
69+
if err := Configure(ctx, kubeClient, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
7070
t.Fatal(err)
7171
}
7272

@@ -94,7 +94,7 @@ func TestConfigureScramSha1(t *testing.T) {
9494
AgentMechanism: "SCRAM-SHA-1",
9595
}
9696

97-
if err := Configure(kubeClient, ctx, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
97+
if err := Configure(ctx, kubeClient, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
9898
t.Fatal(err)
9999
}
100100

@@ -123,7 +123,7 @@ func TestConfigureMultipleAuthenticationMechanisms(t *testing.T) {
123123
},
124124
}
125125

126-
if err := Configure(kubeClient, ctx, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
126+
if err := Configure(ctx, kubeClient, mdbNamespacedName, conn, opts, false, zap.S()); err != nil {
127127
t.Fatal(err)
128128
}
129129

controllers/operator/common_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context,
514514
authOpts.UserOptions = userOpts
515515
}
516516

517-
if err := authentication.Configure(r.client, ctx, types.NamespacedName{Namespace: ar.GetNamespace(), Name: ar.GetName()}, conn, authOpts, isRecovering, log); err != nil {
517+
if err := authentication.Configure(ctx, r.client, types.NamespacedName{Namespace: ar.GetNamespace(), Name: ar.GetName()}, conn, authOpts, isRecovering, log); err != nil {
518518
return workflow.Failed(err), false
519519
}
520520
} else if wantToEnableAuthentication {

docker/mongodb-kubernetes-tests/tests/authentication/sharded_cluster_scram_sha_1_switch_project.py

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,38 @@ def test_ops_manager_state_correctly_updated_in_initial_sharded_cluster(
6060
):
6161
test_helper.test_ops_manager_state_with_expected_authentication(0)
6262

63-
# def test_create_secret(self):
64-
# create_or_update_secret(
65-
# KubernetesTester.get_namespace(),
66-
# self.PASSWORD_SECRET_NAME,
67-
# {
68-
# "password": self.USER_PASSWORD,
69-
# },
70-
# )
71-
72-
# def test_create_user(self, namespace: str):
73-
# mdb = MongoDBUser.from_yaml(
74-
# load_fixture("scram-sha-user.yaml"),
75-
# namespace=namespace,
76-
# )
77-
# mdb["spec"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
78-
79-
# mdb.update()
80-
# mdb.assert_reaches_phase(Phase.Updated, timeout=150)
81-
82-
# def test_ops_manager_state_with_users_correctly_updated(
83-
# self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
84-
# ):
85-
# user_name = "mms-user-1"
86-
# expected_roles = {
87-
# ("admin", "clusterAdmin"),
88-
# ("admin", "userAdminAnyDatabase"),
89-
# ("admin", "readWrite"),
90-
# ("admin", "userAdminAnyDatabase"),
91-
# }
92-
# test_helper.test_ops_manager_state_with_users(
93-
# user_name=user_name, expected_roles=expected_roles, expected_users=1
94-
# )
63+
def test_create_secret(self):
64+
create_or_update_secret(
65+
KubernetesTester.get_namespace(),
66+
self.PASSWORD_SECRET_NAME,
67+
{
68+
"password": self.USER_PASSWORD,
69+
},
70+
)
71+
72+
def test_create_user(self, namespace: str):
73+
mdb = MongoDBUser.from_yaml(
74+
load_fixture("scram-sha-user.yaml"),
75+
namespace=namespace,
76+
)
77+
mdb["spec"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
78+
79+
mdb.update()
80+
mdb.assert_reaches_phase(Phase.Updated, timeout=150)
81+
82+
def test_ops_manager_state_with_users_correctly_updated(
83+
self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
84+
):
85+
user_name = "mms-user-1"
86+
expected_roles = {
87+
("admin", "clusterAdmin"),
88+
("admin", "userAdminAnyDatabase"),
89+
("admin", "readWrite"),
90+
("admin", "userAdminAnyDatabase"),
91+
}
92+
test_helper.test_ops_manager_state_with_users(
93+
user_name=user_name, expected_roles=expected_roles, expected_users=1
94+
)
9595

9696
def test_switch_sharded_cluster_project(self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper):
9797
test_helper.test_switch_sharded_cluster_project()
@@ -104,19 +104,18 @@ def test_sharded_cluster_connectivity_after_switch(
104104
def test_ops_manager_state_correctly_updated_after_switch(
105105
self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
106106
):
107-
test_helper.test_ops_manager_state_with_expected_authentication(expected_users=0)
108-
109-
# def test_ops_manager_state_with_users_correctly_updated_after_switch(
110-
# self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
111-
# ):
112-
# user_name = "mms-user-1"
113-
# expected_roles = {
114-
# ("admin", "clusterAdmin"),
115-
# ("admin", "userAdminAnyDatabase"),
116-
# ("admin", "readWrite"),
117-
# ("admin", "userAdminAnyDatabase"),
118-
# }
119-
# test_helper.test_ops_manager_state_with_users(
120-
# user_name=user_name, expected_roles=expected_roles, expected_users=1
121-
# )
122-
# There should be one user (the previously created user should still exist in the automation configuration). We need to investigate further to understand why the user is not being picked up.
107+
test_helper.test_ops_manager_state_with_expected_authentication(expected_users=1)
108+
109+
def test_ops_manager_state_with_users_correctly_updated_after_switch(
110+
self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
111+
):
112+
user_name = "mms-user-1"
113+
expected_roles = {
114+
("admin", "clusterAdmin"),
115+
("admin", "userAdminAnyDatabase"),
116+
("admin", "readWrite"),
117+
("admin", "userAdminAnyDatabase"),
118+
}
119+
test_helper.test_ops_manager_state_with_users(
120+
user_name=user_name, expected_roles=expected_roles, expected_users=1
121+
)

docker/mongodb-kubernetes-tests/tests/authentication/sharded_cluster_scram_sha_256_switch_project.py

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,38 @@ def test_ops_manager_state_correctly_updated_in_initial_sharded_cluster(
6060
):
6161
test_helper.test_ops_manager_state_with_expected_authentication(0)
6262

63-
# def test_create_secret(self):
64-
# create_or_update_secret(
65-
# KubernetesTester.get_namespace(),
66-
# self.PASSWORD_SECRET_NAME,
67-
# {
68-
# "password": self.USER_PASSWORD,
69-
# },
70-
# )
71-
72-
# def test_create_user(self, namespace: str):
73-
# mdb = MongoDBUser.from_yaml(
74-
# load_fixture("scram-sha-user.yaml"),
75-
# namespace=namespace,
76-
# )
77-
# mdb["spec"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
78-
79-
# mdb.update()
80-
# mdb.assert_reaches_phase(Phase.Updated, timeout=150)
81-
82-
# def test_ops_manager_state_with_users_correctly_updated(
83-
# self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
84-
# ):
85-
# user_name = "mms-user-1"
86-
# expected_roles = {
87-
# ("admin", "clusterAdmin"),
88-
# ("admin", "userAdminAnyDatabase"),
89-
# ("admin", "readWrite"),
90-
# ("admin", "userAdminAnyDatabase"),
91-
# }
92-
# test_helper.test_ops_manager_state_with_users(
93-
# user_name=user_name, expected_roles=expected_roles, expected_users=1
94-
# )
63+
def test_create_secret(self):
64+
create_or_update_secret(
65+
KubernetesTester.get_namespace(),
66+
self.PASSWORD_SECRET_NAME,
67+
{
68+
"password": self.USER_PASSWORD,
69+
},
70+
)
71+
72+
def test_create_user(self, namespace: str):
73+
mdb = MongoDBUser.from_yaml(
74+
load_fixture("scram-sha-user.yaml"),
75+
namespace=namespace,
76+
)
77+
mdb["spec"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
78+
79+
mdb.update()
80+
mdb.assert_reaches_phase(Phase.Updated, timeout=150)
81+
82+
def test_ops_manager_state_with_users_correctly_updated(
83+
self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
84+
):
85+
user_name = "mms-user-1"
86+
expected_roles = {
87+
("admin", "clusterAdmin"),
88+
("admin", "userAdminAnyDatabase"),
89+
("admin", "readWrite"),
90+
("admin", "userAdminAnyDatabase"),
91+
}
92+
test_helper.test_ops_manager_state_with_users(
93+
user_name=user_name, expected_roles=expected_roles, expected_users=1
94+
)
9595

9696
def test_switch_sharded_cluster_project(self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper):
9797
test_helper.test_switch_sharded_cluster_project()
@@ -104,19 +104,18 @@ def test_sharded_cluster_connectivity_after_switch(
104104
def test_ops_manager_state_correctly_updated_after_switch(
105105
self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
106106
):
107-
test_helper.test_ops_manager_state_with_expected_authentication(0)
107+
test_helper.test_ops_manager_state_with_expected_authentication(expected_users=1)
108108

109-
# def test_ops_manager_state_with_users_correctly_updated_after_switch(
110-
# self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
111-
# ):
112-
# user_name = "mms-user-1"
113-
# expected_roles = {
114-
# ("admin", "clusterAdmin"),
115-
# ("admin", "userAdminAnyDatabase"),
116-
# ("admin", "readWrite"),
117-
# ("admin", "userAdminAnyDatabase"),
118-
# }
119-
# test_helper.test_ops_manager_state_with_users(
120-
# user_name=user_name, expected_roles=expected_roles, expected_users=1
121-
# )
122-
# There should be one user (the previously created user should still exist in the automation configuration). We need to investigate further to understand why the user is not being picked up.
109+
def test_ops_manager_state_with_users_correctly_updated_after_switch(
110+
self, test_helper: ShardedClusterCreationAndProjectSwitchTestHelper
111+
):
112+
user_name = "mms-user-1"
113+
expected_roles = {
114+
("admin", "clusterAdmin"),
115+
("admin", "userAdminAnyDatabase"),
116+
("admin", "readWrite"),
117+
("admin", "userAdminAnyDatabase"),
118+
}
119+
test_helper.test_ops_manager_state_with_users(
120+
user_name=user_name, expected_roles=expected_roles, expected_users=1
121+
)

0 commit comments

Comments
 (0)