Skip to content

Commit

Permalink
chore: do not disable enabled addons when upgrade (#6432)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldming authored Jan 12, 2024
1 parent decf61a commit f014514
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 69 deletions.
59 changes: 44 additions & 15 deletions deploy/helm/templates/_addon.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ Example:
{{- include "kubeblocks.addonChartLocationURL" ( dict "name" "apecloud-mysql" "version" "0.5.0" "values" .Values) }}
*/}}
{{- define "kubeblocks.addonChartLocationURL" }}
{{- $fullChart := print .name "-" .version }}
{{- $base := .values.addonChartLocationBase }}
{{- if hasPrefix "oci://" $base }}
chartLocationURL: {{ $base }}/{{ .name }}
{{- else if hasPrefix "https://github.com/apecloud/helm-charts/releases/download" $base }}
chartLocationURL: {{ $base }}/{{ $fullChart }}/{{ $fullChart }}.tgz
{{- else }}
chartLocationURL: {{ $base }}/{{ $fullChart }}.tgz
{{- end }}
chartLocationURL: {{ include "kubeblocks.addonChartLocationURLValue" . }}
{{- end }}

{{- define "kubeblocks.addonChartLocationURLValue" }}
{{- $fullChart := print .name "-" .version -}}
{{- $base := .values.addonChartLocationBase -}}
{{- if hasPrefix "oci://" $base -}}
{{ $base }}/{{ .name }}
{{- else if hasPrefix "https://github.com/apecloud/helm-charts/releases/download" $base -}}
{{ $base }}/{{ $fullChart }}/{{ $fullChart }}.tgz
{{- else -}}
{{ $base }}/{{ $fullChart }}.tgz
{{- end -}}
{{- end -}}

{{/*
Build add-on CR.
When upgrade KubeBlocks, if the add-on CR already exists, we will do not upgrade it if
Expand All @@ -41,17 +45,38 @@ Parameters:
- kbVersion: KubeBlocks version that this addon is compatible with
*/}}
{{- define "kubeblocks.buildAddonCR" }}
{{- $addonImageRegistry := include "kubeblocks.imageRegistry" . }}
{{- $upgrade:= or .Release.IsInstall (and .Release.IsUpgrade .Values.upgradeAddons) }}
{{- $install := .Release.IsInstall }}
{{- $upgrade := (and .Release.IsUpgrade .Values.upgradeAddons) }}
{{- $existingAddon := lookup "extensions.kubeblocks.io/v1alpha1" "Addon" "" .name -}}
{{- if and (not $upgrade) $existingAddon -}}
{{- if or $install (and $upgrade (not $existingAddon)) -}}
{{- include "kubeblocks.buildAddon" . }}
{{- else if and (not $upgrade) $existingAddon -}}
{{- $obj := fromYaml (toYaml $existingAddon) -}}
{{- $metadata := get $obj "metadata" -}}
{{- $metadata = unset $metadata "managedFields" -}}
{{- $metadata = unset $metadata "resourceVersion" -}}
{{- $obj = set $obj "metadata" $metadata -}}
{{ $obj | toYaml }}
{{- else -}}
{{- else if and $upgrade $existingAddon -}}
{{- $addonCR := include "kubeblocks.buildAddon" . -}}
{{- $addonObj := fromYaml $addonCR -}}
{{- $spec := get $addonObj "spec" -}}
{{- $installable := get (get $existingAddon "spec") "installable" }}
{{- if $installable -}}
{{- $spec = set $spec "installable" $installable -}}
{{- end -}}
{{- $install = get (get $existingAddon "spec") "install" -}}
{{- if $install -}}
{{- $spec = set $spec "install" $install -}}
{{- end -}}
{{- $addonObj = set $addonObj "spec" $spec -}}
{{ $addonObj | toYaml }}
{{- end -}}
{{- end -}}

{{- define "kubeblocks.buildAddon" }}
{{- $addonImageRegistry := include "kubeblocks.imageRegistry" . }}
{{- $cloudProvider := (include "kubeblocks.cloudProvider" .) }}
apiVersion: extensions.kubeblocks.io/v1alpha1
kind: Addon
metadata:
Expand All @@ -78,9 +103,13 @@ spec:
{{- if hasPrefix "oci://" .Values.addonChartLocationBase }}
version: {{ .version }}
{{- end }}
{{- if and (eq .name "pulsar") (eq $cloudProvider "huaweiCloud") }}
installValues:
setValues:
- cloudProvider=huaweiCloud
{{- end }}
defaultInstallValues:
- enabled: true
installable:
autoInstall: {{ .autoInstall }}
{{- end -}}
{{- end -}}
{{- end }}
2 changes: 1 addition & 1 deletion deploy/helm/templates/addons/apecloud-mysql-addon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"kbVersion" ">=0.7.0"
"selectorLabels" $selectorLabels
"name" "apecloud-mysql"
"version" "0.8.0-beta.3"
"version" "0.8.0-beta.5"
"model" "RDBMS"
"provider" "apecloud"
"description" "ApeCloud MySQL is a database that is compatible with MySQL syntax and achieves high availability through the utilization of the RAFT consensus protocol."
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/templates/addons/milvus-addon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"kbVersion" ">=0.7.0"
"selectorLabels" $selectorLabels
"name" "milvus"
"version" "0.7.0"
"version" "2.3.2"
"model" "vector"
"provider" "community"
"description" "Milvus is an open source (Apache-2.0 licensed) vector database built to power embedding similarity search and AI applications."
Expand Down
62 changes: 10 additions & 52 deletions deploy/helm/templates/addons/pulsar-addon.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
{{- $name:="pulsar" -}}
{{- $version:="0.7.0" -}}
{{- $upgrade:= or .Release.IsInstall (and .Release.IsUpgrade .Values.upgradeAddons) }}
{{- $existingAddon := lookup "extensions.kubeblocks.io/v1alpha1" "Addon" "" $name -}}
{{- if and (not $upgrade) $existingAddon -}}
{{- $obj := fromYaml (toYaml $existingAddon) -}}
{{- $metadata := get $obj "metadata" -}}
{{- $metadata = unset $metadata "managedFields" -}}
{{- $metadata = unset $metadata "resourceVersion" -}}
{{- $obj = set $obj "metadata" $metadata -}}
{{ $obj | toYaml }}
{{- else -}}
apiVersion: extensions.kubeblocks.io/v1alpha1
kind: Addon
metadata:
name: {{ $name }}
labels:
{{- include "kubeblocks.selectorLabels" . | nindent 4 }}
addon.kubeblocks.io/name: {{ $name }}
addon.kubeblocks.io/version: {{ $version }}
addon.kubeblocks.io/provider: community
addon.kubeblocks.io/model: streaming
annotations:
addon.kubeblocks.io/kubeblocks-version: '>=0.7.0'
{{- if .Values.keepAddons }}
helm.sh/resource-policy: keep
{{- end }}
spec:
description: "Apache® Pulsar™ is an open-source, distributed messaging and streaming platform built for the cloud."
type: Helm
helm:
{{- include "kubeblocks.addonChartLocationURL" ( dict "name" $name "version" $version "values" .Values) | indent 4 }}
{{- include "kubeblocks.addonChartsImage" . | indent 4 }}

installOptions:
{{- if hasPrefix "oci://" .Values.addonChartLocationBase }}
version: {{ default .Chart.Version .Values.versionOverride }}
{{- end }}

installValues:
{{- $cloudProvider := (include "kubeblocks.cloudProvider" .) }}
{{- if eq $cloudProvider "huaweiCloud" }}
setValues:
- cloudProvider=huaweiCloud
{{- end }}

installable:
autoInstall: true

defaultInstallValues:
- enabled: true
{{- end -}}
{{- $selectorLabels := include "kubeblocks.selectorLabels" . }}
{{- include "kubeblocks.buildAddonCR" (merge (dict
"kbVersion" ">=0.7.0"
"selectorLabels" $selectorLabels
"name" "pulsar"
"version" "0.7.1"
"model" "streaming"
"provider" "community"
"description" "Apache® Pulsar™ is an open-source, distributed messaging and streaming platform built for the cloud."
"autoInstall" true) . ) -}}

0 comments on commit f014514

Please sign in to comment.