Skip to content

Commit

Permalink
Merge pull request #424 from gianlucam76/release-0.21
Browse files Browse the repository at this point in the history
Release 0.21
  • Loading branch information
gianlucam76 committed Jan 10, 2024
2 parents 77bde78 + 76ebe98 commit 48bbc7c
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?= v0.21.1

.PHONY: all
all: build
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: projectsveltos/addon-controller-amd64:main
- image: projectsveltos/addon-controller-amd64:v0.21.1
name: controller
11 changes: 10 additions & 1 deletion controllers/clustersummary_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,19 @@ func (r *ClusterSummaryReconciler) reconcileNormal(
return reconcile.Result{Requeue: true, RequeueAfter: normalRequeueAfter}, nil
}

if err := r.updateChartMap(ctx, clusterSummaryScope, logger); err != nil {
err = r.updateChartMap(ctx, clusterSummaryScope, logger)
if err != nil {
return reconcile.Result{Requeue: true, RequeueAfter: normalRequeueAfter}, nil
}

if !clusterSummaryScope.IsContinuousWithDriftDetection() {
err = r.removeResourceSummary(ctx, clusterSummaryScope, logger)
if err != nil {
logger.V(logs.LogInfo).Error(err, "failed to remove ResourceSummary.")
return reconcile.Result{Requeue: true, RequeueAfter: deleteRequeueAfter}, nil
}
}

if err := r.deploy(ctx, clusterSummaryScope, logger); err != nil {
logger.V(logs.LogInfo).Error(err, "failed to deploy")
return reconcile.Result{Requeue: true, RequeueAfter: normalRequeueAfter}, nil
Expand Down
10 changes: 10 additions & 0 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ func deployHelmCharts(ctx context.Context, c client.Client,
if err != nil {
return err
}

// Since we are updating resources to watch for drift, remove helm section in ResourceSummary to eliminate
// un-needed reconciliation (Sveltos is updating those resources so we don't want drift-detection to think
// a configuration drift is happening)
err = deployResourceSummaryInCluster(ctx, c, clusterNamespace, clusterName, clusterSummary.Name,
clusterType, nil, nil, []libsveltosv1alpha1.HelmResources{}, logger)
if err != nil {
logger.V(logs.LogInfo).Error(err, "failed to remove ResourceSummary.")
return err
}
}

adminNamespace, adminName := getClusterSummaryAdmin(clusterSummary)
Expand Down
39 changes: 36 additions & 3 deletions controllers/handlers_kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ func deployKustomizeRefs(ctx context.Context, c client.Client,
}

adminNamespace, adminName := getClusterSummaryAdmin(clusterSummary)
logger = logger.WithValues("cluster", fmt.Sprintf("%s/%s", clusterNamespace, clusterName))
logger = logger.WithValues("clusterSummary", clusterSummary.Name)
logger = logger.WithValues("admin", fmt.Sprintf("%s/%s", adminNamespace, adminName))
logger = logger.WithValues("cluster", fmt.Sprintf("%s/%s", clusterNamespace, clusterName)).
WithValues("clusterSummary", clusterSummary.Name).WithValues("admin", fmt.Sprintf("%s/%s", adminNamespace, adminName))

remoteRestConfig, err := clusterproxy.GetKubernetesRestConfig(ctx, c, clusterNamespace, clusterName,
adminNamespace, adminName, clusterSummary.Spec.ClusterType, logger)
Expand All @@ -86,6 +85,12 @@ func deployKustomizeRefs(ctx context.Context, c client.Client,

logger.V(logs.LogDebug).Info("deploying kustomize resources")

err = handleDriftDetectionManagerDeploymentForKustomize(ctx, clusterSummary, clusterNamespace,
clusterName, clusterType, startDriftDetectionInMgmtCluster(o), logger)
if err != nil {
return err
}

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

Expand Down Expand Up @@ -638,6 +643,34 @@ func cleanKustomizeResources(ctx context.Context, isMgmtCluster bool, destRestCo
return undeployed, nil
}

// handleDriftDetectionManagerDeploymentForKustomize deploys, if sync mode is SyncModeContinuousWithDriftDetection,
// drift-detection-manager in the managed clyuster
func handleDriftDetectionManagerDeploymentForKustomize(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
clusterNamespace, clusterName string, clusterType libsveltosv1alpha1.ClusterType, startInMgmtCluster bool,
logger logr.Logger) error {

if clusterSummary.Spec.ClusterProfileSpec.SyncMode == configv1alpha1.SyncModeContinuousWithDriftDetection {
// Deploy drift detection manager first. Have manager up by the time resourcesummary is created
err := deployDriftDetectionManagerInCluster(ctx, getManagementClusterClient(), clusterNamespace,
clusterName, clusterSummary.Name, clusterType, startInMgmtCluster, logger)
if err != nil {
return err
}

// Since we are updating resources to watch for drift, remove kustomize section in ResourceSummary to eliminate
// un-needed reconciliation (Sveltos is updating those resources so we don't want drift-detection to think
// a configuration drift is happening)
err = handleKustomizeResourceSummaryDeployment(ctx, clusterSummary, clusterNamespace, clusterName,
clusterType, []configv1alpha1.Resource{}, logger)
if err != nil {
logger.V(logs.LogInfo).Error(err, "failed to remove ResourceSummary.")
return err
}
}

return nil
}

// handleKustomizeResourceSummaryDeployment deploys, if sync mode is SyncModeContinuousWithDriftDetection,
// ResourceSummary in the managed cluster
func handleKustomizeResourceSummaryDeployment(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
Expand Down
10 changes: 10 additions & 0 deletions controllers/handlers_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ func handleDriftDetectionManagerDeployment(ctx context.Context, clusterSummary *
if err != nil {
return err
}

// Since we are updating resources to watch for drift, remove resource section in ResourceSummary to eliminate
// un-needed reconciliation (Sveltos is updating those resources so we don't want drift-detection to think
// a configuration drift is happening)
err = handleResourceSummaryDeployment(ctx, clusterSummary, clusterNamespace, clusterName,
clusterType, []configv1alpha1.Resource{}, logger)
if err != nil {
logger.V(logs.LogInfo).Error(err, "failed to remove ResourceSummary.")
return err
}
}

return nil
Expand Down
28 changes: 28 additions & 0 deletions controllers/reloader_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2/textlogger"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -33,10 +36,35 @@ import (
logs "github.com/projectsveltos/libsveltos/lib/logsettings"
)

// isReloaderInstalled returns true if Reloader CRD is installed, false otherwise
func isReloaderInstalled(ctx context.Context, c client.Client) (bool, error) {
clusterCRD := &apiextensionsv1.CustomResourceDefinition{}

err := c.Get(ctx, types.NamespacedName{Name: "reloaders.lib.projectsveltos.io"}, clusterCRD)
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
}

return true, nil
}

// removeReloaderInstance removes Reloader instance from the managed cluster
func removeReloaderInstance(ctx context.Context, remoteClient client.Client,
clusterProfileName string, feature configv1alpha1.FeatureID, logger logr.Logger) error {

installed, err := isReloaderInstalled(ctx, remoteClient)
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to verify if Reloader is installed %v", err))
return err
}

if !installed {
return nil
}

reloader, err := getReloaderInstance(ctx, remoteClient, clusterProfileName,
feature, textlogger.NewLogger(textlogger.NewConfig()))
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions controllers/reloader_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2/textlogger"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

configv1alpha1 "github.com/projectsveltos/addon-controller/api/v1alpha1"
"github.com/projectsveltos/addon-controller/controllers"
libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1"
libsveltoscrd "github.com/projectsveltos/libsveltos/lib/crd"
"github.com/projectsveltos/libsveltos/lib/utils"
)

var _ = Describe("Reloader utils", func() {
Expand Down Expand Up @@ -158,6 +161,11 @@ var _ = Describe("Reloader utils", func() {

c := fake.NewClientBuilder().WithScheme(scheme).Build()

var reloaderCRD *unstructured.Unstructured
reloaderCRD, err := utils.GetUnstructured(libsveltoscrd.GetReloaderCRDYAML())
Expect(err).To(BeNil())
Expect(c.Create(context.TODO(), reloaderCRD)).To(Succeed())

Expect(controllers.CreateReloaderInstance(context.TODO(), c,
clusterProfileName, feature, nil)).To(Succeed())
reloaders := &libsveltosv1alpha1.ReloaderList{}
Expand Down
27 changes: 27 additions & 0 deletions controllers/resourcesummary_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -88,6 +89,17 @@ func collectResourceSummariesFromCluster(ctx context.Context, c client.Client,
return err
}

var installed bool
installed, err = isResourceSummaryInstalled(ctx, remoteClient)
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to verify if ResourceSummary is installed %v", err))
return err
}

if !installed {
return nil
}

logger.V(logs.LogDebug).Info("collecting ResourceSummaries from cluster")
rsList := libsveltosv1alpha1.ResourceSummaryList{}
err = remoteClient.List(ctx, &rsList)
Expand Down Expand Up @@ -115,6 +127,21 @@ func collectResourceSummariesFromCluster(ctx context.Context, c client.Client,
return nil
}

// isResourceSummaryInstalled returns true if ResourceSummary CRD is installed, false otherwise
func isResourceSummaryInstalled(ctx context.Context, c client.Client) (bool, error) {
clusterCRD := &apiextensionsv1.CustomResourceDefinition{}

err := c.Get(ctx, types.NamespacedName{Name: "resourcesummaries.lib.projectsveltos.io"}, clusterCRD)
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
}

return true, nil
}

func processResourceSummary(ctx context.Context, c, remoteClient client.Client,
rs *libsveltosv1alpha1.ResourceSummary, logger logr.Logger) error {

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v0.21.1-0.20240104154531-101b29f82445
github.com/projectsveltos/libsveltos v0.21.1
github.com/prometheus/client_golang v1.17.0
github.com/spf13/pflag v1.0.5
github.com/yuin/gopher-lua v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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.21.1-0.20240104154531-101b29f82445 h1:BRQmPXAGVKTWq5GdlvPPZmAe4D5bmR8Bum1pqPCEd8w=
github.com/projectsveltos/libsveltos v0.21.1-0.20240104154531-101b29f82445/go.mod h1:HnXXTWK9BqzoN4aAQs0kdjK7wpsaSz0nNemN4rMruV4=
github.com/projectsveltos/libsveltos v0.21.1 h1:1frskEue44i87j/c1orlH6a3wziCR2LRXRbBFbrLm1M=
github.com/projectsveltos/libsveltos v0.21.1/go.mod h1:HnXXTWK9BqzoN4aAQs0kdjK7wpsaSz0nNemN4rMruV4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down
2 changes: 1 addition & 1 deletion manifest/deployment-shard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
- --v=5
command:
- /manager
image: projectsveltos/addon-controller-amd64:main
image: projectsveltos/addon-controller-amd64:v0.21.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ spec:
- --v=5
command:
- /manager
image: projectsveltos/addon-controller-amd64:main
image: projectsveltos/addon-controller-amd64:v0.21.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
- --run-mode=do-not-send-updates
command:
- /manager
image: projectsveltos/drift-detection-manager-amd64:main
image: projectsveltos/drift-detection-manager-amd64:v0.21.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
- --run-mode=do-not-send-updates
command:
- /manager
image: projectsveltos/drift-detection-manager-amd64:main
image: projectsveltos/drift-detection-manager-amd64:v0.21.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion pkg/drift-detection/drift-detection-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ spec:
- --run-mode=do-not-send-updates
command:
- /manager
image: projectsveltos/drift-detection-manager-amd64:main
image: projectsveltos/drift-detection-manager-amd64:v0.21.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion pkg/drift-detection/drift-detection-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ spec:
- --run-mode=do-not-send-updates
command:
- /manager
image: projectsveltos/drift-detection-manager-amd64:main
image: projectsveltos/drift-detection-manager-amd64:v0.21.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
5 changes: 5 additions & 0 deletions pkg/scope/clustersummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ func (s *ClusterSummaryScope) SetLastAppliedTime(featureID configv1alpha1.Featur
)
}

// IsContinuousWithDriftDetection returns true if ClusterProfile is set to SyncModeContinuousWithDriftDetection
func (s *ClusterSummaryScope) IsContinuousWithDriftDetection() bool {
return s.ClusterSummary.Spec.ClusterProfileSpec.SyncMode == configv1alpha1.SyncModeContinuousWithDriftDetection
}

// IsContinuousSync returns true if ClusterProfile is set to keep updating workload cluster
func (s *ClusterSummaryScope) IsContinuousSync() bool {
return s.ClusterSummary.Spec.ClusterProfileSpec.SyncMode == configv1alpha1.SyncModeContinuous ||
Expand Down
3 changes: 2 additions & 1 deletion test/fv/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func verifyFeatureStatusIsProvisioned(clusterSummaryNamespace, clusterSummaryNam
}
for i := range currentClusterSummary.Status.FeatureSummaries {
if currentClusterSummary.Status.FeatureSummaries[i].FeatureID == featureID &&
currentClusterSummary.Status.FeatureSummaries[i].Status == configv1alpha1.FeatureStatusProvisioned {
currentClusterSummary.Status.FeatureSummaries[i].Status == configv1alpha1.FeatureStatusProvisioned &&
currentClusterSummary.Status.FeatureSummaries[i].FailureMessage == nil {

return true
}
Expand Down

0 comments on commit 48bbc7c

Please sign in to comment.