Skip to content

Commit

Permalink
Fix log messages for Zone K8s version controller
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
simu committed Nov 15, 2024
1 parent 54c15d4 commit cd8f613
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions controllers/zonek8sversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}

0 comments on commit cd8f613

Please sign in to comment.