diff --git a/Documentation/helm-operator.md b/Documentation/helm-operator.md index b3ecea845..f903941e0 100644 --- a/Documentation/helm-operator.md +++ b/Documentation/helm-operator.md @@ -124,12 +124,15 @@ The following tables lists the configurable parameters of the rook-operator char | `csi.cephFSProvisionerNodeAffinity` | The node labels for affinity of the CephCSI CephFS provisioner deployment (***) | | | `csi.cephFSPluginTolerations` | Array of tolerations in YAML format which will be added to CephCSI CephFS plugin DaemonSet | | | `csi.cephFSPluginNodeAffinity` | The node labels for affinity of the CephCSI CephFS plugin DaemonSet (***) | | +| `csi.nfsProvisionerTolerations` | Array of tolerations in YAML format which will be added to CephCSI NFS provisioner deployment. | | +| `csi.nfsProvisionerNodeAffinity` | The node labels for affinity of the CephCSI NFS provisioner deployment (***) | | | `csi.nfsPluginTolerations` | Array of tolerations in YAML format which will be added to CephCSI NFS plugin DaemonSet | | | `csi.nfsPluginNodeAffinity` | The node labels for affinity of the CephCSI NFS plugin DaemonSet (***) | | | `csi.csiRBDProvisionerResource` | CEPH CSI RBD provisioner resource requirement list. | | | `csi.csiRBDPluginResource` | CEPH CSI RBD plugin resource requirement list. | | | `csi.csiCephFSProvisionerResource` | CEPH CSI CephFS provisioner resource requirement list. | | | `csi.csiCephFSPluginResource` | CEPH CSI CephFS plugin resource requirement list. | | +| `csi.csiNFSProvisionerResource` | CEPH CSI NFS provisioner resource requirement list. | | | `csi.csiNFSPluginResource` | CEPH CSI NFS plugin resource requirement list. | | | `csi.cephfsGrpcMetricsPort` | CSI CephFS driver GRPC metrics port. | `9091` | | `csi.cephfsLivenessMetricsPort` | CSI CephFS driver metrics port. | `9081` | diff --git a/deploy/charts/rook-ceph/templates/clusterrole.yaml b/deploy/charts/rook-ceph/templates/clusterrole.yaml index d2f2a5890..ddd4e315a 100644 --- a/deploy/charts/rook-ceph/templates/clusterrole.yaml +++ b/deploy/charts/rook-ceph/templates/clusterrole.yaml @@ -397,6 +397,38 @@ rules: resources: ["configmaps"] verbs: ["get", "list"] --- +{{- if .Values.csi.nfs.enabled }} +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: ceph-nfs-external-provisioner-runner +rules: + - apiGroups: [""] + resources: ["persistentvolumes"] + verbs: ["get", "list", "watch", "create", "delete"] + - apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["get", "list", "watch", "update"] + - apiGroups: ["storage.k8s.io"] + resources: ["storageclasses"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["events"] + verbs: ["get", "list", "watch", "create", "update", "patch"] + - apiGroups: ["storage.k8s.io"] + resources: ["csinodes"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["nodes"] + verbs: ["get", "list", "watch"] + - apiGroups: ["coordination.k8s.io"] + resources: ["leases"] + verbs: ["get", "list", "watch", "create", "update", "patch"] + - apiGroups: [""] + resources: ["secrets"] + verbs: ["get"] +--- +{{ end }} kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: diff --git a/deploy/charts/rook-ceph/templates/clusterrolebinding.yaml b/deploy/charts/rook-ceph/templates/clusterrolebinding.yaml index c99ec442c..eab75c715 100644 --- a/deploy/charts/rook-ceph/templates/clusterrolebinding.yaml +++ b/deploy/charts/rook-ceph/templates/clusterrolebinding.yaml @@ -87,6 +87,21 @@ roleRef: name: cephfs-external-provisioner-runner apiGroup: rbac.authorization.k8s.io --- +{{- if .Values.csi.nfs.enabled }} +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: ceph-nfs-csi-provisioner-role +subjects: + - kind: ServiceAccount + name: rook-csi-nfs-provisioner-sa + namespace: {{ .Release.Namespace }} # namespace:operator +roleRef: + kind: ClusterRole + name: ceph-nfs-external-provisioner-runner + apiGroup: rbac.authorization.k8s.io +--- +{{ end }} kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: diff --git a/deploy/charts/rook-ceph/templates/configmap.yaml b/deploy/charts/rook-ceph/templates/configmap.yaml index 376037968..f5ec06fad 100644 --- a/deploy/charts/rook-ceph/templates/configmap.yaml +++ b/deploy/charts/rook-ceph/templates/configmap.yaml @@ -121,6 +121,12 @@ data: {{- if .Values.csi.cephFSProvisionerNodeAffinity }} CSI_CEPHFS_PROVISIONER_NODE_AFFINITY: {{ .Values.csi.cephFSProvisionerNodeAffinity }} {{- end }} +{{- if .Values.csi.nfsProvisionerTolerations }} + CSI_NFS_PROVISIONER_TOLERATIONS: {{ toYaml .Values.csi.nfsProvisionerTolerations | quote }} +{{- end }} +{{- if .Values.csi.nfsProvisionerNodeAffinity }} + CSI_NFS_PROVISIONER_NODE_AFFINITY: {{ .Values.csi.nfsProvisionerNodeAffinity }} +{{- end }} {{- if .Values.csi.allowUnsupportedVersion }} ROOK_CSI_ALLOW_UNSUPPORTED_VERSION: {{ .Values.csi.allowUnsupportedVersion | quote }} {{- end }} @@ -181,6 +187,9 @@ data: {{- if .Values.csi.csiCephFSPluginResource }} CSI_CEPHFS_PLUGIN_RESOURCE: {{ .Values.csi.csiCephFSPluginResource | quote }} {{- end }} +{{- if .Values.csi.csiNFSProvisionerResource }} + CSI_NFS_PROVISIONER_RESOURCE: {{ .Values.csi.csiNFSProvisionerResource | quote }} +{{- end }} {{- if .Values.csi.csiNFSPluginResource }} CSI_NFS_PLUGIN_RESOURCE: {{ .Values.csi.csiNFSPluginResource | quote }} {{- end }} diff --git a/deploy/charts/rook-ceph/templates/serviceaccount.yaml b/deploy/charts/rook-ceph/templates/serviceaccount.yaml index ba4fe7e11..28be9c70b 100644 --- a/deploy/charts/rook-ceph/templates/serviceaccount.yaml +++ b/deploy/charts/rook-ceph/templates/serviceaccount.yaml @@ -27,6 +27,14 @@ metadata: namespace: {{ .Release.Namespace }} # namespace:operator {{ template "library.imagePullSecrets" . }} --- +# Service account for the NFS CSI provisioner +apiVersion: v1 +kind: ServiceAccount +metadata: + name: rook-csi-nfs-provisioner-sa + namespace: {{ .Release.Namespace }} # namespace:operator +{{ template "library.imagePullSecrets" . }} +--- {{ end }} # Service account for the CephFS CSI provisioner apiVersion: v1 diff --git a/deploy/charts/rook-ceph/values.yaml b/deploy/charts/rook-ceph/values.yaml index 8cdca8080..b28ecc0a4 100644 --- a/deploy/charts/rook-ceph/values.yaml +++ b/deploy/charts/rook-ceph/values.yaml @@ -261,6 +261,25 @@ csi: limits: memory: 256Mi cpu: 100m + # CEPH CSI NFS provisioner resource requirement list, Put here list of resource + # requests and limits you want to apply for provisioner pod + csiNFSProvisionerResource: | + - name : csi-provisioner + resource: + requests: + memory: 128Mi + cpu: 100m + limits: + memory: 256Mi + cpu: 200m + - name : csi-nfsplugin + resource: + requests: + memory: 512Mi + cpu: 250m + limits: + memory: 1Gi + cpu: 500m # CEPH CSI NFS plugin resource requirement list, Put here list of resource # requests and limits you want to apply for plugin pod csiNFSPluginResource: | diff --git a/deploy/examples/common.yaml b/deploy/examples/common.yaml index 13ec97e74..62a5d1bb0 100644 --- a/deploy/examples/common.yaml +++ b/deploy/examples/common.yaml @@ -13,6 +13,36 @@ metadata: --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: ceph-nfs-external-provisioner-runner +rules: + - apiGroups: [""] + resources: ["persistentvolumes"] + verbs: ["get", "list", "watch", "create", "delete"] + - apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["get", "list", "watch", "update"] + - apiGroups: ["storage.k8s.io"] + resources: ["storageclasses"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["events"] + verbs: ["get", "list", "watch", "create", "update", "patch"] + - apiGroups: ["storage.k8s.io"] + resources: ["csinodes"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["nodes"] + verbs: ["get", "list", "watch"] + - apiGroups: ["coordination.k8s.io"] + resources: ["leases"] + verbs: ["get", "list", "watch", "create", "update", "patch"] + - apiGroups: [""] + resources: ["secrets"] + verbs: ["get"] +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 metadata: name: cephfs-csi-nodeplugin rules: @@ -574,6 +604,19 @@ rules: --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: ceph-nfs-csi-provisioner-role +subjects: + - kind: ServiceAccount + name: rook-csi-nfs-provisioner-sa + namespace: rook-ceph # namespace:operator +roleRef: + kind: ClusterRole + name: ceph-nfs-external-provisioner-runner + apiGroup: rbac.authorization.k8s.io +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 metadata: name: cephfs-csi-nodeplugin subjects: @@ -1371,6 +1414,15 @@ metadata: # imagePullSecrets: # - name: my-registry-secret --- +# Service account for the NFS CSI provisioner +apiVersion: v1 +kind: ServiceAccount +metadata: + name: rook-csi-nfs-provisioner-sa + namespace: rook-ceph # namespace:operator +# imagePullSecrets: +# - name: my-registry-secret +--- # Service account for the RBD CSI driver apiVersion: v1 kind: ServiceAccount diff --git a/deploy/examples/operator-openshift.yaml b/deploy/examples/operator-openshift.yaml index e2c06feb1..b43bcabf7 100644 --- a/deploy/examples/operator-openshift.yaml +++ b/deploy/examples/operator-openshift.yaml @@ -263,6 +263,14 @@ data: # - key: node.rook.io/cephfs # operator: Exists + # (Optional) CephCSI NFS provisioner NodeAffinity (overrides CSI_PROVISIONER_NODE_AFFINITY). + # CSI_NFS_PROVISIONER_NODE_AFFINITY: "role=nfs-node" + # (Optional) CephCSI NFS provisioner tolerations list (overrides CSI_PROVISIONER_TOLERATIONS). + # Put here list of taints you want to tolerate in YAML format. + # CSI provisioner would be best to start on the same nodes as other ceph daemons. + # CSI_NFS_PROVISIONER_TOLERATIONS: | + # - key: node.rook.io/nfs + # operator: Exists # (Optional) CephCSI NFS plugin NodeAffinity (overrides CSI_PLUGIN_NODE_AFFINITY). # CSI_NFS_PLUGIN_NODE_AFFINITY: "role=nfs-node" # (Optional) CephCSI NFS plugin tolerations list (overrides CSI_PLUGIN_TOLERATIONS). @@ -421,6 +429,26 @@ data: # memory: 256Mi # cpu: 100m + + # (Optional) CEPH CSI NFS provisioner resource requirement list, Put here list of resource + # requests and limits you want to apply for provisioner pod + # CSI_NFS_PROVISIONER_RESOURCE: | + # - name : csi-provisioner + # resource: + # requests: + # memory: 128Mi + # cpu: 100m + # limits: + # memory: 256Mi + # cpu: 200m + # - name : csi-nfsplugin + # resource: + # requests: + # memory: 512Mi + # cpu: 250m + # limits: + # memory: 1Gi + # cpu: 500m # (Optional) CEPH CSI NFS plugin resource requirement list, Put here list of resource # requests and limits you want to apply for plugin pod # CSI_NFS_PLUGIN_RESOURCE: | diff --git a/deploy/examples/operator.yaml b/deploy/examples/operator.yaml index 4afbb71a0..57e3f5adf 100644 --- a/deploy/examples/operator.yaml +++ b/deploy/examples/operator.yaml @@ -179,6 +179,14 @@ data: # - key: node.rook.io/cephfs # operator: Exists + # (Optional) CephCSI NFS provisioner NodeAffinity (overrides CSI_PROVISIONER_NODE_AFFINITY). + # CSI_NFS_PROVISIONER_NODE_AFFINITY: "role=nfs-node" + # (Optional) CephCSI NFS provisioner tolerations list (overrides CSI_PROVISIONER_TOLERATIONS). + # Put here list of taints you want to tolerate in YAML format. + # CSI provisioner would be best to start on the same nodes as other ceph daemons. + # CSI_NFS_PROVISIONER_TOLERATIONS: | + # - key: node.rook.io/nfs + # operator: Exists # (Optional) CephCSI NFS plugin NodeAffinity (overrides CSI_PLUGIN_NODE_AFFINITY). # CSI_NFS_PLUGIN_NODE_AFFINITY: "role=nfs-node" # (Optional) CephCSI NFS plugin tolerations list (overrides CSI_PLUGIN_TOLERATIONS). @@ -337,6 +345,25 @@ data: # memory: 256Mi # cpu: 100m + # (Optional) CEPH CSI NFS provisioner resource requirement list, Put here list of resource + # requests and limits you want to apply for provisioner pod + # CSI_NFS_PROVISIONER_RESOURCE: | + # - name : csi-provisioner + # resource: + # requests: + # memory: 128Mi + # cpu: 100m + # limits: + # memory: 256Mi + # cpu: 200m + # - name : csi-nfsplugin + # resource: + # requests: + # memory: 512Mi + # cpu: 250m + # limits: + # memory: 1Gi + # cpu: 500m # (Optional) CEPH CSI NFS plugin resource requirement list, Put here list of resource # requests and limits you want to apply for plugin pod # CSI_NFS_PLUGIN_RESOURCE: | diff --git a/pkg/operator/ceph/csi/spec.go b/pkg/operator/ceph/csi/spec.go index 26163d5c6..6511a02be 100644 --- a/pkg/operator/ceph/csi/spec.go +++ b/pkg/operator/ceph/csi/spec.go @@ -138,6 +138,8 @@ var ( // Local package template path for NFS //go:embed template/nfs/csi-nfsplugin.yaml NFSPluginTemplatePath string + //go:embed template/nfs/csi-nfsplugin-provisioner-dep.yaml + NFSProvisionerDepTemplatePath string ) const ( @@ -160,8 +162,10 @@ const ( cephFSPluginNodeAffinityEnv = "CSI_CEPHFS_PLUGIN_NODE_AFFINITY" // NFS tolerations and node affinity - nfsPluginTolerationsEnv = "CSI_NFS_PLUGIN_TOLERATIONS" - nfsPluginNodeAffinityEnv = "CSI_NFS_PLUGIN_NODE_AFFINITY" + nfsProvisionerTolerationsEnv = "CSI_NFS_PROVISIONER_TOLERATIONS" + nfsProvisionerNodeAffinityEnv = "CSI_NFS_PROVISIONER_NODE_AFFINITY" + nfsPluginTolerationsEnv = "CSI_NFS_PLUGIN_TOLERATIONS" + nfsPluginNodeAffinityEnv = "CSI_NFS_PLUGIN_NODE_AFFINITY" // RBD tolerations and node affinity rbdProvisionerTolerationsEnv = "CSI_RBD_PROVISIONER_TOLERATIONS" @@ -176,7 +180,8 @@ const ( cephFSProvisionerResource = "CSI_CEPHFS_PROVISIONER_RESOURCE" cephFSPluginResource = "CSI_CEPHFS_PLUGIN_RESOURCE" - nfsPluginResource = "CSI_NFS_PLUGIN_RESOURCE" + nfsProvisionerResource = "CSI_NFS_PROVISIONER_RESOURCE" + nfsPluginResource = "CSI_NFS_PLUGIN_RESOURCE" // kubelet directory path DefaultKubeletDirPath = "/var/lib/kubelet" @@ -233,10 +238,10 @@ func validateCSIParam() error { func (r *ReconcileCSI) startDrivers(ver *version.Info, ownerInfo *k8sutil.OwnerInfo, v *CephCSIVersion) error { var ( - err error - rbdPlugin, cephfsPlugin, nfsPlugin *apps.DaemonSet - rbdProvisionerDeployment, cephfsProvisionerDeployment *apps.Deployment - rbdService, cephfsService *corev1.Service + err error + rbdPlugin, cephfsPlugin, nfsPlugin *apps.DaemonSet + rbdProvisionerDeployment, cephfsProvisionerDeployment, nfsProvisionerDeployment *apps.Deployment + rbdService, cephfsService *corev1.Service ) tp := templateParam{ @@ -442,6 +447,11 @@ func (r *ReconcileCSI) startDrivers(ver *version.Info, ownerInfo *k8sutil.OwnerI if err != nil { return errors.Wrap(err, "failed to load nfs plugin template") } + + nfsProvisionerDeployment, err = templateToDeployment("nfs-provisioner", NFSProvisionerDepTemplatePath, tp) + if err != nil { + return errors.Wrap(err, "failed to load nfs provisioner deployment template") + } } // get common provisioner tolerations and node affinity @@ -612,6 +622,37 @@ func (r *ReconcileCSI) startDrivers(ver *version.Info, ownerInfo *k8sutil.OwnerI k8sutil.AddRookVersionLabelToDaemonSet(nfsPlugin) } + if nfsProvisionerDeployment != nil { + // get NFS provisioner tolerations and node affinity, defaults to common tolerations and node affinity if not specified + nfsProvisionerTolerations := getToleration(r.opConfig.Parameters, nfsProvisionerTolerationsEnv, provisionerTolerations) + nfsProvisionerNodeAffinity := getNodeAffinity(r.opConfig.Parameters, nfsProvisionerNodeAffinityEnv, provisionerNodeAffinity) + // apply NFS provisioner tolerations and node affinity + applyToPodSpec(&nfsProvisionerDeployment.Spec.Template.Spec, nfsProvisionerNodeAffinity, nfsProvisionerTolerations) + // get resource details for nfs provisioner + // apply resource request and limit to nfs provisioner containers + applyResourcesToContainers(r.opConfig.Parameters, nfsProvisionerResource, &nfsProvisionerDeployment.Spec.Template.Spec) + err = ownerInfo.SetControllerReference(nfsProvisionerDeployment) + if err != nil { + return errors.Wrapf(err, "failed to set owner reference to nfs provisioner deployment %q", nfsProvisionerDeployment.Name) + } + antiAffinity := GetPodAntiAffinity("app", csiNFSProvisioner) + nfsProvisionerDeployment.Spec.Template.Spec.Affinity.PodAntiAffinity = &antiAffinity + nfsProvisionerDeployment.Spec.Strategy = apps.DeploymentStrategy{ + Type: apps.RecreateDeploymentStrategyType, + } + + _, err = r.applyCephClusterNetworkConfig(r.opManagerContext, &nfsProvisionerDeployment.Spec.Template.ObjectMeta) + if err != nil { + return errors.Wrapf(err, "failed to apply network config to nfs provisioner deployment %q", nfsProvisionerDeployment.Name) + } + _, err = k8sutil.CreateOrUpdateDeployment(r.opManagerContext, r.context.Clientset, nfsProvisionerDeployment) + if err != nil { + return errors.Wrapf(err, "failed to start nfs provisioner deployment %q", nfsProvisionerDeployment.Name) + } + k8sutil.AddRookVersionLabelToDeployment(nfsProvisionerDeployment) + logger.Info("successfully started CSI NFS driver") + } + if EnableRBD { err = csiDriverobj.createCSIDriverInfo(r.opManagerContext, r.context.Clientset, RBDDriverName, k8sutil.GetValue(r.opConfig.Parameters, "CSI_RBD_FSGROUPPOLICY", string(k8scsi.ReadWriteOnceWithFSTypeFSGroupPolicy)), true) if err != nil { diff --git a/pkg/operator/ceph/csi/template/nfs/csi-nfsplugin-provisioner-dep.yaml b/pkg/operator/ceph/csi/template/nfs/csi-nfsplugin-provisioner-dep.yaml new file mode 100644 index 000000000..d9ab7b292 --- /dev/null +++ b/pkg/operator/ceph/csi/template/nfs/csi-nfsplugin-provisioner-dep.yaml @@ -0,0 +1,116 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + name: csi-nfsplugin-provisioner + namespace: {{ .Namespace }} +spec: + replicas: {{ .ProvisionerReplicas }} + selector: + matchLabels: + app: csi-nfsplugin-provisioner + template: + metadata: + labels: + app: csi-nfsplugin-provisioner + {{ range $key, $value := .CSINFSPodLabels }} + {{ $key }}: "{{ $value }}" + {{ end }} + spec: + serviceAccountName: rook-csi-nfs-provisioner-sa + {{ if .ProvisionerPriorityClassName }} + priorityClassName: {{ .ProvisionerPriorityClassName }} + {{ end }} + containers: + - name: csi-provisioner + image: {{ .ProvisionerImage }} + args: + - "--csi-address=$(ADDRESS)" + - "--v={{ .LogLevel }}" + - "--timeout=150s" + - "--retry-interval-start=500ms" + - "--leader-election=true" + - "--leader-election-namespace={{ .Namespace }}" + env: + - name: ADDRESS + value: unix:///csi/csi-provisioner.sock + imagePullPolicy: "IfNotPresent" + volumeMounts: + - name: socket-dir + mountPath: /csi + - name: csi-nfsplugin + image: {{ .CSIPluginImage }} + args: + - "--nodeid=$(NODE_ID)" + - "--type=nfs" + - "--endpoint=$(CSI_ENDPOINT)" + - "--v={{ .LogLevel }}" + - "--controllerserver=true" + - "--drivername={{ .DriverNamePrefix }}nfs.csi.ceph.com" + - "--pidlimit=-1" + env: + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: NODE_ID + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: CSI_ENDPOINT + value: unix:///csi/csi-provisioner.sock + imagePullPolicy: "IfNotPresent" + volumeMounts: + - name: socket-dir + mountPath: /csi + - name: host-sys + mountPath: /sys + - name: lib-modules + mountPath: /lib/modules + readOnly: true + - name: host-dev + mountPath: /dev + - name: ceph-csi-config + mountPath: /etc/ceph-csi-config/ + - name: keys-tmp-dir + mountPath: /tmp/csi/keys + {{ if .MountCustomCephConf }} + - name: ceph-config + mountPath: /etc/ceph/ceph.conf + subPath: ceph.conf + {{ end }} + volumes: + - name: socket-dir + emptyDir: { + medium: "Memory" + } + - name: host-sys + hostPath: + path: /sys + - name: lib-modules + hostPath: + path: /lib/modules + - name: host-dev + hostPath: + path: /dev + - name: ceph-csi-config + configMap: + name: rook-ceph-csi-config + items: + - key: csi-cluster-config-json + path: config.json + - name: keys-tmp-dir + emptyDir: { + medium: "Memory" + } + {{ if .MountCustomCephConf }} + - name: ceph-config + configMap: + name: csi-ceph-conf-override + items: + - key: ceph.conf + path: ceph.conf + {{ end }}