From cd8f6134f77c838924815c9f069bcce7b03324b5 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Fri, 15 Nov 2024 11:18:18 +0100 Subject: [PATCH] Fix log messages for Zone K8s version controller We can't use the default formatting for `version.Info` when we only set a limited amount of fields. Instead we introduce a thin wrapper for the `fmt.Sprintf()` which we already used to set the version on the control-api zone object and use that wrapper for the log messages. --- controllers/zonek8sversion_controller.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/controllers/zonek8sversion_controller.go b/controllers/zonek8sversion_controller.go index e8275fd..2923a74 100644 --- a/controllers/zonek8sversion_controller.go +++ b/controllers/zonek8sversion_controller.go @@ -59,7 +59,7 @@ func (r *ZoneK8sVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque return ctrl.Result{}, err } - l.Info("OCP current version", "version", ocpVersion) + l.Info("OCP current version", "version", formatVersion(ocpVersion)) // We don't use client-go's ServerVersion() so we get context support body, err := r.RESTClient.Get().AbsPath("/version").Do(ctx).Raw() @@ -71,7 +71,7 @@ func (r *ZoneK8sVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { return ctrl.Result{}, err } - l.Info("K8s current version", "version", k8sVersion) + l.Info("K8s current version", "version", formatVersion(&k8sVersion)) // List zones by label because we don't enforce any naming conventions // for the Zone objects on the control-api cluster. @@ -91,10 +91,8 @@ func (r *ZoneK8sVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque var errs []error for _, z := range zones.Items { - z.Data.Features[kubernetesVersionFeatureKey] = - fmt.Sprintf("%s.%s", k8sVersion.Major, k8sVersion.Minor) - z.Data.Features[openshiftVersionFeatureKey] = - fmt.Sprintf("%s.%s", ocpVersion.Major, ocpVersion.Minor) + z.Data.Features[kubernetesVersionFeatureKey] = formatVersion(&k8sVersion) + z.Data.Features[openshiftVersionFeatureKey] = formatVersion(ocpVersion) if err := r.ForeignClient.Update(ctx, &z); err != nil { errs = append(errs, err) } @@ -136,3 +134,7 @@ func extractOpenShiftVersion(cv *configv1.ClusterVersion) (*version.Info, error) } return &version, nil } + +func formatVersion(v *version.Info) string { + return fmt.Sprintf("%s.%s", v.Major, v.Minor) +}