Skip to content

Commit

Permalink
Split release struct (#17)
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Dinov <[email protected]>
  • Loading branch information
atanasdinov committed Jul 24, 2024
1 parent 003e6b2 commit 340d526
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
10 changes: 5 additions & 5 deletions internal/controller/reconcile_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/upgradeplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
30 changes: 17 additions & 13 deletions pkg/release/release.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 340d526

Please sign in to comment.