Skip to content

Commit 05d18a9

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

16 files changed

Lines changed: 57 additions & 36 deletions

File tree

controllers/funcs.go

Lines changed: 8 additions & 1 deletion
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 contains shared utility functions for ironic-operator controllers.
1718
package controllers
1819

1920
import (
2021
"context"
22+
"errors"
2123
"fmt"
2224

2325
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
@@ -29,10 +31,15 @@ import (
2931
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3032
)
3133

34+
// Static errors for ironic controllers
35+
var (
36+
ErrNetworkAttachmentConfig = errors.New("not all pods have interfaces with ips as configured in NetworkAttachments")
37+
)
38+
3239
// fields to index to reconcile when change
3340
const (
3441
passwordSecretField = ".spec.secret"
35-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
42+
caBundleSecretNameField = ".spec.tls.caBundleSecretName" // #nosec G101
3643
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
3744
tlsAPIPublicField = ".spec.tls.api.public.secretName"
3845
transportURLSecretField = ".spec.transportURLSecret"

controllers/ironic_controller.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (r *IronicReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
118118

119119
// Fetch the Ironic instance
120120
instance := &ironicv1.Ironic{}
121-
err := r.Client.Get(ctx, req.NamespacedName, instance)
121+
err := r.Get(ctx, req.NamespacedName, instance)
122122
if err != nil {
123123
if k8s_errors.IsNotFound(err) {
124124
// Request object not found, could have been deleted after reconcile request.
@@ -249,7 +249,7 @@ func (r *IronicReconciler) findObjectForSrc(ctx context.Context, src client.Obje
249249
listOps := &client.ListOptions{
250250
Namespace: src.GetNamespace(),
251251
}
252-
err := r.Client.List(ctx, crList, listOps)
252+
err := r.List(ctx, crList, listOps)
253253
if err != nil {
254254
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
255255
return requests
@@ -913,7 +913,7 @@ func (r *IronicReconciler) generateServiceConfigMaps(
913913
cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(ironic.ServiceName), map[string]string{})
914914

915915
var tlsCfg *tls.Service
916-
if instance.Spec.IronicAPI.TLS.Ca.CaBundleSecretName != "" {
916+
if instance.Spec.IronicAPI.TLS.CaBundleSecretName != "" {
917917
tlsCfg = &tls.Service{}
918918
}
919919

@@ -1119,13 +1119,13 @@ func (r *IronicReconciler) inspectorDeploymentDelete(
11191119
return err
11201120
}
11211121
deploymentObjectKey := client.ObjectKeyFromObject(deployment)
1122-
if err := r.Client.Get(ctx, deploymentObjectKey, deployment); err != nil {
1122+
if err := r.Get(ctx, deploymentObjectKey, deployment); err != nil {
11231123
if k8s_errors.IsNotFound(err) {
11241124
return nil
11251125
}
11261126
return err
11271127
}
1128-
if err := r.Client.Delete(ctx, deployment); err != nil {
1128+
if err := r.Delete(ctx, deployment); err != nil {
11291129
return err
11301130
}
11311131
// Remove inspector APIEndpoints, Services and set ReadyCount 0
@@ -1196,13 +1196,13 @@ func (r *IronicReconciler) ironicNeutronAgentDeploymentDelete(
11961196
return err
11971197
}
11981198
deploymentObjectKey := client.ObjectKeyFromObject(deployment)
1199-
if err := r.Client.Get(ctx, deploymentObjectKey, deployment); err != nil {
1199+
if err := r.Get(ctx, deploymentObjectKey, deployment); err != nil {
12001200
if k8s_errors.IsNotFound(err) {
12011201
return nil
12021202
}
12031203
return err
12041204
}
1205-
if err := r.Client.Delete(ctx, deployment); err != nil {
1205+
if err := r.Delete(ctx, deployment); err != nil {
12061206
return err
12071207
}
12081208
// Set ReadyCount 0
@@ -1311,7 +1311,7 @@ func (r *IronicReconciler) checkIronicAPIGeneration(
13111311
listOpts := []client.ListOption{
13121312
client.InNamespace(instance.Namespace),
13131313
}
1314-
if err := r.Client.List(context.Background(), api, listOpts...); err != nil {
1314+
if err := r.List(context.Background(), api, listOpts...); err != nil {
13151315
Log.Error(err, "Unable to retrieve IronicAPI CR %w")
13161316
return false, err
13171317
}
@@ -1332,7 +1332,7 @@ func (r *IronicReconciler) checkIronicConductorGeneration(
13321332
listOpts := []client.ListOption{
13331333
client.InNamespace(instance.Namespace),
13341334
}
1335-
if err := r.Client.List(context.Background(), cnd, listOpts...); err != nil {
1335+
if err := r.List(context.Background(), cnd, listOpts...); err != nil {
13361336
Log.Error(err, "Unable to retrieve IronicConductor CR %w")
13371337
return false, err
13381338
}
@@ -1353,7 +1353,7 @@ func (r *IronicReconciler) checkIronicInspectorGeneration(
13531353
listOpts := []client.ListOption{
13541354
client.InNamespace(instance.Namespace),
13551355
}
1356-
if err := r.Client.List(context.Background(), nsp, listOpts...); err != nil {
1356+
if err := r.List(context.Background(), nsp, listOpts...); err != nil {
13571357
Log.Error(err, "Unable to retrieve IronicInspector CR %w")
13581358
return false, err
13591359
}
@@ -1374,7 +1374,7 @@ func (r *IronicReconciler) checkNeutronAgentGeneration(
13741374
listOpts := []client.ListOption{
13751375
client.InNamespace(instance.Namespace),
13761376
}
1377-
if err := r.Client.List(context.Background(), ag, listOpts...); err != nil {
1377+
if err := r.List(context.Background(), ag, listOpts...); err != nil {
13781378
Log.Error(err, "Unable to retrieve IronicNeutronAgent CR %w")
13791379
return false, err
13801380
}

controllers/ironicapi_controller.go

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

110110
// Fetch the IronicAPI instance
111111
instance := &ironicv1.IronicAPI{}
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.
@@ -764,7 +764,7 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
764764
condition.TLSInputReadyCondition,
765765
condition.RequestedReason,
766766
condition.SeverityInfo,
767-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
767+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
768768
return ctrl.Result{}, nil
769769
}
770770
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -789,7 +789,7 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
789789
condition.TLSInputReadyCondition,
790790
condition.RequestedReason,
791791
condition.SeverityInfo,
792-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
792+
condition.TLSInputReadyWaitingMessage, err.Error()))
793793
return ctrl.Result{}, nil
794794
}
795795
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -968,7 +968,7 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
968968
if networkReady {
969969
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
970970
} else {
971-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
971+
err := fmt.Errorf("%w: %s", ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
972972
instance.Status.Conditions.Set(condition.FalseCondition(
973973
condition.NetworkAttachmentsReadyCondition,
974974
condition.ErrorReason,

controllers/ironicconductor_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type IronicConductorReconciler struct {
6969
Scheme *runtime.Scheme
7070
}
7171

72-
// getlogger returns a logger object with a prefix of "controller.name" and additional controller context fields
72+
// GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
7373
func (r *IronicConductorReconciler) GetLogger(ctx context.Context) logr.Logger {
7474
return log.FromContext(ctx).WithName("Controllers").WithName("IronicConductor")
7575
}
@@ -103,7 +103,7 @@ func (r *IronicConductorReconciler) Reconcile(ctx context.Context, req ctrl.Requ
103103

104104
// Fetch the IronicConductor instance
105105
instance := &ironicv1.IronicConductor{}
106-
err := r.Client.Get(ctx, req.NamespacedName, instance)
106+
err := r.Get(ctx, req.NamespacedName, instance)
107107
if err != nil {
108108
if k8s_errors.IsNotFound(err) {
109109
// Request object not found, could have been deleted after reconcile request.
@@ -606,7 +606,7 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
606606
condition.TLSInputReadyCondition,
607607
condition.RequestedReason,
608608
condition.SeverityInfo,
609-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
609+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
610610
return ctrl.Result{}, nil
611611
}
612612
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -791,7 +791,7 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
791791
if networkReady {
792792
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
793793
} else {
794-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
794+
err := fmt.Errorf("%w: %s", ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
795795
instance.Status.Conditions.Set(condition.FalseCondition(
796796
condition.NetworkAttachmentsReadyCondition,
797797
condition.ErrorReason,

controllers/ironicinspector_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (r *IronicInspectorReconciler) Reconcile(
126126

127127
// Fetch the IronicInspector instance
128128
instance := &ironicv1.IronicInspector{}
129-
err := r.Client.Get(ctx, req.NamespacedName, instance)
129+
err := r.Get(ctx, req.NamespacedName, instance)
130130
if err != nil {
131131
if k8s_errors.IsNotFound(err) {
132132
// Request object not found, could have been deleted after
@@ -291,7 +291,7 @@ func (r *IronicInspectorReconciler) SetupWithManager(
291291
listOpts := []client.ListOption{
292292
client.InNamespace(o.GetNamespace()),
293293
}
294-
if err := r.Client.List(
294+
if err := r.List(
295295
ctx,
296296
apis,
297297
listOpts...); err != nil {
@@ -434,7 +434,7 @@ func (r *IronicInspectorReconciler) findObjectForSrc(ctx context.Context, src cl
434434
listOps := &client.ListOptions{
435435
Namespace: src.GetNamespace(),
436436
}
437-
err := r.Client.List(ctx, crList, listOps)
437+
err := r.List(ctx, crList, listOps)
438438
if err != nil {
439439
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
440440
return requests
@@ -628,7 +628,7 @@ func (r *IronicInspectorReconciler) reconcileConfigMapsAndSecrets(
628628
condition.TLSInputReadyCondition,
629629
condition.RequestedReason,
630630
condition.SeverityInfo,
631-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
631+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
632632
return ctrl.Result{RequeueAfter: time.Second * 10}, "", nil
633633
}
634634
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -653,7 +653,7 @@ func (r *IronicInspectorReconciler) reconcileConfigMapsAndSecrets(
653653
condition.TLSInputReadyCondition,
654654
condition.RequestedReason,
655655
condition.SeverityInfo,
656-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
656+
condition.TLSInputReadyWaitingMessage, err.Error()))
657657
return ctrl.Result{RequeueAfter: time.Second * 10}, "", nil
658658
}
659659
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -803,7 +803,7 @@ func (r *IronicInspectorReconciler) reconcileStatefulSet(
803803
if networkReady {
804804
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
805805
} else {
806-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
806+
err := fmt.Errorf("%w: %s", ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
807807
instance.Status.Conditions.Set(condition.FalseCondition(
808808
condition.NetworkAttachmentsReadyCondition,
809809
condition.ErrorReason,
@@ -1461,7 +1461,7 @@ func (r *IronicInspectorReconciler) generateServiceSecrets(
14611461
map[string]string{})
14621462
Log := r.GetLogger(ctx)
14631463
var tlsCfg *tls.Service
1464-
if instance.Spec.TLS.Ca.CaBundleSecretName != "" {
1464+
if instance.Spec.TLS.CaBundleSecretName != "" {
14651465
tlsCfg = &tls.Service{}
14661466
}
14671467
// customData hold any customization for the service.

controllers/ironicneutronagent_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type IronicNeutronAgentReconciler struct {
6767
Scheme *runtime.Scheme
6868
}
6969

70-
// getlogger returns a logger object with a prefix of "controller.name" and additional controller context fields
70+
// GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
7171
func (r *IronicNeutronAgentReconciler) GetLogger(ctx context.Context) logr.Logger {
7272
return log.FromContext(ctx).WithName("Controllers").WithName("IronicNeutronAgent")
7373
}
@@ -101,7 +101,7 @@ func (r *IronicNeutronAgentReconciler) Reconcile(
101101

102102
// Fetch the IronicNeutronAgent instance
103103
instance := &ironicv1.IronicNeutronAgent{}
104-
err := r.Client.Get(ctx, req.NamespacedName, instance)
104+
err := r.Get(ctx, req.NamespacedName, instance)
105105
if err != nil {
106106
if k8s_errors.IsNotFound(err) {
107107
// Request object not found, could have been deleted after reconcile request.
@@ -329,7 +329,7 @@ func (r *IronicNeutronAgentReconciler) findObjectForSrc(ctx context.Context, src
329329
listOps := &client.ListOptions{
330330
Namespace: src.GetNamespace(),
331331
}
332-
err := r.Client.List(ctx, crList, listOps)
332+
err := r.List(ctx, crList, listOps)
333333
if err != nil {
334334
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
335335
return requests
@@ -497,7 +497,7 @@ func (r *IronicNeutronAgentReconciler) reconcileConfigMapsAndSecrets(
497497
condition.TLSInputReadyCondition,
498498
condition.RequestedReason,
499499
condition.SeverityInfo,
500-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
500+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
501501
return ctrl.Result{RequeueAfter: time.Second * 10}, "", nil
502502
}
503503
instance.Status.Conditions.Set(condition.FalseCondition(

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 ironic-operator controller manager.
1718
package main
1819

1920
import (

pkg/ironic/const.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 ironic contains ironic service constants and configuration.
1617
package ironic
1718

1819
const (

pkg/ironic/funcs.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ironic
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net"
78

@@ -18,6 +19,12 @@ import (
1819
k8snet "k8s.io/utils/net"
1920
)
2021

22+
// Static errors for ironic package functions
23+
var (
24+
ErrIngressDomainTypeAssertion = errors.New("unable to retrieve ingress domain - invalid type")
25+
ErrIngressDomainNotFound = errors.New("unable to retrieve ingress domain")
26+
)
27+
2128
// GetIngressDomain - Get the Ingress Domain of cluster
2229
func GetIngressDomain(
2330
ctx context.Context,
@@ -49,7 +56,7 @@ func GetIngressDomain(
4956
ingressStatus := ingress.UnstructuredContent()["status"]
5057
ingressStatusMap, ok := ingressStatus.(map[string]interface{})
5158
if !ok {
52-
return "", fmt.Errorf("unable to retrieve ingress domain - wanted type map[string]interface{}; got %T", ingressStatus)
59+
return "", fmt.Errorf("%w: wanted type map[string]interface{}; got %T", ErrIngressDomainTypeAssertion, ingressStatus)
5360
}
5461
for k, v := range ingressStatusMap {
5562
if k == "domain" {
@@ -61,7 +68,7 @@ func GetIngressDomain(
6168
if ingressDomain != "" {
6269
Log.Info(fmt.Sprintf("Found ingress domain: %s", ingressDomain))
6370
} else {
64-
return "", fmt.Errorf("unable to retrieve ingress domain")
71+
return "", ErrIngressDomainNotFound
6572
}
6673

6774
return ingressDomain, nil

pkg/ironicapi/deployment.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 ironicapi contains ironic API deployment functionality.
1617
package ironicapi
1718

1819
import (

0 commit comments

Comments
 (0)