From af359fdfb2613c131977f80c0b136a575a3b10c6 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Mon, 28 Dec 2020 16:20:41 +0200 Subject: [PATCH] operator: Rename deployment CRD name to pmemcsideployment Renaming the operator `Deployment` API to `PmemCSIDeployment'. Prefixed only the `Deployment` type with 'PmemCSI' not its sub-types, because this is what used by the 'kubebuilder' to determine the generated CRD Kind is. FIXES #814 --- deploy/bindata_generated.go | 18 +-- ...tel.com_v1beta1_pmemcsideployment_cr.yaml} | 2 +- ...mem-csi.intel.com_pmemcsideployments.yaml} | 14 ++- .../kustomize/olm-catalog/kustomization.yaml | 4 +- deploy/kustomize/operator/operator.yaml | 6 +- deploy/operator/pmem-csi-operator.yaml | 6 +- docs/design.md | 6 +- docs/install.md | 51 ++++---- pkg/apis/pmemcsi/v1beta1/deployment_types.go | 50 ++++---- .../pmemcsi/v1beta1/deployment_types_test.go | 8 +- .../pmemcsi/v1beta1/zz_generated.deepcopy.go | 118 +++++++++--------- pkg/deployments/load.go | 4 +- pkg/deployments/load_test.go | 2 +- .../deployment/controller_driver.go | 4 +- .../deployment/deployment_controller.go | 18 +-- .../deployment/deployment_controller_test.go | 24 ++-- .../deployment/testcases/testcases.go | 42 +++---- pkg/pmem-csi-operator/main.go | 2 +- test/e2e/deploy/deploy.go | 8 +- test/e2e/deploy/operator.go | 20 +-- test/e2e/operator/deployment_api.go | 66 +++++----- test/e2e/operator/validate/validate.go | 6 +- test/start-operator.sh | 4 +- test/stop-operator.sh | 2 +- 24 files changed, 248 insertions(+), 237 deletions(-) rename deploy/common/{pmem-csi.intel.com_v1beta1_deployment_cr.yaml => pmem-csi.intel.com_v1beta1_pmemcsideployment_cr.yaml} (92%) rename deploy/crd/{pmem-csi.intel.com_deployments.yaml => pmem-csi.intel.com_pmemcsideployments.yaml} (98%) diff --git a/deploy/bindata_generated.go b/deploy/bindata_generated.go index 12b9eaa35a..8f42003788 100644 --- a/deploy/bindata_generated.go +++ b/deploy/bindata_generated.go @@ -100,7 +100,7 @@ func deployKubernetes117DirectPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.17/direct/pmem-csi.yaml", size: 10899, mode: os.FileMode(436), modTime: time.Unix(1610043180, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.17/direct/pmem-csi.yaml", size: 10899, mode: os.FileMode(436), modTime: time.Unix(1610052987, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -120,7 +120,7 @@ func deployKubernetes117LvmPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.17/lvm/pmem-csi.yaml", size: 10848, mode: os.FileMode(436), modTime: time.Unix(1610043183, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.17/lvm/pmem-csi.yaml", size: 10848, mode: os.FileMode(436), modTime: time.Unix(1610052990, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -140,7 +140,7 @@ func deployKubernetes118DirectPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.18/direct/pmem-csi.yaml", size: 10899, mode: os.FileMode(436), modTime: time.Unix(1610043193, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.18/direct/pmem-csi.yaml", size: 10899, mode: os.FileMode(436), modTime: time.Unix(1610052999, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -160,7 +160,7 @@ func deployKubernetes118LvmPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.18/lvm/pmem-csi.yaml", size: 10848, mode: os.FileMode(436), modTime: time.Unix(1610043195, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.18/lvm/pmem-csi.yaml", size: 10848, mode: os.FileMode(436), modTime: time.Unix(1610053002, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -180,7 +180,7 @@ func deployKubernetes119AlphaDirectPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.19-alpha/direct/pmem-csi.yaml", size: 11216, mode: os.FileMode(436), modTime: time.Unix(1610043217, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.19-alpha/direct/pmem-csi.yaml", size: 11216, mode: os.FileMode(436), modTime: time.Unix(1610053023, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -200,7 +200,7 @@ func deployKubernetes119AlphaLvmPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.19-alpha/lvm/pmem-csi.yaml", size: 11165, mode: os.FileMode(436), modTime: time.Unix(1610043219, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.19-alpha/lvm/pmem-csi.yaml", size: 11165, mode: os.FileMode(436), modTime: time.Unix(1610053026, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -220,7 +220,7 @@ func deployKubernetes119DirectPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.19/direct/pmem-csi.yaml", size: 10899, mode: os.FileMode(436), modTime: time.Unix(1610043205, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.19/direct/pmem-csi.yaml", size: 10899, mode: os.FileMode(436), modTime: time.Unix(1610053011, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -240,7 +240,7 @@ func deployKubernetes119FakePmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.19/fake/pmem-csi.yaml", size: 10897, mode: os.FileMode(436), modTime: time.Unix(1610043238, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.19/fake/pmem-csi.yaml", size: 10897, mode: os.FileMode(436), modTime: time.Unix(1610053046, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -260,7 +260,7 @@ func deployKubernetes119LvmPmemCsiYaml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "deploy/kubernetes-1.19/lvm/pmem-csi.yaml", size: 10848, mode: os.FileMode(436), modTime: time.Unix(1610043207, 0)} + info := bindataFileInfo{name: "deploy/kubernetes-1.19/lvm/pmem-csi.yaml", size: 10848, mode: os.FileMode(436), modTime: time.Unix(1610053014, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/deploy/common/pmem-csi.intel.com_v1beta1_deployment_cr.yaml b/deploy/common/pmem-csi.intel.com_v1beta1_pmemcsideployment_cr.yaml similarity index 92% rename from deploy/common/pmem-csi.intel.com_v1beta1_deployment_cr.yaml rename to deploy/common/pmem-csi.intel.com_v1beta1_pmemcsideployment_cr.yaml index bf1cfa2ebd..bec9b30be6 100644 --- a/deploy/common/pmem-csi.intel.com_v1beta1_deployment_cr.yaml +++ b/deploy/common/pmem-csi.intel.com_v1beta1_pmemcsideployment_cr.yaml @@ -1,5 +1,5 @@ apiVersion: pmem-csi.intel.com/v1beta1 -kind: Deployment +kind: PmemCSIDeployment metadata: name: pmem-csi.intel.com spec: diff --git a/deploy/crd/pmem-csi.intel.com_deployments.yaml b/deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml similarity index 98% rename from deploy/crd/pmem-csi.intel.com_deployments.yaml rename to deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml index 3d67b1e7e1..c78dcdb934 100644 --- a/deploy/crd/pmem-csi.intel.com_deployments.yaml +++ b/deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml @@ -7,14 +7,16 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.3.0 creationTimestamp: null - name: deployments.pmem-csi.intel.com + name: pmemcsideployments.pmem-csi.intel.com spec: group: pmem-csi.intel.com names: - kind: Deployment - listKind: DeploymentList - plural: deployments - singular: deployment + kind: PmemCSIDeployment + listKind: PmemCSIDeploymentList + plural: pmemcsideployments + shortNames: + - pcd + singular: pmemcsideployment scope: Cluster versions: - additionalPrinterColumns: @@ -36,7 +38,7 @@ spec: name: v1beta1 schema: openAPIV3Schema: - description: Deployment is the Schema for the deployments API + description: PmemCSIDeployment is the Schema for the deployments API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation diff --git a/deploy/kustomize/olm-catalog/kustomization.yaml b/deploy/kustomize/olm-catalog/kustomization.yaml index 47a399da30..2c55ddafca 100644 --- a/deploy/kustomize/olm-catalog/kustomization.yaml +++ b/deploy/kustomize/olm-catalog/kustomization.yaml @@ -2,8 +2,8 @@ bases: - ../operator resources: -- ../../common/pmem-csi.intel.com_v1beta1_deployment_cr.yaml -- ../../crd/pmem-csi.intel.com_deployments.yaml +- ../../common/pmem-csi.intel.com_v1beta1_pmemcsideployment_cr.yaml +- ../../crd/pmem-csi.intel.com_pmemcsideployments.yaml images: - name: intel/pmem-csi-driver diff --git a/deploy/kustomize/operator/operator.yaml b/deploy/kustomize/operator/operator.yaml index 35149ca792..bfdd5c9586 100644 --- a/deploy/kustomize/operator/operator.yaml +++ b/deploy/kustomize/operator/operator.yaml @@ -72,9 +72,9 @@ rules: - apiGroups: - pmem-csi.intel.com resources: - - deployments - - deployments/status - - deployments/finalizers + - pmemcsideployments + - pmemcsideployments/status + - pmemcsideployments/finalizers verbs: - '*' --- diff --git a/deploy/operator/pmem-csi-operator.yaml b/deploy/operator/pmem-csi-operator.yaml index a601c04351..830d21eb42 100644 --- a/deploy/operator/pmem-csi-operator.yaml +++ b/deploy/operator/pmem-csi-operator.yaml @@ -86,9 +86,9 @@ rules: - apiGroups: - pmem-csi.intel.com resources: - - deployments - - deployments/status - - deployments/finalizers + - pmemcsideployments + - pmemcsideployments/status + - pmemcsideployments/finalizers verbs: - '*' --- diff --git a/docs/design.md b/docs/design.md index 362ccbda6b..32b036ce2d 100644 --- a/docs/design.md +++ b/docs/design.md @@ -420,8 +420,8 @@ on a Kubernetes cluster. This operator is based on the CoreOS [operator-sdk](htt tools and APIs. The driver deployment is controlled by a cluster-scoped [custom resource](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) -named [`Deployment`](./install.md#pmem-csi-deployment-crd) in the +named [`PmemCSIDeployment`](./install.md#pmem-csi-deployment-crd) in the `pmem-csi.intel.com/v1beta1` API group. The operator runs inside the cluster and listens for deployment changes. It makes sure that the required Kubernetes -objects are created for a driver deployment. -Refer to [Deployment CRD](./install.md#deployment) for details. +objects are created for a driver deployment. Refer to the PmemCSIDeployment +CRD for details. diff --git a/docs/install.md b/docs/install.md index a862c589b7..2a4288330e 100644 --- a/docs/install.md +++ b/docs/install.md @@ -256,10 +256,10 @@ particular log output in "text" format. ##### Installing the operator from YAML Alternatively, the you can install the operator manually from YAML files. -First install the PMEM-CSI Deployment CRD: +First install the PmemCSIDeployment CRD: ``` console -$ kubectl create -f https://github.com/intel/pmem-csi/raw/devel/deploy/crd/pmem-csi.intel.com_deployments.yaml +$ kubectl create -f https://github.com/intel/pmem-csi/raw/devel/deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml ``` Then install the PMEM-CSI operator itself: @@ -271,17 +271,17 @@ The operator gets deployed in a namespace called 'pmem-csi' which gets created b ##### Create a driver deployment -Once the operator is installed and running, -it is ready to handle PMEM-CSI `Deployment` objects in the `pmem-csi.intel.com` -API group. Refer to the [Deployment CRD API](#PMEM-CSI-Deployment-CRD) for -a complete list of supported properties. +Once the operator is installed and running, it is ready to handle +`PmemCSIDeployment` objects in the `pmem-csi.intel.com` API group. +Refer to the [PmemCSIDeployment CRD API](#PMEM-CSI-Deployment-CRD) +for a complete list of supported properties. Here is a minimal example driver deployment created with a custom resource: ``` ShellSession $ kubectl create -f - < Annotations: API Version: pmem-csi.intel.com/v1beta1 -Kind: Deployment +Kind: PmemCSIDeployment Metadata: Creation Timestamp: 2020-10-07T07:31:58Z Generation: 1 @@ -338,7 +338,7 @@ Metadata: Operation: Update Time: 2020-10-07T07:32:22Z Resource Version: 1235740 - Self Link: /apis/pmem-csi.intel.com/v1beta1/deployments/pmem-csi.intel.com + Self Link: /apis/pmem-csi.intel.com/v1beta1/pmemcsideployments/pmem-csi.intel.com UID: d8635490-53fa-4eec-970d-cd4c76f53b23 Spec: Device Mode: lvm @@ -385,9 +385,9 @@ By default, the operator creates the needed private keys and certificates requir for running the driver as described in the [driver security](./design.md#security) section. Those certificates are generated by the operator using a self-signed CA. This can be overridden with custom keys and certificates by using appropriate fields -in the [deployment specification](#deploymentspec).These encoded certificates and -private keys are made available to driver pods via Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) -by the operator. +in the [PmemCSIDeployment specification](#deploymentspec). These encoded certificates +and private keys are made available to driver pods via Kubernetes +[secrets](https://kubernetes.io/docs/concepts/configuration/secret/) by the operator. **NOTE:** A production deployment that is not supposed to depend on the operator's self-signed CA instead must provide the certificates generated @@ -1203,7 +1203,7 @@ pmem_csi_node_operations_seconds_count{method_name="/csi.v1.Controller/CreateVol ## PMEM-CSI Deployment CRD -`Deployment` is a cluster-scoped Kubernetes resource in the +`PmemCSIDeployment` is a cluster-scoped Kubernetes resource in the `pmem-csi.intel.com` API group. It describes how a PMEM-CSI driver instance is to be created. @@ -1224,14 +1224,19 @@ The name is also used as prefix for the names of all objects created for the deployment and for the local `/var/lib/` state directory on each node. -The current API for PMEM-CSI `Deployment` resources is: +**NOTE**: Starting from release v0.9.0 reconciling of the `Deployment` +CRD in `pmem-csi.intel.com/v1alpha1` API group is not supported by the +PMEM-CSI operator anymore. Such resources in the cluster must be migrated +manually to new the `PmemCSIDeployment` API. -### Deployment +The current API for `PmemCSIDeployment` resources is: + +### PmemCSIDeployment |Field | Type | Description | |---|---|---| -| apiVersion | string | `pmem-csi.intel.com/v1beta1` or `pmem-csi.intel.com/v1alpha1` | -| kind | string | `Deployment`| +| apiVersion | string | `pmem-csi.intel.com/v1beta1` | +| kind | string | `PmemCSIDeployment`| | metadata | [ObjectMeta](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata) | Object metadata, name used for CSI driver and as prefix for sub-objects | | spec | [DeploymentSpec](#deployment-spec) | Specification of the desired behavior of the deployment | @@ -1298,8 +1303,8 @@ active volumes. A PMEM-CSI Deployment's `status` field is a `DeploymentStatus` object, which carries the detailed state of the driver deployment. It is comprised of [deployment conditions](#deployment-conditions), [driver component status](#driver-component-status), -and a `phase` field. The phase of a Deployment is a high-level summary -of where the Deployment is in its lifecycle. +and a `phase` field. The phase of a PMEM-CSI deployment is a high-level summary +of where the the PmemCSIDployment is in its lifecycle. The possible `phase` values and their meaning are as below: @@ -1307,7 +1312,7 @@ The possible `phase` values and their meaning are as below: |---|---| | empty string | A new deployment. | | Running | The operator has determined that the driver is usable1. | -| Failed | For some reason the state of the `Deployment` failed and cannot be progressed. The failure reason is placed in the `DeploymentStatus.Reason` field. | +| Failed | For some reason, the `PmemCSIDeployment` failed and cannot be progressed. The failure reason is placed in the `DeploymentStatus.Reason` field. | 1 This check has not been implemented yet. Instead, the deployment goes straight to `Running` after creating sub-resources. @@ -1339,7 +1344,7 @@ Below are the fields and their meanings of `DriverStatus`: #### Deployment Events -The PMEM-CSI operator posts events on the progress of a `Deployment`. If the +The PMEM-CSI operator posts events on the progress of a `PmemCSIDeployment`. If the deployment is in the `Failed` state, then one can look into the event(s) using `kubectl describe` on that deployment for the detailed failure reason. diff --git a/pkg/apis/pmemcsi/v1beta1/deployment_types.go b/pkg/apis/pmemcsi/v1beta1/deployment_types.go index 016f7b6bbd..9550ee862f 100644 --- a/pkg/apis/pmemcsi/v1beta1/deployment_types.go +++ b/pkg/apis/pmemcsi/v1beta1/deployment_types.go @@ -198,16 +198,16 @@ type DeploymentStatus struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Deployment is the Schema for the deployments API +// PmemCSIDeployment is the Schema for the deployments API // +kubebuilder:subresource:status -// +kubebuilder:resource:path=deployments,scope=Cluster +// +kubebuilder:resource:path=pmemcsideployments,scope=Cluster,shortName=pcd,singular=pmemcsideployment // +kubebuilder:printcolumn:name="DeviceMode",type=string,JSONPath=`.spec.deviceMode` // +kubebuilder:printcolumn:name="NodeSelector",type=string,JSONPath=`.spec.nodeSelector` // +kubebuilder:printcolumn:name="Image",type=string,JSONPath=`.spec.image` // +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.phase` // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` // +kubebuilder:storageversion -type Deployment struct { +type PmemCSIDeployment struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -217,15 +217,15 @@ type Deployment struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// DeploymentList contains a list of Deployment -type DeploymentList struct { +// PmemCSIDeploymentList contains a list of PmemCSIDeployment objects +type PmemCSIDeploymentList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []Deployment `json:"items"` + Items []PmemCSIDeployment `json:"items"` } func init() { - SchemeBuilder.Register(&Deployment{}, &DeploymentList{}) + SchemeBuilder.Register(&PmemCSIDeployment{}, &PmemCSIDeploymentList{}) } const ( @@ -324,7 +324,7 @@ const ( DeploymentPhaseFailed DeploymentPhase = "Failed" ) -func (d *Deployment) SetCondition(t DeploymentConditionType, state corev1.ConditionStatus, reason string) { +func (d *PmemCSIDeployment) SetCondition(t DeploymentConditionType, state corev1.ConditionStatus, reason string) { for _, c := range d.Status.Conditions { if c.Type == t { c.Status = state @@ -341,7 +341,7 @@ func (d *Deployment) SetCondition(t DeploymentConditionType, state corev1.Condit }) } -func (d *Deployment) SetDriverStatus(t DriverType, status, reason string) { +func (d *PmemCSIDeployment) SetDriverStatus(t DriverType, status, reason string) { if d.Status.Components == nil { d.Status.Components = make([]DriverStatus, 2) } @@ -354,7 +354,7 @@ func (d *Deployment) SetDriverStatus(t DriverType, status, reason string) { } // EnsureDefaults make sure that the deployment object has all defaults set properly -func (d *Deployment) EnsureDefaults(operatorImage string) error { +func (d *PmemCSIDeployment) EnsureDefaults(operatorImage string) error { // Validate the given driver mode. // In a realistic case this check might not needed as it should be // handled by JSON schema as we defined deviceMode as enumeration. @@ -463,85 +463,85 @@ func (d *Deployment) EnsureDefaults(operatorImage string) error { // Most objects created for the deployment will use hyphens in the name, sometimes // with an additional suffix like -controller, but others must use the original // name (like the CSIDriver object). -func (d *Deployment) GetHyphenedName() string { +func (d *PmemCSIDeployment) GetHyphenedName() string { return strings.ReplaceAll(d.GetName(), ".", "-") } // RegistrySecretName returns the name of the registry // Secret object used by the deployment -func (d *Deployment) RegistrySecretName() string { +func (d *PmemCSIDeployment) RegistrySecretName() string { return d.GetHyphenedName() + "-registry-secrets" } // NodeSecretName returns the name of the node-controller // Secret object used by the deployment -func (d *Deployment) NodeSecretName() string { +func (d *PmemCSIDeployment) NodeSecretName() string { return d.GetHyphenedName() + "-node-secrets" } // CSIDriverName returns the name of the CSIDriver // object name for the deployment -func (d *Deployment) CSIDriverName() string { +func (d *PmemCSIDeployment) CSIDriverName() string { return d.GetName() } // ControllerServiceName returns the name of the controller // Service object used by the deployment -func (d *Deployment) ControllerServiceName() string { +func (d *PmemCSIDeployment) ControllerServiceName() string { return d.GetHyphenedName() + "-controller" } // MetricsServiceName returns the name of the controller metrics // Service object used by the deployment -func (d *Deployment) MetricsServiceName() string { +func (d *PmemCSIDeployment) MetricsServiceName() string { return d.GetHyphenedName() + "-metrics" } // ServiceAccountName returns the name of the ServiceAccount // object used by the deployment -func (d *Deployment) ServiceAccountName() string { +func (d *PmemCSIDeployment) ServiceAccountName() string { return d.GetHyphenedName() + "-controller" } // ProvisionerRoleName returns the name of the provisioner's // RBAC Role object name used by the deployment -func (d *Deployment) ProvisionerRoleName() string { +func (d *PmemCSIDeployment) ProvisionerRoleName() string { return d.GetHyphenedName() + "-external-provisioner-cfg" } // ProvisionerRoleBindingName returns the name of the provisioner's // RoleBinding object name used by the deployment -func (d *Deployment) ProvisionerRoleBindingName() string { +func (d *PmemCSIDeployment) ProvisionerRoleBindingName() string { return d.GetHyphenedName() + "-csi-provisioner-role-cfg" } // ProvisionerClusterRoleName returns the name of the // provisioner's ClusterRole object name used by the deployment -func (d *Deployment) ProvisionerClusterRoleName() string { +func (d *PmemCSIDeployment) ProvisionerClusterRoleName() string { return d.GetHyphenedName() + "-external-provisioner-runner" } // ProvisionerClusterRoleBindingName returns the name of the // provisioner ClusterRoleBinding object name used by the deployment -func (d *Deployment) ProvisionerClusterRoleBindingName() string { +func (d *PmemCSIDeployment) ProvisionerClusterRoleBindingName() string { return d.GetHyphenedName() + "-csi-provisioner-role" } // NodeDriverName returns the name of the driver // DaemonSet object name used by the deployment -func (d *Deployment) NodeDriverName() string { +func (d *PmemCSIDeployment) NodeDriverName() string { return d.GetHyphenedName() + "-node" } // ControllerDriverName returns the name of the controller // StatefulSet object name used by the deployment -func (d *Deployment) ControllerDriverName() string { +func (d *PmemCSIDeployment) ControllerDriverName() string { return d.GetHyphenedName() + "-controller" } // GetOwnerReference returns self owner reference could be used by other object // to add this deployment to it's owner reference list. -func (d *Deployment) GetOwnerReference() metav1.OwnerReference { +func (d *PmemCSIDeployment) GetOwnerReference() metav1.OwnerReference { blockOwnerDeletion := true isController := true return metav1.OwnerReference{ @@ -559,7 +559,7 @@ func (d *Deployment) GetOwnerReference() metav1.OwnerReference { // - true with nil error if provided certificates are valid. // - false with nil error if no certificates are provided. // - false with appropriate error if invalid/incomplete certificates provided. -func (d *Deployment) HaveCertificatesConfigured() (bool, error) { +func (d *PmemCSIDeployment) HaveCertificatesConfigured() (bool, error) { // Encoded private keys and certificates caCert := d.Spec.CACert registryPrKey := d.Spec.RegistryPrivateKey diff --git a/pkg/apis/pmemcsi/v1beta1/deployment_types_test.go b/pkg/apis/pmemcsi/v1beta1/deployment_types_test.go index 5e839f4a38..5051b52b32 100644 --- a/pkg/apis/pmemcsi/v1beta1/deployment_types_test.go +++ b/pkg/apis/pmemcsi/v1beta1/deployment_types_test.go @@ -35,7 +35,7 @@ var _ = Describe("Operator", func() { Context("API", func() { It("shall set defaults for empty deployment", func() { - d := api.Deployment{} + d := api.PmemCSIDeployment{} err := d.EnsureDefaults("") Expect(err).ShouldNot(HaveOccurred(), "ensure defaults") @@ -80,7 +80,7 @@ var _ = Describe("Operator", func() { }) It("shall be able to set values", func() { - yaml := `kind: Deployment + yaml := `kind: PmemCSIDeployment apiVersion: pmem-csi.intel.com/v1beta1 metadata: name: test-deployment @@ -114,7 +114,7 @@ spec: Expect(err).Should(BeNil(), "Failed to parse deployment") Expect(obj).ShouldNot(BeNil(), "Nil deployment object") - d := obj.(*api.Deployment) + d := obj.(*api.PmemCSIDeployment) err = d.EnsureDefaults("") Expect(err).ShouldNot(HaveOccurred(), "ensure defaults") @@ -148,7 +148,7 @@ spec: It("should have valid json schema", func() { - crdFile := os.Getenv("REPO_ROOT") + "/deploy/crd/pmem-csi.intel.com_deployments.yaml" + crdFile := os.Getenv("REPO_ROOT") + "/deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml" data, err := ioutil.ReadFile(crdFile) Expect(err).ShouldNot(HaveOccurred(), "load crd data") crd := &apiextensions.CustomResourceDefinition{} diff --git a/pkg/apis/pmemcsi/v1beta1/zz_generated.deepcopy.go b/pkg/apis/pmemcsi/v1beta1/zz_generated.deepcopy.go index b8bfa8155a..7d40cf8e3a 100644 --- a/pkg/apis/pmemcsi/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/pmemcsi/v1beta1/zz_generated.deepcopy.go @@ -9,33 +9,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Deployment) DeepCopyInto(out *Deployment) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Deployment. -func (in *Deployment) DeepCopy() *Deployment { - if in == nil { - return nil - } - out := new(Deployment) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Deployment) 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 *DeploymentCondition) DeepCopyInto(out *DeploymentCondition) { *out = *in @@ -52,38 +25,6 @@ func (in *DeploymentCondition) DeepCopy() *DeploymentCondition { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DeploymentList) DeepCopyInto(out *DeploymentList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Deployment, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentList. -func (in *DeploymentList) DeepCopy() *DeploymentList { - if in == nil { - return nil - } - out := new(DeploymentList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DeploymentList) 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 *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) { *out = *in @@ -203,3 +144,62 @@ func (in *DriverStatus) DeepCopy() *DriverStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PmemCSIDeployment) DeepCopyInto(out *PmemCSIDeployment) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PmemCSIDeployment. +func (in *PmemCSIDeployment) DeepCopy() *PmemCSIDeployment { + if in == nil { + return nil + } + out := new(PmemCSIDeployment) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PmemCSIDeployment) 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 *PmemCSIDeploymentList) DeepCopyInto(out *PmemCSIDeploymentList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PmemCSIDeployment, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PmemCSIDeploymentList. +func (in *PmemCSIDeploymentList) DeepCopy() *PmemCSIDeploymentList { + if in == nil { + return nil + } + out := new(PmemCSIDeploymentList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PmemCSIDeploymentList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/pkg/deployments/load.go b/pkg/deployments/load.go index 5b531a5398..81a61222e7 100644 --- a/pkg/deployments/load.go +++ b/pkg/deployments/load.go @@ -33,7 +33,7 @@ var nameRegex = regexp.MustCompile(`(name|app|secretName|serviceName|serviceAcco // LoadAndCustomizeObjects reads all objects stored in a pmem-csi.yaml reference file // and updates them on-the-fly according to the deployment spec, namespace and name. func LoadAndCustomizeObjects(kubernetes version.Version, deviceMode api.DeviceMode, - namespace string, deployment api.Deployment) ([]unstructured.Unstructured, error) { + namespace string, deployment api.PmemCSIDeployment) ([]unstructured.Unstructured, error) { // Conceptually this function is similar to calling "kustomize" for // our deployments. But because we controll the input, we can do some @@ -124,7 +124,7 @@ func LoadAndCustomizeObjects(kubernetes version.Version, deviceMode api.DeviceMo return loadObjects(kubernetes, deviceMode, patchYAML, patchUnstructured) } -func patchPodTemplate(obj *unstructured.Unstructured, deployment api.Deployment, resources map[string]*corev1.ResourceRequirements) error { +func patchPodTemplate(obj *unstructured.Unstructured, deployment api.PmemCSIDeployment, resources map[string]*corev1.ResourceRequirements) error { if resources == nil { return nil } diff --git a/pkg/deployments/load_test.go b/pkg/deployments/load_test.go index 3a44dc7904..4c9ed82d4b 100644 --- a/pkg/deployments/load_test.go +++ b/pkg/deployments/load_test.go @@ -46,7 +46,7 @@ func TestLoadObjects(t *testing.T) { // currently run as part of test/e2e/operator API testing, with // the code in controller_driver.go serving as reference. namespace := "kube-system" - deployment := api.Deployment{ + deployment := api.PmemCSIDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: "pmem-csi.example.org", }, diff --git a/pkg/pmem-csi-operator/controller/deployment/controller_driver.go b/pkg/pmem-csi-operator/controller/deployment/controller_driver.go index 7f2874c878..3b707e4414 100644 --- a/pkg/pmem-csi-operator/controller/deployment/controller_driver.go +++ b/pkg/pmem-csi-operator/controller/deployment/controller_driver.go @@ -106,7 +106,7 @@ func AllObjectLists() []*unstructured.UnstructuredList { // pmemCSIDeployment represents the desired state of a PMEM-CSI driver // deployment. type pmemCSIDeployment struct { - *api.Deployment + *api.PmemCSIDeployment // operator's namespace used for creating sub-resources namespace string k8sVersion version.Version @@ -577,7 +577,7 @@ func (d *pmemCSIDeployment) handleEvent(ctx context.Context, metaData metav1.Obj if _, err := d.redeploy(ctx, r, handler); err != nil { return fmt.Errorf("failed to redeploy %s: %v", name, err) } - if err := r.patchDeploymentStatus(d.Deployment, client.MergeFrom(org)); err != nil { + if err := r.patchDeploymentStatus(d.PmemCSIDeployment, client.MergeFrom(org)); err != nil { return fmt.Errorf("failed to update deployment CR status: %v", err) } } diff --git a/pkg/pmem-csi-operator/controller/deployment/deployment_controller.go b/pkg/pmem-csi-operator/controller/deployment/deployment_controller.go index 56e3f7f486..8c90ac6de7 100644 --- a/pkg/pmem-csi-operator/controller/deployment/deployment_controller.go +++ b/pkg/pmem-csi-operator/controller/deployment/deployment_controller.go @@ -110,7 +110,7 @@ func add(ctx context.Context, mgr manager.Manager, r *ReconcileDeployment) error } // Watch for changes to primary resource Deployment - if err := c.Watch(&source.Kind{Type: &api.Deployment{}}, &handler.EnqueueRequestForObject{}, p); err != nil { + if err := c.Watch(&source.Kind{Type: &api.PmemCSIDeployment{}}, &handler.EnqueueRequestForObject{}, p); err != nil { return fmt.Errorf("watch: %v", err) } @@ -168,7 +168,7 @@ func add(ctx context.Context, mgr manager.Manager, r *ReconcileDeployment) error for _, resource := range currentObjects { if err := c.Watch(&source.Kind{Type: resource}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &api.Deployment{}, + OwnerType: &api.PmemCSIDeployment{}, }, sop); err != nil { return fmt.Errorf("create watch: %v", err) } @@ -181,7 +181,7 @@ func add(ctx context.Context, mgr manager.Manager, r *ReconcileDeployment) error var _ reconcile.Reconciler = &ReconcileDeployment{} // ReconcileHook function to be invoked on reconciling a deployment. -type ReconcileHook *func(d *api.Deployment) +type ReconcileHook *func(d *api.PmemCSIDeployment) // ReconcileDeployment reconciles a Deployment object type ReconcileDeployment struct { @@ -197,7 +197,7 @@ type ReconcileDeployment struct { // container image used for deploying the operator containerImage string // known deployments - deployments map[string]*api.Deployment + deployments map[string]*api.PmemCSIDeployment // deploymentsMutex protects concurrent access to deployments deploymentsMutex sync.Mutex // reconcileMutex synchronizes concurrent reconcile calls @@ -246,7 +246,7 @@ func NewReconcileDeployment(ctx context.Context, client client.Client, opts pmem k8sVersion: opts.K8sVersion, namespace: opts.Namespace, containerImage: opts.DriverImage, - deployments: map[string]*api.Deployment{}, + deployments: map[string]*api.PmemCSIDeployment{}, reconcileHooks: map[ReconcileHook]struct{}{}, }, nil } @@ -268,7 +268,7 @@ func (r *ReconcileDeployment) Reconcile(request reconcile.Request) (reconcile.Re ctx := logger.Set(r.ctx, l) // Fetch the Deployment instance - deployment := &api.Deployment{} + deployment := &api.PmemCSIDeployment{} err = r.client.Get(ctx, request.NamespacedName, deployment) if err != nil { l.Error(err, "failed to retrieve CR to reconcile", "deployment", request.Name) @@ -375,7 +375,7 @@ func (r *ReconcileDeployment) Delete(obj runtime.Object) error { } // PatchDeploymentStatus patches the give given deployment CR status -func (r *ReconcileDeployment) patchDeploymentStatus(dep *api.Deployment, patch client.Patch) error { +func (r *ReconcileDeployment) patchDeploymentStatus(dep *api.PmemCSIDeployment, patch client.Patch) error { dep.Status.LastUpdated = metav1.Now() // Passing a copy of CR to patch as the fake client used in tests // will write back the changes to both status and spec. @@ -387,13 +387,13 @@ func (r *ReconcileDeployment) patchDeploymentStatus(dep *api.Deployment, patch c return nil } -func (r *ReconcileDeployment) saveDeployment(d *api.Deployment) { +func (r *ReconcileDeployment) saveDeployment(d *api.PmemCSIDeployment) { r.deploymentsMutex.Lock() defer r.deploymentsMutex.Unlock() r.deployments[d.Name] = d } -func (r *ReconcileDeployment) getDeployment(name string) *api.Deployment { +func (r *ReconcileDeployment) getDeployment(name string) *api.PmemCSIDeployment { r.deploymentsMutex.Lock() defer r.deploymentsMutex.Unlock() return r.deployments[name] diff --git a/pkg/pmem-csi-operator/controller/deployment/deployment_controller_test.go b/pkg/pmem-csi-operator/controller/deployment/deployment_controller_test.go index d234d29c45..ccf261d4bb 100644 --- a/pkg/pmem-csi-operator/controller/deployment/deployment_controller_test.go +++ b/pkg/pmem-csi-operator/controller/deployment/deployment_controller_test.go @@ -57,10 +57,10 @@ type pmemDeployment struct { kubeletDir string } -func getDeployment(d *pmemDeployment) *api.Deployment { - dep := &api.Deployment{ +func getDeployment(d *pmemDeployment) *api.PmemCSIDeployment { + dep := &api.PmemCSIDeployment{ TypeMeta: metav1.TypeMeta{ - Kind: "Deployment", + Kind: "PmemCSIDeployment", APIVersion: api.SchemeGroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{ @@ -126,7 +126,7 @@ func getDeployment(d *pmemDeployment) *api.Deployment { } func testDeploymentPhase(t *testing.T, c client.Client, name string, expectedPhase api.DeploymentPhase) { - depObject := &api.Deployment{ + depObject := &api.PmemCSIDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -179,7 +179,7 @@ func objectKey(name string, namespace ...string) client.ObjectKey { } func deleteDeployment(c client.Client, name, ns string) error { - dep := &api.Deployment{} + dep := &api.PmemCSIDeployment{} key := objectKey(name) if err := c.Get(context.TODO(), key, dep); err != nil { return err @@ -262,7 +262,7 @@ func TestDeploymentController(t *testing.T) { } } - validateEvents := func(tc *testContext, dep *api.Deployment, expectedEvents []string) { + validateEvents := func(tc *testContext, dep *api.PmemCSIDeployment, expectedEvents []string) { require.Eventually(tc.t, func() bool { return len(tc.events) >= len(expectedEvents) }, 30*time.Second, time.Second, "receive all expected events") @@ -276,7 +276,7 @@ func TestDeploymentController(t *testing.T) { } validateConditions := func(tc *testContext, name string, expected map[api.DeploymentConditionType]corev1.ConditionStatus) { - dep := &api.Deployment{ + dep := &api.PmemCSIDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -290,9 +290,9 @@ func TestDeploymentController(t *testing.T) { } } - validateDriver := func(tc *testContext, dep *api.Deployment, expectedEvents []string, wasUpdated bool) { + validateDriver := func(tc *testContext, dep *api.PmemCSIDeployment, expectedEvents []string, wasUpdated bool) { // We may have to fill in some defaults, so make a copy first. - dep = dep.DeepCopyObject().(*api.Deployment) + dep = dep.DeepCopyObject().(*api.PmemCSIDeployment) if dep.Spec.Image == "" { dep.Spec.Image = testDriverImage } @@ -595,13 +595,13 @@ func TestDeploymentController(t *testing.T) { name: "modified-deployment", } - var updatedDep *api.Deployment + var updatedDep *api.PmemCSIDeployment dep := getDeployment(d) err := tc.c.Create(tc.ctx, dep) require.NoError(t, err, "failed to create deployment") - hook := func(d *api.Deployment) { + hook := func(d *api.PmemCSIDeployment) { updatedDep = d.DeepCopy() updatedDep.Spec.LogLevel++ err := tc.c.Update(tc.ctx, updatedDep) @@ -634,7 +634,7 @@ func TestDeploymentController(t *testing.T) { testIt := func(restart bool) { tc := setup(t) defer teardown(tc) - dep := testcase.Deployment.DeepCopyObject().(*api.Deployment) + dep := testcase.Deployment.DeepCopyObject().(*api.PmemCSIDeployment) // Assumption is that all the testcases are positive cases. conditions := map[api.DeploymentConditionType]corev1.ConditionStatus{ diff --git a/pkg/pmem-csi-operator/controller/deployment/testcases/testcases.go b/pkg/pmem-csi-operator/controller/deployment/testcases/testcases.go index 47f49e7081..c0562b7965 100644 --- a/pkg/pmem-csi-operator/controller/deployment/testcases/testcases.go +++ b/pkg/pmem-csi-operator/controller/deployment/testcases/testcases.go @@ -23,25 +23,25 @@ import ( // change one or more fields in it. type UpdateTest struct { Name string - Deployment api.Deployment - Mutate func(d *api.Deployment) + Deployment api.PmemCSIDeployment + Mutate func(d *api.PmemCSIDeployment) } func UpdateTests() []UpdateTest { - singleMutators := map[string]func(d *api.Deployment){ - "image": func(d *api.Deployment) { + singleMutators := map[string]func(d *api.PmemCSIDeployment){ + "image": func(d *api.PmemCSIDeployment) { d.Spec.Image = "updated-image" }, - "pullPolicy": func(d *api.Deployment) { + "pullPolicy": func(d *api.PmemCSIDeployment) { d.Spec.PullPolicy = corev1.PullNever }, - "provisionerImage": func(d *api.Deployment) { + "provisionerImage": func(d *api.PmemCSIDeployment) { d.Spec.ProvisionerImage = "still-no-such-provisioner-image" }, - "nodeRegistrarImage": func(d *api.Deployment) { + "nodeRegistrarImage": func(d *api.PmemCSIDeployment) { d.Spec.NodeRegistrarImage = "still-no-such-registrar-image" }, - "controllerDriverResources": func(d *api.Deployment) { + "controllerDriverResources": func(d *api.PmemCSIDeployment) { d.Spec.ControllerDriverResources = &corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("201m"), @@ -49,7 +49,7 @@ func UpdateTests() []UpdateTest { }, } }, - "nodeDriverResources": func(d *api.Deployment) { + "nodeDriverResources": func(d *api.PmemCSIDeployment) { d.Spec.NodeDriverResources = &corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("501m"), @@ -57,7 +57,7 @@ func UpdateTests() []UpdateTest { }, } }, - "provisionerResources": func(d *api.Deployment) { + "provisionerResources": func(d *api.PmemCSIDeployment) { d.Spec.ProvisionerResources = &corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("101m"), @@ -65,7 +65,7 @@ func UpdateTests() []UpdateTest { }, } }, - "nodeRegistrarResources": func(d *api.Deployment) { + "nodeRegistrarResources": func(d *api.PmemCSIDeployment) { d.Spec.NodeRegistrarResources = &corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("301m"), @@ -73,39 +73,39 @@ func UpdateTests() []UpdateTest { }, } }, - "TLS": func(d *api.Deployment) { + "TLS": func(d *api.PmemCSIDeployment) { SetTLSOrDie(&d.Spec) }, - "logLevel": func(d *api.Deployment) { + "logLevel": func(d *api.PmemCSIDeployment) { d.Spec.LogLevel++ }, - "logFormat": func(d *api.Deployment) { + "logFormat": func(d *api.PmemCSIDeployment) { if d.Spec.LogFormat == api.LogFormatText { d.Spec.LogFormat = api.LogFormatJSON } else { d.Spec.LogFormat = api.LogFormatText } }, - "nodeSelector": func(d *api.Deployment) { + "nodeSelector": func(d *api.PmemCSIDeployment) { d.Spec.NodeSelector = map[string]string{ "still-no-such-label": "still-no-such-value", } }, - "pmemPercentage": func(d *api.Deployment) { + "pmemPercentage": func(d *api.PmemCSIDeployment) { d.Spec.PMEMPercentage++ }, - "labels": func(d *api.Deployment) { + "labels": func(d *api.PmemCSIDeployment) { if d.Spec.Labels == nil { d.Spec.Labels = map[string]string{} } d.Spec.Labels["foo"] = "bar" }, - "kubeletDir": func(d *api.Deployment) { + "kubeletDir": func(d *api.PmemCSIDeployment) { d.Spec.KubeletDir = "/foo/bar" }, } - full := api.Deployment{ + full := api.PmemCSIDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: "pmem-csi-with-values", }, @@ -168,7 +168,7 @@ func UpdateTests() []UpdateTest { } SetTLSOrDie(&full.Spec) - baseDeployments := map[string]api.Deployment{ + baseDeployments := map[string]api.PmemCSIDeployment{ "default deployment": { ObjectMeta: metav1.ObjectMeta{ Name: "pmem-csi-with-defaults", @@ -177,7 +177,7 @@ func UpdateTests() []UpdateTest { "deployment with specific values": full, } - updateAll := func(d *api.Deployment) { + updateAll := func(d *api.PmemCSIDeployment) { for _, mutator := range singleMutators { mutator(d) } diff --git a/pkg/pmem-csi-operator/main.go b/pkg/pmem-csi-operator/main.go index c72d8d707e..703f33f407 100644 --- a/pkg/pmem-csi-operator/main.go +++ b/pkg/pmem-csi-operator/main.go @@ -121,7 +121,7 @@ func Main() int { return 1 } - list := &api.DeploymentList{} + list := &api.PmemCSIDeploymentList{} if err := mgr.GetClient().List(ctx, list); err != nil { pmemcommon.ExitError("failed to get deployment list: %v", err) return 1 diff --git a/test/e2e/deploy/deploy.go b/test/e2e/deploy/deploy.go index d378278c20..e00bac0ed7 100644 --- a/test/e2e/deploy/deploy.go +++ b/test/e2e/deploy/deploy.go @@ -352,7 +352,7 @@ func RemoveObjects(c *Cluster, deployment *Deployment) error { // restarting things that we want removed. if list, err := c.dc.Resource(DeploymentResource).List(context.Background(), filter); !failure(err) && list != nil { for _, object := range list.Items { - deployment := api.Deployment{} + deployment := api.PmemCSIDeployment{} err := Scheme.Convert(&object, &deployment, nil) framework.ExpectNoError(err, "convert %v to PMEM-CSI deployment", object) del(deployment.ObjectMeta, deployment, func() error { @@ -923,13 +923,13 @@ func EnsureDeploymentNow(f *framework.Framework, deployment *Deployment) { // GetDriverDeployment returns the spec for the driver deployment that is used // for deployments like operator-lvm-production. -func (d *Deployment) GetDriverDeployment() api.Deployment { - return api.Deployment{ +func (d *Deployment) GetDriverDeployment() api.PmemCSIDeployment { + return api.PmemCSIDeployment{ // TypeMeta is needed because // DefaultUnstructuredConverter does not add it for us. Is there a better way? TypeMeta: metav1.TypeMeta{ APIVersion: api.SchemeGroupVersion.String(), - Kind: "Deployment", + Kind: "PmemCSIDeployment", }, ObjectMeta: metav1.ObjectMeta{ Name: "pmem-csi", diff --git a/test/e2e/deploy/operator.go b/test/e2e/deploy/operator.go index 71e751f768..6a9a9970b2 100644 --- a/test/e2e/deploy/operator.go +++ b/test/e2e/deploy/operator.go @@ -26,13 +26,13 @@ var ( DeploymentResource = schema.GroupVersionResource{ Group: api.SchemeGroupVersion.Group, Version: api.SchemeGroupVersion.Version, - Resource: "deployments", + Resource: "pmemcsideployments", } Scheme = runtime.NewScheme() ) func init() { - api.SchemeBuilder.Register(&api.Deployment{}, &api.DeploymentList{}) + api.SchemeBuilder.Register(&api.PmemCSIDeployment{}, &api.PmemCSIDeploymentList{}) err := apis.AddToScheme(Scheme) if err != nil { panic(err) @@ -53,11 +53,11 @@ func deploymentToUnstructured(in interface{}, gvk schema.GroupVersionKind) *unst return &out } -func DeploymentToUnstructured(in *api.Deployment) *unstructured.Unstructured { +func DeploymentToUnstructured(in *api.PmemCSIDeployment) *unstructured.Unstructured { return deploymentToUnstructured(in, schema.GroupVersionKind{ Group: api.SchemeGroupVersion.Group, Version: api.SchemeGroupVersion.Version, - Kind: "Deployment", + Kind: "PmemCSIDeployment", }) } @@ -66,11 +66,11 @@ func deploymentFromUnstructured(in *unstructured.Unstructured, out interface{}) framework.ExpectNoError(err, "convert from unstructured deployment") } -func DeploymentFromUnstructured(in *unstructured.Unstructured) *api.Deployment { +func DeploymentFromUnstructured(in *unstructured.Unstructured) *api.PmemCSIDeployment { if in == nil { return nil } - var out api.Deployment + var out api.PmemCSIDeployment deploymentFromUnstructured(in, &out) return &out } @@ -87,14 +87,14 @@ func createDeploymentCR(f *framework.Framework, dep *unstructured.Unstructured, return out } -func CreateDeploymentCR(f *framework.Framework, dep api.Deployment) api.Deployment { +func CreateDeploymentCR(f *framework.Framework, dep api.PmemCSIDeployment) api.PmemCSIDeployment { in := DeploymentToUnstructured(&dep) out := createDeploymentCR(f, in, DeploymentResource) framework.Logf("Created deployment %q = (%+v)", dep.Name, out) return *DeploymentFromUnstructured(out) } -func EnsureDeploymentCR(f *framework.Framework, dep api.Deployment) api.Deployment { +func EnsureDeploymentCR(f *framework.Framework, dep api.PmemCSIDeployment) api.PmemCSIDeployment { var out *unstructured.Unstructured gomega.Eventually(func() error { existingDep, err := f.DynamicClient.Resource(DeploymentResource).Get(context.Background(), dep.Name, metav1.GetOptions{}) @@ -133,7 +133,7 @@ func DeleteDeploymentCR(f *framework.Framework, name string) { framework.Logf("Deleted deployment %q", name) } -func UpdateDeploymentCR(f *framework.Framework, dep api.Deployment) api.Deployment { +func UpdateDeploymentCR(f *framework.Framework, dep api.PmemCSIDeployment) api.PmemCSIDeployment { var out *unstructured.Unstructured gomega.Eventually(func() error { @@ -152,7 +152,7 @@ func UpdateDeploymentCR(f *framework.Framework, dep api.Deployment) api.Deployme return *DeploymentFromUnstructured(out) } -func GetDeploymentCR(f *framework.Framework, name string) api.Deployment { +func GetDeploymentCR(f *framework.Framework, name string) api.PmemCSIDeployment { var out *unstructured.Unstructured gomega.Eventually(func() error { var err error diff --git a/test/e2e/operator/deployment_api.go b/test/e2e/operator/deployment_api.go index 4ac6c9c777..6e550053f7 100644 --- a/test/e2e/operator/deployment_api.go +++ b/test/e2e/operator/deployment_api.go @@ -49,8 +49,8 @@ import ( // because these tests do not actually need a running driver. const dummyImage = "unexisting/pmem-csi-driver" -func getDeployment(name string) api.Deployment { - return api.Deployment{ +func getDeployment(name string) api.PmemCSIDeployment { + return api.PmemCSIDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -121,7 +121,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { cancel() }) - validateDriver := func(deployment api.Deployment, what ...interface{}) { + validateDriver := func(deployment api.PmemCSIDeployment, what ...interface{}) { framework.Logf("waiting for expected driver deployment %s", deployment.Name) if what == nil { what = []interface{}{"validate driver"} @@ -150,7 +150,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { } } - validateEvents := func(dep *api.Deployment, expectedEvents []string, what ...interface{}) { + validateEvents := func(dep *api.PmemCSIDeployment, expectedEvents []string, what ...interface{}) { if what == nil { what = []interface{}{"validate events"} } @@ -187,7 +187,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { Context("deployment", func() { - tests := map[string]api.Deployment{ + tests := map[string]api.PmemCSIDeployment{ "with defaults": getDeployment("test-deployment-with-defaults"), "with explicit values": { ObjectMeta: metav1.ObjectMeta{ @@ -261,7 +261,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { // Run in-cluster kubectl from master node ssh := os.Getenv("REPO_ROOT") + "/_work/" + os.Getenv("CLUSTER") + "/ssh.0" - out, err := exec.RunCommand(ssh, "kubectl", "get", "deployments.pmem-csi.intel.com", "--no-headers") + out, err := exec.RunCommand(ssh, "kubectl", "get", "pmemcsideployments.pmem-csi.intel.com", "--no-headers") Expect(err).ShouldNot(HaveOccurred(), "kubectl get: %v", out) Expect(out).Should(MatchRegexp(`%s\s+%s\s+.*"?%s"?:"?%s"?.*\s+%s\s+%s\s+[0-9]+(s|m)`, d.Name, d.Spec.DeviceMode, lblKey, lblValue, d.Spec.Image, d.Status.Phase), "fields mismatch") @@ -559,7 +559,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { postSwitch := postSwitch It(name, func() { driverName := ctx + "-" + strings.Replace(name, " ", "-", -1) - deployment := api.Deployment{ + deployment := api.PmemCSIDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: driverName, }, @@ -623,7 +623,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { testcase := testcase Context(testcase.Name, func() { testIt := func(restart bool) { - deployment := *testcase.Deployment.DeepCopyObject().(*api.Deployment) + deployment := *testcase.Deployment.DeepCopyObject().(*api.PmemCSIDeployment) // Use fake images to prevent pods from actually starting. deployment.Spec.Image = dummyImage @@ -674,65 +674,65 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { Context("recover", func() { Context("deleted sub-resources", func() { - tests := map[string]func(*api.Deployment) apiruntime.Object{ - "registry secret": func(dep *api.Deployment) apiruntime.Object { + tests := map[string]func(*api.PmemCSIDeployment) apiruntime.Object{ + "registry secret": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: dep.RegistrySecretName(), Namespace: d.Namespace, }, } }, - "node secret": func(dep *api.Deployment) apiruntime.Object { + "node secret": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Name: dep.NodeSecretName(), Namespace: d.Namespace}, } }, - "service account": func(dep *api.Deployment) apiruntime.Object { + "service account": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{Name: dep.ServiceAccountName(), Namespace: d.Namespace}, } }, - "controller service": func(dep *api.Deployment) apiruntime.Object { + "controller service": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{Name: dep.ControllerServiceName(), Namespace: d.Namespace}, } }, - "metrics service": func(dep *api.Deployment) apiruntime.Object { + "metrics service": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{Name: dep.MetricsServiceName(), Namespace: d.Namespace}, } }, - "provisioner role": func(dep *api.Deployment) apiruntime.Object { + "provisioner role": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{Name: dep.ProvisionerRoleName(), Namespace: d.Namespace}, } }, - "provisioner role binding": func(dep *api.Deployment) apiruntime.Object { + "provisioner role binding": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{Name: dep.ProvisionerRoleBindingName(), Namespace: d.Namespace}, } }, - "provisioner cluster role": func(dep *api.Deployment) apiruntime.Object { + "provisioner cluster role": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &rbacv1.ClusterRole{ ObjectMeta: metav1.ObjectMeta{Name: dep.ProvisionerClusterRoleName()}, } }, - "provisioner cluster role binding": func(dep *api.Deployment) apiruntime.Object { + "provisioner cluster role binding": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &rbacv1.ClusterRoleBinding{ ObjectMeta: metav1.ObjectMeta{Name: dep.ProvisionerClusterRoleBindingName()}, } }, - "csi driver": func(dep *api.Deployment) apiruntime.Object { + "csi driver": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &storagev1beta1.CSIDriver{ ObjectMeta: metav1.ObjectMeta{Name: dep.GetName()}, } }, - "controller driver": func(dep *api.Deployment) apiruntime.Object { + "controller driver": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{Name: dep.ControllerDriverName(), Namespace: d.Namespace}, } }, - "node driver": func(dep *api.Deployment) apiruntime.Object { + "node driver": func(dep *api.PmemCSIDeployment) apiruntime.Object { return &appsv1.DaemonSet{ ObjectMeta: metav1.ObjectMeta{Name: dep.NodeDriverName(), Namespace: d.Namespace}, } @@ -768,8 +768,8 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { }) Context("conflicting update", func() { - tests := map[string]func(dep *api.Deployment) apiruntime.Object{ - "controller": func(dep *api.Deployment) apiruntime.Object { + tests := map[string]func(dep *api.PmemCSIDeployment) apiruntime.Object{ + "controller": func(dep *api.PmemCSIDeployment) apiruntime.Object { obj := &appsv1.StatefulSet{} key := runtime.ObjectKey{Name: dep.ControllerDriverName(), Namespace: d.Namespace} EventuallyWithOffset(1, func() error { @@ -784,7 +784,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { } return obj }, - "node driver": func(dep *api.Deployment) apiruntime.Object { + "node driver": func(dep *api.PmemCSIDeployment) apiruntime.Object { obj := &appsv1.DaemonSet{} key := runtime.ObjectKey{Name: dep.NodeDriverName(), Namespace: d.Namespace} EventuallyWithOffset(1, func() error { @@ -799,7 +799,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { } return obj }, - "metrics service": func(dep *api.Deployment) apiruntime.Object { + "metrics service": func(dep *api.PmemCSIDeployment) apiruntime.Object { obj := &corev1.Service{} key := runtime.ObjectKey{Name: dep.MetricsServiceName(), Namespace: d.Namespace} EventuallyWithOffset(1, func() error { @@ -815,7 +815,7 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { } return obj }, - "controller service": func(dep *api.Deployment) apiruntime.Object { + "controller service": func(dep *api.PmemCSIDeployment) apiruntime.Object { obj := &corev1.Service{} key := runtime.ObjectKey{Name: dep.ControllerServiceName(), Namespace: d.Namespace} EventuallyWithOffset(1, func() error { @@ -860,18 +860,22 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool { versions := map[string]schema.GroupVersionResource{ "v1beta1": deploy.DeploymentResource, } - for name, gvr := range versions { + for version, gvr := range versions { gvr := gvr - Context(name, func() { + Context(version, func() { toUnstructured := func(in interface{}) *unstructured.Unstructured { var out unstructured.Unstructured err := deploy.Scheme.Convert(in, &out, nil) framework.ExpectNoError(err, "convert to unstructured deployment") - out.SetGroupVersionKind(schema.GroupVersionKind{ + gvk := schema.GroupVersionKind{ Group: gvr.Group, Version: gvr.Version, Kind: "Deployment", - }) + } + if version == "v1beta1" { + gvk.Kind = "PmemCSIDeployment" + } + out.SetGroupVersionKind(gvk) return &out } @@ -1032,7 +1036,7 @@ func startOperator(c *deploy.Cluster, d *deploy.Deployment) { framework.Logf("Operator is restored!") } -func switchDeploymentMode(c *deploy.Cluster, f *framework.Framework, depName, ns string, mode api.DeviceMode) api.Deployment { +func switchDeploymentMode(c *deploy.Cluster, f *framework.Framework, depName, ns string, mode api.DeviceMode) api.PmemCSIDeployment { podNames := []string{} for i := 1; i < c.NumNodes(); i++ { diff --git a/test/e2e/operator/validate/validate.go b/test/e2e/operator/validate/validate.go index dfeecd46c9..14801cdaa2 100644 --- a/test/e2e/operator/validate/validate.go +++ b/test/e2e/operator/validate/validate.go @@ -36,7 +36,7 @@ import ( // objects for a certain deployment spec. deploymentSpec should only have those fields // set which are not the defaults. This call will wait for the expected objects until // the context times out. -func DriverDeploymentEventually(ctx context.Context, client client.Client, k8sver version.Version, namespace string, deployment api.Deployment, initialCreation bool) error { +func DriverDeploymentEventually(ctx context.Context, client client.Client, k8sver version.Version, namespace string, deployment api.PmemCSIDeployment, initialCreation bool) error { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() @@ -106,7 +106,7 @@ func DriverDeploymentEventually(ctx context.Context, client client.Client, k8sve // // A final error is returned when observing a problem that is not going to go away, // like an unexpected update of an object. -func DriverDeployment(client client.Client, k8sver version.Version, namespace string, deployment api.Deployment, resourceVersions map[string]string) (final bool, finalErr error) { +func DriverDeployment(client client.Client, k8sver version.Version, namespace string, deployment api.PmemCSIDeployment, resourceVersions map[string]string) (final bool, finalErr error) { if deployment.GetUID() == "" { return true, errors.New("deployment not an object that was stored in the API server, no UID") } @@ -495,7 +495,7 @@ func prettyPrintObjectID(object unstructured.Unstructured) string { object.GetNamespace()) } -func listAllDeployedObjects(c client.Client, deployment api.Deployment, namespace string) ([]unstructured.Unstructured, error) { +func listAllDeployedObjects(c client.Client, deployment api.PmemCSIDeployment, namespace string) ([]unstructured.Unstructured, error) { objects := []unstructured.Unstructured{} for _, list := range operatordeployment.AllObjectLists() { diff --git a/test/start-operator.sh b/test/start-operator.sh index a84dc0ea7b..7a9665b41f 100755 --- a/test/start-operator.sh +++ b/test/start-operator.sh @@ -75,7 +75,7 @@ function deploy_using_olm() { } function deploy_using_yaml() { - crd=${REPO_DIRECTORY}/deploy/crd/pmem-csi.intel.com_deployments.yaml + crd=${REPO_DIRECTORY}/deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml echo "Deploying '${crd}'..." sed -e "s;\(namespace: \)pmem-csi$;\1${TEST_OPERATOR_NAMESPACE};g" ${crd} | ${SSH} kubectl apply -f - @@ -143,5 +143,5 @@ esac cat <&1 | grep -v NotFound || true echo "Deleting CRD..." - ${KUBECTL} delete crd deployments.pmem-csi.intel.com + ${KUBECTL} delete crd/pmemcsideployments.pmem-csi.intel.com } deploy_method=yaml