Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(new cStor deployments): add OpenEBS base directory in new CStor deployments #1599

Merged
merged 2 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/cspc-operator/app/storagepool_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migration from SPC to CSPC need to be taken care due to this cc: @shubham14bajpai

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @vishnuitta. Just one small question, are we going to ask users to come to the latest version of SPC before migration? If yes then upgrade will take care of this automatically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.. we should do migration from latest openebs version

&hostpathTypeDirectoryOrCreate,
),
volume.NewBuilder().
Expand All @@ -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()
Expand Down
33 changes: 11 additions & 22 deletions cmd/cvc-operator/controller/cstorvolumedeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
),
),
Expand Down
14 changes: 14 additions & 0 deletions pkg/env/v1alpha1/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions pkg/install/v1alpha1/cstor_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down