Skip to content

Commit

Permalink
Issue 547: Add support for init containers in controller and segment …
Browse files Browse the repository at this point in the history
…store pods (#548)

* Added support for init containers

Signed-off-by: anishakj <anisha.kj@dell.com>

* Modified values file

Signed-off-by: anishakj <anisha.kj@dell.com>

* added unit tests

Signed-off-by: anishakj <anisha.kj@dell.com>

* updating crds

Signed-off-by: anishakj <anisha.kj@dell.com>

* Increasing unit test coverage

Signed-off-by: anishakj <anisha.kj@dell.com>

* incorporating review comments

Signed-off-by: anishakj <anisha.kj@dell.com>
  • Loading branch information
anishakj authored May 24, 2021
1 parent 0125f7d commit 38d1b00
Showing 13 changed files with 6,635 additions and 3 deletions.
2,180 changes: 2,180 additions & 0 deletions charts/pravega-operator/templates/pravega.pravega.io_pravegaclusters_crd.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions charts/pravega/README.md
Original file line number Diff line number Diff line change
@@ -138,6 +138,7 @@ The following table lists the configurable parameters of the pravega chart and t
| `controller.annotations` | Annotations to add to the controller pods | `{}` |
| `controller.jvmOptions` | JVM Options for controller | `["-Xms512m", "-XX:+ExitOnOutOfMemoryError", "-XX:+CrashOnOutOfMemoryError", "-XX:+HeapDumpOnOutOfMemoryError", "-XX:HeapDumpPath=/tmp/dumpfile/heap", "-XX:MaxRAMPercentage=50.0", "-XX:+UseContainerSupport", "-XX:+PrintExtendedThreadInfo"]` |
| `controller.svcNameSuffix` | suffix for controller service name | `pravega-controller` |
| `controller.initContainers` | Init Conatiners to add to controller pods | `[]` |
| `segmentStore.replicas` | Number of segmentStore replicas | `1` |
| `segmentStore.maxUnavailableReplicas` | Maximum number of unavailable replicas possible for segmentStore pdb | |
| `segmentStore.secret` | Secret configuration for the segmentStore | `{}` |
@@ -157,6 +158,7 @@ The following table lists the configurable parameters of the pravega chart and t
| `segmentStore.headlessSvcNameSuffix` | suffix for segmentStore headless service name | `pravega-segmentstore-headless` |
| `segmentStore.labels` | Labels to add to the segmentStore pods | `{}` |
| `segmentStore.annotations` | Annotations to add to the segmentStore pods | `{}` |
| `segmentStore.initContainers` | Init Conatiners to add to the segmentStore pods | `[]` |
| `storage.longtermStorage.type` | Type of long term storage backend to be used (filesystem/ecs/hdfs) | `filesystem` |
| `storage.longtermStorage.filesystem.pvc` | Name of the pre-created PVC, if long term storage type is filesystem | `pravega-tier2` |
| `storage.longtermStorage.ecs` | Configuration to use a Dell EMC ECS system, if long term storage type is ecs | `{}` |
8 changes: 8 additions & 0 deletions charts/pravega/templates/pravega.yaml
Original file line number Diff line number Diff line change
@@ -90,6 +90,10 @@ spec:
{{- if .Values.controller.annotations }}
controllerPodAnnotations:
{{ toYaml .Values.controller.annotations | indent 6 }}
{{- end }}
{{- if .Values.controller.initContainers }}
controllerInitContainers:
{{ toYaml .Values.controller.initContainers | indent 6 }}
{{- end }}
{{- if .Values.segmentStore.labels }}
segmentStorePodLabels:
@@ -98,6 +102,10 @@ spec:
{{- if .Values.segmentStore.annotations }}
segmentStorePodAnnotations:
{{ toYaml .Values.segmentStore.annotations | indent 6 }}
{{- end }}
{{- if .Values.segmentStore.initContainers }}
segmentStoreInitContainers:
{{ toYaml .Values.segmentStore.initContainers | indent 6 }}
{{- end }}
image:
repository: {{ .Values.image.repository }}
2 changes: 2 additions & 0 deletions charts/pravega/values.yaml
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ controller:
jvmOptions: ["-Xms512m", "-XX:+ExitOnOutOfMemoryError", "-XX:+CrashOnOutOfMemoryError", "-XX:+HeapDumpOnOutOfMemoryError", "-XX:HeapDumpPath=/tmp/dumpfile/heap", "-XX:MaxRAMPercentage=50.0", "-XX:+UseContainerSupport", "-XX:+PrintExtendedThreadInfo"]
labels: {}
annotations: {}
initContainers: []

segmentStore:
replicas: 1
@@ -95,6 +96,7 @@ segmentStore:
annotations: {}
stsNameSuffix:
headlessSvcNameSuffix:
initContainers:[]

storage:

2,174 changes: 2,174 additions & 0 deletions deploy/crds/pravega.pravega.io_pravegaclusters_crd.yaml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions pkg/apis/pravega/v1beta1/pravega.go
Original file line number Diff line number Diff line change
@@ -219,6 +219,12 @@ type PravegaSpec struct {

// This is used as suffix for segmentstore headless service name
SegmentStoreHeadlessSvcNameSuffix string `json:"segmentStoreHeadlessSvcNameSuffix,omitempty"`

// InitContainers to be added to controller pods
ControllerInitContainers []v1.Container `json:"controllerInitContainers,omitempty"`

// InitContainers to be added to segmentstore pods
SegmentStoreInitContainers []v1.Container `json:"segmentStoreInitContainers,omitempty"`
}

func (s *PravegaSpec) withDefaults() (changed bool) {
14 changes: 14 additions & 0 deletions pkg/apis/pravega/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion pkg/apis/pravega/v1beta1/zz_generated_deepcopy_test.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,21 @@ var _ = Describe("PravegaCluster DeepCopy", func() {
Secret: "seg-secret",
MountPath: "",
},

SegmentStoreInitContainers: []v1.Container{
v1.Container{
Name: "testing",
Image: "dummy-image",
Command: []string{"sh", "-c", "ls;pwd"},
},
},
ControllerInitContainers: []v1.Container{
v1.Container{
Name: "testing",
Image: "dummy-image",
Command: []string{"sh", "-c", "ls;pwd"},
},
},
},
}
p1.WithDefaults()
@@ -90,7 +105,14 @@ var _ = Describe("PravegaCluster DeepCopy", func() {
p1.Spec.Pravega.Options["key"] = "value"
p1.Spec.Pravega.SegmentStoreServiceAnnotations["user"] = "test"
p1.Spec.Pravega.ControllerServiceAnnotations["user"] = "test1"
p1.Spec.Pravega.ControllerPodLabels["user"] = "test2"
p1.Spec.Pravega.SegmentStorePodLabels["user"] = "test2"
p1.Spec.Pravega.ControllerPodAnnotations["user"] = "test2"
p1.Spec.Pravega.SegmentStorePodAnnotations["user"] = "test2"

p2.Spec.Pravega = p1.Spec.Pravega.DeepCopy()
p2.Spec.Pravega.SegmentStoreSecret = p1.Spec.Pravega.SegmentStoreSecret.DeepCopy()

p2.Spec.Pravega.LongTermStorage = p1.Spec.Pravega.LongTermStorage.DeepCopy()
p1.Spec.Pravega.LongTermStorage = &v1beta1.LongTermStorageSpec{
Ecs: &v1beta1.ECSSpec{
@@ -154,6 +176,9 @@ var _ = Describe("PravegaCluster DeepCopy", func() {
It("checking segmentstore secret", func() {
Ω(p2.Spec.TLS.Static.SegmentStoreSecret).To(Equal("segmentstore-secret"))
})
It("checking segmentstore secret inside pravega spec", func() {
Ω(p2.Spec.Pravega.SegmentStoreSecret.Secret).To(Equal("seg-secret"))
})
It("checking image repository", func() {
Ω(p2.Spec.Pravega.Image.Repository).To(Equal("pravega/exmple"))
})
@@ -163,7 +188,12 @@ var _ = Describe("PravegaCluster DeepCopy", func() {
It("checking ControllerSecurityContext", func() {
Ω(fmt.Sprintf("%v", *p2.Spec.Pravega.ControllerSecurityContext.RunAsUser)).To(Equal("0"))
})

It("checking ControllerInitContainer", func() {
Ω(p2.Spec.Pravega.ControllerInitContainers[0].Name).To(Equal("testing"))
})
It("checking SegementStoreInitContainer", func() {
Ω(p2.Spec.Pravega.SegmentStoreInitContainers[0].Name).To(Equal("testing"))
})
It("checking pravega options", func() {
Ω(p2.Spec.Pravega.Options["key"]).To(Equal("value"))
})
3 changes: 3 additions & 0 deletions pkg/controller/pravega/pravega_controller.go
Original file line number Diff line number Diff line change
@@ -206,6 +206,9 @@ func makeControllerPodSpec(p *api.PravegaCluster) *corev1.PodSpec {
if p.Spec.Pravega.ControllerSecurityContext != nil {
podSpec.SecurityContext = p.Spec.Pravega.ControllerSecurityContext
}
if p.Spec.Pravega.ControllerInitContainers != nil {
podSpec.InitContainers = p.Spec.Pravega.ControllerInitContainers
}

configureControllerTLSSecrets(podSpec, p)
configureAuthSecrets(podSpec, p)
26 changes: 24 additions & 2 deletions pkg/controller/pravega/pravega_controller_test.go
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ var _ = Describe("Controller", func() {
"dummy-key": "dummy-value",
"configMapVolumeMounts": "prvg-logback:logback.xml=/opt/pravega/conf/logback.xml",
"emptyDirVolumeMounts": "heap-dump=/tmp/dumpfile/heap,log=/opt/pravega/logs",
"hostPathVolumeMounts": "heap-dump=/tmp/dumpfile/heap,log=/opt/pravega/logs",
},
CacheVolumeClaimTemplate: &corev1.PersistentVolumeClaimSpec{
VolumeName: "abc",
@@ -119,7 +120,16 @@ var _ = Describe("Controller", func() {
securitycontext := corev1.PodSecurityContext{
RunAsUser: &no,
}

p.Spec.Pravega.ControllerSecurityContext = &securitycontext

p.Spec.Pravega.ControllerInitContainers = []corev1.Container{
corev1.Container{
Name: "testing",
Image: "dummy-image",
Command: []string{"sh", "-c", "ls;pwd"},
},
}
})

Context("Controller", func() {
@@ -143,21 +153,33 @@ var _ = Describe("Controller", func() {
Ω(*deploy.Spec.Replicas).Should(Equal(int32(2)))
})

It("should have configMap/emptyDir VolumeMounts set to the values given by user", func() {
It("should have configMap/emptyDir/hostPath VolumeMounts set to the values given by user", func() {
deploy := pravega.MakeControllerPodTemplate(p)
mounthostpath0 := deploy.Spec.Containers[0].VolumeMounts[2].MountPath
mounthostpath0 := deploy.Spec.Containers[0].VolumeMounts[4].MountPath
Ω(mounthostpath0).Should(Equal("/opt/pravega/conf/logback.xml"))
mounthostpath1 := deploy.Spec.Containers[0].VolumeMounts[0].MountPath
Ω(mounthostpath1).Should(Equal("/tmp/dumpfile/heap"))
mounthostpath2 := deploy.Spec.Containers[0].VolumeMounts[1].MountPath
Ω(mounthostpath2).Should(Equal("/opt/pravega/logs"))
mounthostpath3 := deploy.Spec.Containers[0].VolumeMounts[2].MountPath
Ω(mounthostpath3).Should(Equal("/tmp/dumpfile/heap"))
mounthostpath4 := deploy.Spec.Containers[0].VolumeMounts[3].MountPath
Ω(mounthostpath4).Should(Equal("/opt/pravega/logs"))

})

It("should create the service", func() {
svc := pravega.MakeControllerService(p)
Ω(svc.Spec.Type).To(Equal(corev1.ServiceTypeClusterIP))
})
It("should have initcontainer ", func() {
podTemplate := pravega.MakeControllerPodTemplate(p)
Ω(podTemplate.Spec.InitContainers[0].Name).To(Equal("testing"))
Ω(podTemplate.Spec.InitContainers[0].Image).To(Equal("dummy-image"))
Ω(strings.Contains(podTemplate.Spec.InitContainers[0].Command[2], "ls;pwd")).Should(BeTrue())
})
})

Context("Controller with external service type and external access type empty", func() {
BeforeEach(func() {
p.Spec.Pravega.ControllerExternalServiceType = ""
3 changes: 3 additions & 0 deletions pkg/controller/pravega/pravega_segmentstore.go
Original file line number Diff line number Diff line change
@@ -250,6 +250,9 @@ func makeSegmentstorePodSpec(p *api.PravegaCluster) corev1.PodSpec {
podSpec.SecurityContext = p.Spec.Pravega.SegmentStoreSecurityContext
}

if p.Spec.Pravega.SegmentStoreInitContainers != nil {
podSpec.InitContainers = p.Spec.Pravega.SegmentStoreInitContainers
}
configureSegmentstoreSecret(&podSpec, p)

configureSegmentstoreTLSSecret(&podSpec, p)
14 changes: 14 additions & 0 deletions pkg/controller/pravega/pravega_segmentstore_test.go
Original file line number Diff line number Diff line change
@@ -130,6 +130,14 @@ var _ = Describe("PravegaSegmentstore", func() {
RunAsUser: &no,
}
p.Spec.Pravega.SegmentStoreSecurityContext = &securitycontext

p.Spec.Pravega.SegmentStoreInitContainers = []corev1.Container{
corev1.Container{
Name: "testing",
Image: "dummy-image",
Command: []string{"sh", "-c", "ls;pwd"},
},
}
})

Context("First reconcile", func() {
@@ -193,6 +201,12 @@ var _ = Describe("PravegaSegmentstore", func() {
Ω(podTemplate.Labels["service.beta.kubernetes.io/aws-load-balancer-type"]).To(Equal("nlb"))

})
It("should have init container", func() {
podTemplate := pravega.MakeSegmentStorePodTemplate(p)
Ω(podTemplate.Spec.InitContainers[0].Name).To(Equal("testing"))
Ω(podTemplate.Spec.InitContainers[0].Image).To(Equal("dummy-image"))
Ω(strings.Contains(podTemplate.Spec.InitContainers[0].Command[2], "ls;pwd")).Should(BeTrue())
})
})
})

Loading

0 comments on commit 38d1b00

Please sign in to comment.