Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added initial support for PodMetaData, handling Annotations only #210

Merged
merged 4 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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: 4 additions & 0 deletions pkg/apis/m3dboperator/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ type ClusterSpec struct {
// If the InitContainers require any storage volumes
// Provide the complete specification for the required Volumes here
InitVolumes []corev1.Volume `json:"initVolumes,omitempty"`

// PodMetadata is for any Metadata that is unique to the pods, and does
// not belong on any other objects, such as Prometheus scrape tags
PodMetadata metav1.ObjectMeta `json:"podMetadata,omitempty"`
}

// NodeAffinityTerm represents a node label and a set of label values, any of
Expand Down
14 changes: 14 additions & 0 deletions pkg/k8sops/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ func BaseAnnotations(cluster *myspec.M3DBCluster) map[string]string {

return base
}

// PodAnnotations is for specifying annotations that are only to be
// applied to the pods such as prometheus scrape tags
func PodAnnotations(cluster *myspec.M3DBCluster) map[string]string {
base := BaseAnnotations(cluster)
for k := range cluster.Spec.PodMetadata.Annotations {
// accept any user-specified annotations if its safe to do so
if _, found := base[k]; !found {
base[k] = cluster.Spec.PodMetadata.Annotations[k]
}
}

return base
}
31 changes: 31 additions & 0 deletions pkg/k8sops/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,34 @@ func TestGenerateBaseAnnotations(t *testing.T) {

assert.Equal(t, expAnnotations, annotations)
}

func TestGeneratePodAnnotations(t *testing.T) {
cluster := &myspec.M3DBCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-foo",
},
Spec: myspec.ClusterSpec{
PodMetadata: metav1.ObjectMeta{
Annotations: map[string]string{
"pod-annotation": "some-annotation",
},
},
},
}

annotations := PodAnnotations(cluster)
expAnnotations := map[string]string{
"operator.m3db.io/app": "m3db",
"operator.m3db.io/cluster": "cluster-foo",
"pod-annotation": "some-annotation",
}

assert.Equal(t, expAnnotations, annotations)

cluster.Spec.Annotations = map[string]string{"foo": "bar"}
annotations = PodAnnotations(cluster)
expAnnotations["foo"] = "bar"
expAnnotations["pod-annotation"] = "some-annotation"

assert.Equal(t, expAnnotations, annotations)
}
2 changes: 1 addition & 1 deletion pkg/k8sops/m3db/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewBaseStatefulSet(ssName, isolationGroup string, cluster *myspec.M3DBClust
objLabels[k] = v
}

objAnnotations := annotations.BaseAnnotations(cluster)
objAnnotations := annotations.PodAnnotations(cluster)

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