Skip to content

Commit c592027

Browse files
authored
interface: update crp to support override (#662)
1 parent c8397e8 commit c592027

File tree

4 files changed

+253
-0
lines changed

4 files changed

+253
-0
lines changed

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,57 @@ type RolloutStrategy struct {
289289
// Rolling update config params. Present only if RolloutStrategyType = RollingUpdate.
290290
// +optional
291291
RollingUpdate *RollingUpdateConfig `json:"rollingUpdate,omitempty"`
292+
293+
// ApplyStrategy describes how to resolve the conflict if the resource to be placed already exists in the target cluster
294+
// and is owned by other appliers.
295+
// +optional
296+
ApplyStrategy *ApplyStrategy `json:"applyStrategy,omitempty"`
297+
}
298+
299+
// ApplyStrategy describes how to resolve the conflict if the resource to be placed already exists in the target cluster
300+
// and is owned by other appliers.
301+
// Note: If multiple CRPs try to place the same resource with different apply strategy, the later ones will fail with the
302+
// reason ApplyConflictBetweenPlacements.
303+
type ApplyStrategy struct {
304+
// Type defines the type of strategy to use. Default to FailIfExists.
305+
// +kubebuilder:default=FailIfExists
306+
// +kubebuilder:validation:Enum=FailIfExists;ServerSideApply
307+
// +optional
308+
Type ApplyStrategyType `json:"type,omitempty"`
309+
310+
// ServerSideApplyConfig defines the configuration for server side apply. It is honored only when type is ServerSideApply.
311+
// +optional
312+
ServerSideApplyConfig *ServerSideApplyConfig `json:"serverSideApplyConfig,omitempty"`
313+
}
314+
315+
// ApplyStrategyType describes the type of the strategy used to resolve the conflict if the resource to be placed already
316+
// exists in the target cluster and is owned by other appliers.
317+
// +enum
318+
type ApplyStrategyType string
319+
320+
const (
321+
// ApplyStrategyTypeFailIfExists will fail to apply a resource if it already exists in the target cluster and is owned
322+
// by other appliers.
323+
ApplyStrategyTypeFailIfExists ApplyStrategyType = "FailIfExists"
324+
325+
// ApplyStrategyTypeServerSideApply will use server-side apply to resolve conflicts between the resource to be placed
326+
// and the existing resource in the target cluster.
327+
// Details: https://kubernetes.io/docs/reference/using-api/server-side-apply
328+
ApplyStrategyTypeServerSideApply ApplyStrategyType = "ServerSideApply"
329+
)
330+
331+
// ServerSideApplyConfig defines the configuration for server side apply.
332+
// Details: https://kubernetes.io/docs/reference/using-api/server-side-apply/#conflicts
333+
type ServerSideApplyConfig struct {
334+
// Force represents to force apply to succeed when resolving the conflicts
335+
// For any conflicting fields,
336+
// - If true, use the values from the resource to be applied to overwrite the values of the existing resource in the
337+
// target cluster, as well as take over ownership of such fields.
338+
// - If false, apply will fail with the reason ApplyConflictWithOtherApplier.
339+
//
340+
// For non-conflicting fields, values stay unchanged and ownership are shared between appliers.
341+
// +optional
342+
ForceConflicts bool `json:"force"`
292343
}
293344

294345
// +enum
@@ -438,6 +489,16 @@ type ResourcePlacementStatus struct {
438489
// +optional
439490
ClusterName string `json:"clusterName,omitempty"`
440491

492+
// ApplicableResourceOverrides contains a list of applicable ResourceOverride snapshots associated with the selected
493+
// resources.
494+
// +optional
495+
ApplicableResourceOverrides []NamespacedName `json:"applicableResourceOverrides,omitempty"`
496+
497+
// ApplicableClusterResourceOverrides contains a list of applicable ClusterResourceOverride snapshots associated with
498+
// the selected resources.
499+
// +optional
500+
ApplicableClusterResourceOverrides []string `json:"applicableClusterResourceOverrides,omitempty"`
501+
441502
// +kubebuilder:validation:MaxItems=100
442503

443504
// FailedPlacements is a list of all the resources failed to be placed to the given cluster.
@@ -511,8 +572,35 @@ const (
511572
// (i.e., fleet-member-<member-name>) on the hub cluster.
512573
// - "False" means all the selected resources have not been synchronized under the per-cluster namespaces
513574
// (i.e., fleet-member-<member-name>) on the hub cluster yet.
575+
// To be deprecated, it will be replaced by ClusterResourcePlacementRolloutStarted and ClusterResourcePlacementWorkCreated
576+
// conditions.
514577
ClusterResourcePlacementSynchronizedConditionType ClusterResourcePlacementConditionType = "ClusterResourcePlacementSynchronized"
515578

579+
// ClusterResourcePlacementRolloutStartedConditionType indicates whether the selected resources start rolling out or
580+
// not.
581+
// Its condition status can be one of the following:
582+
// - "True" means the selected resources successfully start rolling out in all scheduled clusters.
583+
// - "False" means the selected resources have not been rolled out in all scheduled clusters yet.
584+
ClusterResourcePlacementRolloutStartedConditionType ClusterResourcePlacementConditionType = "ClusterResourcePlacementRolloutStarted"
585+
586+
// ClusterResourcePlacementOverriddenConditionType indicates whether all the selected resources have been overridden
587+
// successfully before applying to the target cluster.
588+
// Its condition status can be one of the following:
589+
// - "True" means all the selected resources are successfully overridden before applying to the target cluster or
590+
// override is not needed if there is no override defined with the reason of NoOverrideSpecified.
591+
// - "False" means some of them have failed. We will place some detailed failure in the FailedResourcePlacement array.
592+
// - "Unknown" means we haven't finished the override yet.
593+
ClusterResourcePlacementOverriddenConditionType ClusterResourcePlacementConditionType = "ClusterResourcePlacementOverridden"
594+
595+
// ClusterResourcePlacementWorkCreatedConditionType indicates whether the selected resources are created under
596+
// the per-cluster namespaces (i.e., fleet-member-<member-name>) on the hub cluster.
597+
// Its condition status can be one of the following:
598+
// - "True" means all the selected resources are successfully created under the per-cluster namespaces
599+
// (i.e., fleet-member-<member-name>) on the hub cluster.
600+
// - "False" means all the selected resources have not been created under the per-cluster namespaces
601+
// (i.e., fleet-member-<member-name>) on the hub cluster yet.
602+
ClusterResourcePlacementWorkCreatedConditionType ClusterResourcePlacementConditionType = "ClusterResourcePlacementWorkCreated"
603+
516604
// ClusterResourcePlacementAppliedConditionType indicates whether all the selected member clusters have applied
517605
// the selected resources locally.
518606
// Its condition status can be one of the following:
@@ -532,6 +620,7 @@ const (
532620
// Its condition status can be one of the following:
533621
// - "True" means we have successfully scheduled the resources to satisfy the placement requirement.
534622
// - "False" means we didn't fully satisfy the placement requirement. We will fill the Message field.
623+
// TODO, use "Scheduled" instead.
535624
ResourceScheduledConditionType ResourcePlacementConditionType = "ResourceScheduled"
536625

537626
// ResourceWorkSynchronizedConditionType indicates whether we have created or updated the corresponding work object(s)
@@ -547,13 +636,44 @@ const (
547636
// - Rollout controller has decided not to create or update the resources in this cluster for now to honor the
548637
// rollout strategy configurations specified in the placement.
549638
// - Work is not created/updated because of the unknown reasons.
639+
// To be deprecated, it will be replaced by RolloutStarted and WorkCreated conditions.
550640
ResourceWorkSynchronizedConditionType ResourcePlacementConditionType = "WorkSynchronized"
551641

642+
// ResourceRolloutStartedConditionType indicates whether the selected resources start rolling out or
643+
// not.
644+
// Its condition status can be one of the following:
645+
// - "True" means the selected resources successfully start rolling out in the target clusters.
646+
// - "False" means the selected resources have not been rolled out in the target cluster yet to honor the rollout
647+
// strategy configurations specified in the placement
648+
// - "Unknown" means it is in the processing state.
649+
ResourceRolloutStartedConditionType ResourcePlacementConditionType = "RolloutStarted"
650+
651+
// ResourceOverriddenConditionType indicates whether all the selected resources have been overridden successfully
652+
// before applying to the target cluster if there is any override defined.
653+
// Its condition status can be one of the following:
654+
// - "True" means all the selected resources are successfully overridden before applying to the target cluster or
655+
// override is not needed if there is no override defined with the reason of NoOverrideSpecified.
656+
// - "False" means some of them have failed.
657+
// - "Unknown" means we haven't finished the override yet.
658+
ResourceOverriddenConditionType ResourcePlacementConditionType = "Overridden"
659+
660+
// ResourceWorkCreatedConditionType indicates whether we have created or updated the corresponding work object(s)
661+
// under the per-cluster namespaces (i.e., fleet-member-<member-name>) which have the latest resources selected by
662+
// the placement.
663+
// Its condition status can be one of the following:
664+
// - "True" means we have successfully created the latest corresponding work(s) or updated the existing work(s) to
665+
// the latest.
666+
// - "False" means we have not created the latest corresponding work(s) or updated the existing work(s) to the latest
667+
// yet.
668+
// - "Unknown" means we haven't finished creating work yet.
669+
ResourceWorkCreatedConditionType ResourcePlacementConditionType = "WorkCreated"
670+
552671
// ResourcesAppliedConditionType indicates whether the selected member cluster has applied the selected resources locally.
553672
// Its condition status can be one of the following:
554673
// - "True" means all the selected resources are successfully applied to the target cluster.
555674
// - "False" means some of them have failed.
556675
// - "Unknown" means we haven't finished the apply yet.
676+
// TODO: use "Applied" instead.
557677
ResourcesAppliedConditionType ResourcePlacementConditionType = "ResourceApplied"
558678
)
559679

apis/placement/v1beta1/commons.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ const (
8181
// This is used to remember if an "unscheduled" binding was moved from a "bound" state or a "scheduled" state.
8282
PreviousBindingStateAnnotation = fleetPrefix + "previous-binding-state"
8383
)
84+
85+
// NamespacedName comprises a resource name, with a mandatory namespace.
86+
type NamespacedName struct {
87+
// Name is the name of the namespaced scope resource.
88+
// +required
89+
Name string `json:"name"`
90+
// Namespace is namespace of the namespaced scope resource.
91+
// +required
92+
Namespace string `json:"namespace"`
93+
}

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/placement.kubernetes-fleet.io_clusterresourceplacements.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,36 @@ spec:
455455
description: The rollout strategy to use to replace existing placement
456456
with new ones.
457457
properties:
458+
applyStrategy:
459+
description: ApplyStrategy describes how to resolve the conflict
460+
if the resource to be placed already exists in the target cluster
461+
and is owned by other appliers.
462+
properties:
463+
serverSideApplyConfig:
464+
description: ServerSideApplyConfig defines the configuration
465+
for server side apply. It is honored only when type is ServerSideApply.
466+
properties:
467+
force:
468+
description: "Force represents to force apply to succeed
469+
when resolving the conflicts For any conflicting fields,
470+
- If true, use the values from the resource to be applied
471+
to overwrite the values of the existing resource in
472+
the target cluster, as well as take over ownership of
473+
such fields. - If false, apply will fail with the reason
474+
ApplyConflictWithOtherApplier. \n For non-conflicting
475+
fields, values stay unchanged and ownership are shared
476+
between appliers."
477+
type: boolean
478+
type: object
479+
type:
480+
default: FailIfExists
481+
description: Type defines the type of strategy to use. Default
482+
to FailIfExists.
483+
enum:
484+
- FailIfExists
485+
- ServerSideApply
486+
type: string
487+
type: object
458488
rollingUpdate:
459489
description: Rolling update config params. Present only if RolloutStrategyType
460490
= RollingUpdate.
@@ -620,6 +650,34 @@ spec:
620650
description: ResourcePlacementStatus represents the placement status
621651
of selected resources for one target cluster.
622652
properties:
653+
applicableClusterResourceOverrides:
654+
description: ApplicableClusterResourceOverrides contains a list
655+
of applicable ClusterResourceOverride snapshots associated
656+
with the selected resources.
657+
items:
658+
type: string
659+
type: array
660+
applicableResourceOverrides:
661+
description: ApplicableResourceOverrides contains a list of
662+
applicable ResourceOverride snapshots associated with the
663+
selected resources.
664+
items:
665+
description: NamespacedName comprises a resource name, with
666+
a mandatory namespace.
667+
properties:
668+
name:
669+
description: Name is the name of the namespaced scope
670+
resource.
671+
type: string
672+
namespace:
673+
description: Namespace is namespace of the namespaced
674+
scope resource.
675+
type: string
676+
required:
677+
- name
678+
- namespace
679+
type: object
680+
type: array
623681
clusterName:
624682
description: ClusterName is the name of the cluster this resource
625683
is assigned to. If it is not empty, its value should be unique

0 commit comments

Comments
 (0)