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

Commit d3cd8d7

Browse files
committed
fix #86
Signed-off-by: tony84727 <tony84727@gmail.com>
1 parent 9aebcc3 commit d3cd8d7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

pkg/apis/mysql/v1alpha1/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ type ClusterSpec struct {
7575
// set of Nodes a Pod can be scheduled on
7676
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
7777
// Resources holds ResourceRequirements for the MySQL Agent & Server Containers
78-
Resources *Resources `json:"resources,omitempty"`
78+
Resources *Resources `json:"resources,omitempty"`
79+
PodLabels map[string]string `json:"podLabels,omitempty"`
7980
}
8081

8182
// ClusterConditionType represents a valid condition of a Cluster.

pkg/resources/statefulsets/statefulset.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic
383383
podLabels[constants.LabelClusterRole] = constants.ClusterRolePrimary
384384
}
385385

386+
if cluster.Spec.PodLabels != nil {
387+
for k, v := range cluster.Spec.PodLabels {
388+
podLabels[k] = v
389+
}
390+
}
391+
386392
ss := &apps.StatefulSet{
387393
ObjectMeta: metav1.ObjectMeta{
388394
Namespace: cluster.Namespace,

pkg/resources/statefulsets/statefulset_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package statefulsets
1616

1717
import (
18+
"github.com/oracle/mysql-operator/pkg/constants"
1819
"reflect"
1920
"testing"
2021

@@ -357,3 +358,23 @@ func TestClusterNotSetGroupExitStateArgs(t *testing.T) {
357358

358359
assert.NotContains(t, cmd, "--loose-group-replication-exit-state-action=READ_ONLY")
359360
}
361+
362+
func TestClusterWithPodLabels(t *testing.T) {
363+
cluster := &v1alpha1.Cluster{
364+
ObjectMeta: metav1.ObjectMeta{
365+
Name: "test",
366+
},
367+
Spec: v1alpha1.ClusterSpec{
368+
PodLabels: map[string]string{
369+
"example.com/testing": "enabled",
370+
},
371+
},
372+
}
373+
cluster.EnsureDefaults()
374+
statefulSet := NewForCluster(cluster, mockOperatorConfig().Images, "mycluster")
375+
376+
// check original labels exist
377+
assert.Equal(t, "test", statefulSet.Spec.Template.Labels[constants.ClusterLabel])
378+
// check additional labels exist
379+
assert.Equal(t, "enabled", statefulSet.Spec.Template.Labels["example.com/testing"])
380+
}

0 commit comments

Comments
 (0)