Skip to content

Commit e8ad2ed

Browse files
committed
proposal change for clusterset api
Signed-off-by: ldpliu <[email protected]>
1 parent 8fa2df8 commit e8ad2ed

File tree

2 files changed

+45
-135
lines changed

2 files changed

+45
-135
lines changed

enhancements/sig-architecture/30-clusterset-override/README.md

Lines changed: 44 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- [ ] Test plan is defined
88
- [ ] Graduation criteria for dev preview, tech preview, GA
99
- [ ] User-facing documentation is created in [website](https://github.com/open-cluster-management/website/)
10-
10+
1111
## Summary
1212
The proposed work enhances the managedClusterSet API to support managedClusterSet Override.
1313

@@ -30,21 +30,18 @@ So, In this proposal, we change the managedClusterSets spec and want to provide
3030

3131
```go
3232
type ManagedClusterSetSpec struct {
33-
// Selector represents a selector of ManagedClusters by labels and names.
33+
// Selector represents a selector of ManagedClusters by labels.
3434
ClusterSelector ManagedClusterSelector `json:"clusterSelector"`
3535
}
3636

3737
type ManagedClusterSelector struct{
38-
// "" means to use the current mechanism of matching label <cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>.
39-
// "LabelSelector" means to use the LabelSelector to select target managedClusters
40-
// "ExclusiveLabel" means to use a particular cluster label. It is guaranteed that clustersets with same label key are exclusive with each others
41-
// +optional
42-
SelectorType SelectorType `json:"selectorType"`
43-
44-
// ExclusiveLabel defines one label which clusterset could use to select target managedClusters. In this way, we will:
45-
// 1. Guarantee clustersets with same label key are exclusive
46-
// 2. Enable additional permission check when cluster joining/leaving a clusterset (the label key should start with the reserved prefix "cluster.open-cluster-management.io/" and "info.open-cluster-management.io/");
47-
ExclusiveLabel *ManagedClusterLabel `json:"exclusiveLabel"`
38+
// SelectorType could only be "ExclusiveClusterSetLabel" or "LabelSelector"
39+
// "ExclusiveClusterSetLabel" means to use label "cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>"" to select target clusters.
40+
// "LabelSelector" means to use LabelSelector to select target clusters
41+
// +kubebuilder:validation:Enum=ExclusiveClusterSetLabel
42+
// +kubebuilder:default:=ExclusiveClusterSetLabel
43+
// +required
44+
SelectorType SelectorType `json:"selectorType,omitempty"`
4845

4946
// LabelSelector define the general labelSelector which clusterset will use to select target managedClusters
5047
LabelSelector *metav1.LabelSelector `json:"labelSelector"`
@@ -53,24 +50,22 @@ type ManagedClusterSelector struct{
5350
type SelectorType string
5451

5552
const (
56-
LabelSelector SelectorType = "LabelSelector"
57-
ExclusiveLabel SelectorType = "ExclusiveLabel"
53+
LabelSelector SelectorType = "LabelSelector"
54+
ExclusiveClusterSetLabel SelectorType = "ExclusiveClusterSetLabel"
5855
)
59-
60-
//ManagedClusterLabel defines one label
61-
type ManagedClusterLabel struct {
62-
Key string `json:"key"`
63-
Value string `json:"value"`
64-
}
6556
```
6657

6758
### RBAC
68-
Currently, When I want to create a managedClusterSet, I only should have `create` permission to the managedClusterSet.
69-
In the managedCluster part, label `cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>` means the cluster is in a managedClusterSet.
70-
If I want to add the label `cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>` to a managedCluster, I must have `create` permission for subresource `managedclustersets/join`.
71-
If I want to add/update other labels, I just need to have `update` permission to the managedCluster resource.
59+
Actually, what we discuss about RBAC is `who can add/remove a managedCluster to/from a managedClusterSet.`
60+
Currently, if a managedCluster which have label `cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>` means the cluster is in a managedClusterSet.
61+
And If I want to add a managedCluster to a managedClusterSet, I must have `create` permission for subresource `managedclustersets/join` with resource name `<ManagedClusterSet Name>`.
7262

73-
In this proposal, managedClusterSet could use any labels to select managedClusters. And if I add a label for a managedCluster, it may lead to the managedCluster added to a managedClusterSet. So we need to rethink about the rbac control of managedClusterSet
63+
In this proposal, managedClusterSet could use two ways to select target clusters, `ExclusiveClusterSetLabel` and `LabelSelector`.
64+
1. ExclusiveClusterSetLabel
65+
In this selector, managedClusterSet select target clusters using label `cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>`. And the RBAC model will not change. If I want to add a managedCluster to a managedClusterSet, I must have `create` permission for subresource `managedclustersets/join` with resource name `<ManagedClusterSet Name>`.
66+
67+
2. LabelSelector
68+
With the `LabelSelector`, any labels may be used to select target clusters. And we will not have external RBAC control for this kind of clustersets.
7469

7570
We will use the following questions to consider the RBAC control.
7671

@@ -81,7 +76,7 @@ c. Create a managedClusterSet which has the same capacity(like: all clusters ena
8176
d. Create a managedClusterSet for each squad for resource group purposes.
8277

8378
#### Who can create a managedClusterSet
84-
Same as the current way, Anyone who has `create` permission to `managedclustersets` could create managedClusterSet.
79+
Same as the current way, Anyone who has `create` permission to `managedclustersets` could create managedClusterSet.
8580
But generally, Cluster admin should not give this permission to others. So only cluster admin could create the managedClusterSet.
8681

8782
#### What kinds of roles exist related to managedClusterSets and managedClusters
@@ -115,7 +110,7 @@ Currently, the controller/agent may add labels like: `region: apac`, `cloud: Ama
115110
3. Non Cluster admin users
116111
Currently, non cluster admin users may also `add/update` some managedClusters labels.
117112

118-
#### Add restrictions for adding/updating/deleting labels to managedClusters
113+
#### [Not Implement] Add restrictions for adding/updating/deleting labels to managedClusters
119114
In this proposal, managedClusterSet could use any labels to select managedClusters. And the new added labels may lead to this managedClusters added to a managedClusterSet.
120115

121116
But for some managedClusterSet(like: Disaster Recovery ManagedClusterSet[a], Resource Group ManagedClusterSet[d]), we do not want any users to add their managedClusters to these managedClusterSets.
@@ -174,8 +169,7 @@ Same as the current way, anyone who has `managedclustersets/bind` permission cou
174169
### Example1: As cluster admin, I want to create a managedClusterSet which includes all clusters in the apac region. Then I can apply certain configurations to all clusters in apac.
175170
1. For each cluster, there should be an agent running on the managedCluster. The agent should have the following permissions:
176171
- `update` permission to its related managedCluster
177-
- `create` permission to subresource `managedclusters/label` with resourceName `info.open-cluster-management.io/region:*`
178-
2. For each cluster in the apac region, related agents should add a label: `info.open-cluster-management.io/region:apac` to these managedClusters.
172+
2. For each cluster in the apac region, related agents should add a label: `region:apac` to these managedClusters.
179173
3. As cluster admin, I could create a managedClusterSet to select all managedClusters in `apac` region
180174
```yaml
181175
apiVersion: cluster.open-cluster-management.io/v1beta1
@@ -184,17 +178,16 @@ metadata:
184178
name: apacset
185179
spec:
186180
clusterSelector:
187-
selectorType: ExclusiveLabel
188-
exclusiveLabel:
189-
key: info.open-cluster-management.io/region
190-
value: apac
181+
selectorType: LabelSelector
182+
labelSelector:
183+
matchLabels:
184+
region: apac
191185
```
192186

193187
### Example2: As a DEV team member, I want to use a managedClusterSet to select clusters based on the middleware enabled on these clusters, so I could run special applications in these clusters.
194188
1. For each cluster, there should be an agent running on the managedCluster. The agent should have the following permissions:
195189
- `update` permission to its related managedCluster
196-
- `create` permission to subresource `managedclusters/label` with resourceName `info.open-cluster-management.io/middlewareEnabled:true`
197-
2. For each cluster which enables the middleware, related agents should add a label: `info.open-cluster-management.io/middlewareEnabled:true` to these managedClusters.
190+
2. For each cluster which enables the middleware, related agents should add a label: `middlewareEnabled:true` to these managedClusters.
198191
3. Cluster admin create a managedClusterSet `middlewareenabledset`
199192
```yaml
200193
apiVersion: cluster.open-cluster-management.io/v1beta1
@@ -206,11 +199,10 @@ spec:
206199
selectorType: LabelSelector
207200
labelSelector:
208201
matchLabels:
209-
info.open-cluster-management.io/middlewareEnabled: true
202+
middlewareEnabled: true
210203
```
211204
4. Cluster admin should give following permissions to DEV team, so these team members could run applications in the managedClusterSet's clusters.
212205
- `get` permission to managedClusterSet `middlewareenabledset`
213-
- `create` permission to subresource `managedclustersets/bind` to managedClusterSet `middlewareenabledset`
214206
```yaml
215207
kind: ClusterRole
216208
apiVersion: rbac.authorization.k8s.io/v1
@@ -234,26 +226,20 @@ rules:
234226
apiVersion: cluster.open-cluster-management.io/v1beta1
235227
kind: ManagedClusterSet
236228
metadata:
237-
name: devset
229+
name: dev
238230
spec:
239231
clusterSelector:
240-
selectorType: ExclusiveLabel
241-
exclusiveLabel:
242-
key: cluster.open-cluster-management.io/clusterset
243-
value: dev
232+
selectorType: ExclusiveClusterSetLabel
244233
```
245234

246235
```yaml
247236
apiVersion: cluster.open-cluster-management.io/v1beta1
248237
kind: ManagedClusterSet
249238
metadata:
250-
name: qaset
239+
name: qa
251240
spec:
252241
clusterSelector:
253-
selectorType: ExclusiveLabel
254-
exclusiveLabel:
255-
key: cluster.open-cluster-management.io/clusterset
256-
value: qa
242+
selectorType: ExclusiveClusterSetLabel
257243
```
258244

259245
2. Cluster admin give the following permission to DEV team and QA team
@@ -269,15 +255,15 @@ rules:
269255
verbs: ["create"]
270256
- apiGroups: ["cluster.open-cluster-management.io"]
271257
resources: ["managedclustersets"]
272-
resourceNames: ["devset"]
258+
resourceNames: ["dev"]
273259
verbs: ["get"]
274260
- apiGroups: ["cluster.open-cluster-management.io"]
275-
resources: ["managedclusters/label"]
276-
resourceNames: ["cluster.open-cluster-management.io/clusterset:devset"]
261+
resources: ["managedclustersets/join"]
262+
resourceNames: ["dev"]
277263
verbs: ["create"]
278264
- apiGroups: ["cluster.open-cluster-management.io"]
279265
resources: ["managedclustersets/bind"]
280-
resourceNames: ["devset"]
266+
resourceNames: ["dev"]
281267
verbs: ["create"]
282268
```
283269

@@ -293,19 +279,19 @@ rules:
293279
verbs: ["create"]
294280
- apiGroups: ["cluster.open-cluster-management.io"]
295281
resources: ["managedclustersets"]
296-
resourceNames: ["qaset"]
282+
resourceNames: ["qa"]
297283
verbs: ["get"]
298284
- apiGroups: ["cluster.open-cluster-management.io"]
299-
resources: ["managedclusters/label"]
300-
resourceNames: ["cluster.open-cluster-management.io/clusterset:qaset"]
285+
resources: ["managedclustersets/join"]
286+
resourceNames: ["qa"]
301287
verbs: ["create"]
302288
- apiGroups: ["cluster.open-cluster-management.io"]
303289
resources: ["managedclustersets/bind"]
304-
resourceNames: ["qaset"]
290+
resourceNames: ["qa"]
305291
verbs: ["create"]
306292
```
307-
3. As a DEV/QA team member, I can `create` a managedCluster, and add label `cluster.open-cluster-management.io/clusterset:devset/qaset` to the managedCluster.
308-
4. As a DEV/QA team member, I could `bind` the managedClusterSet `devset/qaset` to my namespace and run applications in the managedClusterSet.
293+
3. As a DEV/QA team member, I can `create` a managedCluster, and add label `cluster.open-cluster-management.io/clusterset:dev/qa` to the managedCluster.
294+
4. As a DEV/QA team member, I could `bind` the managedClusterSet `dev/qa` to my namespace and run applications in the managedClusterSet.
309295

310296
## Test Plan
311297
- Unit tests will cover the functionality of the controllers.
@@ -315,86 +301,10 @@ rules:
315301
- Create/update/delete managedClusters labels
316302
- Update managedClusterSet spec `clusterSelector` field
317303

318-
## Migration
319-
Currently, managedClusterSet has three consumers: [placement](https://github.com/open-cluster-management-io/placement), [multicloud-operators-foundation](https://github.com/stolostron/multicloud-operators-foundation), [submariner-addon](https://github.com/stolostron/submariner-addon)
320-
321-
- `multicloud-operators-foundation` uses managedClusterSet for resource group purposes. And it should only care about the exclusive managedClusterSet.
322-
- `submariner-addon` uses managedClusterSet to group clusters based on the networks. And in different managedClusterSet, the clusters should be exclusive.
323-
- `placement` select all managedClusters in each managedClusterSet.
324-
325-
So we could finish the migration by four steps, and step 1 and step 2 will be finished in OCM 0.7.0. and step 3 and step 4 will be finished in OCM 0.8.0
326-
327-
1. [Implement in OCM 0.7.0]Update the managedClusterSet API which only includes an exclusive way to select target managedClusters.
328-
329-
```go
330-
type ManagedClusterSetSpec struct {
331-
// Selector represents a selector of ManagedClusters by labels and names.
332-
ClusterSelector ManagedClusterSelector `json:"clusterSelector"`
333-
}
334-
335-
type ManagedClusterSelector struct{
336-
// "" means to use the current mechanism of matching label <cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>.
337-
// (future) "LabelSelector" means to use the LabelSelector to select target managedClusters
338-
// "ExclusiveLabel" means to use a particular cluster label. It is guaranteed that clustersets with same label key are exclusive with each others
339-
// +optional
340-
SelectorType SelectorType `json:"selectorType"`
341-
342-
// ExclusiveLabel defines one label which clusterset could use to select target managedClusters. In this way, we will:
343-
// 1. Guarantee clustersets with same label key are exclusive
344-
// 2. Enable additional permission check when cluster joining/leaving a clusterset (the label key should start with the reserved prefix "cluster.open-cluster-management.io/" and "info.open-cluster-management.io/");
345-
ExclusiveLabel *ExclusiveLabel `json:"exclusiveLabel"`
346-
}
347-
348-
type SelectorType string
349-
350-
const (
351-
ExclusiveLabel SelectorType = "ExclusiveLabel"
352-
)
353-
354-
//ExclusiveLabel defines one cluster label
355-
type ExclusiveLabel struct {
356-
//Key is "cluster.open-cluster-management.io/clusterset" by default and can only be cluster.open-cluster-management.io/
357-
Key string `json:"key"`
358-
//Value can only be empty or the name of the clusterset.
359-
Value string `json:"value"`
360-
}
361-
```
362-
363-
- `LabelSelector` will not be included
364-
- `ExclusiveLabel.Key` must be `cluster.open-cluster-management.io/clusterset` and `ExclusiveLabel.Value` must be `ManagedClusterset Name`
365-
- Both `managedclusterset/join` and `managedclusters/label` permission will be supported
366-
367-
2. [Implement in OCM 0.7.0]`multicloud-operators-foundation`, `submariner-addon`, `placement` change the code to integrate with new managedClusterSet api
368-
369-
a. `multicloud-operators-foundation` uses managedClusterSet for resource group purpose. So it should only watch the following managedClusterSets:
370-
- `spec.ClusterSelector.SelectorType` is `ExclusiveLabel` and the `ExclusiveLabel.Key` must be `cluster.open-cluster-management.io/clusterset`
371-
- `spec.ClusterSelector.SelectorType` is ""
372-
373-
b. `multicloud-operators-foundation` gives the users `join` permission to a managedClusterSet if the user has "admin" permission to the managedClusterSet. So the `join` permission should be changed with the following rule:
374-
```yaml
375-
- apiGroups: ["cluster.open-cluster-management.io"]
376-
resources: ["managedclusters/label"]
377-
resourceNames: ["cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>"]
378-
verbs: ["create"]
379-
```
380-
381-
c. `submariner-addon` uses managedClusterSet group clusters based on the network. And in different managedClusterSet, the clusters should be exclusive. So it should only watch the following managedClusterSet:
382-
- `spec.ClusterSelector.SelectorType` is `ExclusiveLabel` and the `ExclusiveLabel.Key` must be `cluster.open-cluster-management.io/clusterset`, the `ExclusiveLabel.Value` must be managedClusterSet name.
383-
- `spec.ClusterSelector.SelectorType` is ""
384-
385-
d. `placement` using new `ClusterSelector` to select target clusters.
386-
387-
3. [Implement in OCM 0.8.0] Update full managedClusterSet api and RBAC
388-
- Include `LabelSelector`
389-
- Take off the restriction for “ExclusiveLabel.Key” and “ExclusiveLabel.Value”
390-
- Deprecate `managedclusterset/join` permission
391-
392-
4. [Implement in OCM 0.8.0] `placement` uses the new managedClusterSet api to select managedClusters for each managedClusterSet.
393-
394304
## Upgrade / Downgrade Strategy
395305
The new api is compatible with the previous version. So there is no external work needed when upgrading
396306

397307
## Graduation Criteria
398308
### v1beta1
399309
1. The new APIs is reviewed and accepted;
400-
2. Implementation is completed to support the RBAC;
310+
2. Implementation is completed;

enhancements/sig-architecture/30-clusterset-override/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ approvers:
99
- "@elgnay"
1010
- "@deads2k"
1111
creation-date: 2021-11-30
12-
last-updated: 2022-02-24
12+
last-updated: 2022-04-13
1313
status: provisional

0 commit comments

Comments
 (0)