From efe5945eecf51a4f4de87a36676a39a716eacb62 Mon Sep 17 00:00:00 2001 From: gianlucm76 Date: Mon, 17 Apr 2023 14:30:49 +0200 Subject: [PATCH 1/7] Prepare dev to main merge --- Makefile | 2 +- config/default/manager_image_patch.yaml | 2 +- go.mod | 2 +- go.sum | 4 ++-- manifest/manifest.yaml | 2 +- pkg/drift-detection/drift-detection-manager.go | 2 +- pkg/drift-detection/drift-detection-manager.yaml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f4c74b37..026a445a 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ ARCH ?= amd64 OS ?= $(shell uname -s | tr A-Z a-z) K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= v0.9.0 +TAG ?= main # Get cluster-api version and build ldflags clusterapi := $(shell go list -m sigs.k8s.io/cluster-api) diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index 23d81c7b..79e158c9 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: projectsveltos/addon-manager-amd64:v0.9.0 + - image: projectsveltos/addon-manager-amd64:main name: manager diff --git a/go.mod b/go.mod index 04259f37..28db852b 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onsi/ginkgo/v2 v2.9.2 github.com/onsi/gomega v1.27.5 github.com/pkg/errors v0.9.1 - github.com/projectsveltos/libsveltos v0.9.0 + github.com/projectsveltos/libsveltos v0.9.1-0.20230417113503-3f9a563f5522 github.com/prometheus/client_golang v1.14.0 github.com/spf13/pflag v1.0.5 golang.org/x/text v0.8.0 diff --git a/go.sum b/go.sum index cddffe5a..5de1cc79 100644 --- a/go.sum +++ b/go.sum @@ -529,8 +529,8 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg github.com/poy/onpar v0.0.0-20200406201722-06f95a1c68e8/go.mod h1:nSbFQvMj97ZyhFRSJYtut+msi4sOY6zJDGCdSc+/rZU= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/projectsveltos/libsveltos v0.9.0 h1:JYOlEtnFTDqmozNTz7hmuRAW1+VrFlu++ZPZwPv39Rk= -github.com/projectsveltos/libsveltos v0.9.0/go.mod h1:10UR0S+rA8NdP/X8IPWKv1tb0CL4gOOguT2JCXyL/18= +github.com/projectsveltos/libsveltos v0.9.1-0.20230417113503-3f9a563f5522 h1:2oXOc6IV5ig9+yQEtkc8Oi8aDmvBc8XN5shL9KRREXU= +github.com/projectsveltos/libsveltos v0.9.1-0.20230417113503-3f9a563f5522/go.mod h1:10UR0S+rA8NdP/X8IPWKv1tb0CL4gOOguT2JCXyL/18= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index 1051694d..3725dcc0 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -1561,7 +1561,7 @@ spec: - --v=5 command: - /manager - image: projectsveltos/addon-manager-amd64:v0.9.0 + image: projectsveltos/addon-manager-amd64:main livenessProbe: httpGet: path: /healthz diff --git a/pkg/drift-detection/drift-detection-manager.go b/pkg/drift-detection/drift-detection-manager.go index 09193ca2..ab4267d8 100644 --- a/pkg/drift-detection/drift-detection-manager.go +++ b/pkg/drift-detection/drift-detection-manager.go @@ -260,7 +260,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:v0.9.0 + image: projectsveltos/drift-detection-manager-amd64:main livenessProbe: httpGet: path: /healthz diff --git a/pkg/drift-detection/drift-detection-manager.yaml b/pkg/drift-detection/drift-detection-manager.yaml index cafa6547..73998a62 100644 --- a/pkg/drift-detection/drift-detection-manager.yaml +++ b/pkg/drift-detection/drift-detection-manager.yaml @@ -242,7 +242,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:v0.9.0 + image: projectsveltos/drift-detection-manager-amd64:main livenessProbe: httpGet: path: /healthz From 2c182fa14851638597351a739c9b6154ecbe8e6f Mon Sep 17 00:00:00 2001 From: gianlucm76 Date: Wed, 19 Apr 2023 14:44:53 +0200 Subject: [PATCH 2/7] Remove incorrect log Start new release --- Makefile | 2 +- config/default/manager_image_patch.yaml | 2 +- controllers/handlers_utils.go | 1 - manifest/manifest.yaml | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 026a445a..1fd900f9 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ ARCH ?= amd64 OS ?= $(shell uname -s | tr A-Z a-z) K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= main +TAG ?= dev # Get cluster-api version and build ldflags clusterapi := $(shell go list -m sigs.k8s.io/cluster-api) diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index 79e158c9..c4577371 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: projectsveltos/addon-manager-amd64:main + - image: projectsveltos/addon-manager-amd64:dev name: manager diff --git a/controllers/handlers_utils.go b/controllers/handlers_utils.go index 1ff92d95..8d5a5039 100644 --- a/controllers/handlers_utils.go +++ b/controllers/handlers_utils.go @@ -478,7 +478,6 @@ func deployReferencedObjects(ctx context.Context, c client.Client, remoteConfig localConfig.Impersonate = rest.ImpersonationConfig{ UserName: fmt.Sprintf("system:serviceaccount:%s:%s", adminNamespace, adminName), } - logger.Info("MGIANLUC") } tmpResourceReports, err = deployObjects(ctx, c, localConfig, objectsToDeployLocally, clusterSummary, mgtmResources, logger) diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index 3725dcc0..6d795258 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -1561,7 +1561,7 @@ spec: - --v=5 command: - /manager - image: projectsveltos/addon-manager-amd64:main + image: projectsveltos/addon-manager-amd64:dev livenessProbe: httpGet: path: /healthz From d7c9f2e0979cc2052dfabab20b9fac107d786b66 Mon Sep 17 00:00:00 2001 From: gianlucm76 Date: Fri, 21 Apr 2023 08:05:33 +0200 Subject: [PATCH 3/7] Log error when removing ResourceSummaries --- controllers/clustersummary_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/clustersummary_controller.go b/controllers/clustersummary_controller.go index fdc147ac..e6a91a62 100644 --- a/controllers/clustersummary_controller.go +++ b/controllers/clustersummary_controller.go @@ -211,7 +211,7 @@ func (r *ClusterSummaryReconciler) reconcileDelete( err = r.removeResourceSummary(ctx, clusterSummaryScope, logger) if err != nil { - logger.V(logs.LogInfo).Info("failed to remove ResourceSummary.") + logger.V(logs.LogInfo).Error(err, "failed to remove ResourceSummary.") return reconcile.Result{Requeue: true, RequeueAfter: deleteRequeueAfter}, nil } From 9a7c9d36b069325b52d2ebd26c13e4dd24029821 Mon Sep 17 00:00:00 2001 From: gianlucm76 Date: Sat, 22 Apr 2023 16:25:26 +0200 Subject: [PATCH 4/7] Add option missingkey to template --- controllers/template_instantiation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/template_instantiation.go b/controllers/template_instantiation.go index c70dd32e..315d1506 100644 --- a/controllers/template_instantiation.go +++ b/controllers/template_instantiation.go @@ -173,7 +173,7 @@ func instantiateTemplateValues(ctx context.Context, config *rest.Config, c clien } templateName := getTemplateName(clusterNamespace, clusterName, requestorName) - tmpl, err := template.New(templateName).Funcs(sprig.FuncMap()).Parse(values) + tmpl, err := template.New(templateName).Option("missingkey=error").Funcs(sprig.FuncMap()).Parse(values) if err != nil { return "", err } From 81ec42b8faabcd2613c6b83fefc572422b85e376 Mon Sep 17 00:00:00 2001 From: gianlucm76 Date: Sat, 22 Apr 2023 20:14:42 +0200 Subject: [PATCH 5/7] Always set DeployedGroupVersionKind Cleanup of deployed resources needs to be aware of the GVKs deployed by addon-manager. If a subset of resources is deployed and then an error happens, before this PR DeployedGroupVersionKind was not set. This causes addon-manager to leave stale resource (on delete, given DeployedGroupVersionKind was not set addon-manager used to clean up nothing). This PR fixes this behavior by always setting DeployedGroupVersionKind. --- .github/workflows/main.yaml | 2 +- controllers/handlers_resources.go | 11 ++++++----- controllers/handlers_utils.go | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index df35bbb7..531f5cd9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ on: - 'main' - 'dev' pull_request: - types: opened + types: [opened, edited, reopened] jobs: diff --git a/controllers/handlers_resources.go b/controllers/handlers_resources.go index 9427341a..0ab4a870 100644 --- a/controllers/handlers_resources.go +++ b/controllers/handlers_resources.go @@ -72,16 +72,17 @@ func deployResources(ctx context.Context, c client.Client, var remoteResourceReports []configv1alpha1.ResourceReport localResourceReports, remoteResourceReports, err = deployReferencedObjects(ctx, c, remoteRestConfig, clusterSummary, featureHandler, logger) - if err != nil { - return err - } - clusterProfileOwnerRef, err := configv1alpha1.GetClusterProfileOwnerReference(clusterSummary) + // Irrespective of error, update deployed gvks. Otherwise cleanup won't happen in case + gvkErr := updateDeployedGroupVersionKind(ctx, clusterSummary, localResourceReports, remoteResourceReports, logger) if err != nil { return err } + if gvkErr != nil { + return gvkErr + } - err = updateDeployedGroupVersionKind(ctx, clusterSummary, localResourceReports, remoteResourceReports, logger) + clusterProfileOwnerRef, err := configv1alpha1.GetClusterProfileOwnerReference(clusterSummary) if err != nil { return err } diff --git a/controllers/handlers_utils.go b/controllers/handlers_utils.go index 8d5a5039..21a91ef0 100644 --- a/controllers/handlers_utils.go +++ b/controllers/handlers_utils.go @@ -481,18 +481,18 @@ func deployReferencedObjects(ctx context.Context, c client.Client, remoteConfig } tmpResourceReports, err = deployObjects(ctx, c, localConfig, objectsToDeployLocally, clusterSummary, mgtmResources, logger) + localReports = append(localReports, tmpResourceReports...) if err != nil { - return nil, nil, err + return localReports, nil, err } - localReports = append(localReports, tmpResourceReports...) // Deploy all resources that need to be deployed in the managed cluster tmpResourceReports, err = deployObjects(ctx, remoteClient, remoteConfig, objectsToDeployRemotely, clusterSummary, mgtmResources, logger) + remoteReports = append(remoteReports, tmpResourceReports...) if err != nil { - return nil, nil, err + return localReports, remoteReports, err } - remoteReports = append(remoteReports, tmpResourceReports...) return localReports, remoteReports, nil } From 12272746d903c67ede1a9ab0b59b2b030bc05eb1 Mon Sep 17 00:00:00 2001 From: Gianluca Mardente <52940363+gianlucam76@users.noreply.github.com> Date: Sat, 22 Apr 2023 21:00:24 +0200 Subject: [PATCH 6/7] Update main.yaml --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index df35bbb7..531f5cd9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ on: - 'main' - 'dev' pull_request: - types: opened + types: [opened, edited, reopened] jobs: From fbfef461f6f10524eb67ace7955fb0c5318f22e0 Mon Sep 17 00:00:00 2001 From: gianlucm76 Date: Mon, 24 Apr 2023 11:10:40 +0200 Subject: [PATCH 7/7] Release v0.9.1 --- Makefile | 2 +- config/default/manager_image_patch.yaml | 2 +- go.mod | 2 +- go.sum | 4 ++-- manifest/manifest.yaml | 2 +- pkg/drift-detection/drift-detection-manager.go | 2 +- pkg/drift-detection/drift-detection-manager.yaml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 1fd900f9..43a3946f 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ ARCH ?= amd64 OS ?= $(shell uname -s | tr A-Z a-z) K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= dev +TAG ?= v0.9.1 # Get cluster-api version and build ldflags clusterapi := $(shell go list -m sigs.k8s.io/cluster-api) diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index c4577371..44753c0b 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,5 +8,5 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: projectsveltos/addon-manager-amd64:dev + - image: projectsveltos/addon-manager-amd64:v0.9.1 name: manager diff --git a/go.mod b/go.mod index 28db852b..492c1428 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onsi/ginkgo/v2 v2.9.2 github.com/onsi/gomega v1.27.5 github.com/pkg/errors v0.9.1 - github.com/projectsveltos/libsveltos v0.9.1-0.20230417113503-3f9a563f5522 + github.com/projectsveltos/libsveltos v0.9.1 github.com/prometheus/client_golang v1.14.0 github.com/spf13/pflag v1.0.5 golang.org/x/text v0.8.0 diff --git a/go.sum b/go.sum index 5de1cc79..4c1586ca 100644 --- a/go.sum +++ b/go.sum @@ -529,8 +529,8 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg github.com/poy/onpar v0.0.0-20200406201722-06f95a1c68e8/go.mod h1:nSbFQvMj97ZyhFRSJYtut+msi4sOY6zJDGCdSc+/rZU= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/projectsveltos/libsveltos v0.9.1-0.20230417113503-3f9a563f5522 h1:2oXOc6IV5ig9+yQEtkc8Oi8aDmvBc8XN5shL9KRREXU= -github.com/projectsveltos/libsveltos v0.9.1-0.20230417113503-3f9a563f5522/go.mod h1:10UR0S+rA8NdP/X8IPWKv1tb0CL4gOOguT2JCXyL/18= +github.com/projectsveltos/libsveltos v0.9.1 h1:6y6oq2FGlDlQ9/6vyA7tzWC6lq0B3X74kDbpSsV8Y5E= +github.com/projectsveltos/libsveltos v0.9.1/go.mod h1:10UR0S+rA8NdP/X8IPWKv1tb0CL4gOOguT2JCXyL/18= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index 6d795258..c1c50d47 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -1561,7 +1561,7 @@ spec: - --v=5 command: - /manager - image: projectsveltos/addon-manager-amd64:dev + image: projectsveltos/addon-manager-amd64:v0.9.1 livenessProbe: httpGet: path: /healthz diff --git a/pkg/drift-detection/drift-detection-manager.go b/pkg/drift-detection/drift-detection-manager.go index ab4267d8..8097bd9a 100644 --- a/pkg/drift-detection/drift-detection-manager.go +++ b/pkg/drift-detection/drift-detection-manager.go @@ -260,7 +260,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:main + image: projectsveltos/drift-detection-manager-amd64:v0.9.1 livenessProbe: httpGet: path: /healthz diff --git a/pkg/drift-detection/drift-detection-manager.yaml b/pkg/drift-detection/drift-detection-manager.yaml index 73998a62..904e49e0 100644 --- a/pkg/drift-detection/drift-detection-manager.yaml +++ b/pkg/drift-detection/drift-detection-manager.yaml @@ -242,7 +242,7 @@ spec: - --run-mode=do-not-send-updates command: - /manager - image: projectsveltos/drift-detection-manager-amd64:main + image: projectsveltos/drift-detection-manager-amd64:v0.9.1 livenessProbe: httpGet: path: /healthz