Skip to content

Commit

Permalink
Kubevirt dashboard upgrade (#41)
Browse files Browse the repository at this point in the history
* Update KubeVirt definition

* Update kubevirt reconciliation

* Rework recordCreatedObject function

* Remove kubevirt reconciliation
  • Loading branch information
ipetrov117 authored Aug 7, 2024
1 parent 9644735 commit c43d09d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
37 changes: 32 additions & 5 deletions internal/controller/reconcile_kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,48 @@ package controller

import (
"context"
"fmt"

lifecyclev1alpha1 "github.com/suse-edge/upgrade-controller/api/v1alpha1"
"github.com/suse-edge/upgrade-controller/internal/upgrade"
"github.com/suse-edge/upgrade-controller/pkg/release"

corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
)

func (r *UpgradePlanReconciler) reconcileKubevirt(ctx context.Context, upgradePlan *lifecyclev1alpha1.UpgradePlan, kubevirt *release.HelmChart) (ctrl.Result, error) {
state, err := r.upgradeHelmChart(ctx, upgradePlan, kubevirt)
func (r *UpgradePlanReconciler) reconcileKubevirt(ctx context.Context, upgradePlan *lifecyclev1alpha1.UpgradePlan, kubevirt *release.KubeVirt) (ctrl.Result, error) {
kubevirtState, err := r.upgradeHelmChart(ctx, upgradePlan, &kubevirt.KubeVirt)
if err != nil {
return ctrl.Result{}, err
}

setCondition, requeue := evaluateHelmChartState(state)
setCondition(upgradePlan, lifecyclev1alpha1.KubevirtUpgradedCondition, state.FormattedMessage(kubevirt.ReleaseName))
conditionType := lifecyclev1alpha1.KubevirtUpgradedCondition
if kubevirtState != upgrade.ChartStateSucceeded && kubevirtState != upgrade.ChartStateVersionAlreadyInstalled {
setCondition, requeue := evaluateHelmChartState(kubevirtState)
setCondition(upgradePlan, conditionType, kubevirtState.FormattedMessage(kubevirt.KubeVirt.ReleaseName))

return ctrl.Result{Requeue: requeue}, nil
return ctrl.Result{Requeue: requeue}, err
}

dashboardState, err := r.upgradeHelmChart(ctx, upgradePlan, &kubevirt.DashboardExtension)
if err != nil {
return ctrl.Result{}, err
}

switch dashboardState {
case upgrade.ChartStateFailed:
msg := fmt.Sprintf("Main component '%s' upgraded successfully, but add-on component '%s' failed to upgrade", kubevirt.KubeVirt.ReleaseName, kubevirt.DashboardExtension.ReleaseName)
r.recordPlanEvent(upgradePlan, corev1.EventTypeWarning, conditionType, msg)

fallthrough
case upgrade.ChartStateNotInstalled, upgrade.ChartStateVersionAlreadyInstalled:
setCondition, requeue := evaluateHelmChartState(kubevirtState)
setCondition(upgradePlan, conditionType, kubevirtState.FormattedMessage(kubevirt.KubeVirt.ReleaseName))
return ctrl.Result{Requeue: requeue}, nil
default:
setCondition, requeue := evaluateHelmChartState(dashboardState)
setCondition(upgradePlan, conditionType, dashboardState.FormattedMessage(kubevirt.DashboardExtension.ReleaseName))
return ctrl.Result{Requeue: requeue}, nil
}
}
8 changes: 4 additions & 4 deletions internal/controller/upgradeplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *UpgradePlanReconciler) createSecret(ctx context.Context, upgradePlan *l
return fmt.Errorf("creating secret: %w", err)
}

r.recordCreatedObject(upgradePlan, "SecretCreated", fmt.Sprintf("Secret created: %s/%s", secret.Namespace, secret.Name))
r.recordPlanEvent(upgradePlan, corev1.EventTypeNormal, "SecretCreated", fmt.Sprintf("Secret created: %s/%s", secret.Namespace, secret.Name))
return nil
}

Expand All @@ -150,7 +150,7 @@ func (r *UpgradePlanReconciler) createPlan(ctx context.Context, upgradePlan *lif
return fmt.Errorf("creating upgrade plan: %w", err)
}

r.recordCreatedObject(upgradePlan, "PlanCreated", fmt.Sprintf("Upgrade plan created: %s/%s", plan.Namespace, plan.Name))
r.recordPlanEvent(upgradePlan, corev1.EventTypeNormal, "PlanCreated", fmt.Sprintf("Upgrade plan created: %s/%s", plan.Namespace, plan.Name))
return nil
}

Expand All @@ -166,8 +166,8 @@ func (r *UpgradePlanReconciler) createObject(ctx context.Context, upgradePlan *l
return nil
}

func (r *UpgradePlanReconciler) recordCreatedObject(upgradePlan *lifecyclev1alpha1.UpgradePlan, reason, msg string) {
r.Recorder.Eventf(upgradePlan, corev1.EventTypeNormal, reason, msg)
func (r *UpgradePlanReconciler) recordPlanEvent(upgradePlan *lifecyclev1alpha1.UpgradePlan, eventType, reason, msg string) {
r.Recorder.Eventf(upgradePlan, eventType, reason, msg)
}

func isHelmUpgradeFinished(plan *lifecyclev1alpha1.UpgradePlan, conditionType string) bool {
Expand Down
11 changes: 8 additions & 3 deletions manifests/release-3.0.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ components:
chart: oci://registry.suse.com/edge/cdi-chart
version: 0.2.3
kubevirt:
releaseName: kubevirt
chart: oci://registry.suse.com/edge/kubevirt-chart
version: 0.2.4
kubevirt:
releaseName: kubevirt
chart: oci://registry.suse.com/edge/kubevirt-chart
version: 0.2.4
dashboardExtension:
releaseName: kubevirt-dashboard-extension
chart: oci://registry.suse.com/edge/kubevirt-dashboard-extension-chart
version: 1.0.0
neuvector:
crd:
releaseName: neuvector-crd
Expand Down
7 changes: 6 additions & 1 deletion pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Components struct {
Longhorn HelmChart `yaml:"longhorn"`
MetalLB HelmChart `yaml:"metallb"`
CDI HelmChart `yaml:"cdi"`
KubeVirt HelmChart `yaml:"kubevirt"`
KubeVirt KubeVirt `yaml:"kubevirt"`
NeuVector NeuVector `yaml:"neuvector"`
EndpointCopierOperator HelmChart `yaml:"endpointCopierOperator"`
Elemental Elemental `yaml:"elemental"`
Expand Down Expand Up @@ -59,3 +59,8 @@ type SRIOV struct {
CRD HelmChart `yaml:"crd"`
NetworkOperator HelmChart `yaml:"networkOperator"`
}

type KubeVirt struct {
KubeVirt HelmChart `yaml:"kubevirt"`
DashboardExtension HelmChart `yaml:"dashboardExtension"`
}

0 comments on commit c43d09d

Please sign in to comment.