Skip to content

Commit 5bbee53

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

36 files changed

Lines changed: 157 additions & 80 deletions

controllers/aodh_controller.go

Lines changed: 3 additions & 2 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 controllers contains the Kubernetes controllers for managing telemetry components
1718
package controllers
1819

1920
import (
@@ -539,7 +540,7 @@ func (r *AutoscalingReconciler) reconcileNormalAodh(
539540
condition.TLSInputReadyCondition,
540541
condition.RequestedReason,
541542
condition.SeverityInfo,
542-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.Aodh.TLS.CaBundleSecretName)))
543+
condition.TLSInputReadyWaitingMessage, instance.Spec.Aodh.TLS.CaBundleSecretName))
543544
return ctrl.Result{}, nil
544545
}
545546
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -563,7 +564,7 @@ func (r *AutoscalingReconciler) reconcileNormalAodh(
563564
condition.TLSInputReadyCondition,
564565
condition.RequestedReason,
565566
condition.SeverityInfo,
566-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
567+
condition.TLSInputReadyWaitingMessage, err.Error()))
567568
return ctrl.Result{}, nil
568569
}
569570
instance.Status.Conditions.Set(condition.FalseCondition(

controllers/autoscaling_controller.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/openstack-k8s-operators/telemetry-operator/pkg/metricstorage"
26+
telemetry "github.com/openstack-k8s-operators/telemetry-operator/pkg/telemetry"
2627

2728
appsv1 "k8s.io/api/apps/v1"
2829
corev1 "k8s.io/api/core/v1"
@@ -111,7 +112,7 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request)
111112

112113
// Fetch the Autoscaling instance
113114
instance := &telemetryv1.Autoscaling{}
114-
err := r.Client.Get(ctx, req.NamespacedName, instance)
115+
err := r.Get(ctx, req.NamespacedName, instance)
115116
if err != nil {
116117
if k8s_errors.IsNotFound(err) {
117118
// Request object not found, could have been deleted after reconcile request.
@@ -220,7 +221,7 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request)
220221
// fields to index to reconcile when change
221222
const (
222223
autoscalingPasswordSecretField = ".spec.secret"
223-
autoscalingCaBundleSecretNameField = ".spec.tls.caBundleSecretName"
224+
autoscalingCaBundleSecretNameField = ".spec.tls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
224225
autoscalingTLSAPIInternalField = ".spec.tls.api.internal.secretName"
225226
autoscalingTLSAPIPublicField = ".spec.tls.api.public.secretName"
226227
autoscalingTLSField = ".spec.tls.secretName"
@@ -453,7 +454,7 @@ func (r *AutoscalingReconciler) reconcileNormal(
453454
// NOTE: Always do this before calling the generateServiceConfig to get the newest values in the ServiceConfig
454455
//
455456
prometheusEndpointSecret := &corev1.Secret{}
456-
err = r.Client.Get(ctx, client.ObjectKey{
457+
err = r.Get(ctx, client.ObjectKey{
457458
Name: autoscaling.PrometheusEndpointSecret,
458459
Namespace: instance.Namespace,
459460
}, prometheusEndpointSecret)
@@ -474,15 +475,18 @@ func (r *AutoscalingReconciler) reconcileNormal(
474475
if err != nil {
475476
return ctrlResult, err
476477
}
477-
instance.Status.PrometheusPort = int32(port)
478+
if port < 0 || port > 65535 {
479+
return ctrlResult, fmt.Errorf("%w: %d", telemetry.ErrInvalidPortNumber, port)
480+
}
481+
instance.Status.PrometheusPort = int32(port) //nolint:gosec // G109: Port validated to be within valid range
478482
}
479483
} else {
480484
instance.Status.PrometheusPort = instance.Spec.PrometheusPort
481485
}
482486
if instance.Spec.PrometheusHost == "" {
483487
// We're using MetricStorage for Prometheus. Set TLS accordingly
484488
metricStorage := &telemetryv1.MetricStorage{}
485-
err := r.Client.Get(ctx, client.ObjectKey{
489+
err := r.Get(ctx, client.ObjectKey{
486490
Namespace: instance.Namespace,
487491
Name: telemetryv1.DefaultServiceName,
488492
}, metricStorage)
@@ -785,7 +789,7 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
785789
listOpts := []client.ListOption{
786790
client.InNamespace(o.GetNamespace()),
787791
}
788-
if err := r.Client.List(context.Background(), autoscalings, listOpts...); err != nil {
792+
if err := r.List(context.Background(), autoscalings, listOpts...); err != nil {
789793
Log.Error(err, "Unable to retrieve Autoscaling CRs %v")
790794
return nil
791795
}
@@ -818,7 +822,7 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
818822
listOpts := []client.ListOption{
819823
client.InNamespace(o.GetNamespace()),
820824
}
821-
if err := r.Client.List(context.Background(), autoscalings, listOpts...); err != nil {
825+
if err := r.List(context.Background(), autoscalings, listOpts...); err != nil {
822826
Log.Error(err, "Unable to retrieve Autoscaling CRs %w")
823827
return nil
824828
}
@@ -846,7 +850,7 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
846850
listOpts := []client.ListOption{
847851
client.InNamespace(o.GetNamespace()),
848852
}
849-
if err := r.Client.List(context.Background(), autoscalings, listOpts...); err != nil {
853+
if err := r.List(context.Background(), autoscalings, listOpts...); err != nil {
850854
Log.Error(err, "Unable to retrieve Autoscaling CRs %w")
851855
return nil
852856
}
@@ -963,7 +967,7 @@ func (r *AutoscalingReconciler) findObjectsForSrc(ctx context.Context, src clien
963967
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
964968
Namespace: src.GetNamespace(),
965969
}
966-
err := r.Client.List(ctx, crList, listOps)
970+
err := r.List(ctx, crList, listOps)
967971
if err != nil {
968972
return []reconcile.Request{}
969973
}
@@ -994,7 +998,7 @@ func (r *AutoscalingReconciler) findObjectForSrc(ctx context.Context, src client
994998
listOps := &client.ListOptions{
995999
Namespace: src.GetNamespace(),
9961000
}
997-
err := r.Client.List(ctx, crList, listOps)
1001+
err := r.List(ctx, crList, listOps)
9981002
if err != nil {
9991003
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
10001004
return requests

controllers/ceilometer_controller.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (r *CeilometerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
114114

115115
// Fetch the Ceilometer instance
116116
instance := &telemetryv1.Ceilometer{}
117-
err := r.Client.Get(ctx, req.NamespacedName, instance)
117+
err := r.Get(ctx, req.NamespacedName, instance)
118118
if err != nil {
119119
if k8s_errors.IsNotFound(err) {
120120
// Request object not found, could have been deleted after reconcile request.
@@ -236,11 +236,11 @@ func (r *CeilometerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
236236
// fields to index to reconcile when change
237237
const (
238238
ceilometerPasswordSecretField = ".spec.secret"
239-
ceilometerCaBundleSecretNameField = ".spec.tls.caBundleSecretName"
239+
ceilometerCaBundleSecretNameField = ".spec.tls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
240240
ceilometerTLSField = ".spec.tls.secretName"
241-
ksmCaBundleSecretNameField = ".spec.ksmTls.caBundleSecretName"
241+
ksmCaBundleSecretNameField = ".spec.ksmTls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
242242
ksmTLSField = ".spec.ksmTls.secretName"
243-
mysqldExporterCaBundleSecretNameField = ".spec.mysqldExporterTls.caBundleSecretName"
243+
mysqldExporterCaBundleSecretNameField = ".spec.mysqldExporterTls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
244244
mysqldExporterTLSField = ".spec.mysqldExporterTls.secretName"
245245
)
246246

@@ -620,7 +620,7 @@ func (r *CeilometerReconciler) reconcileCeilometer(
620620
condition.TLSInputReadyCondition,
621621
condition.RequestedReason,
622622
condition.SeverityInfo,
623-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName)))
623+
condition.TLSInputReadyWaitingMessage, instance.Spec.TLS.CaBundleSecretName))
624624
return ctrl.Result{}, nil
625625
}
626626
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -646,7 +646,7 @@ func (r *CeilometerReconciler) reconcileCeilometer(
646646
condition.TLSInputReadyCondition,
647647
condition.RequestedReason,
648648
condition.SeverityInfo,
649-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
649+
condition.TLSInputReadyWaitingMessage, err.Error()))
650650
return ctrl.Result{}, nil
651651
}
652652
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -850,7 +850,7 @@ func (r *CeilometerReconciler) reconcileMysqldExporter(
850850
telemetryv1.MysqldExporterTLSInputReadyCondition,
851851
condition.RequestedReason,
852852
condition.SeverityInfo,
853-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.MysqldExporterTLS.CaBundleSecretName)))
853+
condition.TLSInputReadyWaitingMessage, instance.Spec.MysqldExporterTLS.CaBundleSecretName))
854854
return ctrl.Result{}, nil
855855
}
856856
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -876,7 +876,7 @@ func (r *CeilometerReconciler) reconcileMysqldExporter(
876876
telemetryv1.MysqldExporterTLSInputReadyCondition,
877877
condition.RequestedReason,
878878
condition.SeverityInfo,
879-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, err.Error())))
879+
condition.TLSInputReadyWaitingMessage, err.Error()))
880880
return ctrl.Result{}, nil
881881
}
882882
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -1029,7 +1029,7 @@ func (r *CeilometerReconciler) reconcileKSM(
10291029
telemetryv1.KSMTLSInputReadyCondition,
10301030
condition.RequestedReason,
10311031
condition.SeverityInfo,
1032-
fmt.Sprintf(condition.TLSInputReadyWaitingMessage, instance.Spec.KSMTLS.CaBundleSecretName)))
1032+
condition.TLSInputReadyWaitingMessage, instance.Spec.KSMTLS.CaBundleSecretName))
10331033
return ctrl.Result{}, nil
10341034
}
10351035
instance.Status.Conditions.Set(condition.FalseCondition(
@@ -1403,7 +1403,7 @@ func (r *CeilometerReconciler) mysqldExporterEnsureDB(
14031403
// Unfortunatelly access to the database is granted only after creating a db.
14041404
db := mariadbv1.NewDatabaseForAccount(
14051405
dbInstance, // mariadb/galera service to target
1406-
strings.Replace(databaseName, "-", "_", -1), // name used in CREATE DATABASE in mariadb
1406+
strings.ReplaceAll(databaseName, "-", "_"), // name used in CREATE DATABASE in mariadb
14071407
databaseName, // CR name for MariaDBDatabase
14081408
accountName, // CR name for MariaDBAccount
14091409
instance.Namespace, // namespace
@@ -1466,7 +1466,7 @@ func (r *CeilometerReconciler) generateMysqldExporterServiceConfig(
14661466
listOpts := []client.ListOption{
14671467
client.InNamespace(instance.GetNamespace()),
14681468
}
1469-
if err := r.Client.List(context.Background(), galeras, listOpts...); err != nil {
1469+
if err := r.List(context.Background(), galeras, listOpts...); err != nil {
14701470
return ctrl.Result{}, err
14711471
}
14721472

@@ -1620,7 +1620,7 @@ func (r *CeilometerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
16201620
listOpts := []client.ListOption{
16211621
client.InNamespace(o.GetNamespace()),
16221622
}
1623-
if err := r.Client.List(context.Background(), ceilometers, listOpts...); err != nil {
1623+
if err := r.List(context.Background(), ceilometers, listOpts...); err != nil {
16241624
Log.Error(err, "Unable to retrieve Ceilometer CRs %v")
16251625
return nil
16261626
}
@@ -1665,7 +1665,7 @@ func (r *CeilometerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
16651665
listOpts := []client.ListOption{
16661666
client.InNamespace(o.GetNamespace()),
16671667
}
1668-
if err := r.Client.List(context.Background(), ceilometers, listOpts...); err != nil {
1668+
if err := r.List(context.Background(), ceilometers, listOpts...); err != nil {
16691669
Log.Error(err, "Unable to retrieve Ceilometer CRs %v")
16701670
return nil
16711671
}
@@ -1834,7 +1834,7 @@ func (r *CeilometerReconciler) findObjectsForSrc(ctx context.Context, src client
18341834
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
18351835
Namespace: src.GetNamespace(),
18361836
}
1837-
err := r.Client.List(ctx, crList, listOps)
1837+
err := r.List(ctx, crList, listOps)
18381838
if err != nil {
18391839
Log.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace()))
18401840
return requests
@@ -1866,7 +1866,7 @@ func (r *CeilometerReconciler) findObjectForSrc(ctx context.Context, src client.
18661866
listOps := &client.ListOptions{
18671867
Namespace: src.GetNamespace(),
18681868
}
1869-
err := r.Client.List(ctx, crList, listOps)
1869+
err := r.List(ctx, crList, listOps)
18701870
if err != nil {
18711871
Log.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
18721872
return requests

controllers/logging_controller.go

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

7979
// Fetch the Logging instance
8080
instance := &telemetryv1.Logging{}
81-
err := r.Client.Get(ctx, req.NamespacedName, instance)
81+
err := r.Get(ctx, req.NamespacedName, instance)
8282
if err != nil {
8383
if k8s_errors.IsNotFound(err) {
8484
// Request object not found, could have been deleted after reconcile request.
@@ -329,7 +329,7 @@ func (r *LoggingReconciler) retrieveOpenshiftCA(ctx context.Context) []byte {
329329
Namespace: "openshift-service-ca",
330330
}
331331
instance := &corev1.Secret{}
332-
err := r.Client.Get(ctx, namespacedName, instance)
332+
err := r.Get(ctx, namespacedName, instance)
333333
if err != nil {
334334
// No Openshift CA secret in the cluster
335335
return nil

0 commit comments

Comments
 (0)