From f9eb849e218ee27ae4a07fc5014f0d78a8d851c2 Mon Sep 17 00:00:00 2001 From: Chunlin Yang Date: Mon, 7 Mar 2022 09:52:47 +0800 Subject: [PATCH] Support configure annotations (#70) Signed-off-by: clyang82 --- api/v1alpha1/observatorium_types.go | 14 ++++++++ api/v1alpha1/zz_generated.deepcopy.go | 35 +++++++++++++++++++ jsonnet/obs-operator.jsonnet | 20 +++++++++++ .../core.observatorium.io_observatoria.yaml | 25 +++++++++++++ 4 files changed, 94 insertions(+) diff --git a/api/v1alpha1/observatorium_types.go b/api/v1alpha1/observatorium_types.go index 28b036a3..bda2f771 100644 --- a/api/v1alpha1/observatorium_types.go +++ b/api/v1alpha1/observatorium_types.go @@ -152,6 +152,9 @@ type ReceiversSpec struct { // How long to retain raw samples on local storage // +optional Retention string `json:"retention,omitempty"` + // Annotations is an unstructured key value map stored with a service account + // +optional + ServiceAccountAnnotations map[string]string `json:"serviceAccountAnnotations,omitempty"` } type StoreSpec struct { @@ -166,6 +169,9 @@ type StoreSpec struct { // ServiceMonitor enables servicemonitor. // +optional ServiceMonitor bool `json:"serviceMonitor,omitempty"` + // Annotations is an unstructured key value map stored with a service account + // +optional + ServiceAccountAnnotations map[string]string `json:"serviceAccountAnnotations,omitempty"` } // MemCacheSpec describes configuration for Store Memcached @@ -353,6 +359,9 @@ type QuerySpec struct { // The maximum lookback duration for retrieving metrics during expression evaluations. // +optional LookbackDelta string `json:"lookbackDelta,omitempty"` + // Annotations is an unstructured key value map stored with a service account + // +optional + ServiceAccountAnnotations map[string]string `json:"serviceAccountAnnotations,omitempty"` } type RuleConfig struct { @@ -428,6 +437,9 @@ type RuleSpec struct { // Evaluation interval // +optional EvalInterval string `json:"evalInterval,omitempty"` + // Annotations is an unstructured key value map stored with a service account + // +optional + ServiceAccountAnnotations map[string]string `json:"serviceAccountAnnotations,omitempty"` } type CompactSpec struct { @@ -452,6 +464,8 @@ type CompactSpec struct { // Time before a block marked for deletion is deleted from bucket // +optional DeleteDelay string `json:"deleteDelay,omitempty"` + // Annotations is an unstructured key value map stored with a service account + ServiceAccountAnnotations map[string]string `json:"serviceAccountAnnotations,omitempty"` } type VolumeClaimTemplate struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 9b9a7158..6cc650bf 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -140,6 +140,13 @@ func (in *CompactSpec) DeepCopyInto(out *CompactSpec) { } in.VolumeClaimTemplate.DeepCopyInto(&out.VolumeClaimTemplate) in.Resources.DeepCopyInto(&out.Resources) + if in.ServiceAccountAnnotations != nil { + in, out := &in.ServiceAccountAnnotations, &out.ServiceAccountAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CompactSpec. @@ -468,6 +475,13 @@ func (in *QuerySpec) DeepCopyInto(out *QuerySpec) { **out = **in } in.Resources.DeepCopyInto(&out.Resources) + if in.ServiceAccountAnnotations != nil { + in, out := &in.ServiceAccountAnnotations, &out.ServiceAccountAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QuerySpec. @@ -566,6 +580,13 @@ func (in *ReceiversSpec) DeepCopyInto(out *ReceiversSpec) { **out = **in } in.Resources.DeepCopyInto(&out.Resources) + if in.ServiceAccountAnnotations != nil { + in, out := &in.ServiceAccountAnnotations, &out.ServiceAccountAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReceiversSpec. @@ -620,6 +641,13 @@ func (in *RuleSpec) DeepCopyInto(out *RuleSpec) { out.AlertmanagerConfigFile = in.AlertmanagerConfigFile in.Resources.DeepCopyInto(&out.Resources) in.ReloaderResources.DeepCopyInto(&out.ReloaderResources) + if in.ServiceAccountAnnotations != nil { + in, out := &in.ServiceAccountAnnotations, &out.ServiceAccountAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuleSpec. @@ -643,6 +671,13 @@ func (in *StoreSpec) DeepCopyInto(out *StoreSpec) { } in.Cache.DeepCopyInto(&out.Cache) in.Resources.DeepCopyInto(&out.Resources) + if in.ServiceAccountAnnotations != nil { + in, out := &in.ServiceAccountAnnotations, &out.ServiceAccountAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StoreSpec. diff --git a/jsonnet/obs-operator.jsonnet b/jsonnet/obs-operator.jsonnet index c54b4a1e..aa400bc3 100644 --- a/jsonnet/obs-operator.jsonnet +++ b/jsonnet/obs-operator.jsonnet @@ -168,6 +168,26 @@ local operatorObs = obs { if (v.kind == 'StatefulSet' && std.startsWith(v.metadata.name, cr.metadata.name + '-thanos-query-frontend-memcached')) then { name: 'observability-thanos-query-frontend-memcached', } else {} + ) + ( + if (std.objectHas(cr.spec.thanos.compact, 'serviceAccountAnnotations') && v.kind == 'ServiceAccount' && std.startsWith(v.metadata.name, cr.metadata.name + '-thanos-compact')) then { + annotations+: cr.spec.thanos.compact.serviceAccountAnnotations, + } else {} + ) + ( + if (std.objectHas(cr.spec.thanos.query, 'serviceAccountAnnotations') && v.kind == 'ServiceAccount' && std.startsWith(v.metadata.name, cr.metadata.name + '-thanos-query')) then { + annotations+: cr.spec.thanos.query.serviceAccountAnnotations, + } else {} + ) + ( + if (std.objectHas(cr.spec.thanos.store, 'serviceAccountAnnotations') && v.kind == 'ServiceAccount' && std.startsWith(v.metadata.name, cr.metadata.name + '-thanos-store-shard')) then { + annotations+: cr.spec.thanos.store.serviceAccountAnnotations, + } else {} + ) + ( + if (std.objectHas(cr.spec.thanos.receivers, 'serviceAccountAnnotations') && v.kind == 'ServiceAccount' && std.startsWith(v.metadata.name, cr.metadata.name + '-thanos-receive')) then { + annotations+: cr.spec.thanos.store.serviceAccountAnnotations, + } else {} + ) + ( + if (std.objectHas(cr.spec.thanos.rule, 'serviceAccountAnnotations') && v.kind == 'ServiceAccount' && std.startsWith(v.metadata.name, cr.metadata.name + '-thanos-rule')) then { + annotations+: cr.spec.thanos.store.serviceAccountAnnotations, + } else {} ), spec+: ( if (std.objectHas(cr.spec, 'nodeSelector') && (v.kind == 'StatefulSet' || v.kind == 'Deployment')) then { diff --git a/manifests/crds/core.observatorium.io_observatoria.yaml b/manifests/crds/core.observatorium.io_observatoria.yaml index 77af1057..568cda69 100644 --- a/manifests/crds/core.observatorium.io_observatoria.yaml +++ b/manifests/crds/core.observatorium.io_observatoria.yaml @@ -901,6 +901,11 @@ spec: retentionResolutionRaw: description: RetentionResolutionRaw type: string + serviceAccountAnnotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored with a service account + type: object serviceMonitor: description: ServiceMonitor enables servicemonitor. type: boolean @@ -1040,6 +1045,11 @@ spec: description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/' type: object type: object + serviceAccountAnnotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored with a service account + type: object serviceMonitor: description: ServiceMonitor enables servicemonitor. type: boolean @@ -1235,6 +1245,11 @@ spec: retention: description: How long to retain raw samples on local storage type: string + serviceAccountAnnotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored with a service account + type: object serviceMonitor: description: ServiceMonitor enables servicemonitor. type: boolean @@ -1455,6 +1470,11 @@ spec: - name type: object type: array + serviceAccountAnnotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored with a service account + type: object serviceMonitor: description: ServiceMonitor enables servicemonitor. type: boolean @@ -1662,6 +1682,11 @@ spec: description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/' type: object type: object + serviceAccountAnnotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored with a service account + type: object serviceMonitor: description: ServiceMonitor enables servicemonitor. type: boolean