Skip to content

Commit 9a3cd78

Browse files
authored
interface: add the new takeover option never, plus some minor changes (#984)
1 parent 0fb234b commit 9a3cd78

11 files changed

+294
-61
lines changed

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,19 @@ type ApplyStrategy struct {
535535
// differences. No actual apply ops would be executed, and resources will be left alone as they
536536
// are on the member clusters.
537537
//
538+
// If configuration differences are found on a resource, Fleet will consider this as an apply
539+
// error, which might block rollout depending on the specified rollout strategy.
540+
//
538541
// Use ComparisonOption setting to control how the difference is calculated.
539542
//
543+
// ClientSideApply and ServerSideApply apply strategies only work when Fleet can assume
544+
// ownership of a resource (e.g., the resource is created by Fleet, or Fleet has taken over
545+
// the resource). See the comments on the WhenToTakeOver field for more information.
546+
// ReportDiff apply strategy, however, will function regardless of Fleet's ownership
547+
// status. One may set up a CRP with the ReportDiff strategy and the Never takeover option,
548+
// and this will turn Fleet into a detection tool that reports only configuration differences
549+
// but do not touch any resources on the member cluster side.
550+
//
540551
// For a comparison between the different strategies and usage examples, refer to the
541552
// Fleet documentation.
542553
//
@@ -545,10 +556,14 @@ type ApplyStrategy struct {
545556
// +kubebuilder:validation:Optional
546557
Type ApplyStrategyType `json:"type,omitempty"`
547558

548-
// AllowCoOwnership defines whether to apply the resource if it already exists in the target cluster and is not
549-
// solely owned by fleet (i.e., metadata.ownerReferences contains only fleet custom resources).
550-
// If true, apply the resource and add fleet as a co-owner.
551-
// If false, leave the resource unchanged and fail the apply.
559+
// AllowCoOwnership controls whether co-ownership between Fleet and other agents are allowed
560+
// on a Fleet-managed resource. If set to false, Fleet will refuse to apply manifests to
561+
// a resource that has been owned by one or more non-Fleet agents.
562+
//
563+
// Note that Fleet does not support the case where one resource is being placed multiple
564+
// times by different CRPs on the same member cluster. An apply error will be returned if
565+
// Fleet finds that a resource has been owned by another placement attempt by Fleet, even
566+
// with the AllowCoOwnership setting set to true.
552567
AllowCoOwnership bool `json:"allowCoOwnership,omitempty"`
553568

554569
// ServerSideApplyConfig defines the configuration for server side apply. It is honored only when type is ServerSideApply.
@@ -571,8 +586,9 @@ type ApplyStrategy struct {
571586
//
572587
// * IfNoDiff: with this action, Fleet will apply the hub cluster manifests to the member
573588
// clusters if (and only if) pre-existing resources look the same as the hub cluster manifests.
589+
//
574590
// This is a safer option as pre-existing resources that are inconsistent with the hub cluster
575-
// manifests will not be overwritten; in fact, Fleet will ignore them until the inconsistencies
591+
// manifests will not be overwritten; Fleet will ignore them until the inconsistencies
576592
// are resolved properly: any change you make to the hub cluster manifests would not be
577593
// applied, and if you delete the manifests or even the ClusterResourcePlacement itself
578594
// from the hub cluster, these pre-existing resources would not be taken away.
@@ -597,8 +613,24 @@ type ApplyStrategy struct {
597613
// If appropriate, you may also delete the object from the member cluster; Fleet will recreate
598614
// it using the hub cluster manifest.
599615
//
616+
// * Never: with this action, Fleet will not apply a hub cluster manifest to the member
617+
// clusters if there is a corresponding pre-existing resource. However, if a manifest
618+
// has never been applied yet; or it has a corresponding resource which Fleet has assumed
619+
// ownership, apply op will still be executed.
620+
//
621+
// This is the safest option; one will have to remove the pre-existing resources (so that
622+
// Fleet can re-create them) or switch to a different
623+
// WhenToTakeOver option before Fleet starts processing the corresponding hub cluster
624+
// manifests.
625+
//
626+
// If you prefer Fleet stop processing all manifests, use this option along with the
627+
// ReportDiff apply strategy type. This setup would instruct Fleet to touch nothing
628+
// on the member cluster side but still report configuration differences between the
629+
// hub cluster and member clusters. Fleet will not give up ownership
630+
// that it has already assumed though.
631+
//
600632
// +kubebuilder:default=Always
601-
// +kubebuilder:validation:Enum=Always;IfNoDiff
633+
// +kubebuilder:validation:Enum=Always;IfNoDiff;Never
602634
// +kubebuilder:validation:Optional
603635
WhenToTakeOver WhenToTakeOverType `json:"whenToTakeOver,omitempty"`
604636
}
@@ -676,14 +708,35 @@ type ServerSideApplyConfig struct {
676708
type WhenToTakeOverType string
677709

678710
const (
679-
// WhenToTakeOverTypeIfNoDiff will apply manifests from the hub cluster only if there is no difference
680-
// between the current resource snapshot version on the hub cluster and the existing
681-
// resources on the member cluster. Otherwise, we will report the difference.
711+
// WhenToTakeOverTypeIfNoDiff instructs Fleet to apply a manifest with a corresponding
712+
// pre-existing resource on a member cluster if and only if the pre-existing resource
713+
// looks the same as the manifest. Should there be any inconsistency, Fleet will skip
714+
// the apply op; no change will be made on the resource and Fleet will not claim
715+
// ownership on it.
716+
//
717+
// Note that this will not stop Fleet from processing other manifests in the same
718+
// placement that do not concern the takeover process (e.g., the manifests that have
719+
// not been created yet, or that are already under the management of Fleet).
682720
WhenToTakeOverTypeIfNoDiff WhenToTakeOverType = "IfNoDiff"
683721

684-
// WhenToTakeOverTypeAlways will always apply the resource to the member cluster regardless
685-
// if there are differences between the resource on the hub cluster and the existing resources on the member cluster.
722+
// WhenToTakeOverTypeAlways instructs Fleet to always apply manifests to a member cluster,
723+
// even if there are some corresponding pre-existing resources. Some fields on these
724+
// resources might be overwritten, and Fleet will claim ownership on them.
686725
WhenToTakeOverTypeAlways WhenToTakeOverType = "Always"
726+
727+
// WhenToTakeOverTypeNever instructs Fleet to never apply a manifest to a member cluster
728+
// if there is a corresponding pre-existing resource.
729+
//
730+
// Note that this will not stop Fleet from processing other manifests in the same placement
731+
// that do not concern the takeover process (e.g., the manifests that have not been created
732+
// yet, or that are already under the management of Fleet).
733+
//
734+
// If you would like Fleet to stop processing manifests all together and do not assume
735+
// ownership on any pre-existing resources, use this option along with the ReportDiff
736+
// apply strategy type. This setup would instruct Fleet to touch nothing on the member
737+
// cluster side but still report configuration differences between the hub cluster
738+
// and member clusters. Fleet will not give up ownership that it has already assumed, though.
739+
WhenToTakeOverTypeNever WhenToTakeOverType = "Never"
687740
)
688741

689742
// +enum
@@ -978,8 +1031,11 @@ type DiffedResourcePlacement struct {
9781031

9791032
// TargetClusterObservedGeneration is the generation of the resource on the target cluster
9801033
// that contains the configuration differences.
981-
// +kubebuilder:validation:Required
982-
TargetClusterObservedGeneration int64 `json:"targetClusterObservedGeneration"`
1034+
//
1035+
// This might be nil if the resource has not been created yet on the target cluster.
1036+
//
1037+
// +kubebuilder:validation:Optional
1038+
TargetClusterObservedGeneration *int64 `json:"targetClusterObservedGeneration"`
9831039

9841040
// FirstDiffedObservedTime is the first time the resource on the target cluster is
9851041
// observed to have configuration differences.

apis/placement/v1beta1/work_types.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ type WorkResourceIdentifier struct {
102102
// Kind is the kind of the resource.
103103
Kind string `json:"kind,omitempty"`
104104

105-
// Resource is the resource type of the resource
105+
// Resource is the resource type of the resource.
106106
Resource string `json:"resource,omitempty"`
107107

108108
// Namespace is the namespace of the resource, the resource is cluster scoped if the value
109-
// is empty
109+
// is empty.
110110
Namespace string `json:"namespace,omitempty"`
111111

112-
// Name is the name of the resource
112+
// Name is the name of the resource.
113113
Name string `json:"name,omitempty"`
114114
}
115115

@@ -124,7 +124,6 @@ type DriftDetails struct {
124124

125125
// ObservedInMemberClusterGeneration is the generation of the applied manifest on the member
126126
// cluster side.
127-
//
128127
// +kubebuilder:validation:Required
129128
ObservedInMemberClusterGeneration int64 `json:"observedInMemberClusterGeneration"`
130129

@@ -157,8 +156,10 @@ type DiffDetails struct {
157156
// ObservedInMemberClusterGeneration is the generation of the applied manifest on the member
158157
// cluster side.
159158
//
160-
// +kubebuilder:validation:Required
161-
ObservedInMemberClusterGeneration int64 `json:"observedInMemberClusterGeneration"`
159+
// This might be nil if the resource has not been created yet in the member cluster.
160+
//
161+
// +kubebuilder:validation:Optional
162+
ObservedInMemberClusterGeneration *int64 `json:"observedInMemberClusterGeneration"`
162163

163164
// FirsftDiffedObservedTime is the timestamp when the configuration difference
164165
// was first detected.

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 10 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_appliedworks.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,20 @@ spec:
189189
description: Kind is the kind of the resource.
190190
type: string
191191
name:
192-
description: Name is the name of the resource
192+
description: Name is the name of the resource.
193193
type: string
194194
namespace:
195195
description: |-
196196
Namespace is the namespace of the resource, the resource is cluster scoped if the value
197-
is empty
197+
is empty.
198198
type: string
199199
ordinal:
200200
description: |-
201201
Ordinal represents an index in manifests list, so the condition can still be linked
202202
to a manifest even though manifest cannot be parsed successfully.
203203
type: integer
204204
resource:
205-
description: Resource is the resource type of the resource
205+
description: Resource is the resource type of the resource.
206206
type: string
207207
uid:
208208
description: |-

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

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,15 @@ spec:
430430
properties:
431431
allowCoOwnership:
432432
description: |-
433-
AllowCoOwnership defines whether to apply the resource if it already exists in the target cluster and is not
434-
solely owned by fleet (i.e., metadata.ownerReferences contains only fleet custom resources).
435-
If true, apply the resource and add fleet as a co-owner.
436-
If false, leave the resource unchanged and fail the apply.
433+
AllowCoOwnership controls whether co-ownership between Fleet and other agents are allowed
434+
on a Fleet-managed resource. If set to false, Fleet will refuse to apply manifests to
435+
a resource that has been owned by one or more non-Fleet agents.
436+
437+
438+
Note that Fleet does not support the case where one resource is being placed multiple
439+
times by different CRPs on the same member cluster. An apply error will be returned if
440+
Fleet finds that a resource has been owned by another placement attempt by Fleet, even
441+
with the AllowCoOwnership setting set to true.
437442
type: boolean
438443
comparisonOption:
439444
default: PartialComparison
@@ -533,9 +538,22 @@ spec:
533538
are on the member clusters.
534539
535540
541+
If configuration differences are found on a resource, Fleet will consider this as an apply
542+
error, which might block rollout depending on the specified rollout strategy.
543+
544+
536545
Use ComparisonOption setting to control how the difference is calculated.
537546
538547
548+
ClientSideApply and ServerSideApply apply strategies only work when Fleet can assume
549+
ownership of a resource (e.g., the resource is created by Fleet, or Fleet has taken over
550+
the resource). See the comments on the WhenToTakeOver field for more information.
551+
ReportDiff apply strategy, however, will function regardless of Fleet's ownership
552+
status. One may set up a CRP with the ReportDiff strategy and the Never takeover option,
553+
and this will turn Fleet into a detection tool that reports only configuration differences
554+
but do not touch any resources on the member cluster side.
555+
556+
539557
For a comparison between the different strategies and usage examples, refer to the
540558
Fleet documentation.
541559
enum:
@@ -618,8 +636,10 @@ spec:
618636
619637
* IfNoDiff: with this action, Fleet will apply the hub cluster manifests to the member
620638
clusters if (and only if) pre-existing resources look the same as the hub cluster manifests.
639+
640+
621641
This is a safer option as pre-existing resources that are inconsistent with the hub cluster
622-
manifests will not be overwritten; in fact, Fleet will ignore them until the inconsistencies
642+
manifests will not be overwritten; Fleet will ignore them until the inconsistencies
623643
are resolved properly: any change you make to the hub cluster manifests would not be
624644
applied, and if you delete the manifests or even the ClusterResourcePlacement itself
625645
from the hub cluster, these pre-existing resources would not be taken away.
@@ -647,9 +667,29 @@ spec:
647667
648668
If appropriate, you may also delete the object from the member cluster; Fleet will recreate
649669
it using the hub cluster manifest.
670+
671+
672+
* Never: with this action, Fleet will not apply a hub cluster manifest to the member
673+
clusters if there is a corresponding pre-existing resource. However, if a manifest
674+
has never been applied yet; or it has a corresponding resource which Fleet has assumed
675+
ownership, apply op will still be executed.
676+
677+
678+
This is the safest option; one will have to remove the pre-existing resources (so that
679+
Fleet can re-create them) or switch to a different
680+
WhenToTakeOver option before Fleet starts processing the corresponding hub cluster
681+
manifests.
682+
683+
684+
If you prefer Fleet stop processing all manifests, use this option along with the
685+
ReportDiff apply strategy type. This setup would instruct Fleet to touch nothing
686+
on the member cluster side but still report configuration differences between the
687+
hub cluster and member clusters. Fleet will not give up ownership
688+
that it has already assumed though.
650689
enum:
651690
- Always
652691
- IfNoDiff
692+
- Never
653693
type: string
654694
type: object
655695
clusterDecision:
@@ -933,6 +973,9 @@ spec:
933973
description: |-
934974
TargetClusterObservedGeneration is the generation of the resource on the target cluster
935975
that contains the configuration differences.
976+
977+
978+
This might be nil if the resource has not been created yet on the target cluster.
936979
format: int64
937980
type: integer
938981
version:
@@ -943,7 +986,6 @@ spec:
943986
- kind
944987
- name
945988
- observationTime
946-
- targetClusterObservedGeneration
947989
- version
948990
type: object
949991
maxItems: 100

0 commit comments

Comments
 (0)