Skip to content

Commit d9ecdf3

Browse files
committed
fix golangci reported issues
Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent 65f3256 commit d9ecdf3

27 files changed

Lines changed: 213 additions & 126 deletions

controllers/amphoracontroller_controller.go

Lines changed: 11 additions & 11 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 controllers contains the Kubernetes controllers for managing Octavia operator resources
1718
package controllers
1819

1920
import (
@@ -99,7 +100,7 @@ func (r *OctaviaAmphoraControllerReconciler) Reconcile(ctx context.Context, req
99100
Log := r.GetLogger(ctx)
100101

101102
instance := &octaviav1.OctaviaAmphoraController{}
102-
err := r.Client.Get(ctx, req.NamespacedName, instance)
103+
err := r.Get(ctx, req.NamespacedName, instance)
103104
if err != nil {
104105
if k8s_errors.IsNotFound(err) {
105106
// Request object not found, could have been deleted after reconcile request.
@@ -244,7 +245,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
244245
// Prepare NetworkAttachments first, it must be done before generating the
245246
// configuration as the config uses IP addresses of the attachments.
246247
if len(instance.Spec.NetworkAttachments) == 0 {
247-
err := fmt.Errorf("NetworkAttachments list is empty")
248+
err := octavia.ErrNetworkAttachmentsEmpty
248249
instance.Status.Conditions.Set(condition.FalseCondition(
249250
condition.NetworkAttachmentsReadyCondition,
250251
condition.ErrorReason,
@@ -289,7 +290,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
289290
}
290291

291292
serviceLabels := map[string]string{
292-
common.AppSelector: instance.ObjectMeta.Name,
293+
common.AppSelector: instance.Name,
293294
}
294295

295296
// Handle secrets
@@ -323,7 +324,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
323324
condition.TLSInputReadyCondition,
324325
condition.RequestedReason,
325326
condition.SeverityInfo,
326-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
327+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
327328
return ctrl.Result{}, nil
328329
}
329330
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -407,7 +408,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
407408
instance.Name, // finalizer
408409
&instance.Status.Conditions,
409410
labels.GetAppLabelSelector(
410-
instance.ObjectMeta.Name,
411+
instance.Name,
411412
),
412413
)
413414
if err != nil {
@@ -475,7 +476,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
475476
if networkReady {
476477
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
477478
} else {
478-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
479+
err := fmt.Errorf("%w: %s", octavia.ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
479480
instance.Status.Conditions.Set(condition.FalseCondition(
480481
condition.NetworkAttachmentsReadyCondition,
481482
condition.ErrorReason,
@@ -512,7 +513,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceSecrets(
512513
) error {
513514
Log := r.GetLogger(ctx)
514515
Log.Info(fmt.Sprintf("generating service secret for %s (%s)", instance.Name, instance.Kind))
515-
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})
516+
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.Name), map[string]string{})
516517

517518
ospSecret, _, err := oko_secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace)
518519
if err != nil {
@@ -647,8 +648,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceSecrets(
647648
condition.RequestedReason,
648649
condition.SeverityInfo,
649650
condition.InputReadyWaitingMessage))
650-
return fmt.Errorf("OpenStack server CA passphrase secret %s not found",
651-
serverCAPassSecretName)
651+
return fmt.Errorf("%w: %s", octavia.ErrOpenstackServerCAPassphraseNotFound, serverCAPassSecretName)
652652
}
653653
instance.Status.Conditions.Set(condition.FalseCondition(
654654
condition.InputReadyCondition,
@@ -874,7 +874,7 @@ func (r *OctaviaAmphoraControllerReconciler) findObjectsForSrc(ctx context.Conte
874874
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
875875
Namespace: src.GetNamespace(),
876876
}
877-
err := r.Client.List(ctx, crList, listOps)
877+
err := r.List(ctx, crList, listOps)
878878
if err != nil {
879879
Log.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace()))
880880
return requests
@@ -906,7 +906,7 @@ func (r *OctaviaAmphoraControllerReconciler) findObjectForSrc(ctx context.Contex
906906
listOps := &client.ListOptions{
907907
Namespace: src.GetNamespace(),
908908
}
909-
err := r.Client.List(ctx, crList, listOps)
909+
err := r.List(ctx, crList, listOps)
910910
if err != nil {
911911
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
912912
return requests

controllers/octavia_controller.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (r *OctaviaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
123123

124124
// Fetch the Octavia instance
125125
instance := &octaviav1.Octavia{}
126-
err := r.Client.Get(ctx, req.NamespacedName, instance)
126+
err := r.Get(ctx, req.NamespacedName, instance)
127127
if err != nil {
128128
if k8s_errors.IsNotFound(err) {
129129
// Request object not found, could have been deleted after reconcile request.
@@ -236,7 +236,7 @@ func (r *OctaviaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
236236
// fields to index to reconcile when change
237237
const (
238238
passwordSecretField = ".spec.secret"
239-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
239+
caBundleSecretNameField = ".spec.tls.caBundleSecretName" // #nosec G101 -- Field path, not a credential
240240
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
241241
tlsAPIPublicField = ".spec.tls.api.public.secretName"
242242
tlsOvnField = ".spec.tls.ovn.secretName"
@@ -787,7 +787,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
787787
ObjectMeta: metav1.ObjectMeta{
788788
Name: octavia.HmConfigMap,
789789
Namespace: instance.GetNamespace(),
790-
Labels: labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{}),
790+
Labels: labels.GetLabels(instance, labels.GetGroupLabel(instance.Name), map[string]string{}),
791791
},
792792
Data: make(map[string]string),
793793
}
@@ -877,7 +877,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
877877
updatedMap[portName] = hmPort
878878
}
879879

880-
mapLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})
880+
mapLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.Name), map[string]string{})
881881
_, err = controllerutil.CreateOrPatch(ctx, helper.GetClient(), nodeConfigMap, func() error {
882882
nodeConfigMap.Labels = util.MergeStringMaps(nodeConfigMap.Labels, mapLabels)
883883
nodeConfigMap.Data = updatedMap
@@ -920,7 +920,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
920920
instance.Status.Conditions.Set(condition.UnknownCondition(
921921
amphoraControllerReadyCondition(octaviav1.HealthManager),
922922
condition.InitReason,
923-
amphoraControllerErrorMessage(octaviav1.HealthManager),
923+
"%s", amphoraControllerErrorMessage(octaviav1.HealthManager),
924924
))
925925
} else {
926926
instance.Status.OctaviaHealthManagerReadyCount = octaviaHealthManager.Status.ReadyCount
@@ -956,7 +956,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
956956
instance.Status.Conditions.Set(condition.UnknownCondition(
957957
amphoraControllerReadyCondition(octaviav1.Worker),
958958
condition.InitReason,
959-
amphoraControllerErrorMessage(octaviav1.Worker),
959+
"%s", amphoraControllerErrorMessage(octaviav1.Worker),
960960
))
961961
} else {
962962
instance.Status.OctaviaRsyslogReadyCount = octaviaRsyslog.Status.ReadyCount
@@ -985,7 +985,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
985985
instance.Status.Conditions.Set(condition.UnknownCondition(
986986
amphoraControllerReadyCondition(octaviav1.Housekeeping),
987987
condition.InitReason,
988-
amphoraControllerErrorMessage(octaviav1.Housekeeping),
988+
"%s", amphoraControllerErrorMessage(octaviav1.Housekeeping),
989989
))
990990
} else {
991991
instance.Status.OctaviaHousekeepingReadyCount = octaviaHousekeeping.Status.ReadyCount
@@ -1014,7 +1014,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
10141014
instance.Status.Conditions.Set(condition.UnknownCondition(
10151015
amphoraControllerReadyCondition(octaviav1.Worker),
10161016
condition.InitReason,
1017-
amphoraControllerErrorMessage(octaviav1.Worker),
1017+
"%s", amphoraControllerErrorMessage(octaviav1.Worker),
10181018
))
10191019
} else {
10201020
instance.Status.OctaviaWorkerReadyCount = octaviaWorker.Status.ReadyCount
@@ -1380,11 +1380,11 @@ func (r *OctaviaReconciler) getLocalImageURLs(
13801380
// Get the list of images and their hashes
13811381
listURL := fmt.Sprintf("%s/octavia-amphora-image.sha256sum", endpoint)
13821382

1383-
resp, err := http.Get(listURL)
1383+
resp, err := http.Get(listURL) // #nosec G107 -- URL is constructed from trusted configuration parameter
13841384
if err != nil {
13851385
return nil, err
13861386
}
1387-
defer resp.Body.Close()
1387+
defer func() { _ = resp.Body.Close() }()
13881388
scanner := bufio.NewScanner(resp.Body)
13891389
ret := []octavia.AmphoraImage{}
13901390
for scanner.Scan() {
@@ -1421,7 +1421,7 @@ func (r *OctaviaReconciler) generateServiceSecrets(
14211421
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(octavia.ServiceName), map[string]string{})
14221422

14231423
var tlsCfg *tls.Service
1424-
if instance.Spec.OctaviaAPI.TLS.Ca.CaBundleSecretName != "" {
1424+
if instance.Spec.OctaviaAPI.TLS.CaBundleSecretName != "" {
14251425
tlsCfg = &tls.Service{}
14261426
}
14271427

@@ -1743,7 +1743,7 @@ func (r *OctaviaReconciler) checkOctaviaAPIGeneration(
17431743
listOpts := []client.ListOption{
17441744
client.InNamespace(instance.Namespace),
17451745
}
1746-
if err := r.Client.List(context.Background(), api, listOpts...); err != nil {
1746+
if err := r.List(context.Background(), api, listOpts...); err != nil {
17471747
Log.Error(err, "Unable to retrieve OctaviaAPI %w")
17481748
return false, err
17491749
}
@@ -1765,7 +1765,7 @@ func (r *OctaviaReconciler) checkAmphoraGeneration(
17651765
listOpts := []client.ListOption{
17661766
client.InNamespace(instance.Namespace),
17671767
}
1768-
if err := r.Client.List(context.Background(), amph, listOpts...); err != nil {
1768+
if err := r.List(context.Background(), amph, listOpts...); err != nil {
17691769
Log.Error(err, "Unable to retrieve OctaviaAPI %w")
17701770
return false, err
17711771
}

controllers/octaviaapi_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (r *OctaviaAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request)
108108

109109
// Fetch the OctaviaAPI instance
110110
instance := &octaviav1.OctaviaAPI{}
111-
err := r.Client.Get(ctx, req.NamespacedName, instance)
111+
err := r.Get(ctx, req.NamespacedName, instance)
112112
if err != nil {
113113
if k8s_errors.IsNotFound(err) {
114114
// Request object not found, could have been deleted after reconcile request.
@@ -324,7 +324,7 @@ func (r *OctaviaAPIReconciler) findObjectsForSrc(ctx context.Context, src client
324324
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
325325
Namespace: src.GetNamespace(),
326326
}
327-
err := r.Client.List(ctx, crList, listOps)
327+
err := r.List(ctx, crList, listOps)
328328
if err != nil {
329329
Log.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace()))
330330
return requests
@@ -356,7 +356,7 @@ func (r *OctaviaAPIReconciler) findObjectForSrc(ctx context.Context, src client.
356356
listOps := &client.ListOptions{
357357
Namespace: src.GetNamespace(),
358358
}
359-
err := r.Client.List(ctx, crList, listOps)
359+
err := r.List(ctx, crList, listOps)
360360
if err != nil {
361361
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
362362
return requests
@@ -657,7 +657,7 @@ func (r *OctaviaAPIReconciler) reconcileNormal(ctx context.Context, instance *oc
657657
condition.TLSInputReadyCondition,
658658
condition.RequestedReason,
659659
condition.SeverityInfo,
660-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
660+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
661661
return ctrl.Result{}, nil
662662
}
663663
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -681,7 +681,7 @@ func (r *OctaviaAPIReconciler) reconcileNormal(ctx context.Context, instance *oc
681681
condition.TLSInputReadyCondition,
682682
condition.RequestedReason,
683683
condition.SeverityInfo,
684-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
684+
condition.TLSInputReadyWaitingMessage, err.Error()))
685685
return ctrl.Result{}, nil
686686
}
687687
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -884,7 +884,7 @@ func (r *OctaviaAPIReconciler) reconcileNormal(ctx context.Context, instance *oc
884884
if networkReady {
885885
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
886886
} else {
887-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
887+
err := fmt.Errorf("%w: %s", octavia.ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
888888
instance.Status.Conditions.Set(condition.FalseCondition(
889889
condition.NetworkAttachmentsReadyCondition,
890890
condition.ErrorReason,

controllers/octaviarsyslog_controller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
4040
oko_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
4141
octaviav1 "github.com/openstack-k8s-operators/octavia-operator/api/v1beta1"
42+
"github.com/openstack-k8s-operators/octavia-operator/pkg/octavia"
4243
"github.com/openstack-k8s-operators/octavia-operator/pkg/octaviarsyslog"
4344
appsv1 "k8s.io/api/apps/v1"
4445
corev1 "k8s.io/api/core/v1"
@@ -82,7 +83,7 @@ func (r *OctaviaRsyslogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
8283
Log := r.GetLogger(ctx)
8384

8485
instance := &octaviav1.OctaviaRsyslog{}
85-
err := r.Client.Get(ctx, req.NamespacedName, instance)
86+
err := r.Get(ctx, req.NamespacedName, instance)
8687
if err != nil {
8788
if k8s_errors.IsNotFound(err) {
8889
// Request object not found, could have been deleted after reconcile request.
@@ -221,7 +222,7 @@ func (r *OctaviaRsyslogReconciler) reconcileNormal(ctx context.Context, instance
221222
// Prepare NetworkAttachments first, it must be done before generating the
222223
// configuration as the config uses IP addresses of the attachments.
223224
if len(instance.Spec.NetworkAttachments) == 0 {
224-
err := fmt.Errorf("NetworkAttachments list is empty")
225+
err := octavia.ErrNetworkAttachmentsEmpty
225226
instance.Status.Conditions.Set(condition.FalseCondition(
226227
condition.NetworkAttachmentsReadyCondition,
227228
condition.ErrorReason,
@@ -266,7 +267,7 @@ func (r *OctaviaRsyslogReconciler) reconcileNormal(ctx context.Context, instance
266267
}
267268

268269
serviceLabels := map[string]string{
269-
common.AppSelector: instance.ObjectMeta.Name,
270+
common.AppSelector: instance.Name,
270271
}
271272

272273
// Handle secrets
@@ -388,7 +389,7 @@ func (r *OctaviaRsyslogReconciler) reconcileNormal(ctx context.Context, instance
388389
if networkReady {
389390
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
390391
} else {
391-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
392+
err := fmt.Errorf("%w: %s", octavia.ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
392393
instance.Status.Conditions.Set(condition.FalseCondition(
393394
condition.NetworkAttachmentsReadyCondition,
394395
condition.ErrorReason,
@@ -424,7 +425,7 @@ func (r *OctaviaRsyslogReconciler) generateServiceSecrets(
424425
) error {
425426
Log := r.GetLogger(ctx)
426427
Log.Info(fmt.Sprintf("generating service config map for %s (%s)", instance.Name, instance.Kind))
427-
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{})
428+
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.Name), map[string]string{})
428429

429430
customData := map[string]string{}
430431
for key, data := range instance.Spec.DefaultConfigOverwrite {
@@ -527,7 +528,7 @@ func (r *OctaviaRsyslogReconciler) findObjectsForSrc(ctx context.Context, src cl
527528
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
528529
Namespace: src.GetNamespace(),
529530
}
530-
err := r.Client.List(ctx, crList, listOps)
531+
err := r.List(ctx, crList, listOps)
531532
if err != nil {
532533
Log.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace()))
533534
return requests

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 provides the entry point for the Octavia operator
1718
package main
1819

1920
import (

pkg/amphoracontrollers/daemonset.go

Lines changed: 1 addition & 0 deletions
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 amphoracontrollers provides controllers for managing Octavia amphora instances and resources
1617
package amphoracontrollers
1718

1819
import (

pkg/amphoracontrollers/flavors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
290290
flavorSuccess = true
291291
}
292292
if !flavorSuccess {
293-
return "", fmt.Errorf("none of the Octavia flavors could be configured")
293+
return "", octavia.ErrOctaviaFlavorsConfig
294294
}
295295
return defaultFlavorID, nil
296296
}

pkg/amphoracontrollers/volumes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
configMode int32 = 0644
3131
)
3232

33+
// GetVolumes returns the volumes required for amphora controller pods
3334
func GetVolumes(name string) []corev1.Volume {
3435
var config0640AccessMode int32 = 0640
3536
return append(
@@ -48,6 +49,7 @@ func GetVolumes(name string) []corev1.Volume {
4849
)
4950
}
5051

52+
// GetInitVolumeMounts returns the volume mounts for init containers in amphora controller pods
5153
func GetInitVolumeMounts() []corev1.VolumeMount {
5254
return append(
5355
octavia.GetInitVolumeMounts(),

0 commit comments

Comments
 (0)