Skip to content

Commit e7d4a42

Browse files
committed
Remove double negations by turning IsDexDisabled into DexEnabled
1 parent 928020e commit e7d4a42

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

pkg/controller/apiserver/apiserver_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (r *ReconcileAPIServer) Reconcile(ctx context.Context, request reconcile.Re
377377
}
378378

379379
if authenticationCR != nil && authenticationCR.Status.State == operatorv1.TigeraStatusReady {
380-
if !utils.IsDexDisabled(authenticationCR) {
380+
if utils.DexEnabled(authenticationCR) {
381381
// Do not include DEX TLS Secret Name if authentication CR does not have type Dex
382382
secret := render.DexTLSSecretName
383383
certificate, err := certificateManager.GetCertificate(r.client, secret, common.OperatorNamespace())

pkg/controller/authentication/authentication_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2024 Tigera, Inc. All rights reserved.
1+
// Copyright (c) 2025 Tigera, Inc. All rights reserved.
22

33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -383,7 +383,7 @@ func (r *ReconcileAuthentication) Reconcile(ctx context.Context, request reconci
383383
}
384384
r.lastAvailabilityTransition = currentAvailabilityTransition
385385

386-
disableDex := utils.IsDexDisabled(authentication)
386+
enableDex := utils.DexEnabled(authentication)
387387

388388
// DexConfig adds convenience methods around dex related objects in k8s and can be used to configure Dex.
389389
dexCfg := render.NewDexConfig(install.CertificateManagement, authentication, dexSecret, idpSecret, r.clusterDomain)
@@ -397,7 +397,7 @@ func (r *ReconcileAuthentication) Reconcile(ctx context.Context, request reconci
397397
Installation: install,
398398
DexConfig: dexCfg,
399399
ClusterDomain: r.clusterDomain,
400-
DeleteDex: disableDex,
400+
DeleteDex: !enableDex,
401401
TLSKeyPair: tlsKeyPair,
402402
TrustedBundle: trustedBundle,
403403
Authentication: authentication,
@@ -415,7 +415,7 @@ func (r *ReconcileAuthentication) Reconcile(ctx context.Context, request reconci
415415

416416
components := []render.Component{component}
417417

418-
if !disableDex {
418+
if enableDex {
419419
components = append(components,
420420
rcertificatemanagement.CertificateManagement(&rcertificatemanagement.Config{
421421
Namespace: render.DexNamespace,

pkg/controller/manager/manager_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2024 Tigera, Inc. All rights reserved.
1+
// Copyright (c) 2025 Tigera, Inc. All rights reserved.
22

33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -462,8 +462,7 @@ func (r *ReconcileManager) Reconcile(ctx context.Context, request reconcile.Requ
462462
if authenticationCR != nil && authenticationCR.Status.State != operatorv1.TigeraStatusReady {
463463
r.status.SetDegraded(operatorv1.ResourceNotReady, fmt.Sprintf("Authentication is not ready authenticationCR status: %s", authenticationCR.Status.State), nil, logc)
464464
return reconcile.Result{}, nil
465-
} else if authenticationCR != nil && !utils.IsDexDisabled(authenticationCR) {
466-
// Do not include DEX TLS Secret Name is authentication CR does not have type Dex
465+
} else if utils.DexEnabled(authenticationCR) {
467466
trustedSecretNames = append(trustedSecretNames, render.DexTLSSecretName)
468467
}
469468

pkg/controller/utils/utils.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2024 Tigera, Inc. All rights reserved.
1+
// Copyright (c) 2025 Tigera, Inc. All rights reserved.
22

33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -896,12 +896,12 @@ func compareMap(m1, m2 map[string]string) bool {
896896
return true
897897
}
898898

899-
func IsDexDisabled(authentication *operatorv1.Authentication) bool {
900-
disableDex := false
901-
if authentication.Spec.OIDC != nil && authentication.Spec.OIDC.Type == operatorv1.OIDCTypeTigera {
902-
disableDex = true
899+
func DexEnabled(authentication *operatorv1.Authentication) bool {
900+
enableDex := authentication != nil
901+
if enableDex && authentication.Spec.OIDC != nil && authentication.Spec.OIDC.Type == operatorv1.OIDCTypeTigera {
902+
enableDex = false
903903
}
904-
return disableDex
904+
return enableDex
905905
}
906906

907907
func VerifySysctl(pluginData []operatorv1.Sysctl) error {

pkg/controller/utils/utils_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021-2024 Tigera, Inc. All rights reserved.
1+
// Copyright (c) 2025 Tigera, Inc. All rights reserved.
22

33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -433,4 +433,17 @@ var _ = Describe("CreatePredicateForObject", func() {
433433
Expect(p.Delete(event.DeleteEvent{Object: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "other-object", Namespace: "test-namespace"}}})).To(BeFalse())
434434
})
435435
})
436+
437+
DescribeTable("should correctly determine whether Dex is enabled",
438+
func(authentication *opv1.Authentication, expectedResult bool) {
439+
Expect(DexEnabled(authentication)).To(Equal(expectedResult))
440+
},
441+
Entry("when authentication is nil", nil, false),
442+
Entry("when authentication is not nil and OIDC is nil",
443+
&opv1.Authentication{Spec: opv1.AuthenticationSpec{OIDC: nil}}, true),
444+
Entry("when authentication is not nil and OIDC type is OIDCTypeTigera",
445+
&opv1.Authentication{Spec: opv1.AuthenticationSpec{OIDC: &opv1.AuthenticationOIDC{Type: opv1.OIDCTypeTigera}}}, false),
446+
Entry("when authentication is not nil and OIDC type is different",
447+
&opv1.Authentication{Spec: opv1.AuthenticationSpec{OIDC: &opv1.AuthenticationOIDC{Type: opv1.OIDCTypeDex}}}, true),
448+
)
436449
})

0 commit comments

Comments
 (0)