Skip to content

Commit c2f4874

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

25 files changed

Lines changed: 153 additions & 156 deletions

apis/network/v1beta1/ipset_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (r *IPSet) ValidateCreate() (admission.Warnings, error) {
7575
}
7676
// stop if there is no NetConfig in the namespace.
7777
if netcfg == nil {
78-
return nil, fmt.Errorf(fmt.Sprintf("no NetConfig found in namespace %s. Please create one.", r.GetNamespace()))
78+
return nil, fmt.Errorf("no NetConfig found in namespace %s. Please create one.", r.GetNamespace())
7979
}
8080

8181
allErrs := field.ErrorList{}
@@ -126,7 +126,7 @@ func (r *IPSet) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
126126
}
127127
// stop if there is no NetConfig in the namespace.
128128
if netcfg == nil {
129-
return nil, fmt.Errorf(fmt.Sprintf("no NetConfig found in namespace %s. Please create one.", r.GetNamespace()))
129+
return nil, fmt.Errorf("no NetConfig found in namespace %s. Please create one.", r.GetNamespace())
130130
}
131131

132132
basePath := field.NewPath("spec")

apis/network/v1beta1/netconfig_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *NetConfig) ValidateCreate() (admission.Warnings, error) {
7373
}
7474
// stop if there is already a NetConfig in the namespace.
7575
if netcfg != nil {
76-
return nil, fmt.Errorf(fmt.Sprintf("there is already NetConfig %s in namespace %s. There can only be one.", netcfg.GetName(), r.GetNamespace()))
76+
return nil, fmt.Errorf("there is already NetConfig %s in namespace %s. There can only be one.", netcfg.GetName(), r.GetNamespace())
7777
}
7878

7979
allErrs := field.ErrorList{}

controllers/instanceha/instanceha_controller.go

Lines changed: 15 additions & 17 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 instanceha implements the InstanceHA controller for managing high availability instances
1718
package instanceha
1819

1920
import (
@@ -62,7 +63,7 @@ import (
6263
instanceha "github.com/openstack-k8s-operators/infra-operator/pkg/instanceha"
6364
)
6465

65-
// InstanceHaReconciler reconciles a InstanceHa object
66+
// Reconciler reconciles a InstanceHa object
6667
type Reconciler struct {
6768
client.Client
6869
Scheme *runtime.Scheme
@@ -91,11 +92,10 @@ func (r *Reconciler) GetLogger(ctx context.Context) logr.Logger {
9192

9293
// Reconcile -
9394
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) {
94-
9595
Log := r.GetLogger(ctx)
9696

9797
instance := &instancehav1.InstanceHa{}
98-
err := r.Client.Get(context.TODO(), req.NamespacedName, instance)
98+
err := r.Get(context.TODO(), req.NamespacedName, instance)
9999
if err != nil {
100100
if k8s_errors.IsNotFound(err) {
101101
Log.Info("InstanceHa CR not found")
@@ -333,7 +333,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
333333
condition.TLSInputReadyCondition,
334334
condition.RequestedReason,
335335
condition.SeverityInfo,
336-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.CaBundleSecretName)))
336+
condition.TLSInputReadyWaitingMessage, instance.Spec.CaBundleSecretName))
337337
return ctrl.Result{}, nil
338338
}
339339
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -495,7 +495,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
495495
}
496496

497497
return ctrl.Result{}, nil
498-
499498
}
500499

501500
// fields to index to reconcile when change
@@ -508,20 +507,17 @@ const (
508507
topologyField = ".spec.topologyRef.Name"
509508
)
510509

511-
var (
512-
allWatchFields = []string{
513-
caBundleSecretNameField,
514-
openStackConfigMapField,
515-
openStackConfigSecretField,
516-
fencingSecretField,
517-
instanceHaConfigMapField,
518-
topologyField,
519-
}
520-
)
510+
var allWatchFields = []string{
511+
caBundleSecretNameField,
512+
openStackConfigMapField,
513+
openStackConfigSecretField,
514+
fencingSecretField,
515+
instanceHaConfigMapField,
516+
topologyField,
517+
}
521518

522519
// SetupWithManager sets up the controller with the Manager.
523520
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
524-
525521
// index caBundleSecretNameField
526522
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &instancehav1.InstanceHa{}, caBundleSecretNameField, func(rawObj client.Object) []string {
527523
cr := rawObj.(*instancehav1.InstanceHa)
@@ -644,6 +640,8 @@ func (r *Reconciler) findObjectsForSrc(ctx context.Context, src client.Object) [
644640
return requests
645641
}
646642

643+
// GetContainerImage returns the container image to use for the instance, either from
644+
// the provided containerImage parameter or from the infra-instanceha-config ConfigMap
647645
func (r *Reconciler) GetContainerImage(
648646
ctx context.Context,
649647
containerImage string,
@@ -657,7 +655,7 @@ func (r *Reconciler) GetContainerImage(
657655
}
658656

659657
objectKey := client.ObjectKey{Namespace: src.GetNamespace(), Name: instanceHaConfigMapName}
660-
err := r.Client.Get(ctx, objectKey, cm)
658+
err := r.Get(ctx, objectKey, cm)
661659
if err != nil {
662660
return "", err
663661
}

controllers/memcached/memcached_controller.go

Lines changed: 16 additions & 16 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 memcached implements the Memcached controller for managing Memcached instances
1718
package memcached
1819

1920
import (
@@ -64,13 +65,11 @@ const (
6465
topologyField = ".spec.topologyRef.Name"
6566
)
6667

67-
var (
68-
allWatchFields = []string{
69-
serviceSecretNameField,
70-
caSecretNameField,
71-
topologyField,
72-
}
73-
)
68+
var allWatchFields = []string{
69+
serviceSecretNameField,
70+
caSecretNameField,
71+
topologyField,
72+
}
7473

7574
// Reconciler reconciles a Memcached object
7675
type Reconciler struct {
@@ -263,7 +262,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
263262
condition.TLSInputReadyCondition,
264263
condition.RequestedReason,
265264
condition.SeverityInfo,
266-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
265+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
267266
return ctrl.Result{}, nil
268267
}
269268
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -289,7 +288,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
289288
condition.TLSInputReadyCondition,
290289
condition.RequestedReason,
291290
condition.SeverityInfo,
292-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
291+
condition.TLSInputReadyWaitingMessage, err.Error()))
293292
return ctrl.Result{}, nil
294293
}
295294
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -313,7 +312,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
313312
memcachedv1.MTLSInputReadyCondition,
314313
condition.RequestedReason,
315314
condition.SeverityInfo,
316-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
315+
condition.TLSInputReadyWaitingMessage, err.Error()))
317316
return ctrl.Result{}, nil
318317
}
319318
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -332,7 +331,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
332331
memcachedv1.MTLSInputReadyCondition,
333332
condition.RequestedReason,
334333
condition.SeverityInfo,
335-
fmt.Sprintf(memcachedv1.MTLSInputReadyWaitingMessage)))
334+
"%s", fmt.Sprintf(memcachedv1.MTLSInputReadyWaitingMessage)))
336335
return ctrl.Result{}, nil
337336
}
338337
}
@@ -497,9 +496,10 @@ func (r *Reconciler) generateConfigMaps(
497496
"-o ssl_key=/etc/pki/tls/private/memcached.key " +
498497
"-o ssl_ca_cert=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
499498

500-
if instance.Spec.TLS.MTLS.SslVerifyMode == "Request" {
499+
switch instance.Spec.TLS.MTLS.SslVerifyMode {
500+
case "Request":
501501
memcachedTLSOptions = memcachedTLSOptions + " -o ssl_verify_mode=1"
502-
} else if instance.Spec.TLS.MTLS.SslVerifyMode == "Require" {
502+
case "Require":
503503
memcachedTLSOptions = memcachedTLSOptions + " -o ssl_verify_mode=2"
504504
}
505505

@@ -552,8 +552,8 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
552552
// Extract the secret name from the spec, if one is provided
553553
cr := rawObj.(*memcachedv1.Memcached)
554554
tls := &cr.Spec.TLS
555-
if tls.Ca.CaBundleSecretName != "" {
556-
return []string{tls.Ca.CaBundleSecretName}
555+
if tls.CaBundleSecretName != "" {
556+
return []string{tls.CaBundleSecretName}
557557
}
558558
return nil
559559
}); err != nil {
@@ -565,7 +565,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
565565
cr := rawObj.(*memcachedv1.Memcached)
566566
tls := &cr.Spec.TLS
567567
if tls.Enabled() {
568-
return []string{*tls.GenericService.SecretName}
568+
return []string{*tls.SecretName}
569569
}
570570
return nil
571571
}); err != nil {

controllers/network/bgpconfiguration_controller.go

Lines changed: 16 additions & 15 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 network implements network controllers for managing BGP configuration and related network resources
1718
package network
1819

1920
import (
@@ -85,7 +86,7 @@ func (r *BGPConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Req
8586

8687
// Fetch the BGPConfiguration instance
8788
instance := &networkv1.BGPConfiguration{}
88-
err := r.Client.Get(ctx, req.NamespacedName, instance)
89+
err := r.Get(ctx, req.NamespacedName, instance)
8990
if err != nil {
9091
if k8s_errors.IsNotFound(err) {
9192
// Request object not found, could have been deleted after reconcile request.
@@ -175,7 +176,7 @@ func (r *BGPConfigurationReconciler) SetupWithManager(ctx context.Context, mgr c
175176
listOpts := []client.ListOption{
176177
client.InNamespace(o.GetNamespace()),
177178
}
178-
if err := r.Client.List(ctx, bgpConfigurationList, listOpts...); err != nil {
179+
if err := r.List(ctx, bgpConfigurationList, listOpts...); err != nil {
179180
Log.Error(err, "Unable to retrieve BGPConfigurationList in namespace %s", o.GetNamespace())
180181
return nil
181182
}
@@ -214,7 +215,7 @@ func (r *BGPConfigurationReconciler) SetupWithManager(ctx context.Context, mgr c
214215
listOpts := []client.ListOption{
215216
client.InNamespace(bgpConfigurationNamespace),
216217
}
217-
if err := r.Client.List(ctx, bgpConfigurationList, listOpts...); err != nil {
218+
if err := r.List(ctx, bgpConfigurationList, listOpts...); err != nil {
218219
Log.Error(err, "Unable to retrieve BGPConfigurationList in namespace %s", bgpConfigurationNamespace)
219220
return nil
220221
}
@@ -331,7 +332,7 @@ func (r *BGPConfigurationReconciler) reconcileDelete(ctx context.Context, instan
331332

332333
// Delete all FRRConfiguration in the Spec.FRRConfigurationNamespace namespace,
333334
// which have the correct owner and ownernamespace label
334-
err := r.Client.DeleteAllOf(
335+
err := r.DeleteAllOf(
335336
ctx,
336337
&frrk8sv1.FRRConfiguration{},
337338
client.InNamespace(instance.Spec.FRRConfigurationNamespace),
@@ -341,7 +342,7 @@ func (r *BGPConfigurationReconciler) reconcileDelete(ctx context.Context, instan
341342
},
342343
)
343344
if err != nil && !k8s_errors.IsNotFound(err) {
344-
return ctrl.Result{}, fmt.Errorf("Error DeleteAllOf FRRConfiguration: %w", err)
345+
return ctrl.Result{}, fmt.Errorf("error DeleteAllOf FRRConfiguration: %w", err)
345346
}
346347

347348
// Service is deleted so remove the finalizer.
@@ -361,8 +362,8 @@ func (r *BGPConfigurationReconciler) reconcileNormal(ctx context.Context, instan
361362
listOpts := []client.ListOption{
362363
client.InNamespace(instance.Namespace),
363364
}
364-
if err := r.Client.List(ctx, podList, listOpts...); err != nil {
365-
return ctrl.Result{}, fmt.Errorf("Unable to retrieve PodList %w", err)
365+
if err := r.List(ctx, podList, listOpts...); err != nil {
366+
return ctrl.Result{}, fmt.Errorf("unable to retrieve PodList %w", err)
366367
}
367368

368369
// get podDetail all pods which have additional interfaces configured
@@ -376,8 +377,8 @@ func (r *BGPConfigurationReconciler) reconcileNormal(ctx context.Context, instan
376377
listOpts = []client.ListOption{
377378
client.InNamespace(instance.Spec.FRRConfigurationNamespace), // defaults to metallb-system
378379
}
379-
if err := r.Client.List(ctx, frrConfigList, listOpts...); err != nil {
380-
return ctrl.Result{}, fmt.Errorf("Unable to retrieve FRRConfigurationList %w", err)
380+
if err := r.List(ctx, frrConfigList, listOpts...); err != nil {
381+
return ctrl.Result{}, fmt.Errorf("unable to retrieve FRRConfigurationList %w", err)
381382
}
382383

383384
// get all frr configs for the nodes pods are scheduled on
@@ -465,7 +466,7 @@ func (r *BGPConfigurationReconciler) deleteStaleFRRConfigurations(ctx context.Co
465466
idx := slices.IndexFunc(podNetworkDetailList, f)
466467
if idx < 0 {
467468
// There is no pod in the namespace corrsponding to the FRRConfiguration, delete it
468-
if err := r.Client.Delete(ctx, &cfg); err != nil && !k8s_errors.IsNotFound(err) {
469+
if err := r.Delete(ctx, &cfg); err != nil && !k8s_errors.IsNotFound(err) {
469470
return fmt.Errorf("unable to delete FRRConfiguration %w", err)
470471
}
471472
r.GetLogger(ctx).Info(fmt.Sprintf("pod with name: %s either in state deleted, completed, failed or unknown, deleted FRRConfiguration %s", podName, cfg.Name))
@@ -508,7 +509,7 @@ func getPodNetworkDetails(
508509

509510
// verify the nodeName information is already present in the pod spec, otherwise report an error to reconcile
510511
if pod.Spec.NodeName == "" {
511-
return detailList, fmt.Errorf(fmt.Sprintf("empty spec.nodeName on pod %s", pod.Name))
512+
return detailList, fmt.Errorf("empty spec.nodeName on pod %s", pod.Name)
512513
}
513514

514515
detail := bgp.PodDetail{
@@ -525,11 +526,11 @@ func getPodNetworkDetails(
525526
// reflect all requested networks. return with an error to reconcile if the length
526527
// is <= the status. Note: the status also has the pod network
527528
if len(netsStatus) <= len(netAttach) {
528-
return detailList, fmt.Errorf(fmt.Sprintf("metadata.Annotations['k8s.ovn.org/pod-networks'] %s on pod %s, does not match requested networks %s",
529-
pod.GetAnnotations()[k8s_networkv1.NetworkStatusAnnot], pod.Name, netAttachString))
529+
return detailList, fmt.Errorf("metadata.Annotations['k8s.ovn.org/pod-networks'] %s on pod %s, does not match requested networks %s",
530+
pod.GetAnnotations()[k8s_networkv1.NetworkStatusAnnot], pod.Name, netAttachString)
530531
}
531532

532-
var netsStatusCopy = make([]k8s_networkv1.NetworkStatus, len(netsStatus))
533+
netsStatusCopy := make([]k8s_networkv1.NetworkStatus, len(netsStatus))
533534
copy(netsStatusCopy, netsStatus)
534535
// verify there are IP information for all networks in the status, otherwise report an error to reconcile
535536
for idx, netStat := range netsStatusCopy {
@@ -562,7 +563,7 @@ func getPodNetworkDetails(
562563

563564
// verify there is IP information for the network, otherwise report an error to reconcile
564565
if len(netStat.IPs) == 0 {
565-
return detailList, fmt.Errorf(fmt.Sprintf("no IP information for network %s on pod %s", netStat.Name, pod.Name))
566+
return detailList, fmt.Errorf("no IP information for network %s on pod %s", netStat.Name, pod.Name)
566567
}
567568
}
568569

controllers/network/dnsdata_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *DNSDataReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
7171

7272
// Fetch the DNSData instance
7373
instance := &networkv1.DNSData{}
74-
err := r.Client.Get(ctx, req.NamespacedName, instance)
74+
err := r.Get(ctx, req.NamespacedName, instance)
7575
if err != nil {
7676
if k8s_errors.IsNotFound(err) {
7777
// Request object not found, could have been deleted after reconcile request.

controllers/network/dnsmasq_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (r *DNSMasqReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
109109

110110
// Fetch the DNSMasq instance
111111
instance := &networkv1.DNSMasq{}
112-
err := r.Client.Get(ctx, req.NamespacedName, instance)
112+
err := r.Get(ctx, req.NamespacedName, instance)
113113
if err != nil {
114114
if k8s_errors.IsNotFound(err) {
115115
// Request object not found, could have been deleted after reconcile request.
@@ -237,7 +237,7 @@ func (r *DNSMasqReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
237237
listOpts := []client.ListOption{
238238
client.InNamespace(o.GetNamespace()),
239239
}
240-
if err := r.Client.List(ctx, dnsmasqs, listOpts...); err != nil {
240+
if err := r.List(ctx, dnsmasqs, listOpts...); err != nil {
241241
Log.Error(err, "Unable to retrieve DNSMasqList")
242242
return nil
243243
}

controllers/network/ipset_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
4747
)
4848

49+
// CtlPlaneNetwork defines the default control plane network name
4950
const CtlPlaneNetwork = "ctlplane"
5051

5152
// IPSetReconciler reconciles a IPSet object
@@ -76,7 +77,7 @@ func (r *IPSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu
7677
Log := r.GetLogger(ctx)
7778
// Fetch the IPSet instance
7879
instance := &networkv1.IPSet{}
79-
err := r.Client.Get(ctx, req.NamespacedName, instance)
80+
err := r.Get(ctx, req.NamespacedName, instance)
8081
if err != nil {
8182
if k8s_errors.IsNotFound(err) {
8283
// Request object not found, could have been deleted after reconcile request.
@@ -170,7 +171,7 @@ func (r *IPSetReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager)
170171
listOpts := []client.ListOption{
171172
client.InNamespace(o.GetNamespace()),
172173
}
173-
if err := r.Client.List(ctx, ipsets, listOpts...); err != nil {
174+
if err := r.List(ctx, ipsets, listOpts...); err != nil {
174175
Log.Error(err, "Unable to retrieve IPSetList")
175176
return nil
176177
}

0 commit comments

Comments
 (0)