From 4e3d3d0b8b885f6e7add5d9e52b02e5f318a0b25 Mon Sep 17 00:00:00 2001 From: Craig O'Donnell Date: Fri, 13 Oct 2023 13:05:28 -0400 Subject: [PATCH] allow empty status informers (#102) * allow empty status informers * add tests * additional feedback * address additional logging feedback --- .github/workflows/main.yaml | 84 +++++++++++++++++++++++++- chart/templates/replicated-secret.yaml | 2 + chart/values.yaml.tmpl | 2 +- pkg/apiserver/bootstrap.go | 2 +- pkg/appstate/util.go | 2 + 5 files changed, 88 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d9e05073..aa708e6f 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -85,6 +85,11 @@ jobs: exit 1 fi + if ! echo $output | grep -q 'statusInformers: null'; then + printf "default statusInformers should be null:\n\n%s\n\n" "$output" + exit 1 + fi + output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set integration.enabled=true) if ! echo $output | grep -q integration-enabled; then @@ -155,6 +160,17 @@ jobs: fi + cat << EOF > test-values.yaml + statusInformers: [] + EOF + + output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --values test-values.yaml) + + if ! echo $output | grep -q 'statusInformers: \[\]'; then + printf "user-set empty statusInformers should exist:\n\n%s\n\n" "$output" + exit 1 + fi + create-test-release: runs-on: ubuntu-22.04 needs: [ build-and-push-e2e ] @@ -317,7 +333,7 @@ jobs: helm upgrade test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --set replicated.versionLabel=1.0.0 --wait --timeout 2m COUNTER=1 - while [ kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}' | grep -q $oldpodname ]; do + while kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}' | grep -q $oldpodname; do ((COUNTER += 1)) if [ $COUNTER -gt 60 ]; then echo "Pod did not restart after upgrade" @@ -361,7 +377,7 @@ jobs: kubectl rollout status deployment replicated --timeout=2m COUNTER=1 - while [ kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}' | grep -q $oldpodname ]; do + while kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}' | grep -q $oldpodname; do ((COUNTER += 1)) if [ $COUNTER -gt 60 ]; then echo "Pod did not restart after upgrade" @@ -385,6 +401,70 @@ jobs: kubectl wait --for=delete deployment/test-chart --timeout=2m kubectl wait --for=delete deployment/replicated --timeout=2m + # validate status informers + - name: Create empty status informers for validation + run: | + cat << EOF > test-values.yaml + replicated: + statusInformers: [] + EOF + + - name: Install via Helm as subchart in production mode and pass empty status informers + run: | + helm install test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false -f test-values.yaml --wait --timeout 2m + + COUNTER=1 + while ! kubectl logs deploy/replicated | grep -qv 'Generating status informers from Helm release'; do + ((COUNTER += 1)) + if [ $COUNTER -gt 60 ]; then + echo "Did not receive empty status informers" + kubectl logs deploy/replicated + exit 1 + fi + sleep 1 + done + + - name: Upgrade via Helm as subchart in production mode to use default status informers + run: | + helm upgrade test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --wait --timeout 2m + + COUNTER=1 + while ! kubectl logs deploy/replicated | grep -q 'Generating status informers from Helm release'; do + ((COUNTER += 1)) + if [ $COUNTER -gt 60 ]; then + echo "Did not receive default status informers" + kubectl logs deploy/replicated + exit 1 + fi + sleep 1 + done + + - name: Uninstall test-chart via Helm + run: helm uninstall test-chart --wait --timeout 2m + + - name: Install via kubectl as subchart in production mode and pass empty status informers + run: | + helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false -f test-values.yaml | kubectl apply -f - + kubectl rollout status deployment test-chart --timeout=2m + kubectl rollout status deployment replicated --timeout=2m + + COUNTER=1 + while ! kubectl logs deploy/replicated | grep -qv 'Generating status informers from Helm release'; do + ((COUNTER += 1)) + if [ $COUNTER -gt 60 ]; then + echo "Did not receive empty status informers" + kubectl logs deploy/replicated + exit 1 + fi + sleep 1 + done + + - name: Uninstall test-chart via kubectl + run: | + helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false -f test-values.yaml | kubectl delete -f - + kubectl wait --for=delete deployment/test-chart --timeout=2m + kubectl wait --for=delete deployment/replicated --timeout=2m + - name: Remove Cluster uses: replicatedhq/replicated-actions/remove-cluster@v1.1.1 if: ${{ success() || cancelled() }} diff --git a/chart/templates/replicated-secret.yaml b/chart/templates/replicated-secret.yaml index 70cf3cbf..2b7c02a8 100644 --- a/chart/templates/replicated-secret.yaml +++ b/chart/templates/replicated-secret.yaml @@ -28,6 +28,8 @@ stringData: {{- if .Values.statusInformers }} statusInformers: {{- .Values.statusInformers | toYaml | nindent 6 }} + {{- else }} + statusInformers: {{ .Values.statusInformers | toYaml }} {{- end }} replicatedID: {{ .Values.replicatedID | default "" | quote }} appID: {{ .Values.appID | default "" | quote }} diff --git a/chart/values.yaml.tmpl b/chart/values.yaml.tmpl index 61b05ea3..f33efdea 100644 --- a/chart/values.yaml.tmpl +++ b/chart/values.yaml.tmpl @@ -16,7 +16,7 @@ releaseCreatedAt: "" releaseNotes: "" versionLabel: "" parentChartURL: "" -statusInformers: [] +statusInformers: null replicatedAppEndpoint: "" serviceAccountName: "" diff --git a/pkg/apiserver/bootstrap.go b/pkg/apiserver/bootstrap.go index 0a12fad5..478fc2eb 100644 --- a/pkg/apiserver/bootstrap.go +++ b/pkg/apiserver/bootstrap.go @@ -132,7 +132,7 @@ func bootstrap(params APIServerParams) error { // if no status informers are provided, generate them from the helm release informers := params.StatusInformers - if len(informers) == 0 && helm.IsHelmManaged() { + if informers == nil && helm.IsHelmManaged() { helmRelease, err := helm.GetRelease(helm.GetReleaseName()) if err != nil { return errors.Wrap(err, "failed to get helm release") diff --git a/pkg/appstate/util.go b/pkg/appstate/util.go index 9afe7d68..accb6981 100644 --- a/pkg/appstate/util.go +++ b/pkg/appstate/util.go @@ -62,6 +62,8 @@ func resourceStatesApplyNew(resourceStates types.ResourceStates, resourceState t } func GenerateStatusInformersForManifest(manifest string) []types.StatusInformerString { + logger.Info("Generating status informers from Helm release") + informers := []types.StatusInformerString{} for _, doc := range strings.Split(manifest, "\n---\n") {