From 4b5acdec8f1db1bc8cdc1700e23446a1ee83e9d0 Mon Sep 17 00:00:00 2001 From: xingran Date: Wed, 23 Oct 2024 14:11:19 +0800 Subject: [PATCH] chore: upgrade loki to v1.0 API (#1109) --- addons/loki/Chart.yaml | 2 +- addons/loki/templates/_helpers.tpl | 83 +++++++++++++++----- addons/loki/templates/clusterdefinition.yaml | 8 +- addons/loki/templates/cmpd-backend.yaml | 23 +++--- addons/loki/templates/cmpd-gateway.yaml | 15 ++-- addons/loki/templates/cmpd-read.yaml | 23 +++--- addons/loki/templates/cmpd-write.yaml | 23 +++--- addons/loki/templates/cmpv.yaml | 8 +- addons/loki/values.yaml | 6 -- 9 files changed, 119 insertions(+), 72 deletions(-) diff --git a/addons/loki/Chart.yaml b/addons/loki/Chart.yaml index 96d99302d..8474ee3da 100644 --- a/addons/loki/Chart.yaml +++ b/addons/loki/Chart.yaml @@ -13,6 +13,6 @@ maintainers: url: https://github.com/apecloud/kubeblocks/ annotations: - addon.kubeblocks.io/kubeblocks-version: ">=0.8.0" + addon.kubeblocks.io/kubeblocks-version: ">=1.0.0" addon.kubeblocks.io/model: "tsdb" addon.kubeblocks.io/provider: "community" diff --git a/addons/loki/templates/_helpers.tpl b/addons/loki/templates/_helpers.tpl index c113b4066..729bdc8ed 100644 --- a/addons/loki/templates/_helpers.tpl +++ b/addons/loki/templates/_helpers.tpl @@ -24,18 +24,6 @@ If release name contains chart name it will be used as a full name. {{- end }} {{- end }} -{{/* Create a default storage config that uses filesystem storage -This is required for CI, but Loki will not be queryable with this default -applied, thus it is encouraged that users override this. -*/}} -{{- define "loki.storageConfig" -}} -{{- if .Values.loki.storageConfig -}} -{{- .Values.loki.storageConfig | toYaml | nindent 4 -}} -{{- else }} -{{- .Values.loki.defaultStorageConfig | toYaml | nindent 4 }} -{{- end}} -{{- end}} - {{/* Create chart name and version as used by the chart label. */}} @@ -64,15 +52,11 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* -Create the name of the service account to use +Common annotations */}} -{{- define "loki.serviceAccountName" -}} -{{- if .Values.serviceAccount.create -}} - {{ default (include "loki.name" .) .Values.serviceAccount.name }} -{{- else -}} - {{ default "default" .Values.serviceAccount.name }} -{{- end -}} -{{- end -}} +{{- define "loki.annotations" -}} +helm.sh/resource-policy: keep +{{- end }} {{/* Base template for building docker image reference @@ -521,4 +505,61 @@ query-scheduler fullname */}} {{- define "loki.querySchedulerFullname" -}} {{ include "loki.fullname" . }}-query-scheduler -{{- end }} \ No newline at end of file +{{- end }} + +{{/* +Define loki backend component definition name +*/}} +{{- define "loki.backendCmpdName" -}} +loki-backend-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define loki backend component definition regular expression name prefix +*/}} +{{- define "loki.backendCmpdRegexpPattern" -}} +^loki-backend- +{{- end -}} + +{{/* +Define loki gateway component definition name +*/}} +{{- define "loki.gatewayCmpdName" -}} +loki-gateway-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define loki backend component definition regular expression name prefix +*/}} +{{- define "loki.gatewayCmpdRegexpPattern" -}} +^loki-gateway- +{{- end -}} + +{{/* +Define loki read component definition name +*/}} +{{- define "loki.readCmpdName" -}} +loki-read-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define loki read component definition regular expression name prefix +*/}} +{{- define "loki.readCmpdRegexpPattern" -}} +^loki-read- +{{- end -}} + + +{{/* +Define loki write component definition name +*/}} +{{- define "loki.writeCmpdName" -}} +loki-write-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define loki write component definition regular expression name prefix +*/}} +{{- define "loki.writeCmpdRegexpPattern" -}} +^loki-write- +{{- end -}} diff --git a/addons/loki/templates/clusterdefinition.yaml b/addons/loki/templates/clusterdefinition.yaml index 0c59f879b..53c64e223 100644 --- a/addons/loki/templates/clusterdefinition.yaml +++ b/addons/loki/templates/clusterdefinition.yaml @@ -9,13 +9,13 @@ spec: - name: loki-cluster components: - name: write - compDef: loki-write + compDef: {{ include "loki.writeCmpdRegexpPattern" . }} - name: read - compDef: loki-read + compDef: {{ include "loki.readCmpdRegexpPattern" . }} - name: backend - compDef: loki-backend + compDef: {{ include "loki.backendCmpdRegexpPattern" . }} - name: gateway - compDef: loki-gateway + compDef: {{ include "loki.gatewayCmpdRegexpPattern" . }} orders: provision: - backend diff --git a/addons/loki/templates/cmpd-backend.yaml b/addons/loki/templates/cmpd-backend.yaml index 2523ed740..db379b2bc 100644 --- a/addons/loki/templates/cmpd-backend.yaml +++ b/addons/loki/templates/cmpd-backend.yaml @@ -1,9 +1,11 @@ apiVersion: apps.kubeblocks.io/v1 kind: ComponentDefinition metadata: - name: loki-backend + name: {{ include "loki.backendCmpdName" . }} labels: {{- include "loki.labels" . | nindent 4 }} + annotations: + {{- include "loki.annotations" . | nindent 4 }} spec: provider: kubeblocks description: A Loki component definition for Kubernetes @@ -23,6 +25,16 @@ spec: protocol: TCP name: grpc targetPort: grpc + configs: + - name: loki-config + ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. + templateRef: loki + volumeName: config + namespace: {{ .Release.Namespace }} + - name: loki-runtime-config + templateRef: loki-runtime + volumeName: runtime-config + namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -97,12 +109,3 @@ spec: name: data - mountPath: /rules name: sc-rules-volume - configs: - - name: loki-config - templateRef: loki - volumeName: config - namespace: {{ .Release.Namespace }} - - name: loki-runtime-config - templateRef: loki-runtime - volumeName: runtime-config - namespace: {{ .Release.Namespace }} diff --git a/addons/loki/templates/cmpd-gateway.yaml b/addons/loki/templates/cmpd-gateway.yaml index 30744d8c3..b341fe0f6 100644 --- a/addons/loki/templates/cmpd-gateway.yaml +++ b/addons/loki/templates/cmpd-gateway.yaml @@ -1,9 +1,11 @@ apiVersion: apps.kubeblocks.io/v1 kind: ComponentDefinition metadata: - name: loki-gateway + name: {{ include "loki.gatewayCmpdName" . }} labels: {{- include "loki.labels" . | nindent 4 }} + annotations: + {{- include "loki.annotations" . | nindent 4 }} spec: provider: kubeblocks description: A Loki component definition for Kubernetes @@ -17,6 +19,12 @@ spec: protocol: TCP name: http-metrics targetPort: http-metrics + configs: + - name: config-gateway + ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. + templateRef: loki-gateway + volumeName: config + namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -56,8 +64,3 @@ spec: name: tmp - mountPath: /docker-entrypoint.d name: docker-entrypoint-d-override - configs: - - name: config-gateway - templateRef: loki-gateway - volumeName: config - namespace: {{ .Release.Namespace }} diff --git a/addons/loki/templates/cmpd-read.yaml b/addons/loki/templates/cmpd-read.yaml index 79ff4fcca..3c75d1ad5 100644 --- a/addons/loki/templates/cmpd-read.yaml +++ b/addons/loki/templates/cmpd-read.yaml @@ -1,9 +1,11 @@ apiVersion: apps.kubeblocks.io/v1 kind: ComponentDefinition metadata: - name: loki-read + name: {{ include "loki.readCmpdName" . }} labels: {{- include "loki.labels" . | nindent 4 }} + annotations: + {{- include "loki.annotations" . | nindent 4 }} spec: provider: kubeblocks description: A Loki component definition for Kubernetes @@ -23,6 +25,16 @@ spec: protocol: TCP name: grpc targetPort: grpc + configs: + - name: loki-config + ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. + templateRef: loki + volumeName: config + namespace: {{ .Release.Namespace }} + - name: loki-runtime-config + templateRef: loki-runtime + volumeName: runtime-config + namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -76,12 +88,3 @@ spec: name: tmp - mountPath: /var/loki name: data - configs: - - name: loki-config - templateRef: loki - volumeName: config - namespace: {{ .Release.Namespace }} - - name: loki-runtime-config - templateRef: loki-runtime - volumeName: runtime-config - namespace: {{ .Release.Namespace }} diff --git a/addons/loki/templates/cmpd-write.yaml b/addons/loki/templates/cmpd-write.yaml index 109394afb..18f0e3e79 100644 --- a/addons/loki/templates/cmpd-write.yaml +++ b/addons/loki/templates/cmpd-write.yaml @@ -1,9 +1,11 @@ apiVersion: apps.kubeblocks.io/v1 kind: ComponentDefinition metadata: - name: loki-write + name: {{ include "loki.writeCmpdName" . }} labels: {{- include "loki.labels" . | nindent 4 }} + annotations: + {{- include "loki.annotations" . | nindent 4 }} spec: provider: kubeblocks description: A Loki component definition for Kubernetes @@ -23,6 +25,16 @@ spec: protocol: TCP name: grpc targetPort: grpc + configs: + - name: loki-config + ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. + templateRef: loki + volumeName: config + namespace: {{ .Release.Namespace }} + - name: loki-runtime-config + templateRef: loki-runtime + volumeName: runtime-config + namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -73,12 +85,3 @@ spec: name: tmp - mountPath: /var/loki name: data - configs: - - name: loki-config - templateRef: loki - volumeName: config - namespace: {{ .Release.Namespace }} - - name: loki-runtime-config - templateRef: loki-runtime - volumeName: runtime-config - namespace: {{ .Release.Namespace }} diff --git a/addons/loki/templates/cmpv.yaml b/addons/loki/templates/cmpv.yaml index 9290a3034..ef75440c9 100644 --- a/addons/loki/templates/cmpv.yaml +++ b/addons/loki/templates/cmpv.yaml @@ -9,19 +9,19 @@ spec: - releases: - write-1.0.0 compDefs: - - loki-write + - {{ include "loki.writeCmpdRegexpPattern" . }} - releases: - read-1.0.0 compDefs: - - loki-read + - {{ include "loki.readCmpdRegexpPattern" . }} - releases: - backend-1.0.0 compDefs: - - loki-backend + - {{ include "loki.backendCmpdRegexpPattern" . }} - releases: - gateway-1.0.0 compDefs: - - loki-gateway + - {{ include "loki.gatewayCmpdRegexpPattern" . }} releases: - name: write-1.0.0 serviceVersion: 1.0.0 diff --git a/addons/loki/values.yaml b/addons/loki/values.yaml index 7b7f2c6d5..1242e5cf7 100644 --- a/addons/loki/values.yaml +++ b/addons/loki/values.yaml @@ -34,12 +34,6 @@ nameOverride: "" fullnameOverride: "" clusterVersionOverride: "" -## @param resourceNamePrefix Prefix for all resources name created by this chart, that can avoid name conflict -## if you install multiple releases of this chart. -## If specified, the cluster definition will use it as name. -resourceNamePrefix: "" - - global: # -- configures cluster domain ("cluster.local" by default) clusterDomain: "cluster.local"