Skip to content

Commit 04198b2

Browse files
committed
Fix pre-commit
1 parent 9818ce0 commit 04198b2

18 files changed

+102
-101
lines changed

api/bases/telemetry.openstack.org_cloudkitties.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ spec:
615615
type: object
616616
minItems: 1
617617
type: array
618+
x-kubernetes-list-type: atomic
618619
secret:
619620
description: |-
620621
Secret for object storage authentication.
@@ -649,8 +650,6 @@ spec:
649650
CA is the name of a ConfigMap containing a CA certificate.
650651
It needs to be in the same namespace as the CloudKitty custom resource.
651652
type: string
652-
required:
653-
- caName
654653
type: object
655654
type: object
656655
secret:

api/bases/telemetry.openstack.org_telemetries.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ spec:
11811181
type: object
11821182
minItems: 1
11831183
type: array
1184+
x-kubernetes-list-type: atomic
11841185
secret:
11851186
description: |-
11861187
Secret for object storage authentication.
@@ -1215,8 +1216,6 @@ spec:
12151216
CA is the name of a ConfigMap containing a CA certificate.
12161217
It needs to be in the same namespace as the CloudKitty custom resource.
12171218
type: string
1218-
required:
1219-
- caName
12201219
type: object
12211220
type: object
12221221
secret:

api/v1beta1/cloudkitty_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CASpec struct {
5959
// It needs to be in the same namespace as the CloudKitty custom resource.
6060
//
6161
// +kubebuilder:validation:optional
62-
CA string `json:"caName"`
62+
CA string `json:"caName,omitempty"`
6363
}
6464

6565
type ObjectStorageSchema struct {
@@ -108,6 +108,7 @@ type ObjectStorageSpec struct {
108108
// +kubebuilder:validation:Optional
109109
// +kubebuilder:validation:MinItems:=1
110110
// +kubebuilder:default:={{version:v11,effectiveDate:"2020-10-11"}}
111+
// +listType=atomic
111112
Schemas []ObjectStorageSchema `json:"schemas"`
112113

113114
// Secret for object storage authentication.
@@ -188,7 +189,7 @@ type CloudKittySpecBase struct {
188189
// S3 related configuration passed to Loki
189190
// +kubebuilder:validation:Optional
190191
// +kubebuilder:default={secret: {name: "cloudkitty-loki-s3", type: "s3"}}
191-
S3StorageConfig ObjectStorageSpec `json:"s3StorageConfig,omitempty"`
192+
S3StorageConfig ObjectStorageSpec `json:"s3StorageConfig"`
192193

193194
// Storage class used for Loki
194195
// +kubebuilder:validation:Optional

config/crd/bases/telemetry.openstack.org_cloudkitties.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ spec:
615615
type: object
616616
minItems: 1
617617
type: array
618+
x-kubernetes-list-type: atomic
618619
secret:
619620
description: |-
620621
Secret for object storage authentication.
@@ -649,8 +650,6 @@ spec:
649650
CA is the name of a ConfigMap containing a CA certificate.
650651
It needs to be in the same namespace as the CloudKitty custom resource.
651652
type: string
652-
required:
653-
- caName
654653
type: object
655654
type: object
656655
secret:

config/crd/bases/telemetry.openstack.org_telemetries.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ spec:
11811181
type: object
11821182
minItems: 1
11831183
type: array
1184+
x-kubernetes-list-type: atomic
11841185
secret:
11851186
description: |-
11861187
Secret for object storage authentication.
@@ -1215,8 +1216,6 @@ spec:
12151216
CA is the name of a ConfigMap containing a CA certificate.
12161217
It needs to be in the same namespace as the CloudKitty custom resource.
12171218
type: string
1218-
required:
1219-
- caName
12201219
type: object
12211220
type: object
12221221
secret:

controllers/cloudkitty_controller.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (r *CloudKittyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
131131

132132
// Fetch the CloudKitty instance
133133
instance := &telemetryv1.CloudKitty{}
134-
err := r.Client.Get(ctx, req.NamespacedName, instance)
134+
err := r.Get(ctx, req.NamespacedName, instance)
135135
if err != nil {
136136
if k8s_errors.IsNotFound(err) {
137137
// Request object not found, could have been deleted after reconcile request.
@@ -235,7 +235,8 @@ func (r *CloudKittyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
235235

236236
// fields to index to reconcile when change
237237
const (
238-
cloudKittyPasswordSecretField = ".spec.secret"
238+
cloudKittyPasswordSecretField = ".spec.secret"
239+
//nolint:gosec // Not hardcoded credentials, just field name
239240
cloudKittyCaBundleSecretNameField = ".spec.tls.caBundleSecretName"
240241
cloudKittyTLSAPIInternalField = ".spec.tls.api.internal.secretName"
241242
cloudKittyTLSAPIPublicField = ".spec.tls.api.public.secretName"
@@ -280,7 +281,7 @@ func (r *CloudKittyReconciler) SetupWithManager(mgr ctrl.Manager) error {
280281
listOpts := []client.ListOption{
281282
client.InNamespace(o.GetNamespace()),
282283
}
283-
if err := r.Client.List(ctx, cloudkitties, listOpts...); err != nil {
284+
if err := r.List(ctx, cloudkitties, listOpts...); err != nil {
284285
Log.Error(err, "Unable to retrieve CloudKitty CRs %v")
285286
return nil
286287
}
@@ -316,7 +317,7 @@ func (r *CloudKittyReconciler) SetupWithManager(mgr ctrl.Manager) error {
316317
listOpts := []client.ListOption{
317318
client.InNamespace(o.GetNamespace()),
318319
}
319-
if err := r.Client.List(ctx, cloudkitties, listOpts...); err != nil {
320+
if err := r.List(ctx, cloudkitties, listOpts...); err != nil {
320321
Log.Error(err, "Unable to retrieve CloudKitty CRs %w")
321322
return nil
322323
}
@@ -374,7 +375,7 @@ func (r *CloudKittyReconciler) findObjectForSrc(ctx context.Context, src client.
374375
listOps := &client.ListOptions{
375376
Namespace: src.GetNamespace(),
376377
}
377-
err := r.Client.List(ctx, crList, listOps)
378+
err := r.List(ctx, crList, listOps)
378379
if err != nil {
379380
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
380381
return requests
@@ -609,7 +610,9 @@ func (r *CloudKittyReconciler) reconcileNormal(ctx context.Context, instance *te
609610
condition.SeverityError,
610611
telemetryv1.CloudKittyClientCertReadyErrorMessage,
611612
err.Error()))
612-
return ctrl.Result{}, err
613+
return ctrlResult, err
614+
} else if (ctrlResult != ctrl.Result{}) {
615+
return ctrlResult, nil
613616
}
614617

615618
cms := []util.Template{
@@ -641,15 +644,15 @@ func (r *CloudKittyReconciler) reconcileNormal(ctx context.Context, instance *te
641644
instance.Status.Conditions.MarkTrue(telemetryv1.CloudKittyClientCertReadyCondition, telemetryv1.CloudKittyClientCertReadyMessage)
642645

643646
// Deploy Loki
644-
var eventHandler handler.EventHandler = handler.EnqueueRequestForOwner(
647+
var eventHandler = handler.EnqueueRequestForOwner(
645648
r.Scheme,
646649
r.RESTMapper,
647650
&telemetryv1.CloudKitty{},
648651
handler.OnlyControllerOwner(),
649652
)
650653

651654
err = utils.EnsureWatches(
652-
(*utils.ConditionalWatchingReconciler)(r), ctx,
655+
ctx, (*utils.ConditionalWatchingReconciler)(r),
653656
"lokistacks.loki.grafana.com",
654657
&lokistackv1.LokiStack{}, eventHandler, helper,
655658
)
@@ -674,7 +677,7 @@ func (r *CloudKittyReconciler) reconcileNormal(ctx context.Context, instance *te
674677
return err
675678
}
676679
desiredLokiStack.Spec.DeepCopyInto(&lokiStack.Spec)
677-
lokiStack.ObjectMeta.Labels = serviceLabels
680+
lokiStack.Labels = serviceLabels
678681
err = controllerutil.SetControllerReference(instance, lokiStack, r.Scheme)
679682
return err
680683
})
@@ -911,6 +914,7 @@ func (r *CloudKittyReconciler) reconcileNormal(ctx context.Context, instance *te
911914
condition.SeverityInfo,
912915
condition.NetworkAttachmentsReadyWaitingMessage,
913916
netAtt))
917+
//nolint:err113 // Using condition message format from lib-common
914918
return cloudkitty.ResultRequeue, fmt.Errorf(condition.NetworkAttachmentsReadyWaitingMessage, netAtt)
915919
}
916920
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -1036,7 +1040,7 @@ func (r *CloudKittyReconciler) generateServiceConfigs(
10361040
labels := labels.GetLabels(instance, labels.GetGroupLabel(cloudkitty.ServiceName), serviceLabels)
10371041

10381042
var tlsCfg *tls.Service
1039-
if instance.Spec.CloudKittyAPI.TLS.Ca.CaBundleSecretName != "" {
1043+
if instance.Spec.CloudKittyAPI.TLS.CaBundleSecretName != "" {
10401044
tlsCfg = &tls.Service{}
10411045
}
10421046

@@ -1072,7 +1076,7 @@ func (r *CloudKittyReconciler) generateServiceConfigs(
10721076
if instance.Spec.PrometheusHost == "" {
10731077
// We're using MetricStorage for Prometheus.
10741078
prometheusEndpointSecret := &corev1.Secret{}
1075-
err = r.Client.Get(ctx, client.ObjectKey{
1079+
err = r.Get(ctx, client.ObjectKey{
10761080
Name: cloudkitty.PrometheusEndpointSecret,
10771081
Namespace: instance.Namespace,
10781082
}, prometheusEndpointSecret)
@@ -1085,10 +1089,11 @@ func (r *CloudKittyReconciler) generateServiceConfigs(
10851089
if err != nil {
10861090
return err
10871091
}
1092+
//nolint:gosec // G109: Port number is read from a secret and validated to be within valid range
10881093
instance.Status.PrometheusPort = int32(port)
10891094

10901095
metricStorage := &telemetryv1.MetricStorage{}
1091-
err = r.Client.Get(ctx, client.ObjectKey{
1096+
err = r.Get(ctx, client.ObjectKey{
10921097
Namespace: instance.Namespace,
10931098
Name: telemetryv1.DefaultServiceName,
10941099
}, metricStorage)

controllers/cloudkittyapi_controller.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (r *CloudKittyAPIReconciler) Reconcile(ctx context.Context, req ctrl.Reques
112112

113113
// Fetch the CloudKittyAPI instance
114114
instance := &telemetryv1.CloudKittyAPI{}
115-
err := r.Client.Get(ctx, req.NamespacedName, instance)
115+
err := r.Get(ctx, req.NamespacedName, instance)
116116
if err != nil {
117117
if k8s_errors.IsNotFound(err) {
118118
// Request object not found, could have been deleted after reconcile request.
@@ -224,16 +224,16 @@ func (r *CloudKittyAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl
224224
// Watch for changes to secrets we don't own. Global secrets
225225
// (e.g. TransportURLSecret) are handled by the main cloudkitty controller.
226226
secretFn := func(_ context.Context, o client.Object) []reconcile.Request {
227-
var namespace string = o.GetNamespace()
228-
var secretName string = o.GetName()
227+
var namespace = o.GetNamespace()
228+
var secretName = o.GetName()
229229
result := []reconcile.Request{}
230230

231231
// get all API CRs
232232
apis := &telemetryv1.CloudKittyAPIList{}
233233
listOpts := []client.ListOption{
234234
client.InNamespace(namespace),
235235
}
236-
if err := r.Client.List(context.Background(), apis, listOpts...); err != nil {
236+
if err := r.List(context.Background(), apis, listOpts...); err != nil {
237237
Log.Error(err, "Unable to retrieve API CRs %v")
238238
return nil
239239
}
@@ -291,7 +291,7 @@ func (r *CloudKittyAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl
291291

292292
// Fetch the parent CloudKitty instance
293293
parentCloudKitty := &telemetryv1.CloudKitty{}
294-
_ = r.Client.Get(ctx, types.NamespacedName{
294+
_ = r.Get(ctx, types.NamespacedName{
295295
Name: parentCloudKittyName,
296296
Namespace: cr.Namespace,
297297
}, parentCloudKitty)
@@ -316,16 +316,16 @@ func (r *CloudKittyAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl
316316

317317
// Watch for changes to configmaps we don't own.
318318
configMapFn := func(_ context.Context, o client.Object) []reconcile.Request {
319-
var namespace string = o.GetNamespace()
320-
var configMapName string = o.GetName()
319+
var namespace = o.GetNamespace()
320+
var configMapName = o.GetName()
321321
result := []reconcile.Request{}
322322

323323
// get all API CRs
324324
apis := &telemetryv1.CloudKittyAPIList{}
325325
listOpts := []client.ListOption{
326326
client.InNamespace(namespace),
327327
}
328-
if err := r.Client.List(context.Background(), apis, listOpts...); err != nil {
328+
if err := r.List(context.Background(), apis, listOpts...); err != nil {
329329
Log.Error(err, "Unable to retrieve API CRs %v")
330330
return nil
331331
}
@@ -903,6 +903,7 @@ func (r *CloudKittyAPIReconciler) reconcileNormal(ctx context.Context, instance
903903
condition.SeverityInfo,
904904
condition.NetworkAttachmentsReadyWaitingMessage,
905905
netAtt))
906+
//nolint:err113 // Dynamic error message with network attachment name
906907
return cloudkitty.ResultRequeue, fmt.Errorf("network-attachment-definition %s not found", netAtt)
907908
}
908909
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -1038,6 +1039,7 @@ func (r *CloudKittyAPIReconciler) reconcileNormal(ctx context.Context, instance
10381039
ssData = ss.GetStatefulSet()
10391040
if ssData.Generation != ssData.Status.ObservedGeneration {
10401041
ctrlResult = cloudkitty.ResultRequeue
1042+
//nolint:err113 // Dynamic error message with statefulset name
10411043
err = fmt.Errorf("waiting for Statefulset %s to start reconciling", ssData.Name)
10421044
}
10431045
}
@@ -1088,6 +1090,7 @@ func (r *CloudKittyAPIReconciler) reconcileNormal(ctx context.Context, instance
10881090
if networkReady {
10891091
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
10901092
} else {
1093+
//nolint:err113 // Dynamic error message with network attachments
10911094
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
10921095
instance.Status.Conditions.Set(condition.FalseCondition(
10931096
condition.NetworkAttachmentsReadyCondition,

controllers/cloudkittyproc_controller.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (r *CloudKittyProcReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9797

9898
// Fetch the CloudKittyProc instance
9999
instance := &telemetryv1.CloudKittyProc{}
100-
err := r.Client.Get(ctx, req.NamespacedName, instance)
100+
err := r.Get(ctx, req.NamespacedName, instance)
101101
if err != nil {
102102
if k8s_errors.IsNotFound(err) {
103103
// Request object not found, could have been deleted after reconcile request.
@@ -199,16 +199,16 @@ func (r *CloudKittyProcReconciler) SetupWithManager(ctx context.Context, mgr ctr
199199
// Watch for changes to secrets we don't own. Global secrets
200200
// (e.g. TransportURLSecret) are handled by the main cloudkitty controller.
201201
secretFn := func(_ context.Context, o client.Object) []reconcile.Request {
202-
var namespace string = o.GetNamespace()
203-
var secretName string = o.GetName()
202+
var namespace = o.GetNamespace()
203+
var secretName = o.GetName()
204204
result := []reconcile.Request{}
205205

206206
// get all CloudKittyProc CRs
207207
cloudKittyProcs := &telemetryv1.CloudKittyProcList{}
208208
listOpts := []client.ListOption{
209209
client.InNamespace(namespace),
210210
}
211-
if err := r.Client.List(context.Background(), cloudKittyProcs, listOpts...); err != nil {
211+
if err := r.List(context.Background(), cloudKittyProcs, listOpts...); err != nil {
212212
Log.Error(err, "Unable to retrieve scheduler CRs %v")
213213
return nil
214214
}
@@ -266,7 +266,7 @@ func (r *CloudKittyProcReconciler) SetupWithManager(ctx context.Context, mgr ctr
266266

267267
// Fetch the parent CloudKitty instance
268268
parentCloudKitty := &telemetryv1.CloudKitty{}
269-
_ = r.Client.Get(ctx, types.NamespacedName{
269+
_ = r.Get(ctx, types.NamespacedName{
270270
Name: parentCloudKittyName,
271271
Namespace: cr.Namespace,
272272
}, parentCloudKitty)
@@ -291,16 +291,16 @@ func (r *CloudKittyProcReconciler) SetupWithManager(ctx context.Context, mgr ctr
291291

292292
// Watch for changes to configmaps we don't own.
293293
configMapFn := func(_ context.Context, o client.Object) []reconcile.Request {
294-
var namespace string = o.GetNamespace()
295-
var configMapName string = o.GetName()
294+
var namespace = o.GetNamespace()
295+
var configMapName = o.GetName()
296296
result := []reconcile.Request{}
297297

298298
// get all Proc CRs
299299
procs := &telemetryv1.CloudKittyProcList{}
300300
listOpts := []client.ListOption{
301301
client.InNamespace(namespace),
302302
}
303-
if err := r.Client.List(context.Background(), procs, listOpts...); err != nil {
303+
if err := r.List(context.Background(), procs, listOpts...); err != nil {
304304
Log.Error(err, "Unable to retrieve Proc CRs %v")
305305
return nil
306306
}
@@ -613,6 +613,7 @@ func (r *CloudKittyProcReconciler) reconcileNormal(ctx context.Context, instance
613613
condition.SeverityInfo,
614614
condition.NetworkAttachmentsReadyWaitingMessage,
615615
netAtt))
616+
//nolint:err113 // Dynamic error message with network attachment name
616617
return cloudkitty.ResultRequeue, fmt.Errorf("network-attachment-definition %s not found", netAtt)
617618
}
618619
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -686,6 +687,7 @@ func (r *CloudKittyProcReconciler) reconcileNormal(ctx context.Context, instance
686687
ssData = ss.GetStatefulSet()
687688
if ssData.Generation != ssData.Status.ObservedGeneration {
688689
ctrlResult = cloudkitty.ResultRequeue
690+
//nolint:err113 // Dynamic error message with statefulset name
689691
err = fmt.Errorf("waiting for Statefulset %s to start reconciling", ssData.Name)
690692
}
691693
}
@@ -736,6 +738,7 @@ func (r *CloudKittyProcReconciler) reconcileNormal(ctx context.Context, instance
736738
if networkReady {
737739
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
738740
} else {
741+
//nolint:err113 // Dynamic error message with network attachments
739742
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
740743
instance.Status.Conditions.Set(condition.FalseCondition(
741744
condition.NetworkAttachmentsReadyCondition,

0 commit comments

Comments
 (0)