Repository: pravega/zookeeper-operator (go)

Issue:
[Bug]: Pod.securityContext setting in zookeeper chart values.yaml disappear in created zookeeper StatefulSet
### Description

Pod.securityContext setting in zookeeper chart values.yaml disappear in created zookeeper StatefulSet.

### Importance

must-have

### Location

https://github.com/gxglls/zookeeper-operator/blob/fd714b40e4148221dd9ab0c27b5693f51a95ee2a/pkg/zk/generators.go#L108
```golang
if reflect.DeepEqual(v1.PodSecurityContext{}, z.Spec.Pod.SecurityContext) { // should !reflect.DeepEqual() here
    podSpec.SecurityContext = z.Spec.Pod.SecurityContext	
}
```

### Suggestions for an improvement
Fixed by myself in related pr

Pull request:
Issue 333: Fix Pod SecurityContext config error in ZK charts
### Change log description

1. Fix Pod SecurityContext config error in ZK charts

### Purpose of the change
Close #333 

### What the code does

1. Fix Pod SecurityContext config error in ZK charts

### How to verify it

Create a ZK CR with  Pod.SecurityContext  config, then check the created ZK StatufulSet config if contained 
correct Pod.SecurityContext


Patch:
diff --git a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
index 1707ebc..e8c5edd 100644
--- a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
+++ b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml
@@ -3739,6 +3739,47 @@ spec:
                 - name
                 type: object
               type: array
+            volumeMounts:
+              description: Customized volumeMounts for zookeeper container.
+                Cannot be updated.
+              items:
+                description: VolumeMount describes a mounting of a Volume within
+                  a container.
+                properties:
+                  mountPath:
+                    description: Path within the container at which the volume
+                      should be mounted.  Must not contain ':'.
+                    type: string
+                  mountPropagation:
+                    description: mountPropagation determines how mounts are
+                      propagated from the host to container and the other way
+                      around. When not set, MountPropagationNone is used. This
+                      field is beta in 1.10.
+                    type: string
+                  name:
+                    description: This must match the Name of a Volume.
+                    type: string
+                  readOnly:
+                    description: Mounted read-only if true, read-write otherwise
+                      (false or unspecified). Defaults to false.
+                    type: boolean
+                  subPath:
+                    description: Path within the volume from which the container's
+                      volume should be mounted. Defaults to "" (volume's root).
+                    type: string
+                  subPathExpr:
+                    description: Expanded path within the volume from which
+                      the container's volume should be mounted. Behaves similarly
+                      to SubPath but environment variable references $(VAR_NAME)
+                      are expanded using the container's environment. Defaults
+                      to "" (volume's root). SubPathExpr and SubPath are mutually
+                      exclusive.
+                    type: string
+                required:
+                - mountPath
+                - name
+                type: object
+              type: array
           type: object
         status:
           description: ZookeeperClusterStatus defines the observed state of ZookeeperCluster
diff --git a/charts/zookeeper/README.md b/charts/zookeeper/README.md
index 189719c..eb9b3ba 100644
--- a/charts/zookeeper/README.md
+++ b/charts/zookeeper/README.md
@@ -113,3 +113,4 @@ The following table lists the configurable parameters of the zookeeper chart and
 | `ephemeral.emptydirvolumesource.sizeLimit` | Total amount of local storage required for the EmptyDir volume. | `20Gi` |
 | `containers` | Application containers run with the zookeeper pod | `[]` |
 | `volumes` | Named volumes that may be accessed by any container in the pod | `[]` |
+| `volumeMounts` | Customized volumeMounts for zookeeper container that can be configured to mount volumes to zookeeper container | `[]` |
diff --git a/charts/zookeeper/values.yaml b/charts/zookeeper/values.yaml
index 2e90dd9..33f7b46 100644
--- a/charts/zookeeper/values.yaml
+++ b/charts/zookeeper/values.yaml
@@ -95,3 +95,4 @@ hooks:
 
 containers: []
 volumes: []
+volumeMounts: []
diff --git a/deploy/crds/zookeeper.pravega.io_zookeeperclusters_crd.yaml b/deploy/crds/zookeeper.pravega.io_zookeeperclusters_crd.yaml
index c37e0a2..b268006 100644
--- a/deploy/crds/zookeeper.pravega.io_zookeeperclusters_crd.yaml
+++ b/deploy/crds/zookeeper.pravega.io_zookeeperclusters_crd.yaml
@@ -3731,6 +3731,47 @@ spec:
                 - name
                 type: object
               type: array
+            volumeMounts:
+              description: Customized volumeMounts for zookeeper container.
+                Cannot be updated.
+              items:
+                description: VolumeMount describes a mounting of a Volume within
+                  a container.
+                properties:
+                  mountPath:
+                    description: Path within the container at which the volume
+                      should be mounted.  Must not contain ':'.
+                    type: string
+                  mountPropagation:
+                    description: mountPropagation determines how mounts are
+                      propagated from the host to container and the other way
+                      around. When not set, MountPropagationNone is used. This
+                      field is beta in 1.10.
+                    type: string
+                  name:
+                    description: This must match the Name of a Volume.
+                    type: string
+                  readOnly:
+                    description: Mounted read-only if true, read-write otherwise
+                      (false or unspecified). Defaults to false.
+                    type: boolean
+                  subPath:
+                    description: Path within the volume from which the container's
+                      volume should be mounted. Defaults to "" (volume's root).
+                    type: string
+                  subPathExpr:
+                    description: Expanded path within the volume from which
+                      the container's volume should be mounted. Behaves similarly
+                      to SubPath but environment variable references $(VAR_NAME)
+                      are expanded using the container's environment. Defaults
+                      to "" (volume's root). SubPathExpr and SubPath are mutually
+                      exclusive.
+                    type: string
+                required:
+                - mountPath
+                - name
+                type: object
+              type: array
           type: object
         status:
           description: ZookeeperClusterStatus defines the observed state of ZookeeperCluster
diff --git a/pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go b/pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go
index 365484b..2520314 100644
--- a/pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go
+++ b/pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go
@@ -136,6 +136,9 @@ type ZookeeperClusterSpec struct {
 	// Volumes defines to support customized volumes
 	Volumes []v1.Volume `json:"volumes,omitempty"`
 
+	// VolumeMounts defines to support customized volumeMounts
+	VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
+
 	// Probes specifies the timeout values for the Readiness and Liveness Probes
 	// for the zookeeper pods.
 	// +optional
diff --git a/pkg/apis/zookeeper/v1beta1/zz_generated.deepcopy.go b/pkg/apis/zookeeper/v1beta1/zz_generated.deepcopy.go
index 50f7cc1..ee70ca7 100644
--- a/pkg/apis/zookeeper/v1beta1/zz_generated.deepcopy.go
+++ b/pkg/apis/zookeeper/v1beta1/zz_generated.deepcopy.go
@@ -9,6 +9,52 @@ 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 *AdminServerServicePolicy) DeepCopyInto(out *AdminServerServicePolicy) {
+	*out = *in
+	if in.Annotations != nil {
+		in, out := &in.Annotations, &out.Annotations
+		*out = make(map[string]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdminServerServicePolicy.
+func (in *AdminServerServicePolicy) DeepCopy() *AdminServerServicePolicy {
+	if in == nil {
+		return nil
+	}
+	out := new(AdminServerServicePolicy)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *ClientServicePolicy) DeepCopyInto(out *ClientServicePolicy) {
+	*out = *in
+	if in.Annotations != nil {
+		in, out := &in.Annotations, &out.Annotations
+		*out = make(map[string]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClientServicePolicy.
+func (in *ClientServicePolicy) DeepCopy() *ClientServicePolicy {
+	if in == nil {
+		return nil
+	}
+	out := new(ClientServicePolicy)
+	in.DeepCopyInto(out)
+	return out
+}
+
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ClusterCondition) DeepCopyInto(out *ClusterCondition) {
 	*out = *in
@@ -58,6 +104,29 @@ func (in *Ephemeral) DeepCopy() *Ephemeral {
 	return out
 }
 
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *HeadlessServicePolicy) DeepCopyInto(out *HeadlessServicePolicy) {
+	*out = *in
+	if in.Annotations != nil {
+		in, out := &in.Annotations, &out.Annotations
+		*out = make(map[string]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HeadlessServicePolicy.
+func (in *HeadlessServicePolicy) DeepCopy() *HeadlessServicePolicy {
+	if in == nil {
+		return nil
+	}
+	out := new(HeadlessServicePolicy)
+	in.DeepCopyInto(out)
+	return out
+}
+
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *MembersStatus) DeepCopyInto(out *MembersStatus) {
 	*out = *in
@@ -311,6 +380,9 @@ func (in *ZookeeperClusterSpec) DeepCopyInto(out *ZookeeperClusterSpec) {
 		copy(*out, *in)
 	}
 	in.Pod.DeepCopyInto(&out.Pod)
+	in.AdminServerService.DeepCopyInto(&out.AdminServerService)
+	in.ClientService.DeepCopyInto(&out.ClientService)
+	in.HeadlessService.DeepCopyInto(&out.HeadlessService)
 	if in.Persistence != nil {
 		in, out := &in.Persistence, &out.Persistence
 		*out = new(Persistence)
@@ -336,6 +408,13 @@ func (in *ZookeeperClusterSpec) DeepCopyInto(out *ZookeeperClusterSpec) {
 			(*in)[i].DeepCopyInto(&(*out)[i])
 		}
 	}
+	if in.VolumeMounts != nil {
+		in, out := &in.VolumeMounts, &out.VolumeMounts
+		*out = make([]v1.VolumeMount, len(*in))
+		for i := range *in {
+			(*in)[i].DeepCopyInto(&(*out)[i])
+		}
+	}
 	if in.Probes != nil {
 		in, out := &in.Probes, &out.Probes
 		*out = new(Probes)
diff --git a/pkg/zk/generators.go b/pkg/zk/generators.go
index b588be9..3cc5372 100644
--- a/pkg/zk/generators.go
+++ b/pkg/zk/generators.go
@@ -142,10 +142,10 @@ func makeZkPodSpec(z *v1beta1.ZookeeperCluster, volumes []v1.Volume) v1.PodSpec
 				Exec: &v1.ExecAction{Command: []string{"zookeeperLive.sh"}},
 			},
 		},
-		VolumeMounts: []v1.VolumeMount{
+		VolumeMounts: append(z.Spec.VolumeMounts, []v1.VolumeMount{
 			{Name: "data", MountPath: "/data"},
 			{Name: "conf", MountPath: "/conf"},
-		},
+		}...),
 		Lifecycle: &v1.Lifecycle{
 			PreStop: &v1.Handler{
 				Exec: &v1.ExecAction{
@@ -175,7 +175,7 @@ func makeZkPodSpec(z *v1beta1.ZookeeperCluster, volumes []v1.Volume) v1.PodSpec
 		Affinity:   z.Spec.Pod.Affinity,
 		Volumes:    append(z.Spec.Volumes, volumes...),
 	}
-	if reflect.DeepEqual(v1.PodSecurityContext{}, z.Spec.Pod.SecurityContext) {
+	if !reflect.DeepEqual(v1.PodSecurityContext{}, z.Spec.Pod.SecurityContext) {
 		podSpec.SecurityContext = z.Spec.Pod.SecurityContext
 	}
 	podSpec.NodeSelector = z.Spec.Pod.NodeSelector


Test patch:
diff --git a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go
index 922e438..f58586d 100644
--- a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go
+++ b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go
@@ -51,6 +51,12 @@ var _ = Describe("ZookeeperCluster DeepCopy", func() {
 						Name: "testvolume",
 					},
 				},
+				VolumeMounts: []v1.VolumeMount{
+					{
+						Name:      "testvolume",
+						MountPath: "/test/volume",
+					},
+				},
 			}
 
 			z1.WithDefaults()