mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
Feat: support resource update policy (#6003)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2021 The KubeVela Authors.
|
||||
Copyright 2023 The KubeVela Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2021 The KubeVela Authors.
|
||||
Copyright 2023 The KubeVela Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
70
apis/core.oam.dev/v1alpha1/resource_update_policy_types.go
Normal file
70
apis/core.oam.dev/v1alpha1/resource_update_policy_types.go
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright 2023 The KubeVela Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
||||
const (
|
||||
// ResourceUpdatePolicyType refers to the type of resource-update policy
|
||||
ResourceUpdatePolicyType = "resource-update"
|
||||
)
|
||||
|
||||
// ResourceUpdatePolicySpec defines the spec of resource-update policy
|
||||
type ResourceUpdatePolicySpec struct {
|
||||
Rules []ResourceUpdatePolicyRule `json:"rules"`
|
||||
}
|
||||
|
||||
// Type the type name of the policy
|
||||
func (in *ResourceUpdatePolicySpec) Type() string {
|
||||
return ResourceUpdatePolicyType
|
||||
}
|
||||
|
||||
// ResourceUpdatePolicyRule defines the rule for resource-update resources
|
||||
type ResourceUpdatePolicyRule struct {
|
||||
// Selector picks which resources should be affected
|
||||
Selector ResourcePolicyRuleSelector `json:"selector"`
|
||||
// Strategy the strategy for updating resources
|
||||
Strategy ResourceUpdateStrategy `json:"strategy,omitempty"`
|
||||
}
|
||||
|
||||
// ResourceUpdateStrategy the update strategy for resource
|
||||
type ResourceUpdateStrategy struct {
|
||||
// Op the update op for selected resources
|
||||
Op ResourceUpdateOp `json:"op,omitempty"`
|
||||
// RecreateFields the field path which will trigger recreate if changed
|
||||
RecreateFields []string `json:"recreateFields,omitempty"`
|
||||
}
|
||||
|
||||
// ResourceUpdateOp update op for resource
|
||||
type ResourceUpdateOp string
|
||||
|
||||
const (
|
||||
// ResourceUpdateStrategyPatch patch the target resource (three-way patch)
|
||||
ResourceUpdateStrategyPatch ResourceUpdateOp = "patch"
|
||||
// ResourceUpdateStrategyReplace update the target resource
|
||||
ResourceUpdateStrategyReplace ResourceUpdateOp = "replace"
|
||||
)
|
||||
|
||||
// FindStrategy return if the target resource is read-only
|
||||
func (in *ResourceUpdatePolicySpec) FindStrategy(manifest *unstructured.Unstructured) *ResourceUpdateStrategy {
|
||||
for _, rule := range in.Rules {
|
||||
if rule.Selector.Match(manifest) {
|
||||
return &rule.Strategy
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2021 The KubeVela Authors.
|
||||
Copyright 2023 The KubeVela Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -725,6 +725,65 @@ func (in *ResourcePolicyRuleSelector) DeepCopy() *ResourcePolicyRuleSelector {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ResourceUpdatePolicyRule) DeepCopyInto(out *ResourceUpdatePolicyRule) {
|
||||
*out = *in
|
||||
in.Selector.DeepCopyInto(&out.Selector)
|
||||
in.Strategy.DeepCopyInto(&out.Strategy)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceUpdatePolicyRule.
|
||||
func (in *ResourceUpdatePolicyRule) DeepCopy() *ResourceUpdatePolicyRule {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ResourceUpdatePolicyRule)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ResourceUpdatePolicySpec) DeepCopyInto(out *ResourceUpdatePolicySpec) {
|
||||
*out = *in
|
||||
if in.Rules != nil {
|
||||
in, out := &in.Rules, &out.Rules
|
||||
*out = make([]ResourceUpdatePolicyRule, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceUpdatePolicySpec.
|
||||
func (in *ResourceUpdatePolicySpec) DeepCopy() *ResourceUpdatePolicySpec {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ResourceUpdatePolicySpec)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ResourceUpdateStrategy) DeepCopyInto(out *ResourceUpdateStrategy) {
|
||||
*out = *in
|
||||
if in.RecreateFields != nil {
|
||||
in, out := &in.RecreateFields, &out.RecreateFields
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceUpdateStrategy.
|
||||
func (in *ResourceUpdateStrategy) DeepCopy() *ResourceUpdateStrategy {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ResourceUpdateStrategy)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *SharedResourcePolicyRule) DeepCopyInto(out *SharedResourcePolicyRule) {
|
||||
*out = *in
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2021 The KubeVela Authors.
|
||||
Copyright 2023 The KubeVela Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2021 The KubeVela Authors.
|
||||
Copyright 2023 The KubeVela Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user