From fd784e291c2ee08f8fde1a28936dbbc12817c91c Mon Sep 17 00:00:00 2001 From: Somefive Date: Tue, 19 Jul 2022 15:47:01 +0800 Subject: [PATCH] Feat: add several policy definition (#4409) Signed-off-by: Somefive --- .../templates/defwithtemplate/apply-once.yaml | 44 +++++++++++++++++++ .../defwithtemplate/garbage-collect.yaml | 40 +++++++++++++++++ .../templates/defwithtemplate/apply-once.yaml | 44 +++++++++++++++++++ .../defwithtemplate/garbage-collect.yaml | 40 +++++++++++++++++ .../internal/policy/apply-once.cue | 43 ++++++++++++++++++ .../internal/policy/garbage-collect.cue | 38 ++++++++++++++++ 6 files changed, 249 insertions(+) create mode 100644 charts/vela-core/templates/defwithtemplate/apply-once.yaml create mode 100644 charts/vela-core/templates/defwithtemplate/garbage-collect.yaml create mode 100644 charts/vela-minimal/templates/defwithtemplate/apply-once.yaml create mode 100644 charts/vela-minimal/templates/defwithtemplate/garbage-collect.yaml create mode 100644 vela-templates/definitions/internal/policy/apply-once.cue create mode 100644 vela-templates/definitions/internal/policy/garbage-collect.cue diff --git a/charts/vela-core/templates/defwithtemplate/apply-once.yaml b/charts/vela-core/templates/defwithtemplate/apply-once.yaml new file mode 100644 index 000000000..1ab5db19d --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/apply-once.yaml @@ -0,0 +1,44 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/apply-once.cue +apiVersion: core.oam.dev/v1beta1 +kind: PolicyDefinition +metadata: + annotations: + definition.oam.dev/description: Configure the behaviour of preventing configuration drift. + name: apply-once + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + #ApplyOnceStrategy: { + // +usage=Specify the path of the resource that allow configuration drift + path: [...string] + } + #ApplyOncePolicyRule: { + // +usage=Specify how to select the targets of the rule + selector?: #ResourcePolicyRuleSelector + // +usage=Specify the strategy for configuring the resource level configuration drift behaviour + strategy: #ApplyOnceStrategy + } + #ResourcePolicyRuleSelector: { + // +usage=Select resources by component names + componentNames?: [...string] + // +usage=Select resources by component types + componentTypes?: [...string] + // +usage=Select resources by oamTypes (COMPONENT or TRAIT) + oamTypes?: [...string] + // +usage=Select resources by trait types + traitTypes?: [...string] + // +usage=Select resources by resource types (like Deployment) + resourceTypes?: [...string] + // +usage=Select resources by their names + resourceNames?: [...string] + } + parameter: { + // +usage=Whether to enable apply-once for the whole application + enable: *false | bool + // +usage=Specify the rules for configuring apply-once policy in resource level + rules?: [...#ApplyOncePolicyRule] + } + diff --git a/charts/vela-core/templates/defwithtemplate/garbage-collect.yaml b/charts/vela-core/templates/defwithtemplate/garbage-collect.yaml new file mode 100644 index 000000000..bcf8990d9 --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/garbage-collect.yaml @@ -0,0 +1,40 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/garbage-collect.cue +apiVersion: core.oam.dev/v1beta1 +kind: PolicyDefinition +metadata: + annotations: + definition.oam.dev/description: Configure the garbage collect behaviour for the application. + name: garbage-collect + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + #GarbageCollectPolicyRule: { + // +usage=Specify how to select the targets of the rule + selector: [...#ResourcePolicyRuleSelector] + // +usage=Specify the strategy for target resource to recycle + strategy: *"onAppUpdate" | "onAppDelete" | "never" + } + #ResourcePolicyRuleSelector: { + // +usage=Select resources by component names + componentNames?: [...string] + // +usage=Select resources by component types + componentTypes?: [...string] + // +usage=Select resources by oamTypes (COMPONENT or TRAIT) + oamTypes?: [...string] + // +usage=Select resources by trait types + traitTypes?: [...string] + // +usage=Select resources by resource types (like Deployment) + resourceTypes?: [...string] + // +usage=Select resources by their names + resourceNames?: [...string] + } + parameter: { + // +usage=If is set, outdated versioned resourcetracker will not be recycled automatically, outdated resources will be kept until resourcetracker be deleted manually + keepLegacyResource: *false | bool + // +usage=Specify the list of rules to control gc strategy at resource level, if one resource is controlled by multiple rules, first rule will be used + rules?: [...#GarbageCollectPolicyRule] + } + diff --git a/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml b/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml new file mode 100644 index 000000000..1ab5db19d --- /dev/null +++ b/charts/vela-minimal/templates/defwithtemplate/apply-once.yaml @@ -0,0 +1,44 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/apply-once.cue +apiVersion: core.oam.dev/v1beta1 +kind: PolicyDefinition +metadata: + annotations: + definition.oam.dev/description: Configure the behaviour of preventing configuration drift. + name: apply-once + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + #ApplyOnceStrategy: { + // +usage=Specify the path of the resource that allow configuration drift + path: [...string] + } + #ApplyOncePolicyRule: { + // +usage=Specify how to select the targets of the rule + selector?: #ResourcePolicyRuleSelector + // +usage=Specify the strategy for configuring the resource level configuration drift behaviour + strategy: #ApplyOnceStrategy + } + #ResourcePolicyRuleSelector: { + // +usage=Select resources by component names + componentNames?: [...string] + // +usage=Select resources by component types + componentTypes?: [...string] + // +usage=Select resources by oamTypes (COMPONENT or TRAIT) + oamTypes?: [...string] + // +usage=Select resources by trait types + traitTypes?: [...string] + // +usage=Select resources by resource types (like Deployment) + resourceTypes?: [...string] + // +usage=Select resources by their names + resourceNames?: [...string] + } + parameter: { + // +usage=Whether to enable apply-once for the whole application + enable: *false | bool + // +usage=Specify the rules for configuring apply-once policy in resource level + rules?: [...#ApplyOncePolicyRule] + } + diff --git a/charts/vela-minimal/templates/defwithtemplate/garbage-collect.yaml b/charts/vela-minimal/templates/defwithtemplate/garbage-collect.yaml new file mode 100644 index 000000000..bcf8990d9 --- /dev/null +++ b/charts/vela-minimal/templates/defwithtemplate/garbage-collect.yaml @@ -0,0 +1,40 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/garbage-collect.cue +apiVersion: core.oam.dev/v1beta1 +kind: PolicyDefinition +metadata: + annotations: + definition.oam.dev/description: Configure the garbage collect behaviour for the application. + name: garbage-collect + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + #GarbageCollectPolicyRule: { + // +usage=Specify how to select the targets of the rule + selector: [...#ResourcePolicyRuleSelector] + // +usage=Specify the strategy for target resource to recycle + strategy: *"onAppUpdate" | "onAppDelete" | "never" + } + #ResourcePolicyRuleSelector: { + // +usage=Select resources by component names + componentNames?: [...string] + // +usage=Select resources by component types + componentTypes?: [...string] + // +usage=Select resources by oamTypes (COMPONENT or TRAIT) + oamTypes?: [...string] + // +usage=Select resources by trait types + traitTypes?: [...string] + // +usage=Select resources by resource types (like Deployment) + resourceTypes?: [...string] + // +usage=Select resources by their names + resourceNames?: [...string] + } + parameter: { + // +usage=If is set, outdated versioned resourcetracker will not be recycled automatically, outdated resources will be kept until resourcetracker be deleted manually + keepLegacyResource: *false | bool + // +usage=Specify the list of rules to control gc strategy at resource level, if one resource is controlled by multiple rules, first rule will be used + rules?: [...#GarbageCollectPolicyRule] + } + diff --git a/vela-templates/definitions/internal/policy/apply-once.cue b/vela-templates/definitions/internal/policy/apply-once.cue new file mode 100644 index 000000000..687ce9ba0 --- /dev/null +++ b/vela-templates/definitions/internal/policy/apply-once.cue @@ -0,0 +1,43 @@ +"apply-once": { + annotations: {} + description: "Configure the behaviour of preventing configuration drift." + labels: {} + attributes: {} + type: "policy" +} + +template: { + #ApplyOnceStrategy: { + // +usage=Specify the path of the resource that allow configuration drift + path: [...string] + } + + #ApplyOncePolicyRule: { + // +usage=Specify how to select the targets of the rule + selector?: #ResourcePolicyRuleSelector + // +usage=Specify the strategy for configuring the resource level configuration drift behaviour + strategy: #ApplyOnceStrategy + } + + #ResourcePolicyRuleSelector: { + // +usage=Select resources by component names + componentNames?: [...string] + // +usage=Select resources by component types + componentTypes?: [...string] + // +usage=Select resources by oamTypes (COMPONENT or TRAIT) + oamTypes?: [...string] + // +usage=Select resources by trait types + traitTypes?: [...string] + // +usage=Select resources by resource types (like Deployment) + resourceTypes?: [...string] + // +usage=Select resources by their names + resourceNames?: [...string] + } + + parameter: { + // +usage=Whether to enable apply-once for the whole application + enable: *false | bool + // +usage=Specify the rules for configuring apply-once policy in resource level + rules?: [...#ApplyOncePolicyRule] + } +} diff --git a/vela-templates/definitions/internal/policy/garbage-collect.cue b/vela-templates/definitions/internal/policy/garbage-collect.cue new file mode 100644 index 000000000..550e95104 --- /dev/null +++ b/vela-templates/definitions/internal/policy/garbage-collect.cue @@ -0,0 +1,38 @@ +"garbage-collect": { + annotations: {} + description: "Configure the garbage collect behaviour for the application." + labels: {} + attributes: {} + type: "policy" +} + +template: { + #GarbageCollectPolicyRule: { + // +usage=Specify how to select the targets of the rule + selector: [...#ResourcePolicyRuleSelector] + // +usage=Specify the strategy for target resource to recycle + strategy: *"onAppUpdate" | "onAppDelete" | "never" + } + + #ResourcePolicyRuleSelector: { + // +usage=Select resources by component names + componentNames?: [...string] + // +usage=Select resources by component types + componentTypes?: [...string] + // +usage=Select resources by oamTypes (COMPONENT or TRAIT) + oamTypes?: [...string] + // +usage=Select resources by trait types + traitTypes?: [...string] + // +usage=Select resources by resource types (like Deployment) + resourceTypes?: [...string] + // +usage=Select resources by their names + resourceNames?: [...string] + } + + parameter: { + // +usage=If is set, outdated versioned resourcetracker will not be recycled automatically, outdated resources will be kept until resourcetracker be deleted manually + keepLegacyResource: *false | bool + // +usage=Specify the list of rules to control gc strategy at resource level, if one resource is controlled by multiple rules, first rule will be used + rules?: [...#GarbageCollectPolicyRule] + } +}