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

Make ServiceMonitor metadata labels configurable #8

Open
wants to merge 1 commit into
base: main
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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ operator/deployment.yaml: operator/deployment.jsonnet
.bingo/bin/jsonnetfmt -i operator/deployment.jsonnet
.bingo/bin/jsonnet operator/deployment.jsonnet | .bingo/bin/gojsontoyaml > operator/deployment.yaml

.PHONY: container
container:
cp ./kubernetes.libsonnet ./operator/kubernetes.libsonnet
cp -r monitoring/* operator
cd operator && docker build -t quay.io/metalmatze/kube-cockroachdb .

examples: examples/basic/basic.yaml examples/storage/storage.yaml

examples/basic/basic.yaml: examples/basic/basic.jsonnet kubernetes.libsonnet | .bingo/bin/jsonnet .bingo/bin/jsonnetfmt .bingo/bin/gojsontoyaml
Expand Down
13 changes: 8 additions & 5 deletions kubernetes.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ function(params) {
},
resources: {},
storage: {},
serviceMonitor+: {
metadata+: cockroachdb.metadata {
labels+: {
prometheus: 'k8s',
},
},
},
}
+ params, // this merges your parameters with default ones

Expand Down Expand Up @@ -220,11 +227,7 @@ function(params) {
serviceMonitor: {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata: cockroachdb.metadata {
labels+: {
prometheus: 'k8s',
},
},
metadata: cockroachdb.metadata + cockroachdb.serviceMonitor.metadata,
spec: {
endpoints: [
{
Expand Down
8 changes: 8 additions & 0 deletions operator/api/v1alphav1/cockroachdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type CockroachDBSpec struct {

// Storage spec to specify how storage shall be used.
Storage *StorageSpec `json:"storage,omitempty"`

// ServiceMonitor allows overwriting some metadata labels.
ServiceMonitor *ServiceMonitorSpec `json:"serviceMonitor,omitempty"`
}

// Storage parts are taken from the Prometheus Operator:
Expand Down Expand Up @@ -121,3 +124,8 @@ type EmbeddedObjectMetadata struct {
}

type CockroachDBStatus struct{}

type ServiceMonitorSpec struct {
// EmbeddedMetadata contains metadata relevant to an EmbeddedResource.
EmbeddedObjectMetadata `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
}
21 changes: 21 additions & 0 deletions operator/api/v1alphav1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions operator/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local config = import 'generic-operator/config';
replicas: config.spec.replicas,
resources: if std.objectHas(config.spec, 'resources') then config.spec.resources else {},
storage: if std.objectHas(config.spec, 'storage') then config.spec.storage else {},
serviceMonitor: if std.objectHas(config.spec, 'serviceMonitor') then config.spec.serviceMonitor else {},
})
),
rollout: {
Expand Down
32 changes: 32 additions & 0 deletions operator/metalmatze.de_cockroachdbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ spec:
value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
serviceMonitor:
description: ServiceMonitor allows overwriting some metadata labels.
properties:
metadata:
description: EmbeddedMetadata contains metadata relevant to an EmbeddedResource.
properties:
annotations:
additionalProperties:
type: string
description: 'Annotations is an unstructured key value map stored
with a resource that may be set by external tools to store
and retrieve arbitrary metadata. They are not queryable and
should be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations'
type: object
labels:
additionalProperties:
type: string
description: 'Map of string keys and values that can be used
to organize and categorize (scope and select) objects. May
match selectors of replication controllers and services. More
info: http://kubernetes.io/docs/user-guide/labels'
type: object
name:
description: 'Name must be unique within a namespace. Is required
when creating resources, although some resources may allow
a client to request the generation of an appropriate name
automatically. Name is primarily intended for creation idempotence
and configuration definition. Cannot be updated. More info:
http://kubernetes.io/docs/user-guide/identifiers#names'
type: string
type: object
type: object
storage:
description: Storage spec to specify how storage shall be used.
properties:
Expand Down