Skip to content

Commit

Permalink
Merge pull request #887 from gianlucam76/stop-matching
Browse files Browse the repository at this point in the history
StopMatchingBehavior: accept only two correct values
  • Loading branch information
gianlucam76 authored Dec 6, 2024
2 parents 03160d0 + 482fd24 commit b78daa5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ type KustomizationRef struct {
// a ClusterProfile. By default, withdrawpolicies, deployed Helm charts and Kubernetes
// resources will be removed from Cluster. LeavePolicy instead leaves Helm charts
// and Kubernetes policies in the Cluster.
// +kubebuilder:validation:Enum:=WithdrawPolicies;LeavePolicies
type StopMatchingBehavior string

// Define the StopMatchingBehavior constants.
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ type KustomizationRef struct {
// a ClusterProfile. By default, withdrawpolicies, deployed Helm charts and Kubernetes
// resources will be removed from Cluster. LeavePolicy instead leaves Helm charts
// and Kubernetes policies in the Cluster.
// +kubebuilder:validation:Enum:=WithdrawPolicies;LeavePolicies
type StopMatchingBehavior string

// Define the StopMatchingBehavior constants.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -1781,6 +1784,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -1809,6 +1812,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/config.projectsveltos.io_profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -1781,6 +1784,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down
23 changes: 13 additions & 10 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,17 +1361,20 @@ func shouldUpgrade(ctx context.Context, currentRelease *releaseInfo, requestedCh
}

if clusterSummary.Spec.ClusterProfileSpec.SyncMode != configv1beta1.SyncModeContinuousWithDriftDetection {
oldValueHash := getValueHashFromHelmChartSummary(requestedChart, clusterSummary)
if clusterSummary.Spec.ClusterProfileSpec.SyncMode != configv1beta1.SyncModeDryRun {
// In DryRun mode, if values are different, report will be generated
oldValueHash := getValueHashFromHelmChartSummary(requestedChart, clusterSummary)

// If Values configuration has changed, trigger an upgrade
c := getManagementClusterClient()
currentValueHash, err := getHelmChartValuesHash(ctx, c, requestedChart, clusterSummary, logger)
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to get current values hash: %v", err))
currentValueHash = []byte("") // force upgrade
}
if !reflect.DeepEqual(oldValueHash, currentValueHash) {
return true
// If Values configuration has changed, trigger an upgrade
c := getManagementClusterClient()
currentValueHash, err := getHelmChartValuesHash(ctx, c, requestedChart, clusterSummary, logger)
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to get current values hash: %v", err))
currentValueHash = []byte("") // force upgrade
}
if !reflect.DeepEqual(oldValueHash, currentValueHash) {
return true
}
}

// With drift detection mode, there is reconciliation due to configuration drift even
Expand Down
18 changes: 18 additions & 0 deletions manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -2562,6 +2565,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -4184,6 +4190,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -5392,6 +5401,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -6327,6 +6339,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down Expand Up @@ -7525,6 +7540,9 @@ spec:
the ClusterProfile. By default all deployed Helm charts and Kubernetes resources will
be withdrawn from Cluster. Setting StopMatchingBehavior to LeavePolicies will instead
leave ClusterProfile deployed policies in the Cluster.
enum:
- WithdrawPolicies
- LeavePolicies
type: string
syncMode:
default: Continuous
Expand Down

0 comments on commit b78daa5

Please sign in to comment.