Merge pull request #5897 from RainbowMango/pr_stateful_injection_gate

Add stateful application failover status injection feature gate
This commit is contained in:
karmada-bot 2024-11-30 09:19:06 +08:00 committed by GitHub
commit 0f2e0cc0d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 51 additions and 18 deletions

View File

@ -18291,7 +18291,7 @@
"type": "string" "type": "string"
}, },
"statePreservation": { "statePreservation": {
"description": "StatePreservation defines the policy for preserving and restoring state data during failover events for stateful applications.\n\nWhen an application fails over from one cluster to another, this policy enables the extraction of critical data from the original resource configuration. Upon successful migration, the extracted data is then re-injected into the new resource, ensuring that the application can resume operation with its previous state intact. This is particularly useful for stateful applications where maintaining data consistency across failover events is crucial. If not specified, means no state data will be preserved.", "description": "StatePreservation defines the policy for preserving and restoring state data during failover events for stateful applications.\n\nWhen an application fails over from one cluster to another, this policy enables the extraction of critical data from the original resource configuration. Upon successful migration, the extracted data is then re-injected into the new resource, ensuring that the application can resume operation with its previous state intact. This is particularly useful for stateful applications where maintaining data consistency across failover events is crucial. If not specified, means no state data will be preserved.\n\nNote: This requires the StatefulFailoverInjection feature gate to be enabled, which is alpha.",
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.StatePreservation" "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.StatePreservation"
} }
} }

View File

@ -30,7 +30,7 @@ spec:
- --cluster-status-update-frequency=10s - --cluster-status-update-frequency=10s
- --failover-eviction-timeout=30s - --failover-eviction-timeout=30s
- --controllers=*,hpaScaleTargetMarker,deploymentReplicasSyncer - --controllers=*,hpaScaleTargetMarker,deploymentReplicasSyncer
- --feature-gates=PropagationPolicyPreemption=true,MultiClusterService=true - --feature-gates=PropagationPolicyPreemption=true,MultiClusterService=true,StatefulFailoverInjection=true
- --health-probe-bind-address=0.0.0.0:10357 - --health-probe-bind-address=0.0.0.0:10357
- --v=4 - --v=4
livenessProbe: livenessProbe:

View File

@ -177,6 +177,9 @@ spec:
This is particularly useful for stateful applications where maintaining data This is particularly useful for stateful applications where maintaining data
consistency across failover events is crucial. consistency across failover events is crucial.
If not specified, means no state data will be preserved. If not specified, means no state data will be preserved.
Note: This requires the StatefulFailoverInjection feature gate to be enabled,
which is alpha.
properties: properties:
rules: rules:
description: |- description: |-

View File

@ -174,6 +174,9 @@ spec:
This is particularly useful for stateful applications where maintaining data This is particularly useful for stateful applications where maintaining data
consistency across failover events is crucial. consistency across failover events is crucial.
If not specified, means no state data will be preserved. If not specified, means no state data will be preserved.
Note: This requires the StatefulFailoverInjection feature gate to be enabled,
which is alpha.
properties: properties:
rules: rules:
description: |- description: |-

View File

@ -339,6 +339,9 @@ spec:
This is particularly useful for stateful applications where maintaining data This is particularly useful for stateful applications where maintaining data
consistency across failover events is crucial. consistency across failover events is crucial.
If not specified, means no state data will be preserved. If not specified, means no state data will be preserved.
Note: This requires the StatefulFailoverInjection feature gate to be enabled,
which is alpha.
properties: properties:
rules: rules:
description: |- description: |-

View File

@ -339,6 +339,9 @@ spec:
This is particularly useful for stateful applications where maintaining data This is particularly useful for stateful applications where maintaining data
consistency across failover events is crucial. consistency across failover events is crucial.
If not specified, means no state data will be preserved. If not specified, means no state data will be preserved.
Note: This requires the StatefulFailoverInjection feature gate to be enabled,
which is alpha.
properties: properties:
rules: rules:
description: |- description: |-

View File

@ -336,6 +336,9 @@ type ApplicationFailoverBehavior struct {
// This is particularly useful for stateful applications where maintaining data // This is particularly useful for stateful applications where maintaining data
// consistency across failover events is crucial. // consistency across failover events is crucial.
// If not specified, means no state data will be preserved. // If not specified, means no state data will be preserved.
//
// Note: This requires the StatefulFailoverInjection feature gate to be enabled,
// which is alpha.
// +optional // +optional
StatePreservation *StatePreservation `json:"statePreservation,omitempty"` StatePreservation *StatePreservation `json:"statePreservation,omitempty"`
} }

View File

@ -192,18 +192,20 @@ func buildTaskOptions(failoverBehavior *policyv1alpha1.ApplicationFailoverBehavi
taskOpts = append(taskOpts, workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure)) taskOpts = append(taskOpts, workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure))
taskOpts = append(taskOpts, workv1alpha2.WithPurgeMode(failoverBehavior.PurgeMode)) taskOpts = append(taskOpts, workv1alpha2.WithPurgeMode(failoverBehavior.PurgeMode))
if failoverBehavior.StatePreservation != nil && len(failoverBehavior.StatePreservation.Rules) != 0 { if features.FeatureGate.Enabled(features.StatefulFailoverInjection) {
targetStatusItem, exist := findTargetStatusItemByCluster(aggregatedStatus, cluster) if failoverBehavior.StatePreservation != nil && len(failoverBehavior.StatePreservation.Rules) != 0 {
if !exist || targetStatusItem.Status == nil || targetStatusItem.Status.Raw == nil { targetStatusItem, exist := findTargetStatusItemByCluster(aggregatedStatus, cluster)
return nil, fmt.Errorf("the application status has not yet been collected from Cluster(%s)", cluster) if !exist || targetStatusItem.Status == nil || targetStatusItem.Status.Raw == nil {
} return nil, fmt.Errorf("the application status has not yet been collected from Cluster(%s)", cluster)
preservedLabelState, err := buildPreservedLabelState(failoverBehavior.StatePreservation, targetStatusItem.Status.Raw) }
if err != nil { preservedLabelState, err := buildPreservedLabelState(failoverBehavior.StatePreservation, targetStatusItem.Status.Raw)
return nil, err if err != nil {
} return nil, err
if preservedLabelState != nil { }
taskOpts = append(taskOpts, workv1alpha2.WithPreservedLabelState(preservedLabelState)) if preservedLabelState != nil {
taskOpts = append(taskOpts, workv1alpha2.WithClustersBeforeFailover(clustersBeforeFailover)) taskOpts = append(taskOpts, workv1alpha2.WithPreservedLabelState(preservedLabelState))
taskOpts = append(taskOpts, workv1alpha2.WithClustersBeforeFailover(clustersBeforeFailover))
}
} }
} }

View File

@ -30,6 +30,7 @@ import (
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/features"
) )
func TestTimeStampProcess(t *testing.T) { func TestTimeStampProcess(t *testing.T) {
@ -645,6 +646,8 @@ func Test_buildTaskOptions(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
err := features.FeatureGate.Set(fmt.Sprintf("%s=%t", features.StatefulFailoverInjection, true))
assert.NoError(t, err)
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := buildTaskOptions(tt.args.failoverBehavior, tt.args.aggregatedStatus, tt.args.cluster, tt.args.producer, tt.args.clustersBeforeFailover) got, err := buildTaskOptions(tt.args.failoverBehavior, tt.args.aggregatedStatus, tt.args.cluster, tt.args.producer, tt.args.clustersBeforeFailover)
if !tt.wantErr(t, err, fmt.Sprintf("buildTaskOptions(%v, %v, %v, %v, %v)", tt.args.failoverBehavior, tt.args.aggregatedStatus, tt.args.cluster, tt.args.producer, tt.args.clustersBeforeFailover)) { if !tt.wantErr(t, err, fmt.Sprintf("buildTaskOptions(%v, %v, %v, %v, %v)", tt.args.failoverBehavior, tt.args.aggregatedStatus, tt.args.cluster, tt.args.producer, tt.args.clustersBeforeFailover)) {

View File

@ -31,6 +31,7 @@ import (
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1" configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/features"
"github.com/karmada-io/karmada/pkg/resourceinterpreter" "github.com/karmada-io/karmada/pkg/resourceinterpreter"
"github.com/karmada-io/karmada/pkg/util" "github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
@ -113,9 +114,11 @@ func ensureWork(
return err return err
} }
// we need to figure out if the targetCluster is in the cluster we are going to migrate application to. if features.FeatureGate.Enabled(features.StatefulFailoverInjection) {
// If yes, we have to inject the preserved label state to clonedWorkload with the label. // we need to figure out if the targetCluster is in the cluster we are going to migrate application to.
clonedWorkload = injectReservedLabelState(bindingSpec, targetCluster, clonedWorkload, len(targetClusters)) // If yes, we have to inject the preserved label state to the clonedWorkload.
clonedWorkload = injectReservedLabelState(bindingSpec, targetCluster, clonedWorkload, len(targetClusters))
}
workMeta := metav1.ObjectMeta{ workMeta := metav1.ObjectMeta{
Name: names.GenerateWorkName(clonedWorkload.GetKind(), clonedWorkload.GetName(), clonedWorkload.GetNamespace()), Name: names.GenerateWorkName(clonedWorkload.GetKind(), clonedWorkload.GetName(), clonedWorkload.GetNamespace()),

View File

@ -43,6 +43,15 @@ const (
// ResourceQuotaEstimate indicates if enable resource quota check in estimator // ResourceQuotaEstimate indicates if enable resource quota check in estimator
ResourceQuotaEstimate featuregate.Feature = "ResourceQuotaEstimate" ResourceQuotaEstimate featuregate.Feature = "ResourceQuotaEstimate"
// StatefulFailoverInjection controls whether Karmada collects state information
// from the source cluster during a failover event for stateful applications and
// injects this information into the application configuration when it is moved
// to the target cluster.
//
// owner: @mszacillo, @XiShanYongYe-Chang
// alpha: v1.12
StatefulFailoverInjection featuregate.Feature = "StatefulFailoverInjection"
) )
var ( var (
@ -58,6 +67,7 @@ var (
PolicyPreemption: {Default: false, PreRelease: featuregate.Alpha}, PolicyPreemption: {Default: false, PreRelease: featuregate.Alpha},
MultiClusterService: {Default: false, PreRelease: featuregate.Alpha}, MultiClusterService: {Default: false, PreRelease: featuregate.Alpha},
ResourceQuotaEstimate: {Default: false, PreRelease: featuregate.Alpha}, ResourceQuotaEstimate: {Default: false, PreRelease: featuregate.Alpha},
StatefulFailoverInjection: {Default: false, PreRelease: featuregate.Alpha},
} }
) )

View File

@ -3515,7 +3515,7 @@ func schema_pkg_apis_policy_v1alpha1_ApplicationFailoverBehavior(ref common.Refe
}, },
"statePreservation": { "statePreservation": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Description: "StatePreservation defines the policy for preserving and restoring state data during failover events for stateful applications.\n\nWhen an application fails over from one cluster to another, this policy enables the extraction of critical data from the original resource configuration. Upon successful migration, the extracted data is then re-injected into the new resource, ensuring that the application can resume operation with its previous state intact. This is particularly useful for stateful applications where maintaining data consistency across failover events is crucial. If not specified, means no state data will be preserved.", Description: "StatePreservation defines the policy for preserving and restoring state data during failover events for stateful applications.\n\nWhen an application fails over from one cluster to another, this policy enables the extraction of critical data from the original resource configuration. Upon successful migration, the extracted data is then re-injected into the new resource, ensuring that the application can resume operation with its previous state intact. This is particularly useful for stateful applications where maintaining data consistency across failover events is crucial. If not specified, means no state data will be preserved.\n\nNote: This requires the StatefulFailoverInjection feature gate to be enabled, which is alpha.",
Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.StatePreservation"), Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.StatePreservation"),
}, },
}, },