Skip to content

Commit 9dd6bd0

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

26 files changed

Lines changed: 125 additions & 45 deletions

controllers/swift_common.go

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

17+
// Package controllers implements the OpenStack Swift Kubernetes controllers.
1718
package controllers
1819

1920
import (
2021
"context"
2122
"fmt"
23+
"time"
24+
2225
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2326
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
2427
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
2528
"k8s.io/apimachinery/pkg/types"
26-
"time"
2729

2830
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2931
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
@@ -36,7 +38,7 @@ import (
3638
// fields to index to reconcile when change
3739
const (
3840
passwordSecretField = ".spec.secret"
39-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
41+
caBundleSecretNameField = ".spec.tls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
4042
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
4143
tlsAPIPublicField = ".spec.tls.api.public.secretName"
4244
topologyField = ".spec.topologyRef.Name"

controllers/swift_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func (r *SwiftReconciler) checkSwiftProxyGeneration(
584584
listOpts := []client.ListOption{
585585
client.InNamespace(instance.Namespace),
586586
}
587-
if err := r.Client.List(context.Background(), proxy, listOpts...); err != nil {
587+
if err := r.List(context.Background(), proxy, listOpts...); err != nil {
588588
Log.Error(err, "Unable to retrieve SwiftProxy %w")
589589
return false, err
590590
}
@@ -606,7 +606,7 @@ func (r *SwiftReconciler) checkSwiftStorageGeneration(
606606
listOpts := []client.ListOption{
607607
client.InNamespace(instance.Namespace),
608608
}
609-
if err := r.Client.List(context.Background(), sst, listOpts...); err != nil {
609+
if err := r.List(context.Background(), sst, listOpts...); err != nil {
610610
Log.Error(err, "Unable to retrieve SwiftStorage %w")
611611
return false, err
612612
}
@@ -628,7 +628,7 @@ func (r *SwiftReconciler) checkSwiftRingGeneration(
628628
listOpts := []client.ListOption{
629629
client.InNamespace(instance.Namespace),
630630
}
631-
if err := r.Client.List(context.Background(), rings, listOpts...); err != nil {
631+
if err := r.List(context.Background(), rings, listOpts...); err != nil {
632632
Log.Error(err, "Unable to retrieve SwiftRing %w")
633633
return false, err
634634
}

controllers/swiftproxy_controller.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import (
5050
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
5151
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
5252
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
53-
"github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
5453
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
5554
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
5655
service "github.com/openstack-k8s-operators/lib-common/modules/common/service"
@@ -220,7 +219,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
220219
condition.TLSInputReadyCondition,
221220
condition.RequestedReason,
222221
condition.SeverityInfo,
223-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
222+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
224223
return ctrl.Result{}, nil
225224
}
226225
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -245,7 +244,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
245244
condition.TLSInputReadyCondition,
246245
condition.RequestedReason,
247246
condition.SeverityInfo,
248-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
247+
"%s", fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
249248
return ctrl.Result{}, nil
250249
}
251250
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -609,7 +608,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
609608
// networks to attach to
610609
nadList := []networkv1.NetworkAttachmentDefinition{}
611610
for _, netAtt := range instance.Spec.NetworkAttachments {
612-
nad, err := networkattachment.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
611+
nad, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
613612
if err != nil {
614613
if apierrors.IsNotFound(err) {
615614
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -714,7 +713,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
714713
if networkReady || *instance.Spec.Replicas == 0 {
715714
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
716715
} else {
717-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
716+
err := fmt.Errorf("%w: %s", swift.ErrNetworkAttachmentsMismatch, instance.Spec.NetworkAttachments)
718717
instance.Status.Conditions.Set(condition.FalseCondition(
719718
condition.NetworkAttachmentsReadyCondition,
720719
condition.ErrorReason,
@@ -814,7 +813,7 @@ func (r *SwiftProxyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
814813
listOpts := []client.ListOption{
815814
client.InNamespace(o.GetNamespace()),
816815
}
817-
if err := r.Client.List(context.Background(), crList, listOpts...); err != nil {
816+
if err := r.List(context.Background(), crList, listOpts...); err != nil {
818817
Log.Error(err, "Unable to retrieve SwiftProxy CRs %w")
819818
return nil
820819
}
@@ -902,7 +901,7 @@ func (r *SwiftProxyReconciler) findObjectForSrc(ctx context.Context, src client.
902901
listOps := &client.ListOptions{
903902
Namespace: src.GetNamespace(),
904903
}
905-
err := r.Client.List(ctx, crList, listOps)
904+
err := r.List(ctx, crList, listOps)
906905
if err != nil {
907906
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
908907
return requests

controllers/swiftring_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (r *SwiftRingReconciler) reconcileNormal(ctx context.Context, instance *swi
235235
condition.ReadyCondition,
236236
condition.ErrorReason,
237237
condition.SeverityWarning,
238-
err.Error()))
238+
"%s", err.Error()))
239239
return ctrl.Result{}, err
240240
}
241241

@@ -290,7 +290,7 @@ func (r *SwiftRingReconciler) SetupWithManager(mgr ctrl.Manager) error {
290290
result := []reconcile.Request{}
291291
swiftRings := &swiftv1beta1.SwiftRingList{}
292292
listOpts := []client.ListOption{client.InNamespace(o.GetNamespace())}
293-
err := r.Client.List(context.Background(), swiftRings, listOpts...)
293+
err := r.List(context.Background(), swiftRings, listOpts...)
294294
if err != nil {
295295
return nil
296296
}

controllers/swiftstorage_controller.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ func (r *SwiftStorageReconciler) GetLogger(ctx context.Context) logr.Logger {
7676
return log.FromContext(ctx).WithName("Controllers").WithName("SwiftStorage")
7777
}
7878

79-
// Partial struct of the NetworkAttachmentDefinition
80-
// config to retrieve the subnet range
79+
// Netconfig represents a partial NetworkAttachmentDefinition configuration for subnet range retrieval.
8180
type Netconfig struct {
8281
Name string `json:"name"`
8382
Ipam struct {
@@ -375,7 +374,7 @@ func (r *SwiftStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request
375374
if networkReady || *instance.Spec.Replicas == 0 {
376375
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
377376
} else {
378-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
377+
err := fmt.Errorf("%w: %s", swift.ErrNetworkAttachmentsMismatch, instance.Spec.NetworkAttachments)
379378
instance.Status.Conditions.Set(condition.FalseCondition(
380379
condition.NetworkAttachmentsReadyCondition,
381380
condition.ErrorReason,
@@ -417,7 +416,7 @@ func (r *SwiftStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request
417416
}
418417

419418
if len(dnsIP) == 0 {
420-
return ctrl.Result{}, errors.New("Unable to get any IP address for pod")
419+
return ctrl.Result{}, swift.ErrNoPodIPAddress
421420
}
422421

423422
hostName := fmt.Sprintf("%s.%s.%s.svc", swiftPod.Name, instance.Name, swiftPod.Namespace)
@@ -468,7 +467,7 @@ func (r *SwiftStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
468467
listOpts := []client.ListOption{
469468
client.InNamespace(o.GetNamespace()),
470469
}
471-
if err := r.Client.List(context.Background(), crList, listOpts...); err != nil {
470+
if err := r.List(context.Background(), crList, listOpts...); err != nil {
472471
Log.Error(err, "Unable to retrieve SwiftStorage CRs %w")
473472
return nil
474473
}
@@ -569,7 +568,7 @@ func getPodIPInNetwork(swiftPod corev1.Pod, namespace string, networkAttachment
569568
networkName := fmt.Sprintf("%s/%s", namespace, networkAttachment)
570569
netStat, err := networkattachment.GetNetworkStatusFromAnnotation(swiftPod.Annotations)
571570
if err != nil {
572-
err = fmt.Errorf("Error while getting the Network Status for pod %s: %w",
571+
err = fmt.Errorf("error while getting the Network Status for pod %s: %w",
573572
swiftPod.Name, err)
574573
return "", err
575574
}
@@ -582,6 +581,6 @@ func getPodIPInNetwork(swiftPod corev1.Pod, namespace string, networkAttachment
582581
}
583582

584583
// If this is reached it means that no IP was found, construct error and return
585-
err = fmt.Errorf("Error while getting IP address from pod %s in network %s", swiftPod.Name, networkAttachment)
584+
err = fmt.Errorf("%w %s in network %s", swift.ErrPodIPAddressRetrieval, swiftPod.Name, networkAttachment)
586585
return "", err
587586
}

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

1920
import (

pkg/swift/const.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,39 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16+
// Package swift provides common constants and utilities for Swift services
1617
package swift
1718

1819
const (
19-
RunAsUser int64 = 42445
20-
ProxyPort int32 = 8081
20+
// RunAsUser is the UID for running swift containers
21+
RunAsUser int64 = 42445
22+
// ProxyPort is the port for Swift proxy service
23+
ProxyPort int32 = 8081
24+
// ProxyHttpdPort is the HTTP port for Swift proxy
2125
ProxyHttpdPort int32 = 8080
2226

23-
AccountServerPort int32 = 6202
27+
// AccountServerPort is the port for Swift account server
28+
AccountServerPort int32 = 6202
29+
// ContainerServerPort is the port for Swift container server
2430
ContainerServerPort int32 = 6201
25-
ObjectServerPort int32 = 6200
26-
RsyncPort int32 = 873
27-
28-
ServiceName = "swift"
29-
ServiceType = "object-store"
30-
ServiceAccount = "swift-swift"
31+
// ObjectServerPort is the port for Swift object server
32+
ObjectServerPort int32 = 6200
33+
// RsyncPort is the port for rsync service
34+
RsyncPort int32 = 873
35+
36+
// ServiceName is the name of the Swift service
37+
ServiceName = "swift"
38+
// ServiceType is the OpenStack service type for Swift
39+
ServiceType = "object-store"
40+
// ServiceAccount is the service account name for Swift
41+
ServiceAccount = "swift-swift"
42+
// ServiceDescription is the description of the Swift service
3143
ServiceDescription = "Swift Object Storage"
3244

45+
// ClaimName is the persistent volume claim name for Swift
3346
ClaimName = "swift"
3447

35-
// Must match with settings in the dataplane-operator
36-
// and adoption docs/tests
48+
// SwiftConfSecretName is the name of the secret containing swift.conf
49+
// Must match with settings in the dataplane-operator and adoption docs/tests
3750
SwiftConfSecretName = "swift-conf"
3851
)

pkg/swift/errors.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package swift
17+
18+
import "errors"
19+
20+
// Static errors for Swift operator
21+
var (
22+
// ErrNetworkAttachmentsMismatch indicates pods don't have interfaces with IPs as configured in NetworkAttachments
23+
ErrNetworkAttachmentsMismatch = errors.New("not all pods have interfaces with ips as configured in NetworkAttachments")
24+
25+
// ErrNoPodIPAddress indicates unable to get any IP address for pod
26+
ErrNoPodIPAddress = errors.New("unable to get any IP address for pod")
27+
28+
// ErrPodIPAddressRetrieval indicates error while getting IP address from pod in network
29+
ErrPodIPAddressRetrieval = errors.New("error while getting IP address from pod in network")
30+
31+
// ErrPVCNotBound indicates PersistentVolumeClaim found but not bound yet
32+
ErrPVCNotBound = errors.New("PersistentVolumeClaim found, but not bound yet")
33+
34+
// ErrPodNotFound indicates pod not found
35+
ErrPodNotFound = errors.New("pod not found")
36+
37+
// ErrPodNodeNameNotSet indicates pod found but NodeName not yet set
38+
ErrPodNodeNameNotSet = errors.New("pod found, but NodeName not yet set")
39+
)

pkg/swift/funcs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
)
2929

30+
// GetSecurityContext returns the security context for swift containers
3031
func GetSecurityContext() corev1.SecurityContext {
3132
trueVal := true
3233
falseVal := false
@@ -44,19 +45,21 @@ func GetSecurityContext() corev1.SecurityContext {
4445
}
4546
}
4647

48+
// Labels returns the common labels for swift resources
4749
func Labels() map[string]string {
4850
return map[string]string{
4951
common.AppSelector: ServiceName,
5052
common.ComponentSelector: ServiceName, // identical in this case
5153
}
5254
}
5355

56+
// RandomString generates a random string of specified length
5457
func RandomString(length int) string {
5558
sample := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
5659
str := make([]byte, length)
5760

5861
for i := 0; i < length; i++ {
59-
str[i] = sample[rand.Intn(len(sample))]
62+
str[i] = sample[rand.Intn(len(sample))] //nolint:gosec // G404: Non-cryptographic use acceptable for Swift hash generation
6063
}
6164
return string(str)
6265
}

pkg/swift/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
2222
)
2323

24+
// SecretTemplates creates secret templates for swift configuration
2425
func SecretTemplates(instance *swiftv1beta1.Swift, serviceLabels map[string]string) []util.Template {
2526
templateParameters := make(map[string]interface{})
2627
templateParameters["SwiftHashPathPrefix"] = RandomString(16)

0 commit comments

Comments
 (0)