From 92632ef493fca0a5c8961515f2f57f35cd3a385a Mon Sep 17 00:00:00 2001 From: Zhiying Lin Date: Thu, 20 Nov 2025 15:57:31 +0800 Subject: [PATCH 1/2] interface: [option 1] udpate placement api to support on demand resourceSnapshot creation Signed-off-by: Zhiying Lin --- .../v1beta1/clusterresourceplacement_types.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apis/placement/v1beta1/clusterresourceplacement_types.go b/apis/placement/v1beta1/clusterresourceplacement_types.go index 132ee90fd..4064fab6d 100644 --- a/apis/placement/v1beta1/clusterresourceplacement_types.go +++ b/apis/placement/v1beta1/clusterresourceplacement_types.go @@ -152,6 +152,12 @@ type PlacementSpec struct { // +kubebuilder:validation:Optional RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` + // ResourceSnapshotCreationPolicy controls when resource snapshots are created. + // +kubebuilder:validation:Enum=Automatic;OnDemand + // +kubebuilder:default=Automatic + // +kubebuilder:validation:Optional + ResourceSnapshotCreationPolicy ResourceSnapshotCreationPolicyType `json:"resourceSnapshotCreationPolicy,omitempty"` + // StatusReportingScope controls where ClusterResourcePlacement status information is made available. // When set to "ClusterScopeOnly", status is accessible only through the cluster-scoped ClusterResourcePlacement object. // When set to "NamespaceAccessible", a ClusterResourcePlacementStatus object is created in the target namespace, @@ -164,6 +170,16 @@ type PlacementSpec struct { StatusReportingScope StatusReportingScope `json:"statusReportingScope,omitempty"` } +type ResourceSnapshotCreationPolicyType string + +const ( + // AutomaticSnapshotCreation creates snapshots automatically when resources change. + AutomaticSnapshotCreation ResourceSnapshotCreationPolicyType = "Automatic" + + // OnDemandSnapshotCreation creates snapshots on both resource changes and on demand requests. + OnDemandSnapshotCreation ResourceSnapshotCreationPolicyType = "OnDemand" +) + // Tolerations returns tolerations for PlacementSpec to handle nil policy case. func (p *PlacementSpec) Tolerations() []Toleration { if p.Policy != nil { @@ -529,6 +545,15 @@ type RolloutStrategy struct { // +kubebuilder:validation:Enum=RollingUpdate;External Type RolloutStrategyType `json:"type,omitempty"` + // ResourceSnapshotIndex indicates the specific resource snapshot index to be rolled out to the target clusters. + // If not specified, the latest resource snapshot will be used. + // When the specified index does not exist, the behavior depends on the ResourceSnapshotCreationPolicy: + // - For the "Automatic" policy, the rollout will fail with reason ResourceSnapshotNotFound. + // - For the "OnDemand" policy, a new resource snapshot will be created using the current index. + // This field is only valid when RolloutStrategyType = RollingUpdate. + // +kubebuilder:validation:Optional + ResourceSnapshotIndex *string `json:"resourceSnapshotIndex,omitempty"` + // Rolling update config params. Present only if RolloutStrategyType = RollingUpdate. // +kubebuilder:validation:Optional RollingUpdate *RollingUpdateConfig `json:"rollingUpdate,omitempty"` From 4119ec9f88d6b5cf9a3da3a064da1aa01268bb20 Mon Sep 17 00:00:00 2001 From: Zhiying Lin Date: Thu, 20 Nov 2025 17:48:23 +0800 Subject: [PATCH 2/2] fix the comment Signed-off-by: Zhiying Lin --- apis/placement/v1beta1/clusterresourceplacement_types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apis/placement/v1beta1/clusterresourceplacement_types.go b/apis/placement/v1beta1/clusterresourceplacement_types.go index 4064fab6d..9c0469919 100644 --- a/apis/placement/v1beta1/clusterresourceplacement_types.go +++ b/apis/placement/v1beta1/clusterresourceplacement_types.go @@ -549,7 +549,8 @@ type RolloutStrategy struct { // If not specified, the latest resource snapshot will be used. // When the specified index does not exist, the behavior depends on the ResourceSnapshotCreationPolicy: // - For the "Automatic" policy, the rollout will fail with reason ResourceSnapshotNotFound. - // - For the "OnDemand" policy, a new resource snapshot will be created using the current index. + // - For the "OnDemand" policy, a new resource snapshot will be created using the current index if + // it is greater than the latest resourceSnapshot index. // This field is only valid when RolloutStrategyType = RollingUpdate. // +kubebuilder:validation:Optional ResourceSnapshotIndex *string `json:"resourceSnapshotIndex,omitempty"`