@@ -14,10 +14,12 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17+ // Package controllers implements the horizon-operator Kubernetes controllers.
1718package controllers
1819
1920import (
2021 "context"
22+ "errors"
2123 "fmt"
2224 "net/url"
2325 "slices"
@@ -65,6 +67,12 @@ import (
6567 "sigs.k8s.io/controller-runtime/pkg/reconcile"
6668)
6769
70+ // Static errors for horizon controller
71+ var (
72+ ErrNoOpenstackSecret = errors .New ("no openstack secret has been provided" )
73+ ErrNetworkAttachmentConfig = errors .New ("not all pods have interfaces with ips as configured in NetworkAttachments" )
74+ )
75+
6876// GetClient -
6977func (r * HorizonReconciler ) GetClient () client.Client {
7078 return r .Client
@@ -130,7 +138,7 @@ func (r *HorizonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
130138
131139 // Fetch the Horizon instance
132140 instance := & horizonv1beta1.Horizon {}
133- err := r .Client . Get (ctx , req .NamespacedName , instance )
141+ err := r .Get (ctx , req .NamespacedName , instance )
134142 if err != nil {
135143 if k8s_errors .IsNotFound (err ) {
136144 return ctrl.Result {}, nil
@@ -224,7 +232,7 @@ func (r *HorizonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
224232const (
225233 passwordSecretField = ".spec.secret"
226234 tlsField = ".spec.tls.secretName"
227- caBundleSecretNameField = ".spec.tls.caBundleSecretName"
235+ caBundleSecretNameField = ".spec.tls.caBundleSecretName" // #nosec G101
228236 topologyField = ".spec.topologyRef.Name"
229237)
230238
@@ -299,7 +307,7 @@ func (r *HorizonReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
299307 listOpts := []client.ListOption {
300308 client .InNamespace (o .GetNamespace ()),
301309 }
302- if err := r .Client . List (context .Background (), horizons , listOpts ... ); err != nil {
310+ if err := r .List (context .Background (), horizons , listOpts ... ); err != nil {
303311 Log .Error (err , "Unable to retrieve Horizon CRs %w" )
304312 return nil
305313 }
@@ -329,7 +337,7 @@ func (r *HorizonReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
329337 listOpts := []client.ListOption {
330338 client .InNamespace (o .GetNamespace ()),
331339 }
332- if err := r .Client . List (context .Background (), horizonList , listOpts ... ); err != nil {
340+ if err := r .List (context .Background (), horizonList , listOpts ... ); err != nil {
333341 Log .Error (err , "Unable to retrieve Horizon CRs %w" )
334342 return nil
335343 }
@@ -358,7 +366,7 @@ func (r *HorizonReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
358366 listOpts := []client.ListOption {
359367 client .InNamespace (o .GetNamespace ()),
360368 }
361- if err := r .Client . List (context .Background (), horizonList , listOpts ... ); err != nil {
369+ if err := r .List (context .Background (), horizonList , listOpts ... ); err != nil {
362370 Log .Error (err , "Unable to retrieve Horizon CRs %w" )
363371 return nil
364372 }
@@ -419,7 +427,7 @@ func (r *HorizonReconciler) findObjectsForSrc(ctx context.Context, src client.Ob
419427 FieldSelector : fields .OneTermEqualSelector (field , src .GetName ()),
420428 Namespace : src .GetNamespace (),
421429 }
422- err := r .Client . List (ctx , crList , listOps )
430+ err := r .List (ctx , crList , listOps )
423431 if err != nil {
424432 Log .Error (err , fmt .Sprintf ("listing %s for field: %s - %s" , crList .GroupVersionKind ().Kind , field , src .GetNamespace ()))
425433 return requests
@@ -451,7 +459,7 @@ func (r *HorizonReconciler) findObjectForSrc(ctx context.Context, src client.Obj
451459 listOps := & client.ListOptions {
452460 Namespace : src .GetNamespace (),
453461 }
454- err := r .Client . List (ctx , crList , listOps )
462+ err := r .List (ctx , crList , listOps )
455463 if err != nil {
456464 Log .Error (err , fmt .Sprintf ("listing %s for namespace: %s" , crList .GroupVersionKind ().Kind , src .GetNamespace ()))
457465 return requests
@@ -663,9 +671,9 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz
663671 condition .InputReadyCondition ,
664672 missingDependenciesReason ,
665673 condition .SeverityInfo ,
666- missingDependenciesMessage ))
674+ "%s" , missingDependenciesMessage ))
667675
668- return ctrl.Result {}, fmt .Errorf ("no openstack secret has been provided. Unable to reconcile" )
676+ return ctrl.Result {}, fmt .Errorf ("%w: Unable to reconcile" , ErrNoOpenstackSecret )
669677 }
670678
671679 ospSecret , hash , err := oko_secret .GetSecret (ctx , helper , instance .Spec .Secret , instance .Namespace )
@@ -748,7 +756,7 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz
748756 condition .TLSInputReadyCondition ,
749757 condition .RequestedReason ,
750758 condition .SeverityInfo ,
751- fmt . Sprintf ( condition .TLSInputReadyWaitingMessage , instance .Spec .TLS .CaBundleSecretName ) ))
759+ condition .TLSInputReadyWaitingMessage , instance .Spec .TLS .CaBundleSecretName ))
752760 return ctrl.Result {}, nil
753761 }
754762 instance .Status .Conditions .Set (condition .FalseCondition (
@@ -774,7 +782,7 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz
774782 condition .TLSInputReadyCondition ,
775783 condition .RequestedReason ,
776784 condition .SeverityInfo ,
777- fmt . Sprintf ( condition .TLSInputReadyWaitingMessage , err .Error () )))
785+ condition .TLSInputReadyWaitingMessage , err .Error ()))
778786 return ctrl.Result {}, nil
779787 }
780788 instance .Status .Conditions .Set (condition .FalseCondition (
@@ -999,7 +1007,7 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz
9991007 if networkReady {
10001008 instance .Status .Conditions .MarkTrue (condition .NetworkAttachmentsReadyCondition , condition .NetworkAttachmentsReadyMessage )
10011009 } else {
1002- err := fmt .Errorf ("not all pods have interfaces with ips as configured in NetworkAttachments : %s" , instance .Spec .NetworkAttachments )
1010+ err := fmt .Errorf ("%w : %s" , ErrNetworkAttachmentConfig , instance .Spec .NetworkAttachments )
10031011 instance .Status .Conditions .Set (condition .FalseCondition (
10041012 condition .NetworkAttachmentsReadyCondition ,
10051013 condition .ErrorReason ,
0 commit comments