Skip to content

Manifests validation script #1139

@jgato

Description

@jgato

Hi all,
based on this documentation from @mvazquezc
RHsyseng/telco-operations#25
I am thinking on a kind of script that would validate the Manifests (Siteconfigs/PGT) before pushing to ArgoCD.
The motivation: many times you add a new manifest, or do some changes, push the change to your branch, from there a PR to main (or the branch synced with ArgoCD), accept the PR, then sync and... you realize you did a little mistake forgetting to add a file to kustomization, or some incorrect naming, and similar stuff. Repeating all the process again.
The script would be included as part of a CI/CD pipeline, avoiding to merge to main if there are errors, or similar thigs.
I am working in something like this:

    #! /bin/bash
    BASEDIR=$1
    ZTP_SITE_GENERATOR_IMG="quay.io/redhat_emp1/ztp-site-generator:4.10.0-1"

    if [[ $1 == "-h" || $1 == "--help" ]]; then
        echo "Usage:"
        echo "  $(basename $0) PATH_WITH_MANIFESTS"
        exit 1
    fi

    if [[ ! -d $BASEDIR ]]; then
        echo "FATAL: $BASEDIR is not a directory" >&2
        exit 1
    fi

    echo "Cheking yaml syntax"
    yamllint ${BASEDIR} -d relaxed

    if [[ $? != 0  ]]; then
        echo "Error on yamls systax"
        exit 1
    fi

    export KUSTOMIZE_PLUGIN_HOME=/tmp/ztp-kustomize-plugin/

    mkdir -p /tmp/ztp-kustomize-plugin/
    podman cp $(podman create --name policgentool --rm ${ZTP_SITE_GENERATOR_IMG=}):/kustomize/plugin/ran.openshift.io /tmp/ztp-kustomize-plugin/
    podman rm -f policgentool

    kustomize build ${BASEDIR} --enable-alpha-plugins | oc apply --dry-run=client -f -

    if [[ $? != 0  ]]; then
        echo "Error processing manifests"
        exit 1
    fi
    exit 0

It seems that kustomize build does not capture as many errors as ArgoCD does. For example: including a non-existing file in kustomization.yaml.
In ArgoCD you will have the error:

rpc error: code = Unknown desc = Manifest generation error (cached): `kustomize build .site-policies --enable-alpha-plugins` failed exit status 1: Error: loading generator plugins: accumulation err='accumulating resources from 'file-no-exists.yaml': evalsymlink failure on '.site-policies/file-no-exists.yaml' : lstat .site-policies/file-no-exists.yaml: no such file or directory': evalsymlink failure on '.site-policies/file-no-exists.yaml' : lstat .site-policies/file-no-exists.yaml: no such file or directory

but the script above executes with no errors.

any ideas? do you think it makes sense to have something like this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions