Skip to content

Commit

Permalink
Merge branch 'master' into PWX-35604
Browse files Browse the repository at this point in the history
  • Loading branch information
olavangad-px authored Jan 23, 2024
2 parents e8e6b94 + e35aad5 commit f82302f
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 7 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deploy/plugin/plugin-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
ports:
- containerPort: 9443
protocol: TCP
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
2 changes: 1 addition & 1 deletion drivers/storage/portworx/testspec/plugin-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
ports:
- containerPort: 9443
protocol: TCP
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
1 change: 1 addition & 0 deletions drivers/storage/portworx/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func (u *uninstallPortworx) RunNodeWiper(
if strings.Contains(wiperImage, "monitor") {
logrus.Warnf("Using oci-monitor %s as node-wiper image", wiperImage)
ds.Spec.Template.Spec.Containers[0].Command = []string{"/px-node-wiper"}
pxutil.AppendUserVolumeMounts(&ds.Spec.Template.Spec, u.cluster.Spec.Volumes)
}

if u.cluster.Spec.ImagePullSecret != nil && *u.cluster.Spec.ImagePullSecret != "" {
Expand Down
44 changes: 44 additions & 0 deletions drivers/storage/portworx/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,7 @@ func GetTLSCipherSuites(cluster *corev1.StorageCluster) (string, error) {
}
return strings.Join(outList, ","), nil
}

func GetKvdbMap(k8sClient client.Client,
cluster *corev1.StorageCluster,
) map[string]*kvdb_api.BootstrapEntry {
Expand Down Expand Up @@ -1654,6 +1655,7 @@ func GetKvdbMap(k8sClient client.Client,
}
return kvdbNodeMap
}

func blobToBootstrapEntries(
entriesBlob []byte,
) (map[string]*kvdb_api.BootstrapEntry, error) {
Expand All @@ -1670,3 +1672,45 @@ func blobToBootstrapEntries(
}
return retMap, nil
}

// AppendUserVolumeMounts appends "user" vol specs to the pod spec
// - note, the user volume specs will override container mounts, if the mount
// destination directory is the same
// - caveat: caller needs to ensure that the volume specs NAMES are unique
func AppendUserVolumeMounts(
podSpec *v1.PodSpec,
userVolSpecList []corev1.VolumeSpec,
) {
if podSpec == nil {
return
} else if len(userVolSpecList) == 0 {
return
}

// make map of user-volumes, also append vols to pod spec
usrSpecMap := make(map[string]corev1.VolumeSpec)
for _, v := range userVolSpecList {
usrSpecMap[v.MountPath] = v
podSpec.Volumes = append(podSpec.Volumes, v1.Volume{
Name: UserVolumeName(v.Name),
VolumeSource: v.VolumeSource,
})
}

// update container volumes, when destination-dir matches
for idx1, cntr := range podSpec.Containers {
for idx2, cv := range cntr.VolumeMounts {
if uv, has := usrSpecMap[cv.MountPath]; has {
logrus.Debugf("Replacing container %s:%s mount '%s' with user-mount '%s'",
cntr.Name, cv.MountPath, cv.Name, uv.Name)

podSpec.Containers[idx1].VolumeMounts[idx2] = v1.VolumeMount{
Name: UserVolumeName(uv.Name),
MountPath: uv.MountPath,
ReadOnly: uv.ReadOnly,
MountPropagation: uv.MountPropagation,
}
}
}
}
}
112 changes: 112 additions & 0 deletions drivers/storage/portworx/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,115 @@ func TestGetTLSCipherSuites(t *testing.T) {
}
}
}

func TestAppendUserVolumeMounts(t *testing.T) {
podSpecReference := &v1.PodSpec{
Containers: []v1.Container{
{
Name: "px",
VolumeMounts: []v1.VolumeMount{
{
Name: "install-vol",
MountPath: "/opt/pwx",
},
{
Name: "creds-vol",
MountPath: "/var/lib/serviceaccount",
},
{
Name: "osd-vol",
MountPath: "/var/lib/osd",
},
},
},
},
Volumes: []v1.Volume{
{
Name: "install-vol",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/opt/pwx",
},
},
},
{
Name: "creds-vol",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/var/lib/kubelet/pod123/serviceaccount",
},
},
},
{
Name: "osd-vol",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/var/lib/osd",
},
},
},
},
}

// no user volume mounts
podSpec := podSpecReference.DeepCopy()
AppendUserVolumeMounts(podSpec, []corev1.VolumeSpec{})
assert.Equal(t, podSpecReference, podSpec)

// non-overlapping volume mounts
userMounts := []corev1.VolumeSpec{
{
Name: "my-vol1",
MountPath: "/mnt/user-vol1",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/mnt/user-vol1",
},
},
},
{
Name: "my-vol2",
MountPath: "/mnt/my-vol2",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/mnt/my-vol2",
},
},
},
}
AppendUserVolumeMounts(podSpec, userMounts)
assert.Equal(t, podSpecReference.Containers, podSpec.Containers)
assert.Equal(t, len(podSpecReference.Volumes)+2, len(podSpec.Volumes))

// add destination-overlapping volume mounts
userMounts = []corev1.VolumeSpec{
{
Name: "custom-install",
MountPath: "/opt/pwx",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/usr/local/portworx",
},
},
},
{
Name: "custom-osd",
MountPath: "/var/lib/osd",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/var/lib/vcap/store/osd",
},
},
},
}
podSpec = podSpecReference.DeepCopy()
AppendUserVolumeMounts(podSpec, userMounts)
assert.NotEqual(t, podSpecReference.Containers, podSpec.Containers)
assert.Equal(t, len(podSpecReference.Volumes)+2, len(podSpec.Volumes))
assert.Equal(t, "user-custom-install", podSpec.Containers[0].VolumeMounts[0].Name)
assert.Equal(t, "creds-vol", podSpec.Containers[0].VolumeMounts[1].Name)
assert.Equal(t, "user-custom-osd", podSpec.Containers[0].VolumeMounts[2].Name)
assert.Equal(t, podSpecReference.Containers[0].VolumeMounts[0].MountPath, podSpec.Containers[0].VolumeMounts[0].MountPath)
assert.Equal(t, podSpecReference.Containers[0].VolumeMounts[1].MountPath, podSpec.Containers[0].VolumeMounts[1].MountPath)
assert.Equal(t, podSpecReference.Containers[0].VolumeMounts[2].MountPath, podSpec.Containers[0].VolumeMounts[2].MountPath)
}
2 changes: 1 addition & 1 deletion pkg/preflight/pks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package preflight

const (
pksDistribution = "gke"
pksDistribution = "pks"
// PksSystemNamespace PKS system namespace
PksSystemNamespace = "pks-system"
)
Expand Down
17 changes: 16 additions & 1 deletion pkg/util/test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ const (
// that CCM should use
AnnotationTelemetryArcusLocation = pxAnnotationPrefix + "/arcus-location"

// AnnotationIsPKS annotation indicating whether it is a PKS cluster
AnnotationIsPKS = pxAnnotationPrefix + "/is-pks"

// Telemetry default params
productionArcusLocation = "external"
productionArcusRestProxyURL = "rest.cloud-support.purestorage.com"
Expand Down Expand Up @@ -1195,11 +1198,17 @@ func validateStorageClusterPods(
return nil
}

// validateDmthinOnPxNodes greps for dmthin in the /etc/pwx/config.json on each PX pods
// validateDmthinOnPxNodes greps for dmthin in the config.json on each PX pod
// and makes sure its there, if dmthin misc-args annotation is found
func validateDmthinOnPxNodes(cluster *corev1.StorageCluster) error {
listOptions := map[string]string{"name": "portworx"}

// Check if px-storev2 exists in config.json
cmd := "grep -i px-storev2 /etc/pwx/config.json"
if IsPKS(cluster) {
cmd = "grep -i px-storev2 /var/vcap/store/etc/pwx/config.json"
}

miscArgAnnotation := cluster.Annotations["portworx.io/misc-args"]

if !strings.Contains(strings.ToLower(miscArgAnnotation), "-t px-storev2") {
Expand Down Expand Up @@ -1238,6 +1247,12 @@ func validateDmthinOnPxNodes(cluster *corev1.StorageCluster) error {
return nil
}

// IsPKS returns true if the annotation has a PKS annotation and is true value
func IsPKS(cluster *corev1.StorageCluster) bool {
enabled, err := strconv.ParseBool(cluster.Annotations[AnnotationIsPKS])
return err == nil && enabled
}

// validateDmthinViaPodCmd runs command on PX pod and returns true if dmthin is enabled on that PX node
func validateDmthinViaPodCmd(pxPod *v1.Pod, cmd string, namespace string) (bool, error) {
output, err := runCmdInsidePxPod(pxPod, cmd, namespace, false)
Expand Down

0 comments on commit f82302f

Please sign in to comment.