Skip to content

Commit

Permalink
Merge pull request #6515 from yuseinishiyama/label-mon-pods
Browse files Browse the repository at this point in the history
ceph: Label mon pods
  • Loading branch information
travisn committed Oct 30, 2020
2 parents 1c56251 + beaddb9 commit 024d1a8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/rook.io/v1/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (a AnnotationsSpec) All() Annotations {
return a[KeyAll]
}

// ApplyToObjectMeta adds or overwrites if exists annotations to object meta.
// ApplyToObjectMeta adds annotations to object meta unless the keys are already defined.
func (a Annotations) ApplyToObjectMeta(t *metav1.ObjectMeta) {
if t.Annotations == nil {
t.Annotations = map[string]string{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/rook.io/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (a LabelsSpec) All() Labels {
return a[KeyAll]
}

// ApplyToObjectMeta adds or overwrites if exists Labels to object meta.
// ApplyToObjectMeta adds labels to object meta unless the keys are already defined.
func (a Labels) ApplyToObjectMeta(t *metav1.ObjectMeta) {
if t.Labels == nil {
t.Labels = map[string]string{}
Expand Down
58 changes: 49 additions & 9 deletions pkg/apis/rook.io/v1/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,57 @@ mon:
}

func TestLabelsApply(t *testing.T) {
objMeta := &metav1.ObjectMeta{}
testLabels := Labels{
"foo": "bar",
"hello": "world",
tcs := []struct {
name string
target *metav1.ObjectMeta
input Labels
expected Labels
}{
{
name: "it should be able to update meta with no label",
target: &metav1.ObjectMeta{},
input: Labels{
"foo": "bar",
},
expected: Labels{
"foo": "bar",
},
},
{
name: "it should keep the original labels when new labels are set",
target: &metav1.ObjectMeta{
Labels: Labels{
"foo": "bar",
},
},
input: Labels{
"hello": "world",
},
expected: Labels{
"foo": "bar",
"hello": "world",
},
},
{
name: "it should NOT overwrite the existing keys",
target: &metav1.ObjectMeta{
Labels: Labels{
"foo": "bar",
},
},
input: Labels{
"foo": "baz",
},
expected: Labels{
"foo": "bar",
},
},
}
testLabels.ApplyToObjectMeta(objMeta)
assert.Equal(t, testLabels.getMapStringString(), objMeta.Labels)

testLabels["isthisatest"] = "test"
testLabels.ApplyToObjectMeta(objMeta)
assert.Equal(t, testLabels.getMapStringString(), objMeta.Labels)
for _, tc := range tcs {
tc.input.ApplyToObjectMeta(tc.target)
assert.Equal(t, tc.expected.getMapStringString(), tc.target.Labels)
}
}

func TestLabelsMerge(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/ceph/cluster/mon/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (c *Cluster) makeMonPod(monConfig *monConfig, canary bool) (*v1.Pod, error)
Spec: podSpec,
}
cephv1.GetMonAnnotations(c.spec.Annotations).ApplyToObjectMeta(&pod.ObjectMeta)
cephv1.GetMonLabels(c.spec.Labels).ApplyToObjectMeta(&pod.ObjectMeta)

if c.spec.Network.IsHost() {
pod.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
Expand Down

0 comments on commit 024d1a8

Please sign in to comment.