Skip to content

Commit

Permalink
Issue 143: Adding support for init containers (#144)
Browse files Browse the repository at this point in the history
* Issue 143: Adding support for init containers

Signed-off-by: SrishT <[email protected]>

* Issue 143: Fixing E2E Tests

Signed-off-by: SrishT <[email protected]>

* Issue 143: Addressing review comments

Signed-off-by: SrishT <[email protected]>

Co-authored-by: SrishT <[email protected]>
  • Loading branch information
SrishT and SrishT authored May 26, 2021
1 parent a0f1a00 commit 21dc351
Show file tree
Hide file tree
Showing 10 changed files with 2,158 additions and 2 deletions.

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions charts/bookkeeper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ The following table lists the configurable parameters of the Bookkeeper chart an
| `autoRecovery`| Enable bookkeeper auto-recovery | `true` |
| `blockOwnerDeletion`| Enable blockOwnerDeletion | `true` |
| `affinity` | Specifies scheduling constraints on bookie pods | `{}` |
| `labels` | Labels to be added to the Bookie Pods | |
| `annotations` | Annotations to be added to the Bookie Pods | |
| `initContainers` | Init Containers to be added to the Bookie Pods | `[]` |
| `headlessSvcNameSuffix` | suffix for bookkeeper headless service name | `bookie-headless` |
| `probes.readiness.initialDelaySeconds` | Number of seconds after the container has started before readiness probe is initiated | `20` |
| `probes.readiness.periodSeconds` | Number of seconds in which readiness probe will be performed | `10` |
Expand All @@ -178,5 +181,3 @@ The following table lists the configurable parameters of the Bookkeeper chart an
| `jvmOptions.gcLoggingOpts` | GC Logging Options passed to the JVM for bookkeeper performance tuning | `["-Xlog:gc*,safepoint::time,level,tags:filecount=5,filesize=64m"]` |
| `jvmOptions.extraOpts` | Extra Options passed to the JVM for bookkeeper performance tuning | `[]` |
| `options` | List of bookkeeper options | |
| `labels` | Labels to be added to the Bookie Pods | |
| `annotations` | Annotations to be added to the Bookie Pods | |
8 changes: 8 additions & 0 deletions charts/bookkeeper/templates/bookkeeper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ spec:
{{- else }}
blockOwnerDeletion: false
{{- end }}
{{- if .Values.labels }}
labels:
{{ toYaml .Values.labels | indent 4 }}
{{- end }}
{{- if .Values.annotations }}
annotations:
{{ toYaml .Values.annotations | indent 4 }}
{{- end }}
{{- if .Values.initContainers }}
initContainers:
{{ toYaml .Values.initContainers | indent 4 }}
{{- end }}
{{- if .Values.headlessSvcNameSuffix }}
headlessSvcNameSuffix: {{ .Values.headlessSvcNameSuffix }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions charts/bookkeeper/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ blockOwnerDeletion: true
affinity: {}
labels: {}
annotations: {}
initContainers: []
headlessSvcNameSuffix:
probes:
readiness:
Expand Down
1,050 changes: 1,050 additions & 0 deletions deploy/crds/bookkeeper.pravega.io_bookkeeperclusters_crd.yaml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ type BookkeeperClusterSpec struct {
// +optional
Annotations map[string]string `json:"annotations"`

// InitContainers to be added to the bookie pods
// +optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`

// This is used as suffix for bookkeeper headless service name
// +optional
HeadlessSvcNameSuffix string `json:"headlessSvcNameSuffix,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/bookkeeper/v1alpha1/zz_generated.deepcopy.go

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

14 changes: 14 additions & 0 deletions pkg/apis/bookkeeper/v1alpha1/zz_generated.deepcopy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package v1alpha1_test
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -48,6 +49,14 @@ var _ = Describe("DeepCopy", func() {
bk1.Spec.Probes.ReadinessProbe.InitialDelaySeconds = 5
bk1.Spec.Probes.LivenessProbe.FailureThreshold = 2
bk2.Spec.Probes = bk1.Spec.Probes.DeepCopy()
initContainer := []v1.Container{
v1.Container{
Name: "testing",
Image: "dummy-image",
Command: []string{"sh", "-c", "ls;pwd"},
},
}
bk1.Spec.InitContainers = initContainer
bk1.Spec.JVMOptions.MemoryOpts = []string{"1g"}
bk2.Spec.JVMOptions = bk1.Spec.JVMOptions.DeepCopy()
bk2.Spec.Storage = bk1.Spec.Storage.DeepCopy()
Expand Down Expand Up @@ -85,6 +94,11 @@ var _ = Describe("DeepCopy", func() {
It("checking bk2 options ledger field", func() {
Ω(bk2.Spec.Options["ledgers"]).To(Equal("l1"))
})
It("checking init containers", func() {
Ω(bk2.Spec.InitContainers[0].Name).To(Equal("testing"))
Ω(bk2.Spec.InitContainers[0].Image).To(Equal("dummy-image"))
Ω(strings.Contains(bk2.Spec.InitContainers[0].Command[2], "ls;pwd")).To(BeTrue())
})
It("checking bk2 ready members", func() {
Ω(bk2.Status.Members.Ready[0]).To(Equal("bookie-0"))
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/bookkeepercluster/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ func makeBookiePodSpec(bk *v1alpha1.BookkeeperCluster) *corev1.PodSpec {
podSpec.ServiceAccountName = bk.Spec.ServiceAccountName
}

if bk.Spec.InitContainers != nil {
podSpec.InitContainers = bk.Spec.InitContainers
}

return podSpec
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/bookkeepercluster/bookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package bookkeepercluster_test

import (
"strings"
"testing"

"github.com/pravega/bookkeeper-operator/pkg/apis/bookkeeper/v1alpha1"
Expand Down Expand Up @@ -100,6 +101,13 @@ var _ = Describe("Bookie", func() {
Annotations: map[string]string{
"bookie-annotation": "dummyBookie",
},
InitContainers: []corev1.Container{
corev1.Container{
Name: "testing",
Image: "dummy-image",
Command: []string{"sh", "-c", "ls;pwd"},
},
},
}
bk.WithDefaults()
})
Expand Down Expand Up @@ -210,6 +218,13 @@ var _ = Describe("Bookie", func() {
Ω(lp_s).Should(Equal(int32(1)))
Ω(lp_t).Should(Equal(int32(2)))
})

It("should have init container", func() {
podTemplate := bookkeepercluster.MakeBookiePodTemplate(bk)
Ω(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())
})
})
})

Expand Down

0 comments on commit 21dc351

Please sign in to comment.