diff --git a/cmd/cspc-operator/app/storagepool_create.go b/cmd/cspc-operator/app/storagepool_create.go index b0e6b8a26b..62c16d4111 100644 --- a/cmd/cspc-operator/app/storagepool_create.go +++ b/cmd/cspc-operator/app/storagepool_create.go @@ -21,6 +21,7 @@ import ( apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1" apiscsp "github.com/openebs/maya/pkg/cstor/poolinstance/v1alpha3" + env "github.com/openebs/maya/pkg/env/v1alpha1" container "github.com/openebs/maya/pkg/kubernetes/container/v1alpha1" deploy "github.com/openebs/maya/pkg/kubernetes/deployment/appsv1/v1alpha1" pts "github.com/openebs/maya/pkg/kubernetes/podtemplatespec/v1alpha1" @@ -63,6 +64,10 @@ var ( Name: "udev", MountPath: "/run/udev", }, + corev1.VolumeMount{ + Name: "storagepath", + MountPath: "/var/openebs/cstor-pool", + }, } // hostpathType represents the hostpath type hostpathTypeDirectory = corev1.HostPathDirectory @@ -174,7 +179,7 @@ func (pc *PoolConfig) GetPoolDeploySpec(cspi *apis.CStorPoolInstance) (*appsv1.D volume.NewBuilder(). WithName("tmp"). WithHostPathAndType( - getSparseDirPath()+"/shared-"+pc.AlgorithmConfig.CSPC.Name, + env.GetOpenebsBaseDirPath()+"/cstor-pool/"+pc.AlgorithmConfig.CSPC.Name, &hostpathTypeDirectoryOrCreate, ), volume.NewBuilder(). @@ -183,6 +188,12 @@ func (pc *PoolConfig) GetPoolDeploySpec(cspi *apis.CStorPoolInstance) (*appsv1.D getSparseDirPath(), &hostpathTypeDirectoryOrCreate, ), + volume.NewBuilder(). + WithName("storagepath"). + WithHostPathAndType( + env.GetOpenebsBaseDirPath()+"/cstor-pool/"+pc.AlgorithmConfig.CSPC.Name, + &hostpathTypeDirectoryOrCreate, + ), ), ). Build() diff --git a/cmd/cvc-operator/controller/cstorvolumedeployment.go b/cmd/cvc-operator/controller/cstorvolumedeployment.go index 09c1e18324..773bf3f8c4 100644 --- a/cmd/cvc-operator/controller/cstorvolumedeployment.go +++ b/cmd/cvc-operator/controller/cstorvolumedeployment.go @@ -20,6 +20,7 @@ import ( "os" apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1" + env "github.com/openebs/maya/pkg/env/v1alpha1" container "github.com/openebs/maya/pkg/kubernetes/container/v1alpha1" deploy "github.com/openebs/maya/pkg/kubernetes/deployment/appsv1/v1alpha1" pts "github.com/openebs/maya/pkg/kubernetes/podtemplatespec/v1alpha1" @@ -45,10 +46,12 @@ var ( privileged = true resyncInterval = "30" + // MountPropagationBidirectional means that the volume in a container will // receive new mounts from the host or other containers, and its own mounts // will be propagated from the container to the host or other containers. - mountPropagation = corev1.MountPropagationBidirectional + // mountPropagation = corev1.MountPropagationBidirectional + // hostpathType represents the hostpath type hostpathType = corev1.HostPathDirectoryOrCreate @@ -61,6 +64,10 @@ var ( Name: "conf", MountPath: "/usr/local/etc/istgt", }, + corev1.VolumeMount{ + Name: "storagepath", + MountPath: "/var/openebs/cstor-target", + }, } // OpenEBSServiceAccount name of the openebs service accout with required // permissions @@ -193,14 +200,7 @@ func getMonitorMounts() []corev1.VolumeMount { } func getTargetMgmtMounts() []corev1.VolumeMount { - return append( - defaultMounts, - corev1.VolumeMount{ - Name: "tmp", - MountPath: "/tmp", - MountPropagation: &mountPropagation, - }, - ) + return defaultMounts } // getDeployTemplateEnvs return the common env required for @@ -267,17 +267,6 @@ func getVolumeMgmtImage() string { return image } -// getTargetDirPath returns cstor target volume directory for a -// given volume, retrieves the value of the environment variable named -// by the key. -func getTargetDirPath(pvName string) string { - dir, present := os.LookupEnv("OPENEBS_IO_CSTOR_TARGET_DIR") - if !present { - dir = "/var/openebs" - } - return dir + "/shared-" + pvName + "-target" -} - func getContainerPort(port int32) []corev1.ContainerPort { return []corev1.ContainerPort{ corev1.ContainerPort{ @@ -389,9 +378,9 @@ func getOrCreateCStorTargetDeployment( WithName("conf"). WithEmptyDir(&corev1.EmptyDirVolumeSource{}), volume.NewBuilder(). - WithName("tmp"). + WithName("storagepath"). WithHostPathAndType( - getTargetDirPath(vol.Name), + env.GetOpenebsBaseDirPath()+"/cstor-target/"+vol.Name, &hostpathType, ), ), diff --git a/pkg/env/v1alpha1/env.go b/pkg/env/v1alpha1/env.go index c1df59294d..e126756b27 100644 --- a/pkg/env/v1alpha1/env.go +++ b/pkg/env/v1alpha1/env.go @@ -50,6 +50,10 @@ const ( // This environment variable is set via kubernetes downward API Namespace ENVKey = "NAMESPACE" + // OpenEBSBaseDir is the environment variable to get base directory of + // openebs + OpenEBSBaseDir ENVKey = "OPENEBS_IO_BASE_DIR" + // OpenEBSMayaPodName is the environment variable to get maya-apiserver pod // name // @@ -252,3 +256,13 @@ func lookupEnv(envKey string) (value string, present bool) { value = strings.TrimSpace(value) return } + +// GetOpenebsBaseDirPath returns the base path to store openebs related files on +// host machine +func GetOpenebsBaseDirPath() string { + baseDir, isPresent := lookupEnv(string(OpenEBSBaseDir)) + if !isPresent { + return "/var/openebs" + } + return baseDir +} diff --git a/pkg/install/v1alpha1/cstor_volume.go b/pkg/install/v1alpha1/cstor_volume.go index 3b77ee3af6..ca94f31e6e 100644 --- a/pkg/install/v1alpha1/cstor_volume.go +++ b/pkg/install/v1alpha1/cstor_volume.go @@ -616,6 +616,8 @@ spec: mountPath: /var/run - name: conf mountPath: /usr/local/etc/istgt + - name: storagepath + mountPath: /var/openebs/cstor-target {{- end }} - name: cstor-volume-mgmt image: {{ .Config.VolumeControllerImage.value }} @@ -667,7 +669,7 @@ spec: emptyDir: {} - name: storagepath hostPath: - path: {{ .Config.OpenebsBaseDir.value }}/cstor-target/{{ .Volume.owner }}-target + path: {{ .Config.OpenebsBaseDir.value }}/cstor-target/{{ .Volume.owner }} type: DirectoryOrCreate - name: tmp hostPath: