Fix pulsar-cluster-initialize / pulsar-init rendering with kustomize (#572)

* Fix pulsar-cluster-initialize / pulsar-init rendering with kustomize

- reapply #166 changes that were reverted by #544 changes

* Add validation for kustomize output in CI
This commit is contained in:
Lari Hotari 2025-02-19 00:46:24 -08:00 committed by GitHub
parent ab46d2165e
commit f928380124
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 112 additions and 2 deletions

72
.ci/helm.sh Normal file → Executable file
View File

@ -423,3 +423,75 @@ function ci::test_pulsar_manager() {
exit 1 exit 1
fi fi
} }
function ci::validate_kustomize_yaml() {
# if kustomize is not installed, install kustomize to a temp directory
if ! command -v kustomize &> /dev/null; then
KUSTOMIZE_VERSION=5.6.0
KUSTOMIZE_DIR=$(mktemp -d)
echo "Installing kustomize ${KUSTOMIZE_VERSION} to ${KUSTOMIZE_DIR}"
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s ${KUSTOMIZE_VERSION} ${KUSTOMIZE_DIR}
export PATH=${KUSTOMIZE_DIR}:$PATH
fi
# prevent regression of https://github.com/apache/pulsar-helm-chart/issues/569
local kustomize_yaml_dir=$(mktemp -d)
cp ${PULSAR_HOME}/.ci/kustomization.yaml ${kustomize_yaml_dir}
PULSAR_HOME=${PULSAR_HOME} yq -i '.helmGlobals.chartHome = env(PULSAR_HOME) + "/charts"' ${kustomize_yaml_dir}/kustomization.yaml
failures=0
# validate zookeeper init
echo "Validating kustomize yaml output with zookeeper init"
_ci::validate_kustomize_yaml ${kustomize_yaml_dir} || ((failures++))
# validate oxia init
yq -i '.helmCharts[0].valuesInline.components += {"zookeeper": false, "oxia": true}' ${kustomize_yaml_dir}/kustomization.yaml
echo "Validating kustomize yaml output with oxia init"
_ci::validate_kustomize_yaml ${kustomize_yaml_dir} || ((failures++))
if [ $failures -gt 0 ]; then
exit 1
fi
}
function _ci::validate_kustomize_yaml() {
local kustomize_yaml_dir=$1
kustomize build --enable-helm --helm-kube-version 1.23.0 --load-restrictor=LoadRestrictionsNone ${kustomize_yaml_dir} | yq 'select(.spec.template.spec.containers[0].args != null) | .spec.template.spec.containers[0].args' | \
awk '{
if (prev_line ~ /\\$/ && $0 ~ /^$/) {
print "Found issue: backslash at end of line followed by empty line. Must use pipe character for multiline strings to support kustomize due to kubernetes-sigs/kustomize#4201.";
print "Line: " prev_line;
has_issue = 1;
}
prev_line = $0;
}
END {
if (!has_issue) {
print "No issues found: no backslash followed by empty line";
exit 0;
}
exit 1;
}'
}
# lists all available functions in this tool
function ci::list_functions() {
declare -F | awk '{print $NF}' | sort | grep -E '^ci::' | sed 's/^ci:://'
}
# Only run this section if the script is being executed directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [ -z "$1" ]; then
echo "usage: $0 [function_name]"
echo "Available functions:"
ci::list_functions
exit 1
fi
ci_function_name="ci::$1"
shift
if [[ "$(LC_ALL=C type -t "${ci_function_name}")" == "function" ]]; then
eval "$ci_function_name" "$@"
exit $?
else
echo "Invalid ci function"
echo "Available functions:"
ci::list_functions
exit 1
fi
fi

32
.ci/kustomization.yaml Normal file
View File

@ -0,0 +1,32 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
helmGlobals:
chartHome: ../charts
helmCharts:
- name: pulsar
releaseName: pulsar
valuesInline:
kube-prometheus-stack:
enabled: false
components:
pulsar_manager: true
zookeeper: true

View File

@ -157,6 +157,12 @@ jobs:
echo "Validating with Oxia enabled" echo "Validating with Oxia enabled"
validate_helm_template_with_k8s_version $k8s_version --set components.zookeeper=false --set components.oxia=true validate_helm_template_with_k8s_version $k8s_version --set components.zookeeper=false --set components.oxia=true
done done
- name: Validate kustomize yaml for extra new lines in pulsar-init commands
if: ${{ steps.check_changes.outputs.docs_only != 'true' }}
run: |
./.ci/helm.sh validate_kustomize_yaml
- name: Wait for ssh connection when build fails - name: Wait for ssh connection when build fails
# ssh access is enabled for builds in own forks # ssh access is enabled for builds in own forks
uses: ./.github/actions/ssh-access uses: ./.github/actions/ssh-access

View File

@ -119,7 +119,7 @@ spec:
command: ["timeout", "{{ .Values.pulsar_metadata.initTimeout | default 60 }}", "sh", "-c"] command: ["timeout", "{{ .Values.pulsar_metadata.initTimeout | default 60 }}", "sh", "-c"]
{{- if .Values.components.zookeeper }} {{- if .Values.components.zookeeper }}
args: args:
- >- - | # Use the pipe character for the YAML multiline string. Workaround for kubernetes-sigs/kustomize#4201
{{- include "pulsar.toolset.zookeeper.tls.settings" . | nindent 12 }} {{- include "pulsar.toolset.zookeeper.tls.settings" . | nindent 12 }}
export PULSAR_MEM="-Xmx128M"; export PULSAR_MEM="-Xmx128M";
bin/pulsar initialize-cluster-metadata \ bin/pulsar initialize-cluster-metadata \
@ -139,7 +139,7 @@ spec:
{{- end }} {{- end }}
{{- else if .Values.components.oxia }} {{- else if .Values.components.oxia }}
args: args:
- >- - | # Use the pipe character for the YAML multiline string. Workaround for kubernetes-sigs/kustomize#4201
export PULSAR_MEM="-Xmx128M"; export PULSAR_MEM="-Xmx128M";
bin/pulsar initialize-cluster-metadata \ bin/pulsar initialize-cluster-metadata \
--cluster {{ template "pulsar.cluster.name" . }} \ --cluster {{ template "pulsar.cluster.name" . }} \