Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
21 changes: 21 additions & 0 deletions api/v1/perconaservermysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,27 @@ type PodSpec struct {
ContainerSpec `json:",inline"`
}

func (s *PodSpec) Core(selector map[string]string, volumes []corev1.Volume, initContainers []corev1.Container, containers []corev1.Container) corev1.PodSpec {
return corev1.PodSpec{
Volumes: volumes,
InitContainers: initContainers,
Containers: containers,
RestartPolicy: corev1.RestartPolicyAlways,
TerminationGracePeriodSeconds: s.GetTerminationGracePeriodSeconds(),
DNSPolicy: corev1.DNSClusterFirst,
NodeSelector: s.NodeSelector,
ServiceAccountName: s.ServiceAccountName,
SecurityContext: s.PodSecurityContext,
ImagePullSecrets: s.ImagePullSecrets,
Affinity: s.GetAffinity(selector),
SchedulerName: s.SchedulerName,
Tolerations: s.Tolerations,
PriorityClassName: s.PriorityClassName,
RuntimeClassName: s.RuntimeClassName,
TopologySpreadConstraints: s.GetTopologySpreadConstraints(selector),
}
}

type Metadata struct {
// Map of string keys and values that can be used to organize and categorize
// (scope and select) objects. May match selectors of replication controllers
Expand Down
24 changes: 6 additions & 18 deletions pkg/binlogserver/binlog_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash string) *ap
Labels: labels,
Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations),
},
Spec: corev1.PodSpec{
InitContainers: []corev1.Container{
Spec: spec.Core(
labels,
volumes(cr),
[]corev1.Container{
k8s.InitContainer(
cr,
AppName,
Expand All @@ -89,22 +91,8 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash string) *ap
nil,
),
},
Containers: containers(cr),
ServiceAccountName: spec.ServiceAccountName,
NodeSelector: spec.NodeSelector,
Tolerations: spec.Tolerations,
Affinity: spec.GetAffinity(labels),
TopologySpreadConstraints: spec.GetTopologySpreadConstraints(labels),
ImagePullSecrets: spec.ImagePullSecrets,
TerminationGracePeriodSeconds: spec.GetTerminationGracePeriodSeconds(),
PriorityClassName: spec.PriorityClassName,
RuntimeClassName: spec.RuntimeClassName,
RestartPolicy: corev1.RestartPolicyAlways,
SchedulerName: spec.SchedulerName,
DNSPolicy: corev1.DNSClusterFirst,
Volumes: volumes(cr),
SecurityContext: spec.PodSecurityContext,
},
containers(cr),
),
},
},
}
Expand Down
22 changes: 6 additions & 16 deletions pkg/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash st
Labels: Labels(cr),
Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations),
},
Spec: corev1.PodSpec{
NodeSelector: cr.Spec.Proxy.HAProxy.NodeSelector,
Tolerations: cr.Spec.Proxy.HAProxy.Tolerations,
RuntimeClassName: cr.Spec.Proxy.HAProxy.RuntimeClassName,
InitContainers: []corev1.Container{
Spec: cr.Spec.Proxy.HAProxy.Core(
selector,
volumes(cr),
[]corev1.Container{
k8s.InitContainer(
cr,
AppName,
Expand All @@ -180,17 +179,8 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash st
nil,
),
},
Containers: containers(cr, secret),
Affinity: cr.Spec.Proxy.HAProxy.GetAffinity(selector),
TopologySpreadConstraints: cr.Spec.Proxy.HAProxy.GetTopologySpreadConstraints(selector),
ImagePullSecrets: cr.Spec.Proxy.HAProxy.ImagePullSecrets,
TerminationGracePeriodSeconds: cr.Spec.Proxy.HAProxy.GetTerminationGracePeriodSeconds(),
RestartPolicy: corev1.RestartPolicyAlways,
SchedulerName: "default-scheduler",
DNSPolicy: corev1.DNSClusterFirst,
Volumes: volumes(cr),
SecurityContext: cr.Spec.Proxy.HAProxy.PodSecurityContext,
},
containers(cr, secret),
),
},
},
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/haproxy/haproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func TestStatefulset(t *testing.T) {
assert.Equal(t, runtimeClassName, *sts.Spec.Template.Spec.RuntimeClassName)
})

t.Run("service account name", func(t *testing.T) {
cluster := cr.DeepCopy()
sts := StatefulSet(cluster, initImage, configHash, tlsHash, secret)
var e string
assert.Equal(t, e, sts.Spec.Template.Spec.ServiceAccountName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can do assert.Empty(t, sts.Spec.Template.Spec.ServiceAccountName) instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const serviceAccountName = "service"
cluster.Spec.Proxy.HAProxy.ServiceAccountName = serviceAccountName

sts = StatefulSet(cluster, initImage, configHash, tlsHash, secret)
assert.Equal(t, serviceAccountName, sts.Spec.Template.Spec.ServiceAccountName)
})

t.Run("tolerations", func(t *testing.T) {
cluster := cr.DeepCopy()
sts := StatefulSet(cluster, initImage, configHash, tlsHash, secret)
Expand Down
27 changes: 6 additions & 21 deletions pkg/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash st
Labels: Labels(cr),
Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations),
},
Spec: corev1.PodSpec{
InitContainers: []corev1.Container{
Spec: spec.Core(
selector,
append(volumes(cr), spec.SidecarVolumes...),
[]corev1.Container{
k8s.InitContainer(
cr,
AppName,
Expand All @@ -180,25 +182,8 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash st
nil,
),
},
Containers: containers(cr, secret),
ServiceAccountName: cr.Spec.MySQL.ServiceAccountName,
NodeSelector: cr.Spec.MySQL.NodeSelector,
Tolerations: cr.Spec.MySQL.Tolerations,
Affinity: spec.GetAffinity(selector),
TopologySpreadConstraints: spec.GetTopologySpreadConstraints(selector),
ImagePullSecrets: spec.ImagePullSecrets,
TerminationGracePeriodSeconds: spec.GetTerminationGracePeriodSeconds(),
PriorityClassName: spec.PriorityClassName,
RuntimeClassName: spec.RuntimeClassName,
RestartPolicy: corev1.RestartPolicyAlways,
SchedulerName: spec.SchedulerName,
DNSPolicy: corev1.DNSClusterFirst,
Volumes: append(
volumes(cr),
spec.SidecarVolumes...,
),
SecurityContext: spec.PodSecurityContext,
},
containers(cr, secret),
),
},
},
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ func TestStatefulSet(t *testing.T) {
assert.Equal(t, runtimeClassName, *sts.Spec.Template.Spec.RuntimeClassName)
})

t.Run("service account name", func(t *testing.T) {
cluster := cr.DeepCopy()
sts := StatefulSet(cluster, initImage, configHash, tlsHash, secret)
var e string
assert.Equal(t, e, sts.Spec.Template.Spec.ServiceAccountName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can do assert.Empty(t, sts.Spec.Template.Spec.ServiceAccountName) instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const serviceAccountName = "service"
cluster.Spec.MySQL.ServiceAccountName = serviceAccountName

sts = StatefulSet(cluster, initImage, configHash, tlsHash, secret)
assert.Equal(t, serviceAccountName, sts.Spec.Template.Spec.ServiceAccountName)
})

t.Run("tolerations", func(t *testing.T) {
cluster := cr.DeepCopy()
sts := StatefulSet(cluster, initImage, configHash, tlsHash, secret)
Expand Down
24 changes: 6 additions & 18 deletions pkg/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash st
Labels: Labels(cr),
Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations),
},
Spec: corev1.PodSpec{
InitContainers: []corev1.Container{
Spec: spec.Core(
selector,
volumes(cr),
[]corev1.Container{
k8s.InitContainer(
cr,
AppName,
Expand All @@ -153,22 +155,8 @@ func StatefulSet(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash st
nil,
),
},
NodeSelector: cr.Spec.Orchestrator.NodeSelector,
Tolerations: cr.Spec.Orchestrator.Tolerations,
Containers: containers(cr),
Affinity: spec.GetAffinity(selector),
TopologySpreadConstraints: spec.GetTopologySpreadConstraints(selector),
ImagePullSecrets: spec.ImagePullSecrets,
TerminationGracePeriodSeconds: spec.GetTerminationGracePeriodSeconds(),
PriorityClassName: spec.PriorityClassName,
RuntimeClassName: spec.RuntimeClassName,
ServiceAccountName: spec.ServiceAccountName,
RestartPolicy: corev1.RestartPolicyAlways,
SchedulerName: spec.SchedulerName,
DNSPolicy: corev1.DNSClusterFirst,
Volumes: volumes(cr),
SecurityContext: spec.PodSecurityContext,
},
containers(cr),
),
},
},
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/orchestrator/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ func TestStatefulSet(t *testing.T) {
assert.Equal(t, runtimeClassName, *sts.Spec.Template.Spec.RuntimeClassName)
})

t.Run("service account name", func(t *testing.T) {
cluster := cr.DeepCopy()
cluster.Spec.Orchestrator.ServiceAccountName = ""
sts := StatefulSet(cluster, initImage, configHash, tlsHash)
assert.Equal(t, "", sts.Spec.Template.Spec.ServiceAccountName)

const serviceAccountName = "service"
cluster.Spec.Orchestrator.ServiceAccountName = serviceAccountName

sts = StatefulSet(cluster, initImage, configHash, tlsHash)
assert.Equal(t, serviceAccountName, sts.Spec.Template.Spec.ServiceAccountName)
})

t.Run("tolerations", func(t *testing.T) {
cluster := cr.DeepCopy()
sts := StatefulSet(cluster, initImage, configHash, tlsHash)
Expand Down
23 changes: 6 additions & 17 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ func Deployment(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash str
Labels: Labels(cr),
Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations),
},
Spec: corev1.PodSpec{
InitContainers: []corev1.Container{
Spec: spec.Core(
selector,
volumes(cr),
[]corev1.Container{
k8s.InitContainer(
cr,
AppName,
Expand All @@ -153,21 +155,8 @@ func Deployment(cr *apiv1.PerconaServerMySQL, initImage, configHash, tlsHash str
nil,
),
},
Containers: containers(cr),
NodeSelector: cr.Spec.Proxy.Router.NodeSelector,
Tolerations: cr.Spec.Proxy.Router.Tolerations,
Affinity: spec.GetAffinity(selector),
TopologySpreadConstraints: spec.GetTopologySpreadConstraints(selector),
ImagePullSecrets: spec.ImagePullSecrets,
TerminationGracePeriodSeconds: spec.GetTerminationGracePeriodSeconds(),
RestartPolicy: corev1.RestartPolicyAlways,
SchedulerName: spec.SchedulerName,
RuntimeClassName: spec.RuntimeClassName,
ServiceAccountName: spec.ServiceAccountName,
DNSPolicy: corev1.DNSClusterFirst,
SecurityContext: spec.PodSecurityContext,
Volumes: volumes(cr),
},
containers(cr),
),
},
},
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ func TestDeployment(t *testing.T) {
assert.Equal(t, runtimeClassName, *deployment.Spec.Template.Spec.RuntimeClassName)
})

t.Run("service account name", func(t *testing.T) {
cluster := cr.DeepCopy()
deployment := Deployment(cluster, initImage, configHash, tlsHash)
var e string
assert.Equal(t, e, deployment.Spec.Template.Spec.ServiceAccountName)

const serviceAccountName = "service"
cluster.Spec.Proxy.Router.ServiceAccountName = serviceAccountName

deployment = Deployment(cluster, initImage, configHash, tlsHash)
assert.Equal(t, serviceAccountName, deployment.Spec.Template.Spec.ServiceAccountName)
})

t.Run("tolerations", func(t *testing.T) {
cluster := cr.DeepCopy()
deployment := Deployment(cluster, initImage, configHash, tlsHash)
Expand Down
Loading