-
Couldn't load subscription status.
- Fork 2
Description
Description
With #27 @mirzakopic introduced the configurability of a data sink (e.g. Dynatrace) via the DataSink CRD that serves kind of like Crossplane's ProviderConfig.
The deployed DataSink CR can be referenced via the spec.dataSinkRef field in the respective metric CRDs of the api/v1alpha1/ package. This field is always an optional field, see
metrics-operator/api/v1alpha1/metric_types.go
Lines 65 to 69 in 2ee9433
| // DataSinkRef specifies the DataSink to be used for this metric. | |
| // If not specified, the DataSink named "default" in the operator's | |
| // namespace will be used. | |
| // +optional | |
| DataSinkRef *DataSinkReference `json:"dataSinkRef,omitempty"` |
The controller already resolves the defaulting behaviour of dataSinkRef automatically in code, see
metrics-operator/internal/controller/datasink_utils.go
Lines 68 to 72 in bba1109
| // Determine DataSink name | |
| dataSinkName := "default" | |
| if dataSinkRef != nil && dataSinkRef.Name != "" { | |
| dataSinkName = dataSinkRef.Name | |
| } |
Problem
For me as an end user who just uses the API/CRDs, I don't see this defaulting behaviour right from the beginning. It would be nice to see the defaulting mechanism also reflected in the applied CR.
Example
After applying the following resource via kubectl apply -f ...
apiVersion: metrics.cloud.sap/v1alpha1
kind: Metric
metadata:
name: basic-total-pods
spec:
name: pods-metric-total
description: Pods
target:
kind: pod
group: ""
version: v1
interval: 1mthe kube apiserver should default spec.dataSinkRef automatically like so:
apiVersion: metrics.cloud.sap/v1alpha1
kind: Metric
metadata:
name: basic-total-pods
spec:
name: pods-metric-total
description: Pods
target:
kind: pod
group: ""
version: v1
interval: 1m
dataSinkRef:
name: default # spec.dataSinkRef gets automatically defaultedProposal
Using Kubebuilders CRD Validation mechanism to automatically default spec.dataSinkRef while applying one of the metric CRs at a K8s cluster.