Skip to content

Commit

Permalink
Update ClusterClaim to version v1alpha2 (#3755)
Browse files Browse the repository at this point in the history
1. ClusterClaim is upgraded to v1alpha2, with the "Name" field removed
from the "spec".
2. "metadata.name" in ClusterClaim can only be `id.k8s.io` or
`clusterset.k8s.io`
3. Deprecate ClusterClaim version v1alpha1

Signed-off-by: zbangqi <[email protected]>
  • Loading branch information
bangqipropel committed Jul 6, 2022
1 parent 5c27604 commit b766cdc
Show file tree
Hide file tree
Showing 53 changed files with 693 additions and 339 deletions.
14 changes: 11 additions & 3 deletions docs/multicluster/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ used by Antrea Multi-cluster are in the API group `multicluster.crd.antrea.io`,
two CRDs from [mcs-api](https://github.com/kubernetes-sigs/mcs-api) are in group `multicluster.x-k8s.io`
which is defined by Kubernetes upstream [KEP-1645](https://github.com/kubernetes/enhancements/tree/master/keps/sig-multicluster/1645-multi-cluster-services-api).

## CRDs in `multicluster.crd.antrea.io`
## Currently-supported

### CRDs in `multicluster.crd.antrea.io`

| CRD | CRD version | Introduced in | Deprecated in / Planned Deprecation | Planned Removal |
| ------------------------ | ----------- | ------------- | ----------------------------------- | --------------- |
| `ClusterClaims` | v1alpha1 | v1.5.0 | N/A | N/A |
| `ClusterClaims` | v1alpha2 | v1.8.0 | N/A | N/A |
| `ClusterSets` | v1alpha1 | v1.5.0 | N/A | N/A |
| `MemberClusterAnnounces` | v1alpha1 | v1.5.0 | N/A | N/A |
| `ResourceExports` | v1alpha1 | v1.5.0 | N/A | N/A |
| `ResourceImports` | v1alpha1 | v1.5.0 | N/A | N/A |
| `Gateway` | v1alpha1 | v1.7.0 | N/A | N/A |
| `ClusterInfoImport` | v1alpha1 | v1.7.0 | N/A | N/A |

## CRDs in `multicluster.x-k8s.io`
### CRDs in `multicluster.x-k8s.io`

| CRD | CRD version | Introduced in | Deprecated in / Planned Deprecation | Planned Removal |
| ---------------- | ----------- | ------------- | ----------------------------------- | --------------- |
| `ServiceExports` | v1alpha1 | v1.5.0 | N/A | N/A |
| `ServiceImports` | v1alpha1 | v1.5.0 | N/A | N/A |

## Previously-supported

| CRD | API group | CRD version | Introduced in | Deprecated in | Removed in |
| ------------------------ | ---------------------------- | ----------- | ------------- | ------------- | ---------- |
| `ClusterClaims` | `multicluster.crd.antrea.io` | v1alpha1 | v1.5.0 | v1.8.0 | v1.8.0 |
22 changes: 7 additions & 15 deletions docs/multicluster/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,18 @@ with the following YAML manifest (you can also refer to
[multicluster_membercluster_template.yaml](../../multicluster/config/samples/clusterset_init/multicluster_membercluster_template.yaml)):

```yaml
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: id.k8s.io
namespace: kube-system
name: id.k8s.io
value: test-cluster-east
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: clusterset.k8s.io
namespace: kube-system
name: clusterset.k8s.io
value: test-clusterset
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
Expand Down Expand Up @@ -245,15 +243,13 @@ kind: ClusterClaim
metadata:
name: id.k8s.io
namespace: kube-system
name: id.k8s.io
value: test-cluster-west
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: clusterset.k8s.io
namespace: kube-system
name: clusterset.k8s.io
value: test-clusterset
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
Expand All @@ -276,20 +272,18 @@ spec:
[multicluster_clusterset_template.yaml](../../multicluster/config/samples/clusterset_init/multicluster_clusterset_template.yaml)):

```yaml
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: id.k8s.io
namespace: antrea-multicluster
name: id.k8s.io
value: test-cluster-north
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: clusterset.k8s.io
namespace: antrea-multicluster
name: clusterset.k8s.io
value: test-clusterset
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
Expand Down Expand Up @@ -324,20 +318,18 @@ Then create the `ClusterClaim` and `ClusterSet` CRs in cluster
Multi-cluster Controller runs):

```yaml
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: id.k8s.io
namespace: kube-system
name: id.k8s.io
value: test-cluster-north
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
apiVersion: multicluster.crd.antrea.io/v1alpha2
kind: ClusterClaim
metadata:
name: clusterset.k8s.io
namespace: kube-system
name: clusterset.k8s.io
value: test-clusterset
---
apiVersion: multicluster.crd.antrea.io/v1alpha1
Expand Down
22 changes: 9 additions & 13 deletions multicluster/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ multigroup: true
projectName: multicluster
repo: antrea.io/antrea/multicluster
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: crd.antrea.io
group: multicluster
kind: ClusterClaim
path: antrea.io/antrea/multicluster/apis/multicluster/v1alpha1
version: v1alpha1
webhooks:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
Expand Down Expand Up @@ -96,4 +83,13 @@ resources:
kind: Gateway
path: antrea.io/antrea/multicluster/apis/multicluster/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: crd.antrea.io
group: multicluster
kind: ClusterClaim
path: antrea.io/antrea/multicluster/apis/multicluster/v1alpha2
version: v1alpha2
version: "3"
59 changes: 1 addition & 58 deletions multicluster/apis/multicluster/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -36,8 +36,6 @@ const (
type ClusterClaim struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Name of the ClusterClaim.
Name string `json:"name,omitempty"` // TODO: Remove the name as it is already part of ObjectMeta and its confusing to have two names
// Value of the ClusterClaim.
Value string `json:"value,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1alpha2

import (
"fmt"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -29,7 +31,7 @@ func (r *ClusterClaim) SetupWebhookWithManager(mgr ctrl.Manager) error {
Complete()
}

//+kubebuilder:webhook:path=/mutate-multicluster-crd-antrea-io-v1alpha1-clusterclaim,mutating=true,failurePolicy=fail,sideEffects=None,groups=multicluster.crd.antrea.io,resources=clusterclaims,verbs=create;update,versions=v1alpha1,name=mclusterclaim.kb.io,admissionReviewVersions={v1,v1beta1}
//+kubebuilder:webhook:path=/mutate-multicluster-crd-antrea-io-v1alpha2-clusterclaim,mutating=true,failurePolicy=fail,sideEffects=None,groups=multicluster.crd.antrea.io,resources=clusterclaims,verbs=create;update,versions=v1alpha2,name=mclusterclaim.kb.io,admissionReviewVersions={v1,v1beta1}

var _ webhook.Defaulter = &ClusterClaim{}

Expand All @@ -41,15 +43,18 @@ func (r *ClusterClaim) Default() {
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-multicluster-crd-antrea-io-v1alpha1-clusterclaim,mutating=false,failurePolicy=fail,sideEffects=None,groups=multicluster.crd.antrea.io,resources=clusterclaims,verbs=create;update,versions=v1alpha1,name=vclusterclaim.kb.io,admissionReviewVersions={v1,v1beta1}
//+kubebuilder:webhook:path=/validate-multicluster-crd-antrea-io-v1alpha2-clusterclaim,mutating=false,failurePolicy=fail,sideEffects=None,groups=multicluster.crd.antrea.io,resources=clusterclaims,verbs=create;update,versions=v1alpha2,name=vclusterclaim.kb.io,admissionReviewVersions={v1,v1beta1}

var _ webhook.Validator = &ClusterClaim{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *ClusterClaim) ValidateCreate() error {
klog.InfoS("validate create", "name", r.Name)
if r.Name != WellKnownClusterClaimClusterSet && r.Name != WellKnownClusterClaimID {
err := fmt.Errorf("The name %s is not valid, only 'id.k8s.io' and 'clusterset.k8s.io' are valid names for ClusterClaim", r.Name)
return err
}

// TODO(user): fill in your validation logic upon object creation.
return nil
}

Expand Down
17 changes: 17 additions & 0 deletions multicluster/apis/multicluster/v1alpha2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package v1alpha2 is the v1alpha2 version of the API.
// +groupName=multicluster.crd.antrea.io
package v1alpha2
36 changes: 36 additions & 0 deletions multicluster/apis/multicluster/v1alpha2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2022 Antrea Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha2 contains API Schema definitions for the multicluster v1alpha2 API group
//+kubebuilder:object:generate=true
//+groupName=multicluster.crd.antrea.io
package v1alpha2

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "multicluster.crd.antrea.io", Version: "v1alpha2"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
27 changes: 27 additions & 0 deletions multicluster/apis/multicluster/v1alpha2/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha2

import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = GroupVersion

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Loading

0 comments on commit b766cdc

Please sign in to comment.