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

Add podLabels to allow adding additional labels to pods #299

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion pkg/apis/mysql/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ 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 allow adding additional labels to the pods
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"])
}