diff --git a/build/charts/antrea/crds/tier.yaml b/build/charts/antrea/crds/tier.yaml index 1ee1a1ce5fe..ac36e9573f1 100644 --- a/build/charts/antrea/crds/tier.yaml +++ b/build/charts/antrea/crds/tier.yaml @@ -8,6 +8,32 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/build/charts/antrea/templates/webhooks/validating/crdvalidator.yaml b/build/charts/antrea/templates/webhooks/validating/crdvalidator.yaml index ed0d8c1c140..326366fe018 100644 --- a/build/charts/antrea/templates/webhooks/validating/crdvalidator.yaml +++ b/build/charts/antrea/templates/webhooks/validating/crdvalidator.yaml @@ -15,7 +15,7 @@ webhooks: rules: - operations: ["CREATE", "UPDATE", "DELETE"] apiGroups: ["crd.antrea.io"] - apiVersions: ["v1alpha1"] + apiVersions: ["v1alpha1", "v1beta1"] resources: ["tiers"] scope: "Cluster" admissionReviewVersions: ["v1", "v1beta1"] diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index ec792ec21e6..0ddebd35ac2 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -2338,6 +2338,33 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + deprecated: true + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/build/yamls/antrea-crds.yml b/build/yamls/antrea-crds.yml index f1ac54f55ea..8968b192330 100644 --- a/build/yamls/antrea-crds.yml +++ b/build/yamls/antrea-crds.yml @@ -2315,6 +2315,33 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + deprecated: true + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index c8175867cfd..6cf2afccc17 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -2338,6 +2338,33 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + deprecated: true + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 7812ff71dc6..d503e85a8c0 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -2338,6 +2338,33 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + deprecated: true + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index f8f6d4f8538..75bf08299a1 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -2338,6 +2338,33 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + deprecated: true + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 8f9e23e8511..e7dcab76323 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -2338,6 +2338,33 @@ spec: group: crd.antrea.io versions: - name: v1alpha1 + served: true + storage: false + deprecated: true + additionalPrinterColumns: + - name: Priority + type: integer + description: The Priority of this Tier relative to other Tiers. + jsonPath: .spec.priority + - name: Age + type: date + jsonPath: .metadata.creationTimestamp + schema: + openAPIV3Schema: + type: object + properties: + spec: + required: + - priority + type: object + properties: + priority: + type: integer + minimum: 0 + maximum: 255 + description: + type: string + - name: v1beta1 served: true storage: true additionalPrinterColumns: diff --git a/cmd/antrea-controller/controller.go b/cmd/antrea-controller/controller.go index f2655b15289..440123d2e92 100644 --- a/cmd/antrea-controller/controller.go +++ b/cmd/antrea-controller/controller.go @@ -137,7 +137,7 @@ func run(o *Options) error { acnpInformer := crdInformerFactory.Crd().V1alpha1().ClusterNetworkPolicies() eeInformer := crdInformerFactory.Crd().V1alpha2().ExternalEntities() annpInformer := crdInformerFactory.Crd().V1alpha1().NetworkPolicies() - tierInformer := crdInformerFactory.Crd().V1alpha1().Tiers() + tierInformer := crdInformerFactory.Crd().V1beta1().Tiers() tfInformer := crdInformerFactory.Crd().V1alpha1().Traceflows() cgInformer := crdInformerFactory.Crd().V1alpha3().ClusterGroups() grpInformer := crdInformerFactory.Crd().V1alpha3().Groups() diff --git a/docs/antrea-network-policy.md b/docs/antrea-network-policy.md index e36767a0fb6..6c660503a98 100644 --- a/docs/antrea-network-policy.md +++ b/docs/antrea-network-policy.md @@ -89,7 +89,7 @@ as was the case initially. An example Tier might look like this: ```yaml -apiVersion: crd.antrea.io/v1alpha1 +apiVersion: crd.antrea.io/v1beta1 kind: Tier metadata: name: mytier diff --git a/docs/api.md b/docs/api.md index 926930618d8..0d5f6d69531 100644 --- a/docs/api.md +++ b/docs/api.md @@ -35,7 +35,7 @@ These are the CRDs currently available in `crd.antrea.io`. | `ExternalIPPool` | v1alpha2 | v1.2.0 | N/A | N/A | | `Group` | v1alpha3 | v1.8.0 | N/A | N/A | | `NetworkPolicy` | v1alpha1 | v1.0.0 | N/A | N/A | -| `Tier` | v1alpha1 | v1.0.0 | N/A | N/A | +| `Tier` | v1beta1 | v1.13.0 | N/A | N/A | | `Traceflow` | v1alpha1 | v1.0.0 | N/A | N/A | ### Other API groups @@ -70,6 +70,7 @@ These are the API group versions which are curently available when using Antrea. | CRD | CRD version | Introduced in | Deprecated in | Removed in | |---|---|---|---|---| | `ClusterGroup` | v1alpha2 | v1.0.0 | v1.1.0 | v1.12.0 [^1] | +| `Tier` | v1alpha1 | v1.0.0 | v1.13.0 | v2.0.0 | [^1]: The v1alpha2 version of the `ClusterGroup` CRD is no longer served by the apiserver in v1.12 and is completely removed in v1.13. diff --git a/multicluster/controllers/multicluster/member/acnp_resourceimport_controller.go b/multicluster/controllers/multicluster/member/acnp_resourceimport_controller.go index f2870a159d4..8895c410347 100644 --- a/multicluster/controllers/multicluster/member/acnp_resourceimport_controller.go +++ b/multicluster/controllers/multicluster/member/acnp_resourceimport_controller.go @@ -30,6 +30,7 @@ import ( multiclusterv1alpha1 "antrea.io/antrea/multicluster/apis/multicluster/v1alpha1" "antrea.io/antrea/multicluster/controllers/multicluster/common" "antrea.io/antrea/pkg/apis/crd/v1alpha1" + "antrea.io/antrea/pkg/apis/crd/v1beta1" ) const acnpImportFailed string = "ACNPImportFailed" @@ -69,7 +70,7 @@ func (r *ResourceImportReconciler) handleResImpUpdateForClusterNetworkPolicy(ctx } } acnpObj := getMCAntreaClusterPolicy(resImp) - tierObj, tierName := &v1alpha1.Tier{}, acnpObj.Spec.Tier + tierObj, tierName := &v1beta1.Tier{}, acnpObj.Spec.Tier err = r.localClusterClient.Get(ctx, types.NamespacedName{Namespace: "", Name: tierName}, tierObj) tierNotFound := apierrors.IsNotFound(err) if err != nil && !tierNotFound { diff --git a/multicluster/controllers/multicluster/member/acnp_resourceimport_controller_test.go b/multicluster/controllers/multicluster/member/acnp_resourceimport_controller_test.go index 616fd67bd9d..6c109d8a72b 100644 --- a/multicluster/controllers/multicluster/member/acnp_resourceimport_controller_test.go +++ b/multicluster/controllers/multicluster/member/acnp_resourceimport_controller_test.go @@ -34,6 +34,7 @@ import ( "antrea.io/antrea/multicluster/controllers/multicluster/common" "antrea.io/antrea/multicluster/controllers/multicluster/commonarea" "antrea.io/antrea/pkg/apis/crd/v1alpha1" + "antrea.io/antrea/pkg/apis/crd/v1beta1" ) var ( @@ -55,11 +56,11 @@ var ( allowAction = v1alpha1.RuleActionAllow dropAction = v1alpha1.RuleActionDrop - securityOpsTier = &v1alpha1.Tier{ + securityOpsTier = &v1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "securityops", }, - Spec: v1alpha1.TierSpec{ + Spec: v1beta1.TierSpec{ Priority: int32(100), Description: "[READ-ONLY]: System generated SecurityOps Tier", }, diff --git a/multicluster/controllers/multicluster/member/resourceimport_controller_test.go b/multicluster/controllers/multicluster/member/resourceimport_controller_test.go index 5be782db638..5d718788fde 100644 --- a/multicluster/controllers/multicluster/member/resourceimport_controller_test.go +++ b/multicluster/controllers/multicluster/member/resourceimport_controller_test.go @@ -44,6 +44,7 @@ import ( "antrea.io/antrea/multicluster/controllers/multicluster/common" "antrea.io/antrea/multicluster/controllers/multicluster/commonarea" "antrea.io/antrea/pkg/apis/crd/v1alpha1" + "antrea.io/antrea/pkg/apis/crd/v1beta1" ) var ( @@ -121,6 +122,7 @@ var ( func init() { utilruntime.Must(mcsv1alpha1.AddToScheme(scheme)) utilruntime.Must(v1alpha1.AddToScheme(scheme)) + utilruntime.Must(v1beta1.AddToScheme(scheme)) utilruntime.Must(k8smcsapi.AddToScheme(scheme)) utilruntime.Must(k8sscheme.AddToScheme(scheme)) } diff --git a/pkg/apis/crd/v1beta1/register.go b/pkg/apis/crd/v1beta1/register.go index 7ff2c5e2d64..b108eeb5e29 100644 --- a/pkg/apis/crd/v1beta1/register.go +++ b/pkg/apis/crd/v1beta1/register.go @@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &AntreaControllerInfoList{}, &AntreaAgentInfo{}, &AntreaAgentInfoList{}, + &Tier{}, + &TierList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/crd/v1beta1/types.go b/pkg/apis/crd/v1beta1/types.go index 80962b6c4bf..f2f5989f392 100644 --- a/pkg/apis/crd/v1beta1/types.go +++ b/pkg/apis/crd/v1beta1/types.go @@ -154,3 +154,36 @@ type ControllerCondition struct { // Human readable message indicating details Message string `json:"message,omitempty"` } + +// +genclient +// +genclient:nonNamespaced +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type Tier struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Specification of the desired behavior of Tier. + Spec TierSpec `json:"spec"` +} + +// TierSpec defines the desired state for Tier. +type TierSpec struct { + // Priority specfies the order of the Tier relative to other Tiers. + Priority int32 `json:"priority"` + // Description is an optional field to add more information regarding + // the purpose of this Tier. + Description string `json:"description,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type TierList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []Tier `json:"items"` +} diff --git a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go index ab06a42283f..ff66ba3d983 100644 --- a/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1beta1/zz_generated.deepcopy.go @@ -245,3 +245,79 @@ func (in *OVSInfo) DeepCopy() *OVSInfo { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Tier) DeepCopyInto(out *Tier) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Tier. +func (in *Tier) DeepCopy() *Tier { + if in == nil { + return nil + } + out := new(Tier) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Tier) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TierList) DeepCopyInto(out *TierList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Tier, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TierList. +func (in *TierList) DeepCopy() *TierList { + if in == nil { + return nil + } + out := new(TierList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TierList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TierSpec) DeepCopyInto(out *TierSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TierSpec. +func (in *TierSpec) DeepCopy() *TierSpec { + if in == nil { + return nil + } + out := new(TierSpec) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apiserver/openapi/zz_generated.openapi.go b/pkg/apiserver/openapi/zz_generated.openapi.go index fe220e3d179..cdec918c239 100644 --- a/pkg/apiserver/openapi/zz_generated.openapi.go +++ b/pkg/apiserver/openapi/zz_generated.openapi.go @@ -80,6 +80,9 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "antrea.io/antrea/pkg/apis/crd/v1beta1.ControllerCondition": schema_pkg_apis_crd_v1beta1_ControllerCondition(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.NetworkPolicyControllerInfo": schema_pkg_apis_crd_v1beta1_NetworkPolicyControllerInfo(ref), "antrea.io/antrea/pkg/apis/crd/v1beta1.OVSInfo": schema_pkg_apis_crd_v1beta1_OVSInfo(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.Tier": schema_pkg_apis_crd_v1beta1_Tier(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TierList": schema_pkg_apis_crd_v1beta1_TierList(ref), + "antrea.io/antrea/pkg/apis/crd/v1beta1.TierSpec": schema_pkg_apis_crd_v1beta1_TierSpec(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaClusterNetworkPolicyStats": schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStats(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaClusterNetworkPolicyStatsList": schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStatsList(ref), "antrea.io/antrea/pkg/apis/stats/v1alpha1.AntreaNetworkPolicyStats": schema_pkg_apis_stats_v1alpha1_AntreaNetworkPolicyStats(ref), @@ -2891,6 +2894,126 @@ func schema_pkg_apis_crd_v1beta1_OVSInfo(ref common.ReferenceCallback) common.Op } } +func schema_pkg_apis_crd_v1beta1_Tier(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "Standard metadata of the object.", + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Description: "Specification of the desired behavior of Tier.", + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.TierSpec"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.TierSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_TierList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("antrea.io/antrea/pkg/apis/crd/v1beta1.Tier"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "antrea.io/antrea/pkg/apis/crd/v1beta1.Tier", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_pkg_apis_crd_v1beta1_TierSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TierSpec defines the desired state for Tier.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "priority": { + SchemaProps: spec.SchemaProps{ + Description: "Priority specfies the order of the Tier relative to other Tiers.", + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "description": { + SchemaProps: spec.SchemaProps{ + Description: "Description is an optional field to add more information regarding the purpose of this Tier.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"priority"}, + }, + }, + } +} + func schema_pkg_apis_stats_v1alpha1_AntreaClusterNetworkPolicyStats(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go index 672e970dcba..61791bb7ff7 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ type CrdV1beta1Interface interface { RESTClient() rest.Interface AntreaAgentInfosGetter AntreaControllerInfosGetter + TiersGetter } // CrdV1beta1Client is used to interact with features provided by the crd.antrea.io group. @@ -43,6 +44,10 @@ func (c *CrdV1beta1Client) AntreaControllerInfos() AntreaControllerInfoInterface return newAntreaControllerInfos(c) } +func (c *CrdV1beta1Client) Tiers() TierInterface { + return newTiers(c) +} + // NewForConfig creates a new CrdV1beta1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go index cc16e366e0b..c579eeddc78 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_crd_client.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,6 +34,10 @@ func (c *FakeCrdV1beta1) AntreaControllerInfos() v1beta1.AntreaControllerInfoInt return &FakeAntreaControllerInfos{c} } +func (c *FakeCrdV1beta1) Tiers() v1beta1.TierInterface { + return &FakeTiers{c} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeCrdV1beta1) RESTClient() rest.Interface { diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_tier.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_tier.go new file mode 100644 index 00000000000..90f35333462 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/fake/fake_tier.go @@ -0,0 +1,120 @@ +// Copyright 2023 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. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeTiers implements TierInterface +type FakeTiers struct { + Fake *FakeCrdV1beta1 +} + +var tiersResource = schema.GroupVersionResource{Group: "crd.antrea.io", Version: "v1beta1", Resource: "tiers"} + +var tiersKind = schema.GroupVersionKind{Group: "crd.antrea.io", Version: "v1beta1", Kind: "Tier"} + +// Get takes name of the tier, and returns the corresponding tier object, and an error if there is any. +func (c *FakeTiers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Tier, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(tiersResource, name), &v1beta1.Tier{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Tier), err +} + +// List takes label and field selectors, and returns the list of Tiers that match those selectors. +func (c *FakeTiers) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TierList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(tiersResource, tiersKind, opts), &v1beta1.TierList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.TierList{ListMeta: obj.(*v1beta1.TierList).ListMeta} + for _, item := range obj.(*v1beta1.TierList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested tiers. +func (c *FakeTiers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(tiersResource, opts)) +} + +// Create takes the representation of a tier and creates it. Returns the server's representation of the tier, and an error, if there is any. +func (c *FakeTiers) Create(ctx context.Context, tier *v1beta1.Tier, opts v1.CreateOptions) (result *v1beta1.Tier, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(tiersResource, tier), &v1beta1.Tier{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Tier), err +} + +// Update takes the representation of a tier and updates it. Returns the server's representation of the tier, and an error, if there is any. +func (c *FakeTiers) Update(ctx context.Context, tier *v1beta1.Tier, opts v1.UpdateOptions) (result *v1beta1.Tier, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(tiersResource, tier), &v1beta1.Tier{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Tier), err +} + +// Delete takes name of the tier and deletes it. Returns an error if one occurs. +func (c *FakeTiers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(tiersResource, name, opts), &v1beta1.Tier{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTiers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(tiersResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.TierList{}) + return err +} + +// Patch applies the patch and returns the patched tier. +func (c *FakeTiers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Tier, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(tiersResource, name, pt, data, subresources...), &v1beta1.Tier{}) + if obj == nil { + return nil, err + } + return obj.(*v1beta1.Tier), err +} diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go index 9e4c79f4934..b870e75623d 100644 --- a/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,3 +19,5 @@ package v1beta1 type AntreaAgentInfoExpansion interface{} type AntreaControllerInfoExpansion interface{} + +type TierExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/crd/v1beta1/tier.go b/pkg/client/clientset/versioned/typed/crd/v1beta1/tier.go new file mode 100644 index 00000000000..7ff6c292b5e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/crd/v1beta1/tier.go @@ -0,0 +1,166 @@ +// Copyright 2023 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. + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + scheme "antrea.io/antrea/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// TiersGetter has a method to return a TierInterface. +// A group's client should implement this interface. +type TiersGetter interface { + Tiers() TierInterface +} + +// TierInterface has methods to work with Tier resources. +type TierInterface interface { + Create(ctx context.Context, tier *v1beta1.Tier, opts v1.CreateOptions) (*v1beta1.Tier, error) + Update(ctx context.Context, tier *v1beta1.Tier, opts v1.UpdateOptions) (*v1beta1.Tier, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.Tier, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.TierList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Tier, err error) + TierExpansion +} + +// tiers implements TierInterface +type tiers struct { + client rest.Interface +} + +// newTiers returns a Tiers +func newTiers(c *CrdV1beta1Client) *tiers { + return &tiers{ + client: c.RESTClient(), + } +} + +// Get takes name of the tier, and returns the corresponding tier object, and an error if there is any. +func (c *tiers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Tier, err error) { + result = &v1beta1.Tier{} + err = c.client.Get(). + Resource("tiers"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Tiers that match those selectors. +func (c *tiers) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TierList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.TierList{} + err = c.client.Get(). + Resource("tiers"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested tiers. +func (c *tiers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("tiers"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a tier and creates it. Returns the server's representation of the tier, and an error, if there is any. +func (c *tiers) Create(ctx context.Context, tier *v1beta1.Tier, opts v1.CreateOptions) (result *v1beta1.Tier, err error) { + result = &v1beta1.Tier{} + err = c.client.Post(). + Resource("tiers"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(tier). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a tier and updates it. Returns the server's representation of the tier, and an error, if there is any. +func (c *tiers) Update(ctx context.Context, tier *v1beta1.Tier, opts v1.UpdateOptions) (result *v1beta1.Tier, err error) { + result = &v1beta1.Tier{} + err = c.client.Put(). + Resource("tiers"). + Name(tier.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(tier). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the tier and deletes it. Returns an error if one occurs. +func (c *tiers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Resource("tiers"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *tiers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("tiers"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched tier. +func (c *tiers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Tier, err error) { + result = &v1beta1.Tier{} + err = c.client.Patch(pt). + Resource("tiers"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/interface.go b/pkg/client/informers/externalversions/crd/v1beta1/interface.go index 79585d9e5c5..8bf8fa0af06 100644 --- a/pkg/client/informers/externalversions/crd/v1beta1/interface.go +++ b/pkg/client/informers/externalversions/crd/v1beta1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ type Interface interface { AntreaAgentInfos() AntreaAgentInfoInformer // AntreaControllerInfos returns a AntreaControllerInfoInformer. AntreaControllerInfos() AntreaControllerInfoInformer + // Tiers returns a TierInformer. + Tiers() TierInformer } type version struct { @@ -48,3 +50,8 @@ func (v *version) AntreaAgentInfos() AntreaAgentInfoInformer { func (v *version) AntreaControllerInfos() AntreaControllerInfoInformer { return &antreaControllerInfoInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// Tiers returns a TierInformer. +func (v *version) Tiers() TierInformer { + return &tierInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/crd/v1beta1/tier.go b/pkg/client/informers/externalversions/crd/v1beta1/tier.go new file mode 100644 index 00000000000..33c0f5a4e70 --- /dev/null +++ b/pkg/client/informers/externalversions/crd/v1beta1/tier.go @@ -0,0 +1,87 @@ +// Copyright 2023 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. + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + time "time" + + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + versioned "antrea.io/antrea/pkg/client/clientset/versioned" + internalinterfaces "antrea.io/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1beta1 "antrea.io/antrea/pkg/client/listers/crd/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// TierInformer provides access to a shared informer and lister for +// Tiers. +type TierInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.TierLister +} + +type tierInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTierInformer constructs a new informer for Tier type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTierInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTierInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTierInformer constructs a new informer for Tier type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTierInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1beta1().Tiers().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CrdV1beta1().Tiers().Watch(context.TODO(), options) + }, + }, + &crdv1beta1.Tier{}, + resyncPeriod, + indexers, + ) +} + +func (f *tierInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTierInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *tierInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&crdv1beta1.Tier{}, f.defaultInformer) +} + +func (f *tierInformer) Lister() v1beta1.TierLister { + return v1beta1.NewTierLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index c706d13834c..c3bf6052240 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -1,4 +1,4 @@ -// Copyright 2022 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -92,6 +92,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().AntreaAgentInfos().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("antreacontrollerinfos"): return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().AntreaControllerInfos().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("tiers"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Crd().V1beta1().Tiers().Informer()}, nil } diff --git a/pkg/client/listers/crd/v1beta1/expansion_generated.go b/pkg/client/listers/crd/v1beta1/expansion_generated.go index 2181551a0c7..3fed4fe3a2f 100644 --- a/pkg/client/listers/crd/v1beta1/expansion_generated.go +++ b/pkg/client/listers/crd/v1beta1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2021 Antrea Authors +// Copyright 2023 Antrea Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,3 +23,7 @@ type AntreaAgentInfoListerExpansion interface{} // AntreaControllerInfoListerExpansion allows custom methods to be added to // AntreaControllerInfoLister. type AntreaControllerInfoListerExpansion interface{} + +// TierListerExpansion allows custom methods to be added to +// TierLister. +type TierListerExpansion interface{} diff --git a/pkg/client/listers/crd/v1beta1/tier.go b/pkg/client/listers/crd/v1beta1/tier.go new file mode 100644 index 00000000000..6bfa4c7f897 --- /dev/null +++ b/pkg/client/listers/crd/v1beta1/tier.go @@ -0,0 +1,66 @@ +// Copyright 2023 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. + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// TierLister helps list Tiers. +// All objects returned here must be treated as read-only. +type TierLister interface { + // List lists all Tiers in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.Tier, err error) + // Get retrieves the Tier from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.Tier, error) + TierListerExpansion +} + +// tierLister implements the TierLister interface. +type tierLister struct { + indexer cache.Indexer +} + +// NewTierLister returns a new TierLister. +func NewTierLister(indexer cache.Indexer) TierLister { + return &tierLister{indexer: indexer} +} + +// List lists all Tiers in the indexer. +func (s *tierLister) List(selector labels.Selector) (ret []*v1beta1.Tier, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.Tier)) + }) + return ret, err +} + +// Get retrieves the Tier from the index for a given name. +func (s *tierLister) Get(name string) (*v1beta1.Tier, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("tier"), name) + } + return obj.(*v1beta1.Tier), nil +} diff --git a/pkg/controller/networkpolicy/clusternetworkpolicy_test.go b/pkg/controller/networkpolicy/clusternetworkpolicy_test.go index f447860e639..8fcabbac8b0 100644 --- a/pkg/controller/networkpolicy/clusternetworkpolicy_test.go +++ b/pkg/controller/networkpolicy/clusternetworkpolicy_test.go @@ -30,6 +30,7 @@ import ( "antrea.io/antrea/pkg/apis/controlplane" crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" antreatypes "antrea.io/antrea/pkg/controller/types" "antrea.io/antrea/pkg/util/k8s" ) @@ -37,9 +38,9 @@ import ( func TestProcessClusterNetworkPolicy(t *testing.T) { p10 := float64(10) t10 := int32(10) - tierA := crdv1alpha1.Tier{ + tierA := crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{Name: "tier-A", UID: "uidA"}, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: t10, Description: "tier-A", }, @@ -1752,7 +1753,7 @@ func TestGetTierPriority(t *testing.T) { p10 := int32(10) tests := []struct { name string - inputTier *crdv1alpha1.Tier + inputTier *crdv1beta1.Tier expPrio int32 }{ { @@ -1762,9 +1763,9 @@ func TestGetTierPriority(t *testing.T) { }, { name: "tier10", - inputTier: &crdv1alpha1.Tier{ + inputTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{Name: "tA", UID: "uidA"}, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: p10, Description: "tier10", }, diff --git a/pkg/controller/networkpolicy/networkpolicy_controller.go b/pkg/controller/networkpolicy/networkpolicy_controller.go index 84d78d0762a..041c2c2762d 100644 --- a/pkg/controller/networkpolicy/networkpolicy_controller.go +++ b/pkg/controller/networkpolicy/networkpolicy_controller.go @@ -47,12 +47,15 @@ import ( "antrea.io/antrea/pkg/apis/controlplane" secv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" "antrea.io/antrea/pkg/apis/crd/v1alpha2" + secv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/apiserver/storage" "antrea.io/antrea/pkg/client/clientset/versioned" secinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha1" crdv1a3informers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha3" + crdv1b1informers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1beta1" seclisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha1" crdv1a3listers "antrea.io/antrea/pkg/client/listers/crd/v1alpha3" + crdv1b1listers "antrea.io/antrea/pkg/client/listers/crd/v1beta1" "antrea.io/antrea/pkg/controller/grouping" "antrea.io/antrea/pkg/controller/labelidentity" "antrea.io/antrea/pkg/controller/metrics" @@ -178,10 +181,10 @@ type NetworkPolicyController struct { // annpListerSynced is a function which returns true if the AntreaNetworkPolicies shared informer has been synced at least once. annpListerSynced cache.InformerSynced - tierInformer secinformers.TierInformer + tierInformer crdv1b1informers.TierInformer // tierLister is able to list/get Tiers and is populated by the shared informer passed to // NewNetworkPolicyController. - tierLister seclisters.TierLister + tierLister crdv1b1listers.TierLister // tierListerSynced is a function which returns true if the Tiers shared informer has been synced at least once. tierListerSynced cache.InformerSynced @@ -255,7 +258,7 @@ type heartbeat struct { var tierIndexers = cache.Indexers{ PriorityIndex: func(obj interface{}) ([]string, error) { - tr, ok := obj.(*secv1alpha1.Tier) + tr, ok := obj.(*secv1beta1.Tier) if !ok { return []string{}, nil } @@ -384,7 +387,7 @@ func NewNetworkPolicyController(kubeClient clientset.Interface, nodeInformer coreinformers.NodeInformer, acnpInformer secinformers.ClusterNetworkPolicyInformer, annpInformer secinformers.NetworkPolicyInformer, - tierInformer secinformers.TierInformer, + tierInformer crdv1b1informers.TierInformer, cgInformer crdv1a3informers.ClusterGroupInformer, grpInformer crdv1a3informers.GroupInformer, addressGroupStore storage.Interface, diff --git a/pkg/controller/networkpolicy/networkpolicy_controller_test.go b/pkg/controller/networkpolicy/networkpolicy_controller_test.go index 1aaa375211d..aa3021778e4 100644 --- a/pkg/controller/networkpolicy/networkpolicy_controller_test.go +++ b/pkg/controller/networkpolicy/networkpolicy_controller_test.go @@ -134,7 +134,7 @@ func newController(k8sObjects, crdObjects []runtime.Object) (*fake.Clientset, *n informerFactory.Core().V1().Nodes(), crdInformerFactory.Crd().V1alpha1().ClusterNetworkPolicies(), crdInformerFactory.Crd().V1alpha1().NetworkPolicies(), - crdInformerFactory.Crd().V1alpha1().Tiers(), + crdInformerFactory.Crd().V1beta1().Tiers(), cgInformer, gInformer, addressGroupStore, @@ -146,7 +146,7 @@ func newController(k8sObjects, crdObjects []runtime.Object) (*fake.Clientset, *n npController.namespaceListerSynced = alwaysReady npController.networkPolicyListerSynced = alwaysReady npController.acnpListerSynced = alwaysReady - npController.tierLister = crdInformerFactory.Crd().V1alpha1().Tiers().Lister() + npController.tierLister = crdInformerFactory.Crd().V1beta1().Tiers().Lister() npController.tierListerSynced = alwaysReady npController.cgInformer = cgInformer npController.cgLister = cgInformer.Lister() @@ -160,7 +160,7 @@ func newController(k8sObjects, crdObjects []runtime.Object) (*fake.Clientset, *n informerFactory.Networking().V1().NetworkPolicies().Informer().GetStore(), crdInformerFactory.Crd().V1alpha1().ClusterNetworkPolicies().Informer().GetStore(), crdInformerFactory.Crd().V1alpha1().NetworkPolicies().Informer().GetStore(), - crdInformerFactory.Crd().V1alpha1().Tiers().Informer().GetStore(), + crdInformerFactory.Crd().V1beta1().Tiers().Informer().GetStore(), crdInformerFactory.Crd().V1alpha3().ClusterGroups().Informer().GetStore(), crdInformerFactory.Crd().V1alpha3().Groups().Informer().GetStore(), appliedToGroupStore, @@ -186,7 +186,7 @@ func newControllerWithoutEventHandler(k8sObjects, crdObjects []runtime.Object) ( internalGroupStore := store.NewGroupStore() namespaceInformer := informerFactory.Core().V1().Namespaces() networkPolicyInformer := informerFactory.Networking().V1().NetworkPolicies() - tierInformer := crdInformerFactory.Crd().V1alpha1().Tiers() + tierInformer := crdInformerFactory.Crd().V1beta1().Tiers() acnpInformer := crdInformerFactory.Crd().V1alpha1().ClusterNetworkPolicies() annpInformer := crdInformerFactory.Crd().V1alpha1().NetworkPolicies() cgInformer := crdInformerFactory.Crd().V1alpha3().ClusterGroups() diff --git a/pkg/controller/networkpolicy/tier.go b/pkg/controller/networkpolicy/tier.go index ab00242489a..66fd318ff63 100644 --- a/pkg/controller/networkpolicy/tier.go +++ b/pkg/controller/networkpolicy/tier.go @@ -26,7 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - secv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + secv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" ) var ( @@ -61,12 +61,12 @@ var ( // be converted to corresponding Tier CRD names. staticTierSet = sets.New[string]("Emergency", "SecurityOps", "NetworkOps", "Platform", "Application", "Baseline") // systemGeneratedTiers are the Tier CRs to be created at init. - systemGeneratedTiers = []*secv1alpha1.Tier{ + systemGeneratedTiers = []*secv1beta1.Tier{ { ObjectMeta: metav1.ObjectMeta{ Name: baselineTierName, }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: priorityMap[baselineTierName], Description: "[READ-ONLY]: System generated Baseline Tier", }, @@ -75,7 +75,7 @@ var ( ObjectMeta: metav1.ObjectMeta{ Name: defaultTierName, }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: priorityMap[defaultTierName], Description: "[READ-ONLY]: System generated default Application Tier", }, @@ -84,7 +84,7 @@ var ( ObjectMeta: metav1.ObjectMeta{ Name: platformTierName, }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: priorityMap[platformTierName], Description: "[READ-ONLY]: System generated Platform Tier", }, @@ -93,7 +93,7 @@ var ( ObjectMeta: metav1.ObjectMeta{ Name: networkOpsTierName, }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: priorityMap[networkOpsTierName], Description: "[READ-ONLY]: System generated NetworkOps Tier", }, @@ -102,7 +102,7 @@ var ( ObjectMeta: metav1.ObjectMeta{ Name: securityOpsTierName, }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: priorityMap[securityOpsTierName], Description: "[READ-ONLY]: System generated SecurityOps Tier", }, @@ -111,7 +111,7 @@ var ( ObjectMeta: metav1.ObjectMeta{ Name: emergencyTierName, }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: priorityMap[emergencyTierName], Description: "[READ-ONLY]: System generated Emergency Tier", }, @@ -145,14 +145,14 @@ func (n *NetworkPolicyController) InitializeTiers() { // initTier attempts to create system Tiers until they are created using an // exponential backoff period from 1 to max of 8secs. -func (n *NetworkPolicyController) initTier(t *secv1alpha1.Tier) { +func (n *NetworkPolicyController) initTier(t *secv1beta1.Tier) { var err error const maxBackoffTime = 8 * time.Second backoff := 1 * time.Second retryAttempt := 1 for { klog.V(2).InfoS("Creating system Tier", "tier", t.Name) - _, err = n.crdClient.CrdV1alpha1().Tiers().Create(context.TODO(), t, metav1.CreateOptions{}) + _, err = n.crdClient.CrdV1beta1().Tiers().Create(context.TODO(), t, metav1.CreateOptions{}) // Attempt to recreate Tier after a backoff only if it does not exist. if err != nil { if errors.IsAlreadyExists(err) { @@ -178,14 +178,14 @@ func (n *NetworkPolicyController) initTier(t *secv1alpha1.Tier) { // updateTier attempts to update Tiers using an // exponential backoff period from 1 to max of 8secs. -func (n *NetworkPolicyController) updateTier(t *secv1alpha1.Tier) { +func (n *NetworkPolicyController) updateTier(t *secv1beta1.Tier) { var err error const maxBackoffTime = 8 * time.Second backoff := 1 * time.Second retryAttempt := 1 for { klog.V(2).Infof("Updating %s Tier", t.Name) - _, err = n.crdClient.CrdV1alpha1().Tiers().Update(context.TODO(), t, metav1.UpdateOptions{}) + _, err = n.crdClient.CrdV1beta1().Tiers().Update(context.TODO(), t, metav1.UpdateOptions{}) // Attempt to update Tier after a backoff. if err != nil { klog.Warningf("Failed to update %s Tier on init: %v. Retry attempt: %d", t.Name, err, retryAttempt) diff --git a/pkg/controller/networkpolicy/tier_test.go b/pkg/controller/networkpolicy/tier_test.go index de9e6da4901..bcbe2fc549c 100644 --- a/pkg/controller/networkpolicy/tier_test.go +++ b/pkg/controller/networkpolicy/tier_test.go @@ -23,16 +23,16 @@ import ( "k8s.io/apimachinery/pkg/runtime" k8stesting "k8s.io/client-go/testing" - secv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" + secv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/client/clientset/versioned/fake" ) func TestInitTier(t *testing.T) { - testTier := &secv1alpha1.Tier{ + testTier := &secv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: secv1alpha1.TierSpec{ + Spec: secv1beta1.TierSpec{ Priority: 10, }, } diff --git a/pkg/controller/networkpolicy/validate.go b/pkg/controller/networkpolicy/validate.go index c6db75653f4..1a2e19da2dd 100644 --- a/pkg/controller/networkpolicy/validate.go +++ b/pkg/controller/networkpolicy/validate.go @@ -36,6 +36,7 @@ import ( crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/controller/networkpolicy/store" "antrea.io/antrea/pkg/features" "antrea.io/antrea/pkg/util/env" @@ -158,7 +159,7 @@ func (v *NetworkPolicyValidator) Validate(ar *admv1.AdmissionReview) *admv1.Admi switch ar.Request.Kind.Kind { case "Tier": klog.V(2).Info("Validating Tier CRD") - var curTier, oldTier crdv1alpha1.Tier + var curTier, oldTier crdv1beta1.Tier if curRaw != nil { if err := json.Unmarshal(curRaw, &curTier); err != nil { klog.Errorf("Error de-serializing current Tier") @@ -351,7 +352,7 @@ func (v *NetworkPolicyValidator) validateAntreaGroup(curAG, oldAG interface{}, o } // validateTier validates the admission of a Tier resource -func (v *NetworkPolicyValidator) validateTier(curTier, oldTier *crdv1alpha1.Tier, op admv1.Operation, userInfo authenticationv1.UserInfo) (string, bool) { +func (v *NetworkPolicyValidator) validateTier(curTier, oldTier *crdv1beta1.Tier, op admv1.Operation, userInfo authenticationv1.UserInfo) (string, bool) { allowed := true reason := "" switch op { @@ -840,7 +841,7 @@ func (t *tierValidator) createValidate(curObj interface{}, userInfo authenticati if len(t.networkPolicyController.tierInformer.Informer().GetIndexer().ListIndexFuncValues(PriorityIndex)) >= maxSupportedTiers { return fmt.Sprintf("maximum number of Tiers supported: %d", maxSupportedTiers), false } - curTier := curObj.(*crdv1alpha1.Tier) + curTier := curObj.(*crdv1beta1.Tier) // Tier priority must not overlap reserved tier's priority. if reservedTierPriorities.Has(curTier.Spec.Priority) { return fmt.Sprintf("tier %s priority %d is reserved", curTier.Name, curTier.Spec.Priority), false @@ -857,8 +858,8 @@ func (t *tierValidator) createValidate(curObj interface{}, userInfo authenticati func (t *tierValidator) updateValidate(curObj, oldObj interface{}, userInfo authenticationv1.UserInfo) (string, bool) { allowed := true reason := "" - curTier := curObj.(*crdv1alpha1.Tier) - oldTier := oldObj.(*crdv1alpha1.Tier) + curTier := curObj.(*crdv1beta1.Tier) + oldTier := oldObj.(*crdv1beta1.Tier) // Retrieve antrea-controller's Namespace namespace := env.GetAntreaNamespace() // Allow exception of Tier Priority updates performed by the antrea-controller @@ -874,7 +875,7 @@ func (t *tierValidator) updateValidate(curObj, oldObj interface{}, userInfo auth // deleteValidate validates the DELETE events of Tier resources. func (t *tierValidator) deleteValidate(oldObj interface{}, userInfo authenticationv1.UserInfo) (string, bool) { - oldTier := oldObj.(*crdv1alpha1.Tier) + oldTier := oldObj.(*crdv1beta1.Tier) if reservedTierNames.Has(oldTier.Name) { return fmt.Sprintf("cannot delete reserved tier %s", oldTier.Name), false } diff --git a/pkg/controller/networkpolicy/validate_test.go b/pkg/controller/networkpolicy/validate_test.go index 386114c9b68..79c5eaf0d2c 100644 --- a/pkg/controller/networkpolicy/validate_test.go +++ b/pkg/controller/networkpolicy/validate_test.go @@ -28,6 +28,7 @@ import ( crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2" crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/features" ) @@ -2300,8 +2301,8 @@ func TestValidateAntreaGroup(t *testing.T) { func TestValidateTier(t *testing.T) { tests := []struct { name string - curTier *crdv1alpha1.Tier - oldTier *crdv1alpha1.Tier + curTier *crdv1beta1.Tier + oldTier *crdv1beta1.Tier existTierNum int existACNP *crdv1alpha1.ClusterNetworkPolicy existANNP *crdv1alpha1.NetworkPolicy @@ -2311,11 +2312,11 @@ func TestValidateTier(t *testing.T) { }{ { name: "create-tier-pass", - curTier: &crdv1alpha1.Tier{ + curTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-3", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 3, }, }, @@ -2326,11 +2327,11 @@ func TestValidateTier(t *testing.T) { }, { name: "create-tier-failed-with-reserved-priority", - curTier: &crdv1alpha1.Tier{ + curTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-251", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 251, }, }, @@ -2342,11 +2343,11 @@ func TestValidateTier(t *testing.T) { }, { name: "over-max-tier", - curTier: &crdv1alpha1.Tier{ + curTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: int32(maxSupportedTiers) + 1, }, }, @@ -2356,11 +2357,11 @@ func TestValidateTier(t *testing.T) { }, { name: "overlap-tier", - curTier: &crdv1alpha1.Tier{ + curTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-1", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 1, }, }, @@ -2370,19 +2371,19 @@ func TestValidateTier(t *testing.T) { }, { name: "update-tier-not-allowed", - oldTier: &crdv1alpha1.Tier{ + oldTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-3", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 3, }, }, - curTier: &crdv1alpha1.Tier{ + curTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-3", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 5, }, }, @@ -2394,19 +2395,19 @@ func TestValidateTier(t *testing.T) { }, { name: "update-tier-allowed", - oldTier: &crdv1alpha1.Tier{ + oldTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-3", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 3, }, }, - curTier: &crdv1alpha1.Tier{ + curTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-3", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 5, }, }, @@ -2417,11 +2418,11 @@ func TestValidateTier(t *testing.T) { }, { name: "delete-tier-pass", - oldTier: &crdv1alpha1.Tier{ + oldTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-priority-3", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 3, }, }, @@ -2432,11 +2433,11 @@ func TestValidateTier(t *testing.T) { }, { name: "delete-reserved-tier", - oldTier: &crdv1alpha1.Tier{ + oldTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "baseline", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 3, }, }, @@ -2448,11 +2449,11 @@ func TestValidateTier(t *testing.T) { }, { name: "delete-annp-ref-tier", - oldTier: &crdv1alpha1.Tier{ + oldTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-annp-ref", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 0, }, }, @@ -2467,11 +2468,11 @@ func TestValidateTier(t *testing.T) { }, { name: "delete-acnp-ref-tier", - oldTier: &crdv1alpha1.Tier{ + oldTier: &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: "tier-acnp-ref", }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: 0, }, }, @@ -2490,11 +2491,11 @@ func TestValidateTier(t *testing.T) { t.Run(tt.name, func(t *testing.T) { _, controller := newController(nil, nil) for i := 1; i <= tt.existTierNum; i++ { - controller.tierStore.Add(&crdv1alpha1.Tier{ + controller.tierStore.Add(&crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("tier-priority-%d", i), }, - Spec: crdv1alpha1.TierSpec{ + Spec: crdv1beta1.TierSpec{ Priority: int32(i), }, }) diff --git a/pkg/monitor/controller_test.go b/pkg/monitor/controller_test.go index 94f4e7c6995..3b6e6523613 100644 --- a/pkg/monitor/controller_test.go +++ b/pkg/monitor/controller_test.go @@ -63,7 +63,7 @@ func newControllerMonitor(crdClient *fakeclientset.Clientset) *fakeController { nodeInformer := informerFactory.Core().V1().Nodes() acnpInformer := crdInformerFactory.Crd().V1alpha1().ClusterNetworkPolicies() annpInformer := crdInformerFactory.Crd().V1alpha1().NetworkPolicies() - tierInformer := crdInformerFactory.Crd().V1alpha1().Tiers() + tierInformer := crdInformerFactory.Crd().V1beta1().Tiers() cgInformer := crdInformerFactory.Crd().V1alpha3().ClusterGroups() grpInformer := crdInformerFactory.Crd().V1alpha3().Groups() externalNodeInformer := crdInformerFactory.Crd().V1alpha1().ExternalNodes() diff --git a/test/e2e/antreapolicy_test.go b/test/e2e/antreapolicy_test.go index 5335aceff9b..e5f948de006 100644 --- a/test/e2e/antreapolicy_test.go +++ b/test/e2e/antreapolicy_test.go @@ -39,6 +39,7 @@ import ( "antrea.io/antrea/pkg/agent/apiserver/handlers/podinterface" crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/pkg/controller/networkpolicy" "antrea.io/antrea/pkg/features" . "antrea.io/antrea/test/e2e/utils" @@ -311,7 +312,7 @@ func testUpdateValidationInvalidTier(t *testing.T) { failOnError(fmt.Errorf("create Tier failed for tier prio-updated-tier: %v", err), t) } // Update this tier with new priority - newTier := crdv1alpha1.Tier{ + newTier := crdv1beta1.Tier{ ObjectMeta: oldTier.ObjectMeta, Spec: oldTier.Spec, } @@ -4256,7 +4257,7 @@ func waitForResourceReady(t *testing.T, timeout time.Duration, obj metav1.Object case *v1.Service: // The minInterval of AntreaProxy's BoundedFrequencyRunner is 1s, which means a Service may be handled after 1s. time.Sleep(1 * time.Second) - case *crdv1alpha1.Tier: + case *crdv1beta1.Tier: case *crdv1alpha3.ClusterGroup: case *crdv1alpha3.Group: } diff --git a/test/e2e/k8s_util.go b/test/e2e/k8s_util.go index 1c45a522b3f..86dae2de734 100644 --- a/test/e2e/k8s_util.go +++ b/test/e2e/k8s_util.go @@ -34,6 +34,7 @@ import ( crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3" + crdv1beta1 "antrea.io/antrea/pkg/apis/crd/v1beta1" "antrea.io/antrea/test/e2e/utils" ) @@ -738,15 +739,15 @@ func (data *TestData) CleanNetworkPolicies(namespaces map[string]string) error { } // CreateTier is a convenience function for creating an Antrea Policy Tier by name and priority. -func (data *TestData) CreateNewTier(name string, tierPriority int32) (*crdv1alpha1.Tier, error) { +func (data *TestData) CreateNewTier(name string, tierPriority int32) (*crdv1beta1.Tier, error) { log.Infof("Creating tier %s", name) - _, err := data.crdClient.CrdV1alpha1().Tiers().Get(context.TODO(), name, metav1.GetOptions{}) + _, err := data.crdClient.CrdV1beta1().Tiers().Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { - tr := &crdv1alpha1.Tier{ + tr := &crdv1beta1.Tier{ ObjectMeta: metav1.ObjectMeta{Name: name}, - Spec: crdv1alpha1.TierSpec{Priority: tierPriority}, + Spec: crdv1beta1.TierSpec{Priority: tierPriority}, } - tr, err = data.crdClient.CrdV1alpha1().Tiers().Create(context.TODO(), tr, metav1.CreateOptions{}) + tr, err = data.crdClient.CrdV1beta1().Tiers().Create(context.TODO(), tr, metav1.CreateOptions{}) if err != nil { log.Debugf("Unable to create tier %s: %s", name, err) } @@ -756,25 +757,25 @@ func (data *TestData) CreateNewTier(name string, tierPriority int32) (*crdv1alph } // GetTier is a convenience function for getting Tier. -func (data *TestData) GetTier(name string) (*crdv1alpha1.Tier, error) { - return data.crdClient.CrdV1alpha1().Tiers().Get(context.TODO(), name, metav1.GetOptions{}) +func (data *TestData) GetTier(name string) (*crdv1beta1.Tier, error) { + return data.crdClient.CrdV1beta1().Tiers().Get(context.TODO(), name, metav1.GetOptions{}) } // UpdateTier is a convenience function for updating an Antrea Policy Tier. -func (data *TestData) UpdateTier(tier *crdv1alpha1.Tier) (*crdv1alpha1.Tier, error) { +func (data *TestData) UpdateTier(tier *crdv1beta1.Tier) (*crdv1beta1.Tier, error) { log.Infof("Updating tier %s", tier.Name) - updatedTier, err := data.crdClient.CrdV1alpha1().Tiers().Update(context.TODO(), tier, metav1.UpdateOptions{}) + updatedTier, err := data.crdClient.CrdV1beta1().Tiers().Update(context.TODO(), tier, metav1.UpdateOptions{}) return updatedTier, err } // DeleteTier is a convenience function for deleting an Antrea Policy Tier with specific name. func (data *TestData) DeleteTier(name string) error { - _, err := data.crdClient.CrdV1alpha1().Tiers().Get(context.TODO(), name, metav1.GetOptions{}) + _, err := data.crdClient.CrdV1beta1().Tiers().Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { return errors.Wrapf(err, "unable to get tier %s", name) } log.Infof("Deleting tier %s", name) - if err = data.crdClient.CrdV1alpha1().Tiers().Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { + if err = data.crdClient.CrdV1beta1().Tiers().Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return errors.Wrapf(err, "unable to delete tier %s", name) } return nil