diff --git a/apis/v1/clusterresourceplacement_types.go b/apis/v1/clusterresourceplacement_types.go index d20b4e725..bcfba88d9 100644 --- a/apis/v1/clusterresourceplacement_types.go +++ b/apis/v1/clusterresourceplacement_types.go @@ -28,6 +28,8 @@ import ( // Note that you can't select the following resources: // - reserved namespaces including: default, kube-* (reserved for Kubernetes system namespaces), fleet-* (reserved for fleet system namespaces). // - reserved fleet resource types including: MemberCluster, InternalMemberCluster, ClusterResourcePlacement, MultiClusterService, ServiceImport, etc. +// The `ClusterResourceBinding` will be created and it represents a scheduling decision that binds a group of resources +// to a cluster. type ClusterResourcePlacement struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -109,11 +111,6 @@ type PlacementPolicy struct { // +optional NumberOfClusters *int32 `json:"numberOfClusters,omitempty"` - // The rollout strategy to use to replace existing applications with new ones. - // +optional - // +patchStrategy=retainKeys - Strategy *RolloutStrategy `json:"strategy,omitempty" patchStrategy:"retainKeys" patchMergeKey:"type"` - // Affinity contains cluster affinity scheduling rules. Defines which member clusters to place the selected resources. // +optional Affinity *Affinity `json:"affinity,omitempty"` @@ -322,25 +319,6 @@ const ( PickNPlacementType PlacementType = "PickN" ) -// RolloutStrategy describes how to replace existing application with new ones. -type RolloutStrategy struct { - // Type of rollout strategy. Can be "Recreate" or "OnDelete". Default is "Recreate". - // +optional - Type RolloutStrategyType `json:"type,omitempty"` -} - -// RolloutStrategyType identifies the type of strategy we use to roll out new resources. -// +enum -type RolloutStrategyType string - -const ( - // RecreateRolloutStrategyType removes all existing resources from the clusters before creating new ones. - RecreateRolloutStrategyType RolloutStrategyType = "Recreate" - - // OnDeleteRolloutStrategy schedules a new resource binding only after an old binding is deleted. - OnDeleteRolloutStrategy RolloutStrategyType = "OnDelete" -) - // ClusterResourcePlacementList contains a list of ClusterResourcePlacement. // +kubebuilder:resource:scope="Cluster" // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/apis/v1/policysnapshot_types.go b/apis/v1/policysnapshot_types.go index 05182559b..cf78b3bfa 100644 --- a/apis/v1/policysnapshot_types.go +++ b/apis/v1/policysnapshot_types.go @@ -39,17 +39,17 @@ type ClusterPolicySnapshot struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - // The desired state of PolicySnapShot. + // The desired state of PolicySnapshot. // +required - Spec PolicySnapShotSpec `json:"spec"` + Spec PolicySnapshotSpec `json:"spec"` - // The observed status of PolicySnapShot. + // The observed status of PolicySnapshot. // +optional - Status PolicySnapShotStatus `json:"status,omitempty"` + Status PolicySnapshotStatus `json:"status,omitempty"` } -// PolicySnapShotSpec defines the desired state of PolicySnapShot. -type PolicySnapShotSpec struct { +// PolicySnapshotSpec defines the desired state of PolicySnapshot. +type PolicySnapshotSpec struct { // Policy defines how to select member clusters to place the selected resources. // If unspecified, all the joined member clusters are selected. // +optional @@ -60,14 +60,14 @@ type PolicySnapShotSpec struct { PolicyHash []byte `json:"policyHash"` } -// PolicySnapShotStatus defines the observed state of PolicySnapShot. -type PolicySnapShotStatus struct { +// PolicySnapshotStatus defines the observed state of PolicySnapshot. +type PolicySnapshotStatus struct { // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type - // Conditions is an array of current observed conditions for PolicySnapShot. + // Conditions is an array of current observed conditions for PolicySnapshot. // +optional Conditions []metav1.Condition `json:"conditions"` @@ -79,16 +79,16 @@ type PolicySnapShotStatus struct { ClusterDecisions []ClusterDecision `json:"targetClusters,omitempty"` } -// PolicySnapShotConditionType identifies a specific condition of the PolicySnapShot. -type PolicySnapShotConditionType string +// PolicySnapshotConditionType identifies a specific condition of the PolicySnapshot. +type PolicySnapshotConditionType string const ( - // Scheduled indicates the scheduled condition of the given policySnapShot. + // Scheduled indicates the scheduled condition of the given policySnapshot. // Its condition status can be one of the following: - // - "True" means the corresponding policySnapShot is fully scheduled. - // - "False" means the corresponding policySnapShot is not scheduled yet. + // - "True" means the corresponding policySnapshot is fully scheduled. + // - "False" means the corresponding policySnapshot is not scheduled yet. // - "Unknown" means this policy does not have a full schedule yet. - PolicySnapshotScheduled PolicySnapShotConditionType = "Scheduled" + PolicySnapshotScheduled PolicySnapshotConditionType = "Scheduled" ) // ClusterDecision represents a decision from a placement @@ -128,10 +128,10 @@ type ClusterScore struct { TopologySpreadScore *int32 `json:"priorityScore,omitempty"` } -// ClusterPolicySnapShotList contains a list of ClusterPolicySnapShot. +// ClusterPolicySnapshotList contains a list of ClusterPolicySnapshot. // +kubebuilder:resource:scope="Cluster" // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ClusterPolicySnapShotList struct { +type ClusterPolicySnapshotList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` Items []ClusterPolicySnapshot `json:"items"` @@ -150,5 +150,5 @@ func (m *ClusterPolicySnapshot) GetCondition(conditionType string) *metav1.Condi } func init() { - SchemeBuilder.Register(&ClusterPolicySnapshot{}, &ClusterPolicySnapShotList{}) + SchemeBuilder.Register(&ClusterPolicySnapshot{}, &ClusterPolicySnapshotList{}) } diff --git a/apis/v1/resourcesnapshot_types.go b/apis/v1/resourcesnapshot_types.go index e5c442265..978021aff 100644 --- a/apis/v1/resourcesnapshot_types.go +++ b/apis/v1/resourcesnapshot_types.go @@ -52,23 +52,24 @@ type ClusterResourceSnapshot struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - // The desired state of ResourceSnapShot. + // The desired state of ResourceSnapshot. // +required - Spec ResourceSnapShotSpec `json:"spec"` + Spec ResourceSnapshotSpec `json:"spec"` - // The observed status of ResourceSnapShot. + // The observed status of ResourceSnapshot. // +optional - Status ResourceSnapShotStatus `json:"status,omitempty"` + Status ResourceSnapshotStatus `json:"status,omitempty"` } -// ResourceSnapShotSpec defines the desired state of ResourceSnapShot. -type ResourceSnapShotSpec struct { +// ResourceSnapshotSpec defines the desired state of ResourceSnapshot. +type ResourceSnapshotSpec struct { // SelectedResources contains a list of resources selected by ResourceSelectors. // +required SelectedResources []ResourceContent `json:"selectedResources"` - // PolicySnapShotName is the name of the policy snapshot that this resource snapshot is pointing to. - PolicySnapShotName string `json:"policySnapShotName"` + // PolicySnapshotName is the name of the policy snapshot that this resource snapshot is pointing to. + // +required + PolicySnapshotName string `json:"policySnapshotName"` } // ResourceContent contains the content of a resource @@ -78,21 +79,21 @@ type ResourceContent struct { runtime.RawExtension `json:"-,inline"` } -type ResourceSnapShotStatus struct { +type ResourceSnapshotStatus struct { // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type - // Conditions is an array of current observed conditions for ResourceSnapShot. + // Conditions is an array of current observed conditions for ResourceSnapshot. // +optional Conditions []metav1.Condition `json:"conditions"` } -// ClusterResourceSnapShotList contains a list of ClusterResourceSnapshot. +// ClusterResourceSnapshotList contains a list of ClusterResourceSnapshot. // +kubebuilder:resource:scope="Cluster" // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ClusterResourceSnapShotList struct { +type ClusterResourceSnapshotList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` Items []ClusterResourceSnapshot `json:"items"` @@ -111,5 +112,5 @@ func (m *ClusterResourceSnapshot) GetCondition(conditionType string) *metav1.Con } func init() { - SchemeBuilder.Register(&ClusterResourceSnapshot{}, &ClusterResourceSnapShotList{}) + SchemeBuilder.Register(&ClusterResourceSnapshot{}, &ClusterResourceSnapshotList{}) } diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index f82d82513..b957c4de7 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -107,31 +107,26 @@ func (in *ClusterDecision) DeepCopy() *ClusterDecision { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterPolicySnapShotList) DeepCopyInto(out *ClusterPolicySnapShotList) { +func (in *ClusterPolicySnapshot) DeepCopyInto(out *ClusterPolicySnapshot) { *out = *in out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]ClusterPolicySnapshot, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterPolicySnapShotList. -func (in *ClusterPolicySnapShotList) DeepCopy() *ClusterPolicySnapShotList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterPolicySnapshot. +func (in *ClusterPolicySnapshot) DeepCopy() *ClusterPolicySnapshot { if in == nil { return nil } - out := new(ClusterPolicySnapShotList) + out := new(ClusterPolicySnapshot) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterPolicySnapShotList) DeepCopyObject() runtime.Object { +func (in *ClusterPolicySnapshot) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -139,26 +134,31 @@ func (in *ClusterPolicySnapShotList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterPolicySnapshot) DeepCopyInto(out *ClusterPolicySnapshot) { +func (in *ClusterPolicySnapshotList) DeepCopyInto(out *ClusterPolicySnapshotList) { *out = *in out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterPolicySnapshot, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterPolicySnapshot. -func (in *ClusterPolicySnapshot) DeepCopy() *ClusterPolicySnapshot { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterPolicySnapshotList. +func (in *ClusterPolicySnapshotList) DeepCopy() *ClusterPolicySnapshotList { if in == nil { return nil } - out := new(ClusterPolicySnapshot) + out := new(ClusterPolicySnapshotList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterPolicySnapshot) DeepCopyObject() runtime.Object { +func (in *ClusterPolicySnapshotList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -370,31 +370,26 @@ func (in *ClusterResourceSelector) DeepCopy() *ClusterResourceSelector { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterResourceSnapShotList) DeepCopyInto(out *ClusterResourceSnapShotList) { +func (in *ClusterResourceSnapshot) DeepCopyInto(out *ClusterResourceSnapshot) { *out = *in out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]ClusterResourceSnapshot, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResourceSnapShotList. -func (in *ClusterResourceSnapShotList) DeepCopy() *ClusterResourceSnapShotList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResourceSnapshot. +func (in *ClusterResourceSnapshot) DeepCopy() *ClusterResourceSnapshot { if in == nil { return nil } - out := new(ClusterResourceSnapShotList) + out := new(ClusterResourceSnapshot) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterResourceSnapShotList) DeepCopyObject() runtime.Object { +func (in *ClusterResourceSnapshot) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -402,26 +397,31 @@ func (in *ClusterResourceSnapShotList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterResourceSnapshot) DeepCopyInto(out *ClusterResourceSnapshot) { +func (in *ClusterResourceSnapshotList) DeepCopyInto(out *ClusterResourceSnapshotList) { *out = *in out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterResourceSnapshot, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResourceSnapshot. -func (in *ClusterResourceSnapshot) DeepCopy() *ClusterResourceSnapshot { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResourceSnapshotList. +func (in *ClusterResourceSnapshotList) DeepCopy() *ClusterResourceSnapshotList { if in == nil { return nil } - out := new(ClusterResourceSnapshot) + out := new(ClusterResourceSnapshotList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterResourceSnapshot) DeepCopyObject() runtime.Object { +func (in *ClusterResourceSnapshotList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -723,11 +723,6 @@ func (in *PlacementPolicy) DeepCopyInto(out *PlacementPolicy) { *out = new(int32) **out = **in } - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(RolloutStrategy) - **out = **in - } if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity *out = new(Affinity) @@ -753,7 +748,7 @@ func (in *PlacementPolicy) DeepCopy() *PlacementPolicy { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PolicySnapShotSpec) DeepCopyInto(out *PolicySnapShotSpec) { +func (in *PolicySnapshotSpec) DeepCopyInto(out *PolicySnapshotSpec) { *out = *in if in.Policy != nil { in, out := &in.Policy, &out.Policy @@ -767,18 +762,18 @@ func (in *PolicySnapShotSpec) DeepCopyInto(out *PolicySnapShotSpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PolicySnapShotSpec. -func (in *PolicySnapShotSpec) DeepCopy() *PolicySnapShotSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PolicySnapshotSpec. +func (in *PolicySnapshotSpec) DeepCopy() *PolicySnapshotSpec { if in == nil { return nil } - out := new(PolicySnapShotSpec) + out := new(PolicySnapshotSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PolicySnapShotStatus) DeepCopyInto(out *PolicySnapShotStatus) { +func (in *PolicySnapshotStatus) DeepCopyInto(out *PolicySnapshotStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions @@ -796,12 +791,12 @@ func (in *PolicySnapShotStatus) DeepCopyInto(out *PolicySnapShotStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PolicySnapShotStatus. -func (in *PolicySnapShotStatus) DeepCopy() *PolicySnapShotStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PolicySnapshotStatus. +func (in *PolicySnapshotStatus) DeepCopy() *PolicySnapshotStatus { if in == nil { return nil } - out := new(PolicySnapShotStatus) + out := new(PolicySnapshotStatus) in.DeepCopyInto(out) return out } @@ -891,7 +886,7 @@ func (in *ResourceIdentifier) DeepCopy() *ResourceIdentifier { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourceSnapShotSpec) DeepCopyInto(out *ResourceSnapShotSpec) { +func (in *ResourceSnapshotSpec) DeepCopyInto(out *ResourceSnapshotSpec) { *out = *in if in.SelectedResources != nil { in, out := &in.SelectedResources, &out.SelectedResources @@ -902,18 +897,18 @@ func (in *ResourceSnapShotSpec) DeepCopyInto(out *ResourceSnapShotSpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSnapShotSpec. -func (in *ResourceSnapShotSpec) DeepCopy() *ResourceSnapShotSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSnapshotSpec. +func (in *ResourceSnapshotSpec) DeepCopy() *ResourceSnapshotSpec { if in == nil { return nil } - out := new(ResourceSnapShotSpec) + out := new(ResourceSnapshotSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourceSnapShotStatus) DeepCopyInto(out *ResourceSnapShotStatus) { +func (in *ResourceSnapshotStatus) DeepCopyInto(out *ResourceSnapshotStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions @@ -924,12 +919,12 @@ func (in *ResourceSnapShotStatus) DeepCopyInto(out *ResourceSnapShotStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSnapShotStatus. -func (in *ResourceSnapShotStatus) DeepCopy() *ResourceSnapShotStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSnapshotStatus. +func (in *ResourceSnapshotStatus) DeepCopy() *ResourceSnapshotStatus { if in == nil { return nil } - out := new(ResourceSnapShotStatus) + out := new(ResourceSnapshotStatus) in.DeepCopyInto(out) return out } @@ -964,21 +959,6 @@ func (in *ResourceUsage) DeepCopy() *ResourceUsage { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RolloutStrategy) DeepCopyInto(out *RolloutStrategy) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutStrategy. -func (in *RolloutStrategy) DeepCopy() *RolloutStrategy { - if in == nil { - return nil - } - out := new(RolloutStrategy) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TopologySpreadConstraint) DeepCopyInto(out *TopologySpreadConstraint) { *out = *in diff --git a/config/crd/bases/fleet.azure.com_clusterpolicysnapshots.yaml b/config/crd/bases/fleet.azure.com_clusterpolicysnapshots.yaml index 557119182..33c35d013 100644 --- a/config/crd/bases/fleet.azure.com_clusterpolicysnapshots.yaml +++ b/config/crd/bases/fleet.azure.com_clusterpolicysnapshots.yaml @@ -28,9 +28,13 @@ spec: name: v1 schema: openAPIV3Schema: - description: ClusterPolicySnapshot is used to store a snapshot of cluster - placement policy. It is immutable. It must have `CRPTrackingLabel`, `PolicyIndexLabel` - and `IsLatestSnapshotLabel` labels. + description: 'ClusterPolicySnapshot is used to store a snapshot of cluster + placement policy. Its spec is immutable. The naming convention of a ClusterPolicySnapshot + is {CRPName}-{PolicySnapshotIndex}. PolicySnapshotIndex will begin with + 0. Each snapshot must have the following labels: - `CRPTrackingLabel` which + points to its owner CRP. - `PolicyIndexLabel` which is the index of the + policy snapshot. - `IsLatestSnapshotLabel` which indicates whether the snapshot + is the latest one.' properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -45,7 +49,7 @@ spec: metadata: type: object spec: - description: The desired state of PolicySnapShot. + description: The desired state of PolicySnapshot. properties: policy: description: Policy defines how to select member clusters to place @@ -244,15 +248,6 @@ spec: description: Type of placement. Can be "PickAll" or "PickN". Default is PickAll. type: string - strategy: - description: The rollout strategy to use to replace existing applications - with new ones. - properties: - type: - description: Type of rollout strategy. Can be "Recreate" or - "OnDelete". Default is "Recreate". - type: string - type: object topologySpreadConstraints: description: TopologySpreadConstraints describes how a group of resources ought to spread across multiple topology domains. @@ -297,18 +292,18 @@ spec: type: array type: object policyHash: - description: PolicyHash is the sha-256 hash value of the Policy field + description: PolicyHash is the sha-256 hash value of the Policy field. format: byte type: string required: - policyHash type: object status: - description: The observed status of PolicySnapShot. + description: The observed status of PolicySnapshot. properties: conditions: description: Conditions is an array of current observed conditions - for PolicySnapShot. + for PolicySnapshot. items: description: "Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct diff --git a/config/crd/bases/fleet.azure.com_clusterresourcebindings.yaml b/config/crd/bases/fleet.azure.com_clusterresourcebindings.yaml index 1aa7ccdd8..8dd31c16d 100644 --- a/config/crd/bases/fleet.azure.com_clusterresourcebindings.yaml +++ b/config/crd/bases/fleet.azure.com_clusterresourcebindings.yaml @@ -28,9 +28,9 @@ spec: name: v1 schema: openAPIV3Schema: - description: ClusterResourceBinding is represents a scheduling decision that - binds a group of resources to a cluster. it must have CRPTrackingLabel that - points to the cluster resource policy that creates it. + description: ClusterResourceBinding represents a scheduling decision that + binds a group of resources to a cluster. It MUST have a label named `CRPTrackingLabel` + that points to the cluster resource policy that creates it. properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -47,22 +47,18 @@ spec: spec: description: The desired state of ClusterResourceBinding. properties: - resourcePolicyName: - description: ResourcePolicyName is the name of the resource policy - that this resource binding points to. + resourceSnapshotName: + description: ResourceSnapshotName is the name of the resource snapshot + that this resource binding points to. If the resources are divided + into multiple snapshots because of the resource size limit, it points + to the name of the leading snapshot of the index group. type: string - resourceSnapshotIndex: - description: ResourceSnapshotIndex is the index of the resource snapshot - to which that this resource binding points to. - format: int32 - type: integer targetCluster: description: TargetCluster is the name of the cluster that the scheduler assigns the resources to. type: string required: - - resourcePolicyName - - resourceSnapshotIndex + - resourceSnapshotName - targetCluster type: object status: diff --git a/config/crd/bases/fleet.azure.com_clusterresourceplacements.yaml b/config/crd/bases/fleet.azure.com_clusterresourceplacements.yaml index d7bacf7ee..ae82593c7 100644 --- a/config/crd/bases/fleet.azure.com_clusterresourceplacements.yaml +++ b/config/crd/bases/fleet.azure.com_clusterresourceplacements.yaml @@ -48,7 +48,8 @@ spec: default, kube-* (reserved for Kubernetes system namespaces), fleet-* (reserved for fleet system namespaces). - reserved fleet resource types including: MemberCluster, InternalMemberCluster, ClusterResourcePlacement, MultiClusterService, - ServiceImport, etc.' + ServiceImport, etc. The `ClusterResourceBinding` will be created and it + represents a scheduling decision that binds a group of resources to a cluster.' properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -262,15 +263,6 @@ spec: description: Type of placement. Can be "PickAll" or "PickN". Default is PickAll. type: string - strategy: - description: The rollout strategy to use to replace existing applications - with new ones. - properties: - type: - description: Type of rollout strategy. Can be "Recreate" or - "OnDelete". Default is "Recreate". - type: string - type: object topologySpreadConstraints: description: TopologySpreadConstraints describes how a group of resources ought to spread across multiple topology domains. diff --git a/config/crd/bases/fleet.azure.com_clusterresourcesnapshots.yaml b/config/crd/bases/fleet.azure.com_clusterresourcesnapshots.yaml index 5e9b325ff..9bd402ebe 100644 --- a/config/crd/bases/fleet.azure.com_clusterresourcesnapshots.yaml +++ b/config/crd/bases/fleet.azure.com_clusterresourcesnapshots.yaml @@ -28,12 +28,22 @@ spec: name: v1 schema: openAPIV3Schema: - description: ClusterResourceSnapshot is used to store a snapshot of selected - resources by a resource placement policy. It is immutable. We may need to - produce more than one resourceSnapshot for one ResourcePlacement to get - around the 1MB size limit of k8s objects. Each snapshot must have `CRPTrackingLabel`, - `ResourceIndexLabel` and `IsLatestSnapshotLabel` Each snapshot must have - an annotation "fleet.azure.com/" with value as the s + description: "ClusterResourceSnapshot is used to store a snapshot of selected + resources by a resource placement policy. Its spec is immutable. We may + need to produce more than one resourceSnapshot for all the resources a ResourcePlacement + selected to get around the 1MB size limit of k8s objects. We assign an ever-increasing + index for each such group of resourceSnapshots. The name convention of a + clusterResourceSnapshot is {CRPName}-{resourceIndex}(-{subindex})* where + the name of the first snapshot of a group has no subindex part so its name + is {CRPName}-{resourceIndex}. Each snapshot MUST have the following labels: + - `CRPTrackingLabel` which points to its owner CRP. - `ResourceIndexLabel` + which is the index of the snapshot group. - `IsLatestSnapshotLabel` which + indicates whether the snapshot is the latest one. \n All the snapshots within + the same index group must have the same ResourceIndexLabel. \n The first + snapshot of the index group MUST have the following annotations: - \"NumberOfResourceSnapshots\" + to store the total number of resource snapshots in the index group. - `ResourceGroupHashAnnotation` + whose value is the sha-256 hash of all the snapshots belong to the same + snapshot index." properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -48,17 +58,10 @@ spec: metadata: type: object spec: - description: The desired state of ResourceSnapShot. + description: The desired state of ResourceSnapshot. properties: - index: - description: Index is the parent index of this resource snapshot. - Each index can have multiple snapshots. All the snapshots with the - same index have the same label "fleet.azure.com/snapshotGroup" that - points to the index. - format: int32 - type: integer - policySnapShotName: - description: PolicySnapShotName is the name of the policy snapshot + policySnapshotName: + description: PolicySnapshotName is the name of the policy snapshot that this resource snapshot is pointing to. type: string selectedResources: @@ -71,16 +74,15 @@ spec: x-kubernetes-preserve-unknown-fields: true type: array required: - - index - - policySnapShotName + - policySnapshotName - selectedResources type: object status: - description: The observed status of ResourceSnapShot. + description: The observed status of ResourceSnapshot. properties: conditions: description: Conditions is an array of current observed conditions - for ResourceSnapShot. + for ResourceSnapshot. items: description: "Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct diff --git a/pkg/controllers/clusterresourceplacement/placement_controller.go b/pkg/controllers/clusterresourceplacement/placement_controller.go index 77ff01922..b5e765d22 100644 --- a/pkg/controllers/clusterresourceplacement/placement_controller.go +++ b/pkg/controllers/clusterresourceplacement/placement_controller.go @@ -381,7 +381,7 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1.ClusterResou fleetv1.PolicyIndexLabel: strconv.Itoa(latestPolicySnapshotIndex), }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: crp.Spec.Policy, PolicyHash: []byte(policyHash), }, @@ -423,7 +423,7 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1.ClusterResou // invalid label value. // 2 & 3 should never happen. func (r *Reconciler) lookupLatestClusterPolicySnapshot(ctx context.Context, crp *fleetv1.ClusterResourcePlacement) (*fleetv1.ClusterPolicySnapshot, int, error) { - snapshotList := &fleetv1.ClusterPolicySnapShotList{} + snapshotList := &fleetv1.ClusterPolicySnapshotList{} latestSnapshotLabelMatcher := client.MatchingLabels{ fleetv1.CRPTrackingLabel: crp.Name, fleetv1.IsLatestSnapshotLabel: strconv.FormatBool(true), diff --git a/pkg/controllers/clusterresourceplacement/placement_controller_test.go b/pkg/controllers/clusterresourceplacement/placement_controller_test.go index a1dc6cd28..c2ab0622e 100644 --- a/pkg/controllers/clusterresourceplacement/placement_controller_test.go +++ b/pkg/controllers/clusterresourceplacement/placement_controller_test.go @@ -127,7 +127,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -155,7 +155,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -180,7 +180,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -210,7 +210,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -233,7 +233,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -258,7 +258,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -281,7 +281,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -304,7 +304,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -332,7 +332,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -357,7 +357,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -380,7 +380,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -408,7 +408,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -430,7 +430,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -455,7 +455,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ // Policy is not specified. PolicyHash: unspecifiedPolicyHash, }, @@ -478,7 +478,7 @@ func TestHandleUpdate(t *testing.T) { }, }, }, - Spec: fleetv1.PolicySnapShotSpec{ + Spec: fleetv1.PolicySnapshotSpec{ Policy: placementPolicyForTest(), PolicyHash: policyHash, }, @@ -508,15 +508,15 @@ func TestHandleUpdate(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("handleUpdate() = %+v, want %+v", got, want) } - clusterPolicySnapshotList := &fleetv1.ClusterPolicySnapShotList{} + clusterPolicySnapshotList := &fleetv1.ClusterPolicySnapshotList{} if err := fakeClient.List(ctx, clusterPolicySnapshotList); err != nil { - t.Fatalf("clusterPolicySnapShot List() got error %v, want no error", err) + t.Fatalf("clusterPolicySnapshot List() got error %v, want no error", err) } options := []cmp.Option{ cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion"), } if diff := cmp.Diff(tc.wantPolicySnapshots, clusterPolicySnapshotList.Items, options...); diff != "" { - t.Errorf("clusterPolicySnapShot List() mismatch (-want, +got):\n%s", diff) + t.Errorf("clusterPolicysnapShot List() mismatch (-want, +got):\n%s", diff) } }) }