Skip to content

Commit

Permalink
Merge pull request #147 from SovereignCloudStack/remove-k8s-version
Browse files Browse the repository at this point in the history
🌱 Remove kubernetes version from cluster addon api
  • Loading branch information
janiskemper authored May 13, 2024
2 parents a69b583 + 9d140b1 commit 62835dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
4 changes: 0 additions & 4 deletions api/v1alpha1/clusteraddon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ type ClusterAddonStatus struct {
// +optional
CurrentHook string `json:"currentHook,omitempty"`

// KubernetesVersion is the kubernetes version of the current cluster stack release.
// +optional
KubernetesVersion string `json:"kubernetesVersion,omitempty"`

// HelmChartStatus defines the status of helm chart in the cluster addon.
// +optional
HelmChartStatus map[string]HelmChartStatusConditions `json:"helmChartStatus,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ spec:
description: HelmChartStatus defines the status of helm chart in the
cluster addon.
type: object
kubernetesVersion:
description: KubernetesVersion is the kubernetes version of the current
cluster stack release.
type: string
ready:
default: false
type: boolean
Expand Down
36 changes: 20 additions & 16 deletions internal/controller/clusteraddon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,13 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
return reconcile.Result{}, fmt.Errorf("failed to get addon stages input: %w", err)
}

var (
oldRelease release.Release
requeue bool
)

if clusterAddon.Spec.ClusterStack != "" {
oldClusterStackAddonChartPath, requeue, err := r.downloadOldClusterStackRelease(ctx, clusterAddon)
oldRelease, requeue, err = r.downloadOldClusterStackRelease(ctx, clusterAddon)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to download old cluster stack releases: %w", err)
}
Expand All @@ -291,10 +296,10 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re

// src - /tmp/cluster-stacks/docker-ferrol-1-27-v1/docker-ferrol-1-27-cluster-addon-v1.tgz
// dst - /tmp/cluster-stacks/docker-ferrol-1-27-v1/docker-ferrol-1-27-cluster-addon-v1/
in.oldDestinationClusterAddonChartDir = strings.TrimSuffix(oldClusterStackAddonChartPath, ".tgz")
in.oldDestinationClusterAddonChartDir = strings.TrimSuffix(oldRelease.ClusterAddonChartPath(), ".tgz")

if err := unTarContent(oldClusterStackAddonChartPath, in.oldDestinationClusterAddonChartDir); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to untar cluster addon chart: %q: %w", oldClusterStackAddonChartPath, err)
if err := unTarContent(oldRelease.ClusterAddonChartPath(), in.oldDestinationClusterAddonChartDir); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to untar cluster addon chart: %q: %w", oldRelease.ClusterAddonChartPath(), err)
}
}

Expand All @@ -306,7 +311,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re

// In case the Kubernetes version stays the same, the hook server does not trigger.
// Therefore, we have to check whether the ClusterStack is upgraded and if that is the case, the ClusterAddons have to be upgraded as well.
if clusterAddon.Spec.ClusterStack != cluster.Spec.Topology.Class && clusterAddon.Status.KubernetesVersion == releaseAsset.Meta.Versions.Kubernetes {
if clusterAddon.Spec.ClusterStack != cluster.Spec.Topology.Class && oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes {
if clusterAddon.Spec.Version != releaseAsset.Meta.Versions.Components.ClusterAddon {
clusterAddon.Status.HelmChartStatus = make(map[string]csov1alpha1.HelmChartStatusConditions)
clusterAddon.Status.CurrentHook = clusterAddon.Spec.Hook
Expand All @@ -333,7 +338,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re

// In case the Kubernetes version stayed the same during an upgrade, the hook server does not trigger and
// we just take the Helm charts that are supposed to be installed in the BeforeClusterUpgrade hook and apply them.
if clusterAddon.Status.KubernetesVersion == releaseAsset.Meta.Versions.Kubernetes {
if oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes {
clusterAddon.Spec.Hook = "BeforeClusterUpgrade"
for _, stage := range clusterAddonConfig.AddonStages["BeforeClusterUpgrade"] {
shouldRequeue, err := r.executeStage(ctx, stage, in)
Expand Down Expand Up @@ -391,8 +396,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
// remove the status resource if hook is finished
clusterAddon.Status.Resources = make([]*csov1alpha1.Resource, 0)

// store the release kubernetes version and current hook
clusterAddon.Status.KubernetesVersion = releaseAsset.Meta.Versions.Kubernetes
// set the current hook and make cluster addon ready
clusterAddon.Status.CurrentHook = clusterAddon.Spec.Hook
clusterAddon.Status.Ready = true
}
Expand Down Expand Up @@ -633,7 +637,7 @@ check:
}

// downloadOldClusterStackRelease downloads the old cluster stack if not present and returns release clusterAddon chart path if requeue and error.
func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Context, clusterAddon *csov1alpha1.ClusterAddon) (string, bool, error) {
func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Context, clusterAddon *csov1alpha1.ClusterAddon) (release.Release, bool, error) {
// initiate github release.
gc, err := r.GitHubClientFactory.NewClient(ctx)
if err != nil {
Expand All @@ -648,9 +652,9 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont

// give the github client a second change
if isSet {
return "", true, nil
return release.Release{}, true, nil
}
return "", false, nil
return release.Release{}, false, nil
}

conditions.MarkTrue(clusterAddon, csov1alpha1.GitAPIAvailableCondition)
Expand All @@ -659,7 +663,7 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont
releaseAsset, download, err := release.New(release.ConvertFromClusterClassToClusterStackFormat(clusterAddon.Spec.ClusterStack), r.ReleaseDirectory)
if err != nil {
conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, err.Error())
return "", true, nil
return release.Release{}, true, nil
}
if download {
// if download is true, it means that the release assets have not been downloaded yet
Expand All @@ -670,13 +674,13 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont
r.clusterStackRelDownloadDirectoryMutex.Lock()

if err := downloadReleaseAssets(ctx, release.ConvertFromClusterClassToClusterStackFormat(clusterAddon.Spec.ClusterStack), releaseAsset.LocalDownloadPath, gc); err != nil {
return "", false, fmt.Errorf("failed to download release assets: %w", err)
return release.Release{}, false, fmt.Errorf("failed to download release assets: %w", err)
}

r.clusterStackRelDownloadDirectoryMutex.Unlock()

// requeue to make sure release assets can be accessed
return "", true, nil
return release.Release{}, true, nil
}

if err := releaseAsset.CheckHelmCharts(); err != nil {
Expand All @@ -689,13 +693,13 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont
msg,
)
record.Warnf(clusterAddon, "ValidateHelmChartFailed", msg)
return "", false, nil
return release.Release{}, false, nil
}

// set downloaded condition if able to read metadata file
conditions.MarkTrue(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition)

return releaseAsset.ClusterAddonChartPath(), false, nil
return releaseAsset, false, nil
}

func (r *ClusterAddonReconciler) templateAndApplyNewClusterStackAddonHelmChart(ctx context.Context, in templateAndApplyClusterAddonInput, helmChartName string) (bool, error) {
Expand Down

0 comments on commit 62835dc

Please sign in to comment.