From 02aa5c01f0b5738ba7141947e5792b3efb561b49 Mon Sep 17 00:00:00 2001 From: "Shi, Crane" Date: Wed, 12 May 2021 22:14:56 +0800 Subject: [PATCH 1/6] add customized volumeMounts support Signed-off-by: Shi, Crane --- pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go | 3 +++ pkg/zk/generators.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go b/pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go index 365484b47..25203149b 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/zk/generators.go b/pkg/zk/generators.go index b588be9b8..a7b510417 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{ From 41ce707bd37800dfbfc9f6288d9e4a5fcf9bbd95 Mon Sep 17 00:00:00 2001 From: Aaron Wu Date: Fri, 14 May 2021 04:34:17 -0400 Subject: [PATCH 2/6] operator-sdk generate code Signed-off-by: Aaron Wu --- .../v1beta1/zz_generated.deepcopy.go | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/pkg/apis/zookeeper/v1beta1/zz_generated.deepcopy.go b/pkg/apis/zookeeper/v1beta1/zz_generated.deepcopy.go index 50f7cc1f1..ee70ca7c1 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) From 52042115bf0ee66b48ecf40a8dc653864742056f Mon Sep 17 00:00:00 2001 From: "Shi, Crane" Date: Sat, 15 May 2021 15:38:28 +0800 Subject: [PATCH 3/6] Change related charts and crds for customized volumeMounts --- ...eper.pravega.io_zookeeperclusters_crd.yaml | 41 +++++++++++++++++++ charts/zookeeper/README.md | 1 + charts/zookeeper/values.yaml | 1 + ...eper.pravega.io_zookeeperclusters_crd.yaml | 41 +++++++++++++++++++ 4 files changed, 84 insertions(+) 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 5bcef7963..2020f890a 100644 --- a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml +++ b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml @@ -3735,6 +3735,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 189719c90..eb9b3ba02 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 2e90dd932..33f7b4614 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 c37e0a21f..b26800620 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 From 091d01732839c6584fecea7218ee9f71941b4a72 Mon Sep 17 00:00:00 2001 From: "Shi, Crane" Date: Thu, 27 May 2021 12:38:38 +0800 Subject: [PATCH 4/6] Add UT code to cover code for customized volumeMounts --- pkg/apis/zookeeper/v1beta1/deepcopy_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go index 922e4386b..5256d6a12 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", + Name: "/test/volume", + }, + }, } z1.WithDefaults() From ddae2d719fb5d2cbc58a5fd003114a311aee64ff Mon Sep 17 00:00:00 2001 From: "Shi, Crane" Date: Thu, 27 May 2021 13:06:59 +0800 Subject: [PATCH 5/6] fix typo --- pkg/apis/zookeeper/v1beta1/deepcopy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go index 5256d6a12..a576b6132 100644 --- a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go +++ b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go @@ -54,7 +54,7 @@ var _ = Describe("ZookeeperCluster DeepCopy", func() { VolumeMounts: []v1.VolumeMount{ { Name: "testvolume", - Name: "/test/volume", + MountPath: "/test/volume", }, }, } From a8c3ea392e7e6eb83a0922fb0968208b8f3fd6e4 Mon Sep 17 00:00:00 2001 From: "Shi, Crane" Date: Thu, 27 May 2021 13:17:38 +0800 Subject: [PATCH 6/6] gofmt fix --- pkg/apis/zookeeper/v1beta1/deepcopy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go index a576b6132..f58586d0f 100644 --- a/pkg/apis/zookeeper/v1beta1/deepcopy_test.go +++ b/pkg/apis/zookeeper/v1beta1/deepcopy_test.go @@ -53,7 +53,7 @@ var _ = Describe("ZookeeperCluster DeepCopy", func() { }, VolumeMounts: []v1.VolumeMount{ { - Name: "testvolume", + Name: "testvolume", MountPath: "/test/volume", }, },