@@ -14,12 +14,14 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17+ // Package controllers contains the Galera and MariaDB account controllers for the mariadb-operator.
1718package controllers
1819
1920import (
2021 "bytes"
2122 "context"
2223 "encoding/json"
24+ "errors"
2325 "fmt"
2426 "sort"
2527 "strconv"
@@ -63,16 +65,23 @@ import (
6365 "sigs.k8s.io/controller-runtime/pkg/reconcile"
6466
6567 topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
66- databasev1beta1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
6768 mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
6869 mariadb "github.com/openstack-k8s-operators/mariadb-operator/pkg/mariadb"
6970)
7071
7172// fields to index to reconcile on CR change
7273const (
73- serviceSecretNameField = ".spec.tls.genericService.SecretName"
74- caSecretNameField = ".spec.tls.ca.caBundleSecretName"
75- topologyField = ".spec.topologyRef.Name"
74+ // serviceSecretNameField specifies the field path for TLS service secret name
75+ serviceSecretNameField = ".spec.tls.genericService.SecretName" // #nosec G101 -- This is a field path, not a credential
76+ // caSecretNameField specifies the field path for CA bundle secret name
77+ caSecretNameField = ".spec.tls.ca.caBundleSecretName" // #nosec G101 -- This is a field path, not a credential
78+ topologyField = ".spec.topologyRef.Name"
79+ )
80+
81+ // Static errors
82+ var (
83+ // ErrOpenStackSecretNotFound indicates that the OpenStack secret was not found
84+ ErrOpenStackSecretNotFound = errors .New ("OpenStack secret not found" )
7685)
7786
7887var allWatchFields = []string {
@@ -574,7 +583,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
574583 condition .RequestedReason ,
575584 condition .SeverityInfo ,
576585 condition .InputReadyWaitingMessage ))
577- return res , fmt .Errorf ("OpenStack secret %s not found" , instance .Spec .Secret )
586+ return res , fmt .Errorf ("%w: %s" , ErrOpenStackSecretNotFound , instance .Spec .Secret )
578587 }
579588 instance .Status .Conditions .Set (condition .FalseCondition (
580589 condition .InputReadyCondition ,
@@ -605,7 +614,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
605614 condition .TLSInputReadyCondition ,
606615 condition .RequestedReason ,
607616 condition .SeverityInfo ,
608- fmt . Sprintf ( condition .TLSInputReadyWaitingMessage , instance .Spec .TLS .CaBundleSecretName ) ))
617+ condition .TLSInputReadyWaitingMessage , instance .Spec .TLS .CaBundleSecretName ))
609618 return ctrl.Result {}, nil
610619 }
611620 instance .Status .Conditions .Set (condition .FalseCondition (
@@ -631,7 +640,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
631640 condition .TLSInputReadyCondition ,
632641 condition .RequestedReason ,
633642 condition .SeverityInfo ,
634- fmt . Sprintf ( condition .TLSInputReadyWaitingMessage , err .Error () )))
643+ condition .TLSInputReadyWaitingMessage , err .Error ()))
635644 return ctrl.Result {}, nil
636645 }
637646 instance .Status .Conditions .Set (condition .FalseCondition (
@@ -662,7 +671,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
662671
663672 // build state of the restart hash. this is used to decide whether the
664673 // statefulset must stop all its pods before applying a config update
665- clusterPropertiesEnv ["GCommTLS" ] = env .SetValue (strconv .FormatBool (instance .Spec .TLS .Enabled () && instance .Spec .TLS .Ca . CaBundleSecretName != "" ))
674+ clusterPropertiesEnv ["GCommTLS" ] = env .SetValue (strconv .FormatBool (instance .Spec .TLS .Enabled () && instance .Spec .TLS .CaBundleSecretName != "" ))
666675 clusterPropertiesHash , err := util .HashOfInputHashes (clusterPropertiesEnv )
667676 if err != nil {
668677 return ctrl.Result {}, err
@@ -981,8 +990,8 @@ func (r *GaleraReconciler) SetupWithManager(mgr ctrl.Manager) error {
981990 // Extract the secret name from the spec, if one is provided
982991 cr := rawObj .(* mariadbv1.Galera )
983992 tls := & cr .Spec .TLS
984- if tls .Ca . CaBundleSecretName != "" {
985- return []string {tls .Ca . CaBundleSecretName }
993+ if tls .CaBundleSecretName != "" {
994+ return []string {tls .CaBundleSecretName }
986995 }
987996 return nil
988997 }); err != nil {
@@ -994,7 +1003,7 @@ func (r *GaleraReconciler) SetupWithManager(mgr ctrl.Manager) error {
9941003 cr := rawObj .(* mariadbv1.Galera )
9951004 tls := & cr .Spec .TLS
9961005 if tls .Enabled () {
997- return []string {* tls .GenericService . SecretName }
1006+ return []string {* tls .SecretName }
9981007 }
9991008 return nil
10001009 }); err != nil {
@@ -1036,8 +1045,8 @@ func (r *GaleraReconciler) SetupWithManager(mgr ctrl.Manager) error {
10361045// GetDatabaseObject - returns either a Galera or MariaDB object (and an associated client.Object interface).
10371046// used by both MariaDBDatabaseReconciler and MariaDBAccountReconciler
10381047// this will later return only Galera objects, so as a lookup it's part of the galera controller
1039- func GetDatabaseObject (ctx context.Context , clientObj client.Client , name string , namespace string ) (* databasev1beta1 .Galera , error ) {
1040- dbGalera := & databasev1beta1 .Galera {
1048+ func GetDatabaseObject (ctx context.Context , clientObj client.Client , name string , namespace string ) (* mariadbv1 .Galera , error ) {
1049+ dbGalera := & mariadbv1 .Galera {
10411050 ObjectMeta : metav1.ObjectMeta {
10421051 Name : name ,
10431052 Namespace : namespace ,
@@ -1089,7 +1098,7 @@ func (r *GaleraReconciler) findObjectsForSrc(ctx context.Context, src client.Obj
10891098 return requests
10901099}
10911100
1092- func (r * GaleraReconciler ) reconcileDelete (ctx context.Context , instance * databasev1beta1 .Galera , helper * helper.Helper ) (ctrl.Result , error ) {
1101+ func (r * GaleraReconciler ) reconcileDelete (ctx context.Context , instance * mariadbv1 .Galera , helper * helper.Helper ) (ctrl.Result , error ) {
10931102 helper .GetLogger ().Info ("Reconciling Service delete" )
10941103
10951104 // Remove our finalizer from the db svc
0 commit comments