diff --git a/docs/user/clusters.md b/docs/user/clusters.md index 0cb80df2b..aef46e460 100644 --- a/docs/user/clusters.md +++ b/docs/user/clusters.md @@ -50,6 +50,30 @@ spec: name: mysql-root-user-secret ``` +### Create a cluster with initContainers + +The following example will create a MySQL Cluster with a containers. +Format same as Kubernetes container. +```yaml +apiVersion: mysql.oracle.com/v1alpha1 +kind: Cluster +metadata: + name: mysql-cluster-with-init-container +spec: + members: 1 + initContainers: + - name: sleep + image: busybox + command: + - echo + - "This is first init container" + - name: sleep + image: busybox + command: + - echo + - "This is second init container" +``` + ### Create a cluster with a persistent volume The following example will create a MySQL Cluster with a persistent local volume. diff --git a/examples/cluster/cluster-with-init-container.yaml b/examples/cluster/cluster-with-init-container.yaml new file mode 100644 index 000000000..6aa3c56bd --- /dev/null +++ b/examples/cluster/cluster-with-init-container.yaml @@ -0,0 +1,17 @@ +apiVersion: mysql.oracle.com/v1alpha1 +kind: Cluster +metadata: + name: mysql +spec: + members: 1 + initContainers: + - name: sleep + image: busybox + command: + - echo + - "This is first init container" + - name: sleep + image: busybox + command: + - echo + - "This is second init container" diff --git a/pkg/apis/mysql/v1alpha1/types.go b/pkg/apis/mysql/v1alpha1/types.go index dcc8735cf..a740edb8d 100644 --- a/pkg/apis/mysql/v1alpha1/types.go +++ b/pkg/apis/mysql/v1alpha1/types.go @@ -76,6 +76,8 @@ type ClusterSpec struct { Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"` // Resources holds ResourceRequirements for the MySQL Agent & Server Containers Resources *Resources `json:"resources,omitempty"` + // Init containers + InitContainers []corev1.Container `json:"initContainers,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..f6c9a7587 100644 --- a/pkg/resources/statefulsets/statefulset.go +++ b/pkg/resources/statefulsets/statefulset.go @@ -388,6 +388,7 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic ServiceAccountName: "mysql-agent", NodeSelector: cluster.Spec.NodeSelector, Affinity: cluster.Spec.Affinity, + InitContainers: cluster.Spec.InitContainers, Containers: containers, Volumes: podVolumes, },