Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Enhancement for adding SidecarContainers and AdditionalVolume under Spec #247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/cluster/cluster-with-additional-volume.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
33 changes: 33 additions & 0 deletions examples/cluster/cluster-with-sidecar.yaml
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 4 additions & 0 deletions pkg/apis/mysql/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions pkg/resources/statefulsets/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
}
Expand Down