diff --git a/internal/controller/reconcile_kubernetes.go b/internal/controller/reconcile_kubernetes.go index ff2e89f..b549bc6 100644 --- a/internal/controller/reconcile_kubernetes.go +++ b/internal/controller/reconcile_kubernetes.go @@ -16,13 +16,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func (r *UpgradePlanReconciler) reconcileKubernetes(ctx context.Context, upgradePlan *lifecyclev1alpha1.UpgradePlan, release *release.Release) (ctrl.Result, error) { +func (r *UpgradePlanReconciler) reconcileKubernetes(ctx context.Context, upgradePlan *lifecyclev1alpha1.UpgradePlan, kubernetes *release.Kubernetes) (ctrl.Result, error) { nodeList := &corev1.NodeList{} if err := r.List(ctx, nodeList); err != nil { return ctrl.Result{}, fmt.Errorf("listing nodes: %w", err) } - kubernetesVersion, err := targetKubernetesVersion(nodeList, release) + kubernetesVersion, err := targetKubernetesVersion(nodeList, kubernetes) if err != nil { return ctrl.Result{}, fmt.Errorf("identifying target kubernetes version: %w", err) } @@ -72,7 +72,7 @@ func (r *UpgradePlanReconciler) reconcileKubernetes(ctx context.Context, upgrade return ctrl.Result{Requeue: true}, nil } -func targetKubernetesVersion(nodeList *corev1.NodeList, release *release.Release) (string, error) { +func targetKubernetesVersion(nodeList *corev1.NodeList, kubernetes *release.Kubernetes) (string, error) { if len(nodeList.Items) == 0 { return "", fmt.Errorf("unable to determine current kubernetes version due to empty node list") } @@ -81,9 +81,9 @@ func targetKubernetesVersion(nodeList *corev1.NodeList, release *release.Release switch { case strings.Contains(kubeletVersion, "k3s"): - return release.Components.Kubernetes.K3S.Version, nil + return kubernetes.K3S.Version, nil case strings.Contains(kubeletVersion, "rke2"): - return release.Components.Kubernetes.RKE2.Version, nil + return kubernetes.RKE2.Version, nil default: return "", fmt.Errorf("upgrading from kubernetes version %s is not supported", kubeletVersion) } diff --git a/internal/controller/upgradeplan_controller.go b/internal/controller/upgradeplan_controller.go index e44f865..68075c2 100644 --- a/internal/controller/upgradeplan_controller.go +++ b/internal/controller/upgradeplan_controller.go @@ -89,7 +89,7 @@ func (r *UpgradePlanReconciler) executePlan(ctx context.Context, upgradePlan *li // Upgrade OS here... if !meta.IsStatusConditionTrue(upgradePlan.Status.Conditions, lifecyclev1alpha1.KubernetesUpgradedCondition) { - return r.reconcileKubernetes(ctx, upgradePlan, release) + return r.reconcileKubernetes(ctx, upgradePlan, &release.Components.Kubernetes) } // Upgrade rest of the components here... diff --git a/pkg/release/release.go b/pkg/release/release.go index 0a2092c..713dd05 100644 --- a/pkg/release/release.go +++ b/pkg/release/release.go @@ -1,19 +1,23 @@ package release type Release struct { - APIVersion float64 `yaml:"apiVersion"` - ReleaseVersion string `yaml:"releaseVersion"` - Components struct { - Kubernetes struct { - K3S struct { - Version string `yaml:"version"` - } `yaml:"k3s"` - RKE2 struct { - Version string `yaml:"version"` - } `yaml:"rke2"` - } `yaml:"kubernetes"` - OperatingSystem OperatingSystem `yaml:"operatingSystem"` - } `yaml:"components"` + APIVersion float64 `yaml:"apiVersion"` + ReleaseVersion string `yaml:"releaseVersion"` + Components Components `yaml:"components"` +} + +type Components struct { + Kubernetes Kubernetes `yaml:"kubernetes"` + OperatingSystem OperatingSystem `yaml:"operatingSystem"` +} + +type Kubernetes struct { + K3S KubernetesDistribution `yaml:"k3s"` + RKE2 KubernetesDistribution `yaml:"rke2"` +} + +type KubernetesDistribution struct { + Version string `yaml:"version"` } type OperatingSystem struct {