From 2e6b5156b0152bfd1a54bf7981def5098c570e90 Mon Sep 17 00:00:00 2001 From: Zhiying Lin Date: Mon, 2 Dec 2024 17:54:39 +0800 Subject: [PATCH 1/2] interface: support crp attached override --- apis/placement/v1alpha1/override_types.go | 22 ++++++++++++++ .../v1alpha1/zz_generated.deepcopy.go | 30 +++++++++++++++++-- ...tes-fleet.io_clusterresourceoverrides.yaml | 15 ++++++++++ ...t.io_clusterresourceoverridesnapshots.yaml | 15 ++++++++++ ...kubernetes-fleet.io_resourceoverrides.yaml | 18 +++++++++++ ...es-fleet.io_resourceoverridesnapshots.yaml | 18 +++++++++++ 6 files changed, 115 insertions(+), 3 deletions(-) diff --git a/apis/placement/v1alpha1/override_types.go b/apis/placement/v1alpha1/override_types.go index 0343cb9fa..4092b0560 100644 --- a/apis/placement/v1alpha1/override_types.go +++ b/apis/placement/v1alpha1/override_types.go @@ -48,6 +48,21 @@ type ClusterResourceOverrideSpec struct { // Policy defines how to override the selected resources on the target clusters. // +required Policy *OverridePolicy `json:"policy"` + + // Placement defines whether the override is applied to a specific placement or not. + // If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + // Otherwise, it will be applied to the next rollout. + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="spec.placement is immutable" + // +optional + Placement *PlacementRef `json:"placement,omitempty"` +} + +// PlacementRef is the reference to a placement. +// For now, we only support ClusterResourcePlacement. +type PlacementRef struct { + // Name is the reference to the name of placement. + // +required + Name string `json:"name"` } // OverridePolicy defines how to override the selected resources on the target clusters. @@ -133,6 +148,13 @@ type ResourceOverrideSpec struct { // Policy defines how to override the selected resources on the target clusters. // +required Policy *OverridePolicy `json:"policy"` + + // Placement defines whether the override is applied to a specific placement or not. + // If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + // Otherwise, it will be applied to the next rollout. + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="spec.placement is immutable" + // +optional + Placement *PlacementRef `json:"placement,omitempty"` } // ResourceSelector is used to select namespace scoped resources as the target resources to be placed. diff --git a/apis/placement/v1alpha1/zz_generated.deepcopy.go b/apis/placement/v1alpha1/zz_generated.deepcopy.go index 1a3f72658..91fe880f3 100644 --- a/apis/placement/v1alpha1/zz_generated.deepcopy.go +++ b/apis/placement/v1alpha1/zz_generated.deepcopy.go @@ -10,11 +10,10 @@ Licensed under the MIT license. package v1alpha1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "go.goms.io/fleet/apis/placement/v1beta1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" - - "go.goms.io/fleet/apis/placement/v1beta1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -303,6 +302,11 @@ func (in *ClusterResourceOverrideSpec) DeepCopyInto(out *ClusterResourceOverride *out = new(OverridePolicy) (*in).DeepCopyInto(*out) } + if in.Placement != nil { + in, out := &in.Placement, &out.Placement + *out = new(PlacementRef) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResourceOverrideSpec. @@ -708,6 +712,21 @@ func (in *PlacementEvictionStatus) DeepCopy() *PlacementEvictionStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PlacementRef) DeepCopyInto(out *PlacementRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PlacementRef. +func (in *PlacementRef) DeepCopy() *PlacementRef { + if in == nil { + return nil + } + out := new(PlacementRef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceOverride) DeepCopyInto(out *ResourceOverride) { *out = *in @@ -858,6 +877,11 @@ func (in *ResourceOverrideSpec) DeepCopyInto(out *ResourceOverrideSpec) { *out = new(OverridePolicy) (*in).DeepCopyInto(*out) } + if in.Placement != nil { + in, out := &in.Placement, &out.Placement + *out = new(PlacementRef) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceOverrideSpec. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml index c047bcfee..a2a69962e 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml @@ -129,6 +129,21 @@ spec: maxItems: 20 minItems: 1 type: array + placement: + description: |- + Placement defines whether the override is applied to a specific placement or not. + If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + Otherwise, it will be applied to the next rollout. + properties: + name: + description: Name is the reference to the name of placement. + type: string + required: + - name + type: object + x-kubernetes-validations: + - message: spec.placement is immutable + rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml index 4c9fa8682..8c1d74955 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml @@ -143,6 +143,21 @@ spec: maxItems: 20 minItems: 1 type: array + placement: + description: |- + Placement defines whether the override is applied to a specific placement or not. + If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + Otherwise, it will be applied to the next rollout. + properties: + name: + description: Name is the reference to the name of placement. + type: string + required: + - name + type: object + x-kubernetes-validations: + - message: spec.placement is immutable + rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml index a61b71d69..b2cfab3af 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml @@ -44,6 +44,21 @@ spec: spec: description: The desired state of ResourceOverrideSpec. properties: + placement: + description: |- + Placement defines whether the override is applied to a specific placement or not. + If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + Otherwise, it will be applied to the next rollout. + properties: + name: + description: Name is the reference to the name of placement. + type: string + required: + - name + type: object + x-kubernetes-validations: + - message: spec.placement is immutable + rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. @@ -251,7 +266,10 @@ spec: minItems: 1 type: array overrideType: +<<<<<<< HEAD default: JSONPatch +======= +>>>>>>> 683fa05 (interface: support crp attached override) description: OverrideType defines the type of the override rules. enum: diff --git a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml index 33cbe2b12..d3582577d 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml @@ -58,6 +58,21 @@ spec: overrideSpec: description: OverrideSpec stores the spec of ResourceOverride. properties: + placement: + description: |- + Placement defines whether the override is applied to a specific placement or not. + If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + Otherwise, it will be applied to the next rollout. + properties: + name: + description: Name is the reference to the name of placement. + type: string + required: + - name + type: object + x-kubernetes-validations: + - message: spec.placement is immutable + rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. @@ -265,7 +280,10 @@ spec: minItems: 1 type: array overrideType: +<<<<<<< HEAD default: JSONPatch +======= +>>>>>>> 683fa05 (interface: support crp attached override) description: OverrideType defines the type of the override rules. enum: From 7736d21cdadb36f0623c440b91d3881a735dd7ee Mon Sep 17 00:00:00 2001 From: Zhiying Lin Date: Tue, 10 Dec 2024 14:45:58 +0800 Subject: [PATCH 2/2] address comments --- apis/cluster/v1beta1/zz_generated.deepcopy.go | 2 +- apis/placement/v1alpha1/override_types.go | 28 +++++++++---------- .../v1alpha1/zz_generated.deepcopy.go | 20 ++++++------- .../v1beta1/zz_generated.deepcopy.go | 2 +- apis/v1alpha1/zz_generated.deepcopy.go | 2 +- ...tes-fleet.io_clusterresourceoverrides.yaml | 6 ++-- ...t.io_clusterresourceoverridesnapshots.yaml | 6 ++-- ...kubernetes-fleet.io_resourceoverrides.yaml | 9 ++---- ...es-fleet.io_resourceoverridesnapshots.yaml | 9 ++---- test/apis/v1alpha1/zz_generated.deepcopy.go | 2 +- 10 files changed, 36 insertions(+), 50 deletions(-) diff --git a/apis/cluster/v1beta1/zz_generated.deepcopy.go b/apis/cluster/v1beta1/zz_generated.deepcopy.go index 6c25f0189..6d06cb15b 100644 --- a/apis/cluster/v1beta1/zz_generated.deepcopy.go +++ b/apis/cluster/v1beta1/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ Licensed under the MIT license. package v1beta1 import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) diff --git a/apis/placement/v1alpha1/override_types.go b/apis/placement/v1alpha1/override_types.go index 4092b0560..9459d10cc 100644 --- a/apis/placement/v1alpha1/override_types.go +++ b/apis/placement/v1alpha1/override_types.go @@ -34,6 +34,13 @@ type ClusterResourceOverride struct { // If the resource is selected by both ClusterResourceOverride and ResourceOverride, ResourceOverride will win when resolving // conflicts. type ClusterResourceOverrideSpec struct { + // Placement defines whether the override is applied to a specific placement or not. + // If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + // Otherwise, it will be applied to the next rollout. + // The recommended way is to set the placement so that the override can be rolled out immediately. + // +optional + Placement *PlacementRef `json:"placement,omitempty"` + // ClusterResourceSelectors is an array of selectors used to select cluster scoped resources. The selectors are `ORed`. // If a namespace is selected, ALL the resources under the namespace are selected automatically. // LabelSelector is not supported. @@ -48,13 +55,6 @@ type ClusterResourceOverrideSpec struct { // Policy defines how to override the selected resources on the target clusters. // +required Policy *OverridePolicy `json:"policy"` - - // Placement defines whether the override is applied to a specific placement or not. - // If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. - // Otherwise, it will be applied to the next rollout. - // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="spec.placement is immutable" - // +optional - Placement *PlacementRef `json:"placement,omitempty"` } // PlacementRef is the reference to a placement. @@ -137,6 +137,13 @@ type ResourceOverride struct { // If the resource is selected by both ClusterResourceOverride and ResourceOverride, ResourceOverride will win when resolving // conflicts. type ResourceOverrideSpec struct { + // Placement defines whether the override is applied to a specific placement or not. + // If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + // Otherwise, it will be applied to the next rollout. + // The recommended way is to set the placement so that the override can be rolled out immediately. + // +optional + Placement *PlacementRef `json:"placement,omitempty"` + // ResourceSelectors is an array of selectors used to select namespace scoped resources. The selectors are `ORed`. // You can have 1-20 selectors. // +kubebuilder:validation:Required @@ -148,13 +155,6 @@ type ResourceOverrideSpec struct { // Policy defines how to override the selected resources on the target clusters. // +required Policy *OverridePolicy `json:"policy"` - - // Placement defines whether the override is applied to a specific placement or not. - // If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. - // Otherwise, it will be applied to the next rollout. - // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="spec.placement is immutable" - // +optional - Placement *PlacementRef `json:"placement,omitempty"` } // ResourceSelector is used to select namespace scoped resources as the target resources to be placed. diff --git a/apis/placement/v1alpha1/zz_generated.deepcopy.go b/apis/placement/v1alpha1/zz_generated.deepcopy.go index 91fe880f3..755b15f16 100644 --- a/apis/placement/v1alpha1/zz_generated.deepcopy.go +++ b/apis/placement/v1alpha1/zz_generated.deepcopy.go @@ -290,6 +290,11 @@ func (in *ClusterResourceOverrideSnapshotSpec) DeepCopy() *ClusterResourceOverri // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterResourceOverrideSpec) DeepCopyInto(out *ClusterResourceOverrideSpec) { *out = *in + if in.Placement != nil { + in, out := &in.Placement, &out.Placement + *out = new(PlacementRef) + **out = **in + } if in.ClusterResourceSelectors != nil { in, out := &in.ClusterResourceSelectors, &out.ClusterResourceSelectors *out = make([]v1beta1.ClusterResourceSelector, len(*in)) @@ -302,11 +307,6 @@ func (in *ClusterResourceOverrideSpec) DeepCopyInto(out *ClusterResourceOverride *out = new(OverridePolicy) (*in).DeepCopyInto(*out) } - if in.Placement != nil { - in, out := &in.Placement, &out.Placement - *out = new(PlacementRef) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResourceOverrideSpec. @@ -867,6 +867,11 @@ func (in *ResourceOverrideSnapshotSpec) DeepCopy() *ResourceOverrideSnapshotSpec // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResourceOverrideSpec) DeepCopyInto(out *ResourceOverrideSpec) { *out = *in + if in.Placement != nil { + in, out := &in.Placement, &out.Placement + *out = new(PlacementRef) + **out = **in + } if in.ResourceSelectors != nil { in, out := &in.ResourceSelectors, &out.ResourceSelectors *out = make([]ResourceSelector, len(*in)) @@ -877,11 +882,6 @@ func (in *ResourceOverrideSpec) DeepCopyInto(out *ResourceOverrideSpec) { *out = new(OverridePolicy) (*in).DeepCopyInto(*out) } - if in.Placement != nil { - in, out := &in.Placement, &out.Placement - *out = new(PlacementRef) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceOverrideSpec. diff --git a/apis/placement/v1beta1/zz_generated.deepcopy.go b/apis/placement/v1beta1/zz_generated.deepcopy.go index 497454532..803ac0287 100644 --- a/apis/placement/v1beta1/zz_generated.deepcopy.go +++ b/apis/placement/v1beta1/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ Licensed under the MIT license. package v1beta1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index ac4844274..0d4061551 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -11,7 +11,7 @@ package v1alpha1 import ( corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml index a2a69962e..3aa2b04c4 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverrides.yaml @@ -132,8 +132,9 @@ spec: placement: description: |- Placement defines whether the override is applied to a specific placement or not. - If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. Otherwise, it will be applied to the next rollout. + The recommended way is to set the placement so that the override can be rolled out immediately. properties: name: description: Name is the reference to the name of placement. @@ -141,9 +142,6 @@ spec: required: - name type: object - x-kubernetes-validations: - - message: spec.placement is immutable - rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml index 8c1d74955..d89c326a0 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterresourceoverridesnapshots.yaml @@ -146,8 +146,9 @@ spec: placement: description: |- Placement defines whether the override is applied to a specific placement or not. - If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. Otherwise, it will be applied to the next rollout. + The recommended way is to set the placement so that the override can be rolled out immediately. properties: name: description: Name is the reference to the name of placement. @@ -155,9 +156,6 @@ spec: required: - name type: object - x-kubernetes-validations: - - message: spec.placement is immutable - rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml index b2cfab3af..6f1a80678 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverrides.yaml @@ -47,8 +47,9 @@ spec: placement: description: |- Placement defines whether the override is applied to a specific placement or not. - If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. Otherwise, it will be applied to the next rollout. + The recommended way is to set the placement so that the override can be rolled out immediately. properties: name: description: Name is the reference to the name of placement. @@ -56,9 +57,6 @@ spec: required: - name type: object - x-kubernetes-validations: - - message: spec.placement is immutable - rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. @@ -266,10 +264,7 @@ spec: minItems: 1 type: array overrideType: -<<<<<<< HEAD default: JSONPatch -======= ->>>>>>> 683fa05 (interface: support crp attached override) description: OverrideType defines the type of the override rules. enum: diff --git a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml index d3582577d..d502dd686 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_resourceoverridesnapshots.yaml @@ -61,8 +61,9 @@ spec: placement: description: |- Placement defines whether the override is applied to a specific placement or not. - If so, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. + If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate. Otherwise, it will be applied to the next rollout. + The recommended way is to set the placement so that the override can be rolled out immediately. properties: name: description: Name is the reference to the name of placement. @@ -70,9 +71,6 @@ spec: required: - name type: object - x-kubernetes-validations: - - message: spec.placement is immutable - rule: self == oldSelf policy: description: Policy defines how to override the selected resources on the target clusters. @@ -280,10 +278,7 @@ spec: minItems: 1 type: array overrideType: -<<<<<<< HEAD default: JSONPatch -======= ->>>>>>> 683fa05 (interface: support crp attached override) description: OverrideType defines the type of the override rules. enum: diff --git a/test/apis/v1alpha1/zz_generated.deepcopy.go b/test/apis/v1alpha1/zz_generated.deepcopy.go index ef7e4433a..0b5d2e30b 100644 --- a/test/apis/v1alpha1/zz_generated.deepcopy.go +++ b/test/apis/v1alpha1/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ Licensed under the MIT license. package v1alpha1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" )