Skip to content

Commit 00aadc0

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

16 files changed

Lines changed: 61 additions & 41 deletions

File tree

controllers/funcs.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ 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"
24+
2225
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2326
rbacv1 "k8s.io/api/rbac/v1"
2427

@@ -27,10 +30,15 @@ import (
2730
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2831
)
2932

33+
// Static errors for ironic controllers
34+
var (
35+
ErrNetworkAttachmentConfig = errors.New("not all pods have interfaces with ips as configured in NetworkAttachments")
36+
)
37+
3038
// fields to index to reconcile when change
3139
const (
3240
passwordSecretField = ".spec.secret"
33-
caBundleSecretNameField = ".spec.tls.caBundleSecretName"
41+
caBundleSecretNameField = ".spec.tls.caBundleSecretName" // #nosec G101
3442
tlsAPIInternalField = ".spec.tls.api.internal.secretName"
3543
tlsAPIPublicField = ".spec.tls.api.public.secretName"
3644
topologyField = ".spec.topologyRef.Name"

controllers/ironic_controller.go

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

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

928928
var tlsCfg *tls.Service
929-
if instance.Spec.IronicAPI.TLS.Ca.CaBundleSecretName != "" {
929+
if instance.Spec.IronicAPI.TLS.CaBundleSecretName != "" {
930930
tlsCfg = &tls.Service{}
931931
}
932932

@@ -1091,13 +1091,13 @@ func (r *IronicReconciler) inspectorDeploymentDelete(
10911091
return err
10921092
}
10931093
deploymentObjectKey := client.ObjectKeyFromObject(deployment)
1094-
if err := r.Client.Get(ctx, deploymentObjectKey, deployment); err != nil {
1094+
if err := r.Get(ctx, deploymentObjectKey, deployment); err != nil {
10951095
if k8s_errors.IsNotFound(err) {
10961096
return nil
10971097
}
10981098
return err
10991099
}
1100-
if err := r.Client.Delete(ctx, deployment); err != nil {
1100+
if err := r.Delete(ctx, deployment); err != nil {
11011101
return err
11021102
}
11031103
// Remove inspector APIEndpoints, Services and set ReadyCount 0
@@ -1168,13 +1168,13 @@ func (r *IronicReconciler) ironicNeutronAgentDeploymentDelete(
11681168
return err
11691169
}
11701170
deploymentObjectKey := client.ObjectKeyFromObject(deployment)
1171-
if err := r.Client.Get(ctx, deploymentObjectKey, deployment); err != nil {
1171+
if err := r.Get(ctx, deploymentObjectKey, deployment); err != nil {
11721172
if k8s_errors.IsNotFound(err) {
11731173
return nil
11741174
}
11751175
return err
11761176
}
1177-
if err := r.Client.Delete(ctx, deployment); err != nil {
1177+
if err := r.Delete(ctx, deployment); err != nil {
11781178
return err
11791179
}
11801180
// Set ReadyCount 0
@@ -1283,7 +1283,7 @@ func (r *IronicReconciler) checkIronicAPIGeneration(
12831283
listOpts := []client.ListOption{
12841284
client.InNamespace(instance.Namespace),
12851285
}
1286-
if err := r.Client.List(context.Background(), api, listOpts...); err != nil {
1286+
if err := r.List(context.Background(), api, listOpts...); err != nil {
12871287
Log.Error(err, "Unable to retrieve IronicAPI CR %w")
12881288
return false, err
12891289
}
@@ -1304,7 +1304,7 @@ func (r *IronicReconciler) checkIronicConductorGeneration(
13041304
listOpts := []client.ListOption{
13051305
client.InNamespace(instance.Namespace),
13061306
}
1307-
if err := r.Client.List(context.Background(), cnd, listOpts...); err != nil {
1307+
if err := r.List(context.Background(), cnd, listOpts...); err != nil {
13081308
Log.Error(err, "Unable to retrieve IronicConductor CR %w")
13091309
return false, err
13101310
}
@@ -1325,7 +1325,7 @@ func (r *IronicReconciler) checkIronicInspectorGeneration(
13251325
listOpts := []client.ListOption{
13261326
client.InNamespace(instance.Namespace),
13271327
}
1328-
if err := r.Client.List(context.Background(), nsp, listOpts...); err != nil {
1328+
if err := r.List(context.Background(), nsp, listOpts...); err != nil {
13291329
Log.Error(err, "Unable to retrieve IronicInspector CR %w")
13301330
return false, err
13311331
}
@@ -1346,7 +1346,7 @@ func (r *IronicReconciler) checkNeutronAgentGeneration(
13461346
listOpts := []client.ListOption{
13471347
client.InNamespace(instance.Namespace),
13481348
}
1349-
if err := r.Client.List(context.Background(), ag, listOpts...); err != nil {
1349+
if err := r.List(context.Background(), ag, listOpts...); err != nil {
13501350
Log.Error(err, "Unable to retrieve IronicNeutronAgent CR %w")
13511351
return false, err
13521352
}

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.
@@ -752,7 +752,7 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
752752
condition.TLSInputReadyCondition,
753753
condition.RequestedReason,
754754
condition.SeverityInfo,
755-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
755+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
756756
return ctrl.Result{}, nil
757757
}
758758
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -777,7 +777,7 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
777777
condition.TLSInputReadyCondition,
778778
condition.RequestedReason,
779779
condition.SeverityInfo,
780-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
780+
condition.TLSInputReadyWaitingMessage, err.Error()))
781781
return ctrl.Result{}, nil
782782
}
783783
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -976,7 +976,7 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro
976976
if networkReady {
977977
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
978978
} else {
979-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
979+
err := fmt.Errorf("%w: %s", ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
980980
instance.Status.Conditions.Set(condition.FalseCondition(
981981
condition.NetworkAttachmentsReadyCondition,
982982
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.
@@ -594,7 +594,7 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
594594
condition.TLSInputReadyCondition,
595595
condition.RequestedReason,
596596
condition.SeverityInfo,
597-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
597+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
598598
return ctrl.Result{}, nil
599599
}
600600
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -799,7 +799,7 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
799799
if networkReady {
800800
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
801801
} else {
802-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
802+
err := fmt.Errorf("%w: %s", ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
803803
instance.Status.Conditions.Set(condition.FalseCondition(
804804
condition.NetworkAttachmentsReadyCondition,
805805
condition.ErrorReason,

controllers/ironicinspector_controller.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
job "github.com/openstack-k8s-operators/lib-common/modules/common/job"
3434
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
3535
common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac"
36-
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
3736
oko_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
3837
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
3938
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
@@ -43,7 +42,6 @@ import (
4342
routev1 "github.com/openshift/api/route/v1"
4443
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
4544
"k8s.io/apimachinery/pkg/fields"
46-
"k8s.io/apimachinery/pkg/types"
4745
k8s_types "k8s.io/apimachinery/pkg/types"
4846
"k8s.io/utils/ptr"
4947

@@ -127,7 +125,7 @@ func (r *IronicInspectorReconciler) Reconcile(
127125

128126
// Fetch the IronicInspector instance
129127
instance := &ironicv1.IronicInspector{}
130-
err := r.Client.Get(ctx, req.NamespacedName, instance)
128+
err := r.Get(ctx, req.NamespacedName, instance)
131129
if err != nil {
132130
if k8s_errors.IsNotFound(err) {
133131
// Request object not found, could have been deleted after
@@ -292,7 +290,7 @@ func (r *IronicInspectorReconciler) SetupWithManager(
292290
listOpts := []client.ListOption{
293291
client.InNamespace(o.GetNamespace()),
294292
}
295-
if err := r.Client.List(
293+
if err := r.List(
296294
ctx,
297295
apis,
298296
listOpts...); err != nil {
@@ -434,7 +432,7 @@ func (r *IronicInspectorReconciler) findObjectForSrc(ctx context.Context, src cl
434432
listOps := &client.ListOptions{
435433
Namespace: src.GetNamespace(),
436434
}
437-
err := r.Client.List(ctx, crList, listOps)
435+
err := r.List(ctx, crList, listOps)
438436
if err != nil {
439437
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
440438
return requests
@@ -445,7 +443,7 @@ func (r *IronicInspectorReconciler) findObjectForSrc(ctx context.Context, src cl
445443

446444
requests = append(requests,
447445
reconcile.Request{
448-
NamespacedName: types.NamespacedName{
446+
NamespacedName: k8s_types.NamespacedName{
449447
Name: item.GetName(),
450448
Namespace: item.GetNamespace(),
451449
},
@@ -464,7 +462,7 @@ func (r *IronicInspectorReconciler) getTransportURL(
464462
if instance.Spec.RPCTransport != "oslo" {
465463
return "fake://", nil
466464
}
467-
transportURLSecret, _, err := secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace)
465+
transportURLSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace)
468466
if err != nil {
469467
return "", err
470468
}
@@ -604,7 +602,7 @@ func (r *IronicInspectorReconciler) reconcileConfigMapsAndSecrets(
604602
condition.TLSInputReadyCondition,
605603
condition.RequestedReason,
606604
condition.SeverityInfo,
607-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
605+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
608606
return ctrl.Result{RequeueAfter: time.Second * 10}, "", nil
609607
}
610608
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -629,7 +627,7 @@ func (r *IronicInspectorReconciler) reconcileConfigMapsAndSecrets(
629627
condition.TLSInputReadyCondition,
630628
condition.RequestedReason,
631629
condition.SeverityInfo,
632-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
630+
condition.TLSInputReadyWaitingMessage, err.Error()))
633631
return ctrl.Result{RequeueAfter: time.Second * 10}, "", nil
634632
}
635633
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -779,7 +777,7 @@ func (r *IronicInspectorReconciler) reconcileStatefulSet(
779777
if networkReady {
780778
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
781779
} else {
782-
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
780+
err := fmt.Errorf("%w: %s", ErrNetworkAttachmentConfig, instance.Spec.NetworkAttachments)
783781
instance.Status.Conditions.Set(condition.FalseCondition(
784782
condition.NetworkAttachmentsReadyCondition,
785783
condition.ErrorReason,
@@ -1482,7 +1480,7 @@ func (r *IronicInspectorReconciler) generateServiceSecrets(
14821480
map[string]string{})
14831481
Log := r.GetLogger(ctx)
14841482
var tlsCfg *tls.Service
1485-
if instance.Spec.TLS.Ca.CaBundleSecretName != "" {
1483+
if instance.Spec.TLS.CaBundleSecretName != "" {
14861484
tlsCfg = &tls.Service{}
14871485
}
14881486
// customData hold any customization for the service.
@@ -1517,7 +1515,7 @@ func (r *IronicInspectorReconciler) generateServiceSecrets(
15171515
if err != nil {
15181516
return err
15191517
}
1520-
ospSecret, _, err := secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
1518+
ospSecret, _, err := oko_secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
15211519
if err != nil {
15221520
return err
15231521
}

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
@@ -472,7 +472,7 @@ func (r *IronicNeutronAgentReconciler) reconcileConfigMapsAndSecrets(
472472
condition.TLSInputReadyCondition,
473473
condition.RequestedReason,
474474
condition.SeverityInfo,
475-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
475+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
476476
return ctrl.Result{RequeueAfter: time.Second * 10}, "", nil
477477
}
478478
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

0 commit comments

Comments
 (0)