Skip to content

Commit d63d5f3

Browse files
xmcqueenschallert
andauthored
Added initial support for PodMetaData, handling Annotations only (#210)
Co-authored-by: Matt Schallert <[email protected]>
1 parent 895fc3f commit d63d5f3

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ClusterSpec defines the desired state for a M3 cluster to be converge to.
6565
| externalCoordinatorSelector | Specify a \"controlling\" coordinator for the cluster It is expected that there is a separate standalone coordinator cluster It is externally managed - not managed by this operator It is expected to have a service endpoint Setup this db cluster, but do not assume a co-located coordinator Instead provide a selector here so we can point to a separate coordinator service Specify here the labels required for the selector | map[string]string | false |
6666
| initContainers | Custom setup for db nodes can be done via initContainers Provide the complete spec for the initContainer here If any storage volumes are needed in the initContainer see InitVolumes below | []corev1.Container | false |
6767
| initVolumes | If the InitContainers require any storage volumes Provide the complete specification for the required Volumes here | []corev1.Volume | false |
68+
| podMetadata | PodMetadata is for any Metadata that is unique to the pods, and does not belong on any other objects, such as Prometheus scrape tags | [metav1.ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#objectmeta-v1-meta) | false |
6869

6970
[Back to TOC](#table-of-contents)
7071

pkg/apis/m3dboperator/v1alpha1/cluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ type ClusterSpec struct {
295295
// If the InitContainers require any storage volumes
296296
// Provide the complete specification for the required Volumes here
297297
InitVolumes []corev1.Volume `json:"initVolumes,omitempty"`
298+
299+
// PodMetadata is for any Metadata that is unique to the pods, and does
300+
// not belong on any other objects, such as Prometheus scrape tags
301+
PodMetadata metav1.ObjectMeta `json:"podMetadata,omitempty"`
298302
}
299303

300304
// NodeAffinityTerm represents a node label and a set of label values, any of

pkg/k8sops/annotations/annotations.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ func BaseAnnotations(cluster *myspec.M3DBCluster) map[string]string {
5151

5252
return base
5353
}
54+
55+
// PodAnnotations is for specifying annotations that are only to be
56+
// applied to the pods such as prometheus scrape tags
57+
func PodAnnotations(cluster *myspec.M3DBCluster) map[string]string {
58+
base := BaseAnnotations(cluster)
59+
for k := range cluster.Spec.PodMetadata.Annotations {
60+
// accept any user-specified annotations if its safe to do so
61+
if _, found := base[k]; !found {
62+
base[k] = cluster.Spec.PodMetadata.Annotations[k]
63+
}
64+
}
65+
66+
return base
67+
}

pkg/k8sops/annotations/annotations_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,34 @@ func TestGenerateBaseAnnotations(t *testing.T) {
5151

5252
assert.Equal(t, expAnnotations, annotations)
5353
}
54+
55+
func TestGeneratePodAnnotations(t *testing.T) {
56+
cluster := &myspec.M3DBCluster{
57+
ObjectMeta: metav1.ObjectMeta{
58+
Name: "cluster-foo",
59+
},
60+
Spec: myspec.ClusterSpec{
61+
PodMetadata: metav1.ObjectMeta{
62+
Annotations: map[string]string{
63+
"pod-annotation": "some-annotation",
64+
},
65+
},
66+
},
67+
}
68+
69+
annotations := PodAnnotations(cluster)
70+
expAnnotations := map[string]string{
71+
"operator.m3db.io/app": "m3db",
72+
"operator.m3db.io/cluster": "cluster-foo",
73+
"pod-annotation": "some-annotation",
74+
}
75+
76+
assert.Equal(t, expAnnotations, annotations)
77+
78+
cluster.Spec.Annotations = map[string]string{"foo": "bar"}
79+
annotations = PodAnnotations(cluster)
80+
expAnnotations["foo"] = "bar"
81+
expAnnotations["pod-annotation"] = "some-annotation"
82+
83+
assert.Equal(t, expAnnotations, annotations)
84+
}

pkg/k8sops/m3db/statefulset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewBaseStatefulSet(ssName, isolationGroup string, cluster *myspec.M3DBClust
6363
objLabels[k] = v
6464
}
6565

66-
objAnnotations := annotations.BaseAnnotations(cluster)
66+
objAnnotations := annotations.PodAnnotations(cluster)
6767

6868
// TODO(schallert): we're currently using the health of the coordinator for
6969
// liveness probes until https://github.com/m3db/m3/issues/996 is fixed. Move

0 commit comments

Comments
 (0)