Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split release struct #17

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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