Skip to content

Commit

Permalink
Merge pull request #548 from gianlucam76/bump-helm
Browse files Browse the repository at this point in the history
Handle release uninstalled scenario
  • Loading branch information
gianlucam76 committed May 16, 2024
2 parents 20c9fe1 + cb6bf88 commit 9abb06d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 35 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # tag=v4.1.5
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: 1.22.0
- name: Build
Expand All @@ -33,9 +33,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # tag=v4.1.5
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: 1.22.0
- name: ut
Expand All @@ -46,9 +46,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # tag=v4.1.5
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: 1.22.0
- name: Free Disk Space (Ubuntu)
Expand All @@ -74,9 +74,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # tag=v4.1.5
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: 1.22.0
- name: Free Disk Space (Ubuntu)
Expand All @@ -102,9 +102,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # tag=v4.1.5
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # tag=v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: 1.22.0
- name: Free Disk Space (Ubuntu)
Expand Down
11 changes: 3 additions & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ linters-settings:
goimports:
local-prefixes: github.com/projectsveltos
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
checks: argument,case,condition,return
gomodguard:
# Although this is almost empty, we will evolve the list below with the
# modules we shouldn't use for technical and/or security reasons.
Expand All @@ -51,7 +48,7 @@ linters-settings:
# Don't merge replace directives using local path.
local_replace_directives: true
govet:
check-shadowing: true
shadow: true
settings:
printf:
funcs:
Expand Down Expand Up @@ -177,6 +174,4 @@ run:
allow-parallel-runners: true
# Timeout for analysis
timeout: 5m
# files to skip: they will be analyzed, but issues from them won't be reported.
skip-dirs:
- cmd/example/gen

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CLUSTERCTL := $(TOOLS_BIN_DIR)/clusterctl
KIND := $(TOOLS_BIN_DIR)/kind
KUBECTL := $(TOOLS_BIN_DIR)/kubectl

GOLANGCI_LINT_VERSION := "v1.55.2"
GOLANGCI_LINT_VERSION := "v1.57.2"
CLUSTERCTL_VERSION := "v1.7.2"

KUSTOMIZE_VER := v4.5.2
Expand Down
9 changes: 9 additions & 0 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,15 @@ func shouldInstall(currentRelease *releaseInfo, requestedChart *configv1alpha1.H
return false
}

// If the release was uninstalled with KeepHistory flag, this is the
// status seen at this point. Release should be installed in this state.
// Upgrade would fail
if currentRelease != nil &&
currentRelease.Status == release.StatusUninstalled.String() {

return true
}

if currentRelease != nil &&
currentRelease.ChartVersion != requestedChart.ChartVersion {

Expand Down
10 changes: 6 additions & 4 deletions controllers/handlers_kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ func deployKustomizeRefs(ctx context.Context, c client.Client,
return err
}

localResourceReports, remoteResourceReports, err := deployEachKustomizeRefs(ctx, c, remoteRestConfig,
localResourceReports, remoteResourceReports, deployError := deployEachKustomizeRefs(ctx, c, remoteRestConfig,
clusterSummary, logger)

// Irrespective of error, update deployed gvks. Otherwise cleanup won't happen in case
gvkErr := updateDeployedGroupVersionKind(ctx, clusterSummary, configv1alpha1.FeatureKustomize,
localResourceReports, remoteResourceReports, logger)
if err != nil {
return err
}
if gvkErr != nil {
return gvkErr
}
Expand Down Expand Up @@ -150,6 +147,11 @@ func deployKustomizeRefs(ctx context.Context, c client.Client,
if clusterSummary.Spec.ClusterProfileSpec.SyncMode == configv1alpha1.SyncModeDryRun {
return &configv1alpha1.DryRunReconciliationError{}
}

if deployError != nil {
return deployError
}

return validateHealthPolicies(ctx, remoteRestConfig, clusterSummary, configv1alpha1.FeatureKustomize, logger)
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/handlers_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func deployPolicyRefs(ctx context.Context, c client.Client, remoteConfig *rest.C

var objectsToDeployLocally []client.Object
var objectsToDeployRemotely []client.Object
// collect all referenced ConfigMaps/Secrets whose content need to be deployed
// collect all referenced resources whose content need to be deployed
// in the management cluster (local) or manaded cluster (remote)
objectsToDeployLocally, objectsToDeployRemotely, err =
collectReferencedObjects(ctx, c, clusterSummary.Namespace, refs, logger)
Expand Down
33 changes: 22 additions & 11 deletions test/fv/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ var _ = Describe("DryRun", func() {
Byf("Delete ClusterProfile %s", clusterProfile.Name)
deleteClusterProfile(clusterProfile)

Byf("Verifying ServiceAccount kong/kong-serviceaccount is removed from managed cluster")
workloadClient, err := getKindWorkloadClusterKubeconfig()
Expect(err).To(BeNil())
Expect(workloadClient).ToNot(BeNil())

currentServiceAccount := &corev1.ServiceAccount{}
err = workloadClient.Get(context.TODO(),
types.NamespacedName{Namespace: "kong", Name: "kong-serviceaccount"}, currentServiceAccount)
Expect(err).ToNot(BeNil())
Expect(apierrors.IsNotFound(err)).To(BeTrue())

Byf("Changing syncMode to Continuous and HelmCharts (all install) for ClusterProfile %s", dryRunClusterProfile.Name)
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: dryRunClusterProfile.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.SyncMode = configv1alpha1.SyncModeContinuous
Expand Down Expand Up @@ -323,6 +334,11 @@ var _ = Describe("DryRun", func() {
Byf("Verifying ClusterSummary %s status is set to Deployed for Helm feature", dryRunClusterSummary.Name)
verifyFeatureStatusIsProvisioned(kindWorkloadCluster.Namespace, dryRunClusterSummary.Name, configv1alpha1.FeatureHelm)

Byf("Verifying ServiceAccount kong/kong-serviceaccount is deployed managed cluster")
err = workloadClient.Get(context.TODO(),
types.NamespacedName{Namespace: "kong", Name: "kong-serviceaccount"}, currentServiceAccount)
Expect(err).To(BeNil())

Byf("Changing syncMode to DryRun and HelmCharts (some install, one uninstall) for ClusterProfile %s", dryRunClusterProfile.Name)
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: dryRunClusterProfile.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.SyncMode = configv1alpha1.SyncModeDryRun
Expand Down Expand Up @@ -370,7 +386,7 @@ var _ = Describe("DryRun", func() {
By("Verifying ClusterReport")
Eventually(func() error {
currentClusterReport := &configv1alpha1.ClusterReport{}
err := k8sClient.Get(context.TODO(),
err = k8sClient.Get(context.TODO(),
types.NamespacedName{Namespace: dryRunClusterSummary.Spec.ClusterNamespace, Name: clusterReportName}, currentClusterReport)
if err != nil {
return err
Expand Down Expand Up @@ -399,7 +415,7 @@ var _ = Describe("DryRun", func() {
By("Verifying ClusterReport for policy reports")
Eventually(func() error {
currentClusterReport := &configv1alpha1.ClusterReport{}
err := k8sClient.Get(context.TODO(),
err = k8sClient.Get(context.TODO(),
types.NamespacedName{Namespace: dryRunClusterSummary.Spec.ClusterNamespace, Name: clusterReportName}, currentClusterReport)
if err != nil {
return err
Expand Down Expand Up @@ -432,7 +448,7 @@ var _ = Describe("DryRun", func() {
// First wait for clusterSummary to be marked for deletion
Eventually(func() bool {
currentClusterSummary := &configv1alpha1.ClusterSummary{}
err := k8sClient.Get(context.TODO(),
err = k8sClient.Get(context.TODO(),
types.NamespacedName{Namespace: dryRunClusterSummary.Namespace, Name: dryRunClusterSummary.Name}, currentClusterSummary)
if err != nil {
return false
Expand All @@ -443,7 +459,7 @@ var _ = Describe("DryRun", func() {
// Then verify ClusterSummary is not removed.
Consistently(func() bool {
currentClusterSummary := &configv1alpha1.ClusterSummary{}
err := k8sClient.Get(context.TODO(),
err = k8sClient.Get(context.TODO(),
types.NamespacedName{Namespace: dryRunClusterSummary.Namespace, Name: dryRunClusterSummary.Name}, currentClusterSummary)
if err != nil {
return false
Expand All @@ -454,7 +470,7 @@ var _ = Describe("DryRun", func() {
By("Verifying ClusterReport")
Eventually(func() error {
currentClusterReport := &configv1alpha1.ClusterReport{}
err := k8sClient.Get(context.TODO(),
err = k8sClient.Get(context.TODO(),
types.NamespacedName{Namespace: dryRunClusterSummary.Spec.ClusterNamespace, Name: clusterReportName}, currentClusterReport)
if err != nil {
return err
Expand Down Expand Up @@ -483,7 +499,7 @@ var _ = Describe("DryRun", func() {
By("Verifying ClusterReport for policy reports")
Eventually(func() error {
currentClusterReport := &configv1alpha1.ClusterReport{}
err := k8sClient.Get(context.TODO(),
err = k8sClient.Get(context.TODO(),
types.NamespacedName{Namespace: dryRunClusterSummary.Spec.ClusterNamespace, Name: clusterReportName}, currentClusterReport)
if err != nil {
return err
Expand Down Expand Up @@ -517,11 +533,6 @@ var _ = Describe("DryRun", func() {
deleteClusterProfile(dryRunClusterProfile)

Byf("Verifying ServiceAccount kong/kong-serviceaccount is removed from managed cluster")
workloadClient, err := getKindWorkloadClusterKubeconfig()
Expect(err).To(BeNil())
Expect(workloadClient).ToNot(BeNil())

currentServiceAccount := &corev1.ServiceAccount{}
err = workloadClient.Get(context.TODO(),
types.NamespacedName{Namespace: "kong", Name: "kong-serviceaccount"}, currentServiceAccount)
Expect(err).ToNot(BeNil())
Expand Down

0 comments on commit 9abb06d

Please sign in to comment.