diff --git a/apis/core.oam.dev/v1alpha1/applyonce_types.go b/apis/core.oam.dev/v1alpha1/applyonce_types.go index d713c18dc..9493f1b96 100644 --- a/apis/core.oam.dev/v1alpha1/applyonce_types.go +++ b/apis/core.oam.dev/v1alpha1/applyonce_types.go @@ -23,8 +23,17 @@ import ( const ( // ApplyOncePolicyType refers to the type of configuration drift policy ApplyOncePolicyType = "apply-once" + // ApplyOnceStrategyOnAppUpdate policy takes effect on application updating + ApplyOnceStrategyOnAppUpdate ApplyOnceAffectStrategy = "onUpdate" + // ApplyOnceStrategyOnAppStateKeep policy takes effect on application state keep + ApplyOnceStrategyOnAppStateKeep ApplyOnceAffectStrategy = "onStateKeep" + // ApplyOnceStrategyAlways policy takes effect always + ApplyOnceStrategyAlways ApplyOnceAffectStrategy = "always" ) +// ApplyOnceAffectStrategy is a string that mark the policy effective stage +type ApplyOnceAffectStrategy string + // ApplyOncePolicySpec defines the spec of preventing configuration drift type ApplyOncePolicySpec struct { Enable bool `json:"enable"` @@ -45,6 +54,9 @@ type ApplyOnceStrategy struct { // Path the specified path that allow configuration drift // like 'spec.template.spec.containers[0].resources' and '*' means the whole target allow configuration drift Path []string `json:"path"` + // ApplyOnceAffectStrategy Decide when the strategy will take effect + // like affect:onUpdate/onStateKeep/always + ApplyOnceAffectStrategy ApplyOnceAffectStrategy `json:"affect"` } // FindStrategy find apply-once strategy for target resource diff --git a/charts/vela-core/templates/defwithtemplate/apply-once.yaml b/charts/vela-core/templates/defwithtemplate/apply-once.yaml index 6a07df1b0..68563ff44 100644 --- a/charts/vela-core/templates/defwithtemplate/apply-once.yaml +++ b/charts/vela-core/templates/defwithtemplate/apply-once.yaml @@ -12,6 +12,8 @@ spec: cue: template: | #ApplyOnceStrategy: { + // +usage=When the strategy takes effect,e.g. onUpdate、onStateKeep + affect?: string // +usage=Specify the path of the resource that allow configuration drift path: [...string] } diff --git a/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml b/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml index 6a07df1b0..68563ff44 100644 --- a/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml @@ -12,6 +12,8 @@ spec: cue: template: | #ApplyOnceStrategy: { + // +usage=When the strategy takes effect,e.g. onUpdate、onStateKeep + affect?: string // +usage=Specify the path of the resource that allow configuration drift path: [...string] } diff --git a/docs/examples/app-with-policy/apply-once-policy/apply-once.md b/docs/examples/app-with-policy/apply-once-policy/apply-once.md index 94755b5ff..f5f2ecb5d 100644 --- a/docs/examples/app-with-policy/apply-once-policy/apply-once.md +++ b/docs/examples/app-with-policy/apply-once-policy/apply-once.md @@ -120,4 +120,61 @@ EOF In the `apply-once-app-3` case, any changes of `hello-cosmos` deployment will not be brought back and any changes of `hello-cosmos` service will be brought back in the next reconcile loop. In the same time, any changes -of `hello-world` component will be brought back in the next reconcile loop. \ No newline at end of file +of `hello-world` component will be brought back in the next reconcile loop. + +```shell +$ cat <