From e312ca7df218b60d179a3950a75a8c026fcb5980 Mon Sep 17 00:00:00 2001 From: Desmond Ho Date: Thu, 27 Dec 2018 15:00:16 +0800 Subject: [PATCH 1/2] UPT: added SidecarContainers and AdditionalVolume under Spec --- .../cluster-with-additional-volume.yaml | 10 ++++++ examples/cluster/cluster-with-sidecar.yaml | 33 +++++++++++++++++++ pkg/apis/mysql/v1alpha1/types.go | 4 +++ pkg/resources/statefulsets/statefulset.go | 17 ++++++++++ 4 files changed, 64 insertions(+) create mode 100644 examples/cluster/cluster-with-additional-volume.yaml create mode 100644 examples/cluster/cluster-with-sidecar.yaml diff --git a/examples/cluster/cluster-with-additional-volume.yaml b/examples/cluster/cluster-with-additional-volume.yaml new file mode 100644 index 000000000..bd39f4af0 --- /dev/null +++ b/examples/cluster/cluster-with-additional-volume.yaml @@ -0,0 +1,10 @@ +apiVersion: mysql.oracle.com/v1alpha1 +kind: Cluster +metadata: + name: mysql +spec: + members: 3 + AdditionalVolume: + # will mount to /mnt/$name + - name: test-volume + emptyDir: {} diff --git a/examples/cluster/cluster-with-sidecar.yaml b/examples/cluster/cluster-with-sidecar.yaml new file mode 100644 index 000000000..2b5c33549 --- /dev/null +++ b/examples/cluster/cluster-with-sidecar.yaml @@ -0,0 +1,33 @@ +apiVersion: mysql.oracle.com/v1alpha1 +kind: Cluster +metadata: + name: mysql +spec: + members: 3 + SidecarContainers: + - name: test-container + env: + - name: busybox + value: test-container + image: busybox:1.29.3 + resources: + limits: + cpu: 500m + memory: 256Mi + requests: + cpu: 250m + memory: 128Mi + command: ["sleep", "3600"] + - name: test-container2 + env: + - name: busybox + value: test-container2 + image: busybox:1.29.3 + resources: + limits: + cpu: 500m + memory: 256Mi + requests: + cpu: 250m + memory: 128Mi + command: ["sleep", "3600"] diff --git a/pkg/apis/mysql/v1alpha1/types.go b/pkg/apis/mysql/v1alpha1/types.go index dcc8735cf..bf6071454 100644 --- a/pkg/apis/mysql/v1alpha1/types.go +++ b/pkg/apis/mysql/v1alpha1/types.go @@ -76,6 +76,10 @@ type ClusterSpec struct { Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"` // Resources holds ResourceRequirements for the MySQL Agent & Server Containers Resources *Resources `json:"resources,omitempty"` + // Resources for sidecar + SidecarContainers *[]corev1.Container `json:"sidecarContainers,omitempty"` + // Resources for additional volume + AdditionalVolume *[]corev1.Volume `json:"additionalVolume,omitempty"` } // ClusterConditionType represents a valid condition of a Cluster. diff --git a/pkg/resources/statefulsets/statefulset.go b/pkg/resources/statefulsets/statefulset.go index ebfea7a10..443066607 100644 --- a/pkg/resources/statefulsets/statefulset.go +++ b/pkg/resources/statefulsets/statefulset.go @@ -74,6 +74,15 @@ func volumeMounts(cluster *v1alpha1.Cluster) []v1.VolumeMount { SubPath: "mysql", }) + if cluster.Spec.AdditionalVolume != nil { + for _, v := range *cluster.Spec.AdditionalVolume { + mounts = append(mounts, v1.VolumeMount{ + Name: v.Name, + MountPath: fmt.Sprintf("/mnt/%s", v.Name), + }) + } + } + // A user may explicitly define a my.cnf configuration file for // their MySQL cluster. if cluster.RequiresConfigMount() { @@ -344,10 +353,18 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic }) } + if cluster.Spec.AdditionalVolume != nil && len(*cluster.Spec.AdditionalVolume) > 0 { + podVolumes = append(podVolumes, *cluster.Spec.AdditionalVolume...) + } + containers := []v1.Container{ mysqlServerContainer(cluster, cluster.Spec.Repository, rootPassword, members, baseServerID), mysqlAgentContainer(cluster, images.MySQLAgentImage, rootPassword, members)} + if cluster.Spec.SidecarContainers != nil && len(*cluster.Spec.SidecarContainers) > 0 { + containers = append(containers, *cluster.Spec.SidecarContainers...) + } + podLabels := map[string]string{ constants.ClusterLabel: cluster.Name, } From 64fbae34e031d424548f6171bf99c942cd5782d2 Mon Sep 17 00:00:00 2001 From: Desmond Ho Date: Tue, 8 Jan 2019 18:31:05 +0800 Subject: [PATCH 2/2] FIX: typo in examples --- examples/cluster/cluster-with-additional-volume.yaml | 2 +- examples/cluster/cluster-with-sidecar.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cluster/cluster-with-additional-volume.yaml b/examples/cluster/cluster-with-additional-volume.yaml index bd39f4af0..de871a399 100644 --- a/examples/cluster/cluster-with-additional-volume.yaml +++ b/examples/cluster/cluster-with-additional-volume.yaml @@ -4,7 +4,7 @@ metadata: name: mysql spec: members: 3 - AdditionalVolume: + additionalVolume: # will mount to /mnt/$name - name: test-volume emptyDir: {} diff --git a/examples/cluster/cluster-with-sidecar.yaml b/examples/cluster/cluster-with-sidecar.yaml index 2b5c33549..b2cebf138 100644 --- a/examples/cluster/cluster-with-sidecar.yaml +++ b/examples/cluster/cluster-with-sidecar.yaml @@ -4,7 +4,7 @@ metadata: name: mysql spec: members: 3 - SidecarContainers: + sidecarContainers: - name: test-container env: - name: busybox