Skip to content

Commit 2b8bd6b

Browse files
committed
fix golangci reported issues
Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent 066246f commit 2b8bd6b

6 files changed

Lines changed: 28 additions & 17 deletions

File tree

controllers/horizon_controller.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package controllers implements the horizon-operator Kubernetes controllers.
1718
package controllers
1819

1920
import (
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 -
6977
func (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
224232
const (
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,

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package main implements the horizon-operator controller manager.
1718
package main
1819

1920
import (

pkg/horizon/const.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16+
// Package horizon contains horizon service constants and configuration.
1617
package horizon
1718

1819
import (
@@ -62,6 +63,7 @@ const (
6263
// logVolume -
6364
logVolume = "logs"
6465

66+
// DefaultsConfigFileName - Default configuration file name
6567
DefaultsConfigFileName = "00-config.conf"
6668
// ServiceConfigFileName - Represents service config generated in the operator
6769
ServiceConfigFileName = "01-config.conf"
@@ -71,7 +73,7 @@ const (
7173
CustomServiceConfigFileName = "03-config.conf"
7274
// CustomServiceConfigSecretsFileName - Snippet generated by Secrets passed
7375
// to the sub CR
74-
CustomServiceConfigSecretsFileName = "04-config.conf"
76+
CustomServiceConfigSecretsFileName = "04-config.conf" // #nosec G101
7577
)
7678

7779
// HorizonPropagation is the definition of the Horizon propagation service

pkg/horizon/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (t *TLSRequiredOptions) formatTLSOptions(instance *horizonv1.Horizon) error
215215
var err error
216216
var svc *tls.Service
217217

218-
svc, err = instance.Spec.TLS.GenericService.ToService()
218+
svc, err = instance.Spec.TLS.ToService()
219219
if err != nil {
220220
return err
221221
}

pkg/horizon/deployment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type testCase struct {
2020

2121
func TestFormatTLSOptions(t *testing.T) {
2222

23-
var tlsSecretName = "generic-tls-secret"
23+
var tlsSecretName = "generic-tls-secret" // #nosec G101
2424
var defaultMode int32 = 256
2525
testCases := []testCase{
2626
{

tests/functional/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ const (
7777

7878
interval = time.Millisecond * 200
7979

80-
InternalCertSecretName = "horizon-tls-certs"
80+
InternalCertSecretName = "horizon-tls-certs" // #nosec G101
8181

82-
CABundleSecretName = "combined-ca-bundle"
82+
CABundleSecretName = "combined-ca-bundle" // #nosec G101
8383
)
8484

8585
func TestAPIs(t *testing.T) {

0 commit comments

Comments
 (0)