From d944f60baf05ed55cb4ec00e1ed7a100bae376dd Mon Sep 17 00:00:00 2001 From: yati1998 Date: Tue, 26 Jul 2022 11:45:38 +0530 Subject: [PATCH] deploy: enable multigroup api This commit enables the multigroup api to allow different group for csi-addons and volume-replication updates: #116 Signed-off-by: yati1998 --- Makefile | 2 +- PROJECT | 17 ++ cmd/manager/main.go | 2 + config/crd/kustomization.yaml | 6 + .../bases/clusterserviceversion.yaml.in | 10 + controllers/csiaddons/suite_test.go | 85 ++++++ deploy/controller/crds.yaml | 253 ++++++++++++++++++ 7 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 controllers/csiaddons/suite_test.go diff --git a/Makefile b/Makefile index 48161b1e3c31..07965b070dd6 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ help: ## Display this help. .PHONY: manifests manifests: controller-gen kustomize ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. - $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="{./api/...,./cmd/...,./controllers/...,./sidecar/...}" output:crd:artifacts:config=config/crd/bases + $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="{./apis/...,./api/...,./cmd/...,./controllers/...,./sidecar/...}" output:crd:artifacts:config=config/crd/bases cd config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLLER_IMG} rbac-proxy=${RBAC_PROXY_IMG} $(KUSTOMIZE) build config/crd > deploy/controller/crds.yaml $(KUSTOMIZE) build config/rbac > deploy/controller/rbac.yaml diff --git a/PROJECT b/PROJECT index 6284df684d06..2a30a2cc0734 100644 --- a/PROJECT +++ b/PROJECT @@ -1,6 +1,7 @@ domain: openshift.io layout: - go.kubebuilder.io/v3 +multigroup: true projectName: kubernetes-csi-addons repo: github.com/csi-addons/kubernetes-csi-addons resources: @@ -40,4 +41,20 @@ resources: kind: PersistentVolumeClaim path: k8s.io/api/core/v1 version: v1 +- api: + crdVersion: v1 + namespaced: true + domain: openshift.io + group: replication.storage + kind: VolumeReplication + path: github.com/csi-addons/kubernetes-csi-addons/apis/replication.storage/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + domain: openshift.io + group: replication.storage + kind: VolumeReplicationClass + path: github.com/csi-addons/kubernetes-csi-addons/apis/replication.storage/v1alpha1 + version: v1alpha1 version: "3" diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 915a1049dcc2..b87fc9228c77 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -33,6 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" csiaddonsv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/v1alpha1" + replicationstoragev1alpha1 "github.com/csi-addons/kubernetes-csi-addons/apis/replication.storage/v1alpha1" "github.com/csi-addons/kubernetes-csi-addons/controllers" "github.com/csi-addons/kubernetes-csi-addons/internal/connection" //+kubebuilder:scaffold:imports @@ -51,6 +52,7 @@ func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) utilruntime.Must(csiaddonsv1alpha1.AddToScheme(scheme)) + utilruntime.Must(replicationstoragev1alpha1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 2130ea8699b7..ebc0b321e81c 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -6,6 +6,8 @@ resources: - bases/csiaddons.openshift.io_reclaimspacecronjobs.yaml - bases/csiaddons.openshift.io_reclaimspacejobs.yaml - bases/csiaddons.openshift.io_networkfences.yaml +- bases/replication.storage.openshift.io_volumereplications.yaml +- bases/replication.storage.openshift.io_volumereplicationclasses.yaml #+kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: @@ -13,12 +15,16 @@ patchesStrategicMerge: # patches here are for enabling the conversion webhook for each CRD #- patches/webhook_in_csiaddonsnodes.yaml #- patches/webhook_in_reclaimspacejobs.yaml +#- patches/webhook_in_volumereplications.yaml +#- patches/webhook_in_volumereplicationclasses.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD #- patches/cainjection_in_csiaddonsnodes.yaml #- patches/cainjection_in_reclaimspacejobs.yaml +#- patches/cainjection_in_volumereplications.yaml +#- patches/cainjection_in_volumereplicationclasses.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/manifests/bases/clusterserviceversion.yaml.in b/config/manifests/bases/clusterserviceversion.yaml.in index 4ad5afe06444..176f34762f9c 100644 --- a/config/manifests/bases/clusterserviceversion.yaml.in +++ b/config/manifests/bases/clusterserviceversion.yaml.in @@ -31,6 +31,16 @@ spec: kind: ReclaimSpaceJob name: reclaimspacejobs.csiaddons.openshift.io version: v1alpha1 + - description: VolumeReplicationClass is the Schema for the volumereplicationclasses API + displayName: Volume Replication Class + kind: VolumeReplicationClass + name: volumereplicationclasses.replication.storage.openshift.io + version: v1alpha1 + - description: VolumeReplication is the Schema for the volumereplications API + displayName: Volume Replication + kind: VolumeReplication + name: volumereplications.replication.storage.openshift.io + version: v1alpha1 description: CSI Addons provides the CSI Addons Controller that enables advanced storage operations for CSI-drivers. displayName: CSI Addons diff --git a/controllers/csiaddons/suite_test.go b/controllers/csiaddons/suite_test.go new file mode 100644 index 000000000000..22c40bfee58b --- /dev/null +++ b/controllers/csiaddons/suite_test.go @@ -0,0 +1,85 @@ +/* +Copyright 2021 The Kubernetes-CSI-Addons 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 controllers + +import ( + "path/filepath" + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + "sigs.k8s.io/controller-runtime/pkg/envtest/printer" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + + corev1 "k8s.io/api/core/v1" + + csiaddonsv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/apis/csiaddons/v1alpha1" + //+kubebuilder:scaffold:imports +) + +// These tests use Ginkgo (BDD-style Go testing framework). Refer to +// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. + +var cfg *rest.Config +var k8sClient client.Client +var testEnv *envtest.Environment + +func TestAPIs(t *testing.T) { + RegisterFailHandler(Fail) + + RunSpecsWithDefaultAndCustomReporters(t, + "Controller Suite", + []Reporter{printer.NewlineReporter{}}) +} + +var _ = BeforeSuite(func() { + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) + + By("bootstrapping test environment") + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, + } + + cfg, err := testEnv.Start() + Expect(err).NotTo(HaveOccurred()) + Expect(cfg).NotTo(BeNil()) + + err = csiaddonsv1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = corev1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + //+kubebuilder:scaffold:scheme + + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) + Expect(err).NotTo(HaveOccurred()) + Expect(k8sClient).NotTo(BeNil()) + +}, 60) + +var _ = AfterSuite(func() { + By("tearing down the test environment") + err := testEnv.Stop() + Expect(err).NotTo(HaveOccurred()) +}) diff --git a/deploy/controller/crds.yaml b/deploy/controller/crds.yaml index 1e4cdb2c7288..eb0dcb8b6c8b 100644 --- a/deploy/controller/crds.yaml +++ b/deploy/controller/crds.yaml @@ -669,3 +669,256 @@ spec: storage: true subresources: status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.9.1 + creationTimestamp: null + name: volumereplicationclasses.replication.storage.openshift.io +spec: + group: replication.storage.openshift.io + names: + kind: VolumeReplicationClass + listKind: VolumeReplicationClassList + plural: volumereplicationclasses + shortNames: + - vrc + singular: volumereplicationclass + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .spec.provisioner + name: provisioner + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: VolumeReplicationClass is the Schema for the volumereplicationclasses + API. + properties: + apiVersion: + 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 + kind: + 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 + metadata: + type: object + spec: + description: VolumeReplicationClassSpec specifies parameters that an underlying + storage system uses when creating a volume replica. A specific VolumeReplicationClass + is used by specifying its name in a VolumeReplication object. + properties: + parameters: + additionalProperties: + type: string + description: Parameters is a key-value map with storage provisioner + specific configurations for creating volume replicas + type: object + provisioner: + description: Provisioner is the name of storage provisioner + type: string + required: + - provisioner + type: object + status: + description: VolumeReplicationClassStatus defines the observed state of + VolumeReplicationClass. + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.9.1 + creationTimestamp: null + name: volumereplications.replication.storage.openshift.io +spec: + group: replication.storage.openshift.io + names: + kind: VolumeReplication + listKind: VolumeReplicationList + plural: volumereplications + shortNames: + - vr + singular: volumereplication + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + - jsonPath: .spec.volumeReplicationClass + name: volumeReplicationClass + type: string + - jsonPath: .spec.dataSource.name + name: pvcName + type: string + - jsonPath: .spec.replicationState + name: desiredState + type: string + - jsonPath: .status.state + name: currentState + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: VolumeReplication is the Schema for the volumereplications API. + properties: + apiVersion: + 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 + kind: + 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 + metadata: + type: object + spec: + description: VolumeReplicationSpec defines the desired state of VolumeReplication. + properties: + autoResync: + description: AutoResync represents the volume to be auto resynced + when ReplicationState is "secondary" + type: boolean + dataSource: + description: DataSource represents the object associated with the + volume + properties: + apiGroup: + description: APIGroup is the group for the resource being referenced. + If APIGroup is not specified, the specified Kind must be in + the core API group. For any other third-party types, APIGroup + is required. + type: string + kind: + description: Kind is the type of resource being referenced + type: string + name: + description: Name is the name of resource being referenced + type: string + required: + - apiGroup + - kind + - name + type: object + replicationHandle: + description: replicationHandle represents an existing (but new) replication + id + type: string + replicationState: + description: ReplicationState represents the replication operation + to be performed on the volume. Supported operations are "primary", + "secondary" and "resync" + enum: + - primary + - secondary + - resync + type: string + volumeReplicationClass: + description: VolumeReplicationClass is the VolumeReplicationClass + name for this VolumeReplication resource + type: string + required: + - autoResync + - dataSource + - replicationState + - volumeReplicationClass + type: object + status: + description: VolumeReplicationStatus defines the observed state of VolumeReplication. + properties: + conditions: + description: Conditions are the list of conditions and their status. + items: + description: "Condition contains details for one aspect of the current + state of this API Resource. --- This struct is intended for direct + use as an array at the field path .status.conditions. For example, + type FooStatus struct{ // Represents the observations of a foo's + current state. // Known .status.conditions.type are: \"Available\", + \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge + // +listType=map // +listMapKey=type Conditions []metav1.Condition + `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" + protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }" + properties: + lastTransitionTime: + description: lastTransitionTime is the last time the condition + transitioned from one status to another. This should be when + the underlying condition changed. If that is not known, then + using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: message is a human readable message indicating + details about the transition. This may be an empty string. + type: string + observedGeneration: + description: observedGeneration represents the .metadata.generation + that the condition was set based upon. For instance, if .metadata.generation + is currently 12, but the .status.conditions[x].observedGeneration + is 9, the condition is out of date with respect to the current + state of the instance. + format: int64 + type: integer + reason: + description: reason contains a programmatic identifier indicating + the reason for the condition's last transition. Producers + of specific condition types may define expected values and + meanings for this field, and whether the values are considered + a guaranteed API. The value should be a CamelCase string. + This field may not be empty. + type: string + status: + description: status of the condition, one of True, False, Unknown. + type: string + type: + description: type of condition in CamelCase or in foo.example.com/CamelCase. + --- Many .condition.type values are consistent across resources + like Available, but because arbitrary conditions can be useful + (see .node.status.conditions), the ability to deconflict is + important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array + lastCompletionTime: + format: date-time + type: string + lastStartTime: + format: date-time + type: string + message: + type: string + observedGeneration: + description: observedGeneration is the last generation change the + operator has dealt with + format: int64 + type: integer + state: + description: State captures the latest state of the replication operation. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {}