Skip to content

Commit a913281

Browse files
committed
remove new fixtures and use existing ones instead
1 parent 863e347 commit a913281

34 files changed

+162
-591
lines changed

controllers/om/automation_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func AuthSecretName(mdbName string) string {
448448
// EnsurePassword makes sure that there is an Automation Agent password
449449
// that the agents will use to communicate with the deployments. The password
450450
// is returned, so it can be provided to the other agents.
451-
func (ac *AutomationConfig) EnsurePassword(k8sClient secret.GetUpdateCreator, ctx context.Context, mdbNamespacedName *types.NamespacedName) (string, error) {
451+
func (ac *AutomationConfig) EnsurePassword(ctx context.Context, k8sClient secret.GetUpdateCreator, mdbNamespacedName types.NamespacedName) (string, error) {
452452
secretName := AuthSecretName(mdbNamespacedName.Name)
453453
secretNamespacedName := client.ObjectKey{Name: secretName, Namespace: mdbNamespacedName.Namespace}
454454
var password string

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(r.client, ctx, 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: 6 additions & 6 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(client kubernetesClient.Client, ctx context.Context, 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.
@@ -155,7 +155,7 @@ func Configure(client kubernetesClient.Client, ctx context.Context, mdbNamespace
155155

156156
// Disable disables all authentication mechanisms, and waits for the agents to reach goal state. It is still required to provide
157157
// automation agent username, password and keyfile contents to ensure a valid Automation Config.
158-
func Disable(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, deleteUsers bool, log *zap.SugaredLogger) error {
158+
func Disable(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, deleteUsers bool, log *zap.SugaredLogger) error {
159159
ac, err := conn.ReadAutomationConfig()
160160
if err != nil {
161161
return xerrors.Errorf("error reading automation config: %w", err)
@@ -185,7 +185,7 @@ func Disable(client kubernetesClient.Client, ctx context.Context, mdbNamespacedN
185185
if err := ac.EnsureKeyFileContents(); err != nil {
186186
return xerrors.Errorf("error ensuring keyfile contents: %w", err)
187187
}
188-
if _, err := ac.EnsurePassword(client, ctx, mdbNamespacedName); err != nil {
188+
if _, err := ac.EnsurePassword(ctx, client, mdbNamespacedName); err != nil {
189189
return xerrors.Errorf("error ensuring agent password: %w", err)
190190
}
191191

@@ -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(client kubernetesClient.Client, ctx context.Context, 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)
@@ -369,14 +369,14 @@ 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(client kubernetesClient.Client, ctx context.Context, 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
376376
}
377377

378378
log.Infof("Enabling %s agent authentication", mechanism.GetName())
379-
return mechanism.EnableAgentAuthentication(client, ctx, mdbNamespacedName, conn, opts, log)
379+
return mechanism.EnableAgentAuthentication(ctx, client, mdbNamespacedName, conn, opts, log)
380380
}
381381

382382
// ensureDeploymentMechanisms configures the given AutomationConfig to allow deployments to

controllers/operator/authentication/authentication_mechanism.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
// Mechanism is an interface that needs to be implemented for any Ops Manager authentication mechanism
1818
type Mechanism interface {
19-
EnableAgentAuthentication(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error
19+
EnableAgentAuthentication(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error
2020
DisableAgentAuthentication(conn om.Connection, log *zap.SugaredLogger) error
2121
EnableDeploymentAuthentication(conn om.Connection, opts Options, log *zap.SugaredLogger) error
2222
DisableDeploymentAuthentication(conn om.Connection, log *zap.SugaredLogger) error

controllers/operator/authentication/configure_authentication_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func init() {
2222
func TestConfigureScramSha256(t *testing.T) {
2323
ctx := context.Background()
2424
kubeClient, _ := mock.NewDefaultFakeClient()
25-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
25+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
2626

2727
dep := om.NewDeployment()
2828
conn := om.NewMockedOmConnection(dep)
@@ -50,7 +50,7 @@ func TestConfigureScramSha256(t *testing.T) {
5050
func TestConfigureX509(t *testing.T) {
5151
ctx := context.Background()
5252
kubeClient, _ := mock.NewDefaultFakeClient()
53-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
53+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
5454

5555
dep := om.NewDeployment()
5656
conn := om.NewMockedOmConnection(dep)
@@ -82,7 +82,7 @@ func TestConfigureX509(t *testing.T) {
8282
func TestConfigureScramSha1(t *testing.T) {
8383
ctx := context.Background()
8484
kubeClient, _ := mock.NewDefaultFakeClient()
85-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
85+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
8686

8787
dep := om.NewDeployment()
8888
conn := om.NewMockedOmConnection(dep)
@@ -108,7 +108,7 @@ func TestConfigureScramSha1(t *testing.T) {
108108
func TestConfigureMultipleAuthenticationMechanisms(t *testing.T) {
109109
ctx := context.Background()
110110
kubeClient, _ := mock.NewDefaultFakeClient()
111-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
111+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
112112

113113
dep := om.NewDeployment()
114114
conn := om.NewMockedOmConnection(dep)
@@ -145,7 +145,7 @@ func TestConfigureMultipleAuthenticationMechanisms(t *testing.T) {
145145
func TestDisableAuthentication(t *testing.T) {
146146
ctx := context.Background()
147147
kubeClient, _ := mock.NewDefaultFakeClient()
148-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
148+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
149149

150150
dep := om.NewDeployment()
151151
conn := om.NewMockedOmConnection(dep)
@@ -156,7 +156,7 @@ func TestDisableAuthentication(t *testing.T) {
156156
return nil
157157
}, zap.S())
158158

159-
if err := Disable(kubeClient, ctx, mdbNamespacedName, conn, Options{}, true, zap.S()); err != nil {
159+
if err := Disable(ctx, kubeClient, mdbNamespacedName, conn, Options{}, true, zap.S()); err != nil {
160160
t.Fatal(err)
161161
}
162162

@@ -237,9 +237,9 @@ func assertDeploymentMechanismsConfigured(t *testing.T, authMechanism Mechanism,
237237
func assertAgentAuthenticationDisabled(t *testing.T, authMechanism Mechanism, conn om.Connection, opts Options) {
238238
ctx := context.Background()
239239
kubeClient, _ := mock.NewDefaultFakeClient()
240-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
240+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
241241

242-
err := authMechanism.EnableAgentAuthentication(kubeClient, ctx, mdbNamespacedName, conn, opts, zap.S())
242+
err := authMechanism.EnableAgentAuthentication(ctx, kubeClient, mdbNamespacedName, conn, opts, zap.S())
243243
require.NoError(t, err)
244244

245245
ac, err := conn.ReadAutomationConfig()

controllers/operator/authentication/ldap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (l *ldapAuthMechanism) GetName() MechanismName {
1919
return LDAPPlain
2020
}
2121

22-
func (l *ldapAuthMechanism) EnableAgentAuthentication(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error {
22+
func (l *ldapAuthMechanism) EnableAgentAuthentication(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error {
2323
log.Info("Configuring LDAP authentication")
2424
err := conn.ReadUpdateAutomationConfig(func(ac *om.AutomationConfig) error {
2525
if err := ac.EnsureKeyFileContents(); err != nil {

controllers/operator/authentication/ldap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestLdapDeploymentMechanism(t *testing.T) {
5050
func TestLdapEnableAgentAuthentication(t *testing.T) {
5151
ctx := context.Background()
5252
kubeClient, _ := mock.NewDefaultFakeClient()
53-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
53+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
5454

5555
conn := om.NewMockedOmConnection(om.NewDeployment())
5656
opts := Options{
@@ -62,7 +62,7 @@ func TestLdapEnableAgentAuthentication(t *testing.T) {
6262
AutoPwd: "LDAPPassword.",
6363
}
6464

65-
err := ldapPlainMechanism.EnableAgentAuthentication(kubeClient, ctx, mdbNamespacedName, conn, opts, zap.S())
65+
err := ldapPlainMechanism.EnableAgentAuthentication(ctx, kubeClient, mdbNamespacedName, conn, opts, zap.S())
6666
require.NoError(t, err)
6767

6868
ac, err := conn.ReadAutomationConfig()

controllers/operator/authentication/oidc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (o *oidcAuthMechanism) GetName() MechanismName {
2323
return MongoDBOIDC
2424
}
2525

26-
func (o *oidcAuthMechanism) EnableAgentAuthentication(_ kubernetesClient.Client, _ context.Context, _ *types.NamespacedName, _ om.Connection, _ Options, _ *zap.SugaredLogger) error {
26+
func (o *oidcAuthMechanism) EnableAgentAuthentication(_ context.Context, _ kubernetesClient.Client, _ types.NamespacedName, _ om.Connection, _ Options, _ *zap.SugaredLogger) error {
2727
return xerrors.Errorf("OIDC agent authentication is not supported")
2828
}
2929

controllers/operator/authentication/oidc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestOIDC_EnableDeploymentAuthentication(t *testing.T) {
8282
func TestOIDC_EnableAgentAuthentication(t *testing.T) {
8383
ctx := context.Background()
8484
kubeClient, _ := mock.NewDefaultFakeClient()
85-
mdbNamespacedName := &types.NamespacedName{Namespace: "test", Name: "test"}
85+
mdbNamespacedName := types.NamespacedName{Namespace: "test", Name: "test"}
8686

8787
conn := om.NewMockedOmConnection(om.NewDeployment())
8888
opts := Options{
@@ -95,7 +95,7 @@ func TestOIDC_EnableAgentAuthentication(t *testing.T) {
9595
configured := mongoDBOIDCMechanism.IsAgentAuthenticationConfigured(ac, opts)
9696
assert.False(t, configured)
9797

98-
err = mongoDBOIDCMechanism.EnableAgentAuthentication(kubeClient, ctx, mdbNamespacedName, conn, opts, zap.S())
98+
err = mongoDBOIDCMechanism.EnableAgentAuthentication(ctx, kubeClient, mdbNamespacedName, conn, opts, zap.S())
9999
require.Error(t, err)
100100

101101
err = mongoDBOIDCMechanism.DisableAgentAuthentication(conn, zap.S())

controllers/operator/authentication/scramsha.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func (s *automationConfigScramSha) GetName() MechanismName {
2222
return s.MechanismName
2323
}
2424

25-
func (s *automationConfigScramSha) EnableAgentAuthentication(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error {
25+
func (s *automationConfigScramSha) EnableAgentAuthentication(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, conn om.Connection, opts Options, log *zap.SugaredLogger) error {
2626
return conn.ReadUpdateAutomationConfig(func(ac *om.AutomationConfig) error {
27-
if err := configureScramAgentUsers(client, ctx, mdbNamespacedName, ac, opts); err != nil {
27+
if err := configureScramAgentUsers(ctx, client, mdbNamespacedName, ac, opts); err != nil {
2828
return err
2929
}
3030
if err := ac.EnsureKeyFileContents(); err != nil {
@@ -95,8 +95,8 @@ func (s *automationConfigScramSha) IsDeploymentAuthenticationEnabled(ac *om.Auto
9595
}
9696

9797
// configureScramAgentUsers makes sure that the given automation config always has the correct SCRAM-SHA users
98-
func configureScramAgentUsers(client kubernetesClient.Client, ctx context.Context, mdbNamespacedName *types.NamespacedName, ac *om.AutomationConfig, authOpts Options) error {
99-
agentPassword, err := ac.EnsurePassword(client, ctx, mdbNamespacedName)
98+
func configureScramAgentUsers(ctx context.Context, client kubernetesClient.Client, mdbNamespacedName types.NamespacedName, ac *om.AutomationConfig, authOpts Options) error {
99+
agentPassword, err := ac.EnsurePassword(ctx, client, mdbNamespacedName)
100100
if err != nil {
101101
return err
102102
}

0 commit comments

Comments
 (0)