Skip to content

Commit d431faa

Browse files
authored
interface: add support select ns only for CRP (#163)
--------- Signed-off-by: Zhiying Lin <[email protected]>
1 parent 570b44c commit d431faa

12 files changed

+111
-32
lines changed

apis/cluster/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/placement/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ type ClusterResourceSelector struct {
173173
Version string `json:"version"`
174174

175175
// Kind of the cluster-scoped resource.
176-
// Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
176+
// Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
177177
// +kubebuilder:validation:Required
178178
Kind string `json:"kind"`
179179

@@ -188,8 +188,25 @@ type ClusterResourceSelector struct {
188188
// Note that namespace-scoped resources can't be selected even if they match the query.
189189
// +kubebuilder:validation:Optional
190190
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
191+
192+
// SelectionScope defines the scope of resource selections when the Kind is `namespace`.
193+
// +kubebuilder:validation:Enum=NamespaceOnly;NamespaceWithResources
194+
// +kubebuilder:default=NamespaceWithResources
195+
// +kubebuilder:validation:Optional
196+
SelectionScope SelectionScope `json:"selectionScope,omitempty"`
191197
}
192198

199+
// SelectionScope defines the scope of resource selections.
200+
type SelectionScope string
201+
202+
const (
203+
// NamespaceOnly means only the namespace itself is selected.
204+
NamespaceOnly SelectionScope = "NamespaceOnly"
205+
206+
// NamespaceWithResources means all the resources under the namespace including namespace itself are selected.
207+
NamespaceWithResources SelectionScope = "NamespaceWithResources"
208+
)
209+
193210
// PlacementPolicy contains the rules to select target member clusters to place the selected resources.
194211
// Note that only clusters that are both joined and satisfying the rules will be selected.
195212
//

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
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_clusterresourceoverrides.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ spec:
415415
kind:
416416
description: |-
417417
Kind of the cluster-scoped resource.
418-
Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
418+
Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
419419
type: string
420420
labelSelector:
421421
description: |-
@@ -468,6 +468,14 @@ spec:
468468
name:
469469
description: Name of the cluster-scoped resource.
470470
type: string
471+
selectionScope:
472+
default: NamespaceWithResources
473+
description: SelectionScope defines the scope of resource selections
474+
when the Kind is `namespace`.
475+
enum:
476+
- NamespaceOnly
477+
- NamespaceWithResources
478+
type: string
471479
version:
472480
description: Version of the cluster-scoped resource.
473481
type: string
@@ -776,7 +784,7 @@ spec:
776784
kind:
777785
description: |-
778786
Kind of the cluster-scoped resource.
779-
Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
787+
Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
780788
type: string
781789
labelSelector:
782790
description: |-
@@ -829,6 +837,14 @@ spec:
829837
name:
830838
description: Name of the cluster-scoped resource.
831839
type: string
840+
selectionScope:
841+
default: NamespaceWithResources
842+
description: SelectionScope defines the scope of resource selections
843+
when the Kind is `namespace`.
844+
enum:
845+
- NamespaceOnly
846+
- NamespaceWithResources
847+
type: string
832848
version:
833849
description: Version of the cluster-scoped resource.
834850
type: string

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ spec:
447447
kind:
448448
description: |-
449449
Kind of the cluster-scoped resource.
450-
Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
450+
Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
451451
type: string
452452
labelSelector:
453453
description: |-
@@ -500,6 +500,14 @@ spec:
500500
name:
501501
description: Name of the cluster-scoped resource.
502502
type: string
503+
selectionScope:
504+
default: NamespaceWithResources
505+
description: SelectionScope defines the scope of resource
506+
selections when the Kind is `namespace`.
507+
enum:
508+
- NamespaceOnly
509+
- NamespaceWithResources
510+
type: string
503511
version:
504512
description: Version of the cluster-scoped resource.
505513
type: string
@@ -826,7 +834,7 @@ spec:
826834
kind:
827835
description: |-
828836
Kind of the cluster-scoped resource.
829-
Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
837+
Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
830838
type: string
831839
labelSelector:
832840
description: |-
@@ -879,6 +887,14 @@ spec:
879887
name:
880888
description: Name of the cluster-scoped resource.
881889
type: string
890+
selectionScope:
891+
default: NamespaceWithResources
892+
description: SelectionScope defines the scope of resource
893+
selections when the Kind is `namespace`.
894+
enum:
895+
- NamespaceOnly
896+
- NamespaceWithResources
897+
type: string
882898
version:
883899
description: Version of the cluster-scoped resource.
884900
type: string

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ spec:
16001600
kind:
16011601
description: |-
16021602
Kind of the cluster-scoped resource.
1603-
Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
1603+
Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
16041604
type: string
16051605
labelSelector:
16061606
description: |-
@@ -1653,6 +1653,14 @@ spec:
16531653
name:
16541654
description: Name of the cluster-scoped resource.
16551655
type: string
1656+
selectionScope:
1657+
default: NamespaceWithResources
1658+
description: SelectionScope defines the scope of resource selections
1659+
when the Kind is `namespace`.
1660+
enum:
1661+
- NamespaceOnly
1662+
- NamespaceWithResources
1663+
type: string
16561664
version:
16571665
description: Version of the cluster-scoped resource.
16581666
type: string

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ spec:
535535
kind:
536536
description: |-
537537
Kind of the cluster-scoped resource.
538-
Note: When `Kind` is `namespace`, ALL the resources under the selected namespaces are selected.
538+
Note: When `Kind` is `namespace`, by default ALL the resources under the selected namespaces are selected.
539539
type: string
540540
labelSelector:
541541
description: |-
@@ -588,6 +588,14 @@ spec:
588588
name:
589589
description: Name of the cluster-scoped resource.
590590
type: string
591+
selectionScope:
592+
default: NamespaceWithResources
593+
description: SelectionScope defines the scope of resource selections
594+
when the Kind is `namespace`.
595+
enum:
596+
- NamespaceOnly
597+
- NamespaceWithResources
598+
type: string
591599
version:
592600
description: Version of the cluster-scoped resource.
593601
type: string

pkg/controllers/clusterresourceplacement/resource_selector.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ func (r *Reconciler) selectResources(placement *fleetv1alpha1.ClusterResourcePla
115115
func convertResourceSelector(old []fleetv1alpha1.ClusterResourceSelector) []fleetv1beta1.ClusterResourceSelector {
116116
res := make([]fleetv1beta1.ClusterResourceSelector, len(old))
117117
for i, item := range old {
118-
res[i] = fleetv1beta1.ClusterResourceSelector(item)
118+
res[i] = fleetv1beta1.ClusterResourceSelector{
119+
Group: item.Group,
120+
Version: item.Version,
121+
Kind: item.Kind,
122+
Name: item.Name,
123+
LabelSelector: item.LabelSelector,
124+
SelectionScope: fleetv1beta1.NamespaceWithResources,
125+
}
119126
}
120127
return res
121128
}

0 commit comments

Comments
 (0)