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

Commit

Permalink
fix #86
Browse files Browse the repository at this point in the history
Signed-off-by: tony84727 <tony84727@gmail.com>
  • Loading branch information
tony84727 committed Jan 8, 2020
1 parent 9aebcc3 commit d3cd8d7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/apis/mysql/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ type ClusterSpec struct {
// set of Nodes a Pod can be scheduled on
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
// Resources holds ResourceRequirements for the MySQL Agent & Server Containers
Resources *Resources `json:"resources,omitempty"`
Resources *Resources `json:"resources,omitempty"`
PodLabels map[string]string `json:"podLabels,omitempty"`
}

// ClusterConditionType represents a valid condition of a Cluster.
Expand Down
6 changes: 6 additions & 0 deletions pkg/resources/statefulsets/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ func NewForCluster(cluster *v1alpha1.Cluster, images operatoropts.Images, servic
podLabels[constants.LabelClusterRole] = constants.ClusterRolePrimary
}

if cluster.Spec.PodLabels != nil {
for k, v := range cluster.Spec.PodLabels {
podLabels[k] = v
}
}

ss := &apps.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Expand Down
21 changes: 21 additions & 0 deletions pkg/resources/statefulsets/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package statefulsets

import (
"github.com/oracle/mysql-operator/pkg/constants"
"reflect"
"testing"

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

assert.NotContains(t, cmd, "--loose-group-replication-exit-state-action=READ_ONLY")
}

func TestClusterWithPodLabels(t *testing.T) {
cluster := &v1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: v1alpha1.ClusterSpec{
PodLabels: map[string]string{
"example.com/testing": "enabled",
},
},
}
cluster.EnsureDefaults()
statefulSet := NewForCluster(cluster, mockOperatorConfig().Images, "mycluster")

// check original labels exist
assert.Equal(t, "test", statefulSet.Spec.Template.Labels[constants.ClusterLabel])
// check additional labels exist
assert.Equal(t, "enabled", statefulSet.Spec.Template.Labels["example.com/testing"])
}

0 comments on commit d3cd8d7

Please sign in to comment.