diff --git a/examples/cluster/cluster-with-additional-volume.yaml b/examples/cluster/cluster-with-additional-volume.yaml new file mode 100644 index 000000000..de871a399 --- /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..b2cebf138 --- /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, }