-
Notifications
You must be signed in to change notification settings - Fork 58
telco-hub: add first set of reference templates for the cluster-compare tool #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
97cd9a9
05ef418
260dd53
c692667
6a4eba5
1fb009a
097ca3b
a717a8a
3eec9ff
47e6167
ae21130
987381a
3bbe1b7
1b34ced
93f16d7
dee2308
2da5e68
094ec1d
0a8f11c
dbf34cd
43206ac
c15a291
725422b
b064ed7
155be99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| --- | ||
| - op: replace | ||
| path: /data/ca-bundle.crt | ||
| value: | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| .PHONY: check | ||
| check: metadata_lint compare | ||
|
|
||
| kubectl-cluster_compare: | ||
| @command -v kubectl-cluster_compare > /dev/null 2>&1 || { \ | ||
| echo "kubectl-cluster_compare tool isn't installed; please download it from https://github.com/openshift/kube-compare"; \ | ||
| } | ||
|
|
||
| helm-convert: | ||
| @command -v helm-convert > /dev/null 2>&1 || { \ | ||
| echo "helm-convert isn't installed; please download and install it"; \ | ||
| } | ||
|
|
||
| .PHONY: metadata_lint | ||
| metadata_lint: kubectl-cluster_compare | ||
| @echo "Running kube-compare to ensure metadata.yaml is sane" | ||
| @COMPARE_OUTPUT=$$(./kubectl-cluster_compare -r ./metadata.yaml -f /dev/null 2>&1); \ | ||
| if grep -q 'an error occurred while parsing template' <<<"$${COMPARE_OUTPUT}"; then \ | ||
| echo "Template parsing error"; \ | ||
| echo "$${COMPARE_OUTPUT}"; \ | ||
| exit 1; \ | ||
| fi; \ | ||
| echo "Okay"; \ | ||
| exit 0 | ||
|
|
||
| .PHONY: clean | ||
| clean: | ||
| rm -rf kubectl-cluster_compare Chartv1 renderedv1 helm | ||
|
|
||
|
|
||
| .PHONY: convert | ||
| convert: helm-convert helm | ||
| @echo "Converting reference files to Helm Charts." | ||
| @rm -rf Chartv1 renderedv1 | ||
| @helm-convert -r ./metadata.yaml -n Chartv1 -v default_value.yaml | ||
| @echo "Rendering Helm Charts to CR files." | ||
| @helm template renderedv1 ./Chartv1 --output-dir renderedv1 | ||
|
|
||
| helm: | ||
| @command -v helm > /dev/null 2>&1 || { \ | ||
| echo "helm isn't installed; please download and install it"; \ | ||
| } | ||
|
|
||
| .PHONY: compare | ||
| compare: convert | ||
| @./compare.sh "../reference-crs" renderedv1 | ||
|
|
||
| .PHONY: sync | ||
| sync: convert | ||
| @./compare.sh --sync "../reference-crs" renderedv1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| apiVersion: config.openshift.io/v1 | ||
| kind: ClusterVersion | ||
| metadata: | ||
| name: version | ||
| status: | ||
| desired: | ||
| version: {{ template "versionMatch" (list .status.desired.version "4.19") }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HEAD is currently 4.20, isn't it?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently 4.19 which will very soon get copied back to release-4.19 and then main updated to 4.20 |
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, let's share the same
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be implemented in a follow-up PR as discussed. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| #! /bin/bash | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| function cleanup() { | ||
| rm -rf source_file rendered_file same_file | ||
| } | ||
|
|
||
| function read_dir() { | ||
| local dir=$1 | ||
| local file | ||
|
|
||
| for file in "$dir"/*; do | ||
| if [ -d "$file" ]; then | ||
| read_dir "$file" | ||
| else | ||
| echo "$file" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| function compare_cr { | ||
| local rendered_dir=$1 | ||
| local source_dir=$2 | ||
| local exclusionfile=$3 | ||
| local status=0 | ||
|
|
||
| local DIFF=${DIFF:-colordiff} | ||
| if ! command -v "$DIFF" >/dev/null; then | ||
| echo "Warning: Requested diff tool '$DIFF' is not found; falling back to plain old 'diff'" | ||
| DIFF="diff" | ||
| fi | ||
|
|
||
| read_dir "$rendered_dir" |grep yaml > rendered_file | ||
| read_dir "$source_dir" |grep yaml > source_file | ||
|
|
||
| # Apply ignore filtering before comparison | ||
| while IFS= read -r file; do | ||
| [[ ${file::1} != "#" ]] || continue # Skip any comment lines in the exclusionfile | ||
| [[ -n ${file} ]] || continue # Skip empty lines | ||
| sed -i "/${file##*/}/d" source_file | ||
| sed -i "/${file##*/}/d" rendered_file | ||
| done < "$exclusionfile" | ||
|
|
||
| local source_cr rendered | ||
| while IFS= read -r source_cr; do | ||
| while IFS= read -r rendered; do | ||
| if [ "${source_cr##*/}" = "${rendered##*/}" ]; then | ||
| # helm adds a yaml doc header (---) and a leading comment to every source_cr file; so remove those lines | ||
| tail -n +3 "$rendered" > "$rendered.fixed" | ||
| mv "$rendered.fixed" "$rendered" | ||
|
|
||
| # Check the differences | ||
| if ! "$DIFF" -u "$source_cr" "$rendered"; then | ||
| status=$(( status || 1 )) | ||
| printf "\n\n**********************************************************************************\n\n" | ||
| fi | ||
| # cleanup | ||
| echo "$source_cr" >> same_file | ||
| fi | ||
| done < rendered_file | ||
| done < source_file | ||
|
|
||
| # Filter out files with a source-cr/reference match from the full list of potentiol source-crs/reference files | ||
| while IFS= read -r file; do | ||
| [[ ${file::1} != "#" ]] || continue # Skip any comment lines in the exclusionfile | ||
| [[ -n ${file} ]] || continue # Skip empty lines | ||
| sed -i "/${file##*/}/d" source_file | ||
| sed -i "/${file##*/}/d" rendered_file | ||
| done < <(cat same_file "$exclusionfile") | ||
|
|
||
| if [[ -s source_file || -s rendered_file ]]; then | ||
| [ -s source_file ] && printf "\n\nThe following files exist in source-crs only, but not found in reference:\n" && cat source_file | ||
| [ -s rendered_file ] && printf "\nThe following files exist in reference only, but not found in source-crs:\n" && cat rendered_file | ||
| status=1 | ||
| fi | ||
|
|
||
| return $status | ||
| } | ||
|
|
||
| sync_cr() { | ||
| local rendered_dir=$1 | ||
| local source_dir=$2 | ||
| local exclusionfile=$3 | ||
| local status=0 | ||
|
|
||
| local -a renderedFiles | ||
| readarray -t renderedFiles < <(read_dir "$rendered_dir" | grep yaml) | ||
|
|
||
| local -a sourceFiles | ||
| readarray -t sourceFiles < <(read_dir "$source_dir" | grep yaml) | ||
|
|
||
| local -a excludedFiles | ||
| readarray -t excludedFiles < <(grep -v '^#' "$exclusionfile" | grep -v '^$') | ||
|
|
||
| local source rendered excluded found | ||
| for rendered in "${renderedFiles[@]}"; do | ||
| found=0 | ||
| for source in "${sourceFiles[@]}"; do | ||
| if [ "${source##*/}" = "${rendered##*/}" ]; then | ||
| # Match found! | ||
| found=1 | ||
| break | ||
| fi | ||
| done | ||
| if [[ $found == 0 ]]; then | ||
| source="$source_dir/${rendered##*/}" | ||
| fi | ||
|
|
||
| # Replace the CR with the rendered copy (minus the helm-rendered heading) | ||
| tail -n +3 "$rendered" >"$source" | ||
| git add "$source" | ||
| done | ||
|
|
||
| for source in "${sourceFiles[@]}"; do | ||
| found=0 | ||
| for rendered in "${renderedFiles[@]}"; do | ||
| if [ "${source##*/}" = "${rendered##*/}" ]; then | ||
| # Match found! | ||
| found=1 | ||
| break | ||
| fi | ||
| done | ||
| for excluded in "${excludedFiles[@]}"; do | ||
| if [ "${source##*/}" = "${excluded##*/}" ]; then | ||
| # Match found! | ||
| found=1 | ||
| break | ||
| fi | ||
| done | ||
| if [[ $found == 0 ]]; then | ||
| git rm -f "$source" | ||
| fi | ||
| done | ||
|
|
||
| git diff --cached --stat --exit-code | ||
| } | ||
|
|
||
| usage() { | ||
| echo "$(basename "$0") [--sync] sourceDir renderDir" | ||
| echo | ||
| echo "Compares the rendered reference-based CRs to the CRs in the compare directory" | ||
| } | ||
|
|
||
| DOSYNC=0 | ||
| for arg in "$@"; do | ||
| case "$arg" in | ||
| -h | --help) | ||
| usage | ||
| exit 0 | ||
| ;; | ||
| --sync) | ||
| DOSYNC=1 | ||
| shift | ||
| ;; | ||
| esac | ||
| done | ||
| SOURCEDIR=$1 | ||
| if [[ ! -d $SOURCEDIR ]]; then | ||
| echo "No such source directory $SOURCEDIR" | ||
| usage | ||
| exit 1 | ||
| fi | ||
| RENDERDIR=$2 | ||
| if [[ ! -d $RENDERDIR ]]; then | ||
| echo "No such source directory $RENDERDIR" | ||
| usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ $DOSYNC == 1 ]]; then | ||
| sync_cr "$RENDERDIR" "$SOURCEDIR" compare_ignore | ||
| else | ||
| compare_cr "$RENDERDIR" "$SOURCEDIR" compare_ignore | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Internal files for cluster-compare, not real CRs | ||
| metadata.yaml | ||
|
|
||
| # Used in the reference only for version compliance checks | ||
| ReferenceVersionCheck.yaml | ||
|
|
||
| # Not yet published in the RDS: | ||
| optional/quay/quayNS.yaml | ||
| optional/quay/quayOperatorGroup.yaml | ||
| optional/quay/quaySubscription.yaml | ||
|
|
||
| # Reference templates not implemented yet: | ||
| optional/logging/clusterLogForwarder.yaml | ||
| optional/logging/clusterLogServiceAccount.yaml | ||
| optional/logging/clusterLogServiceAccountAuditBinding.yaml | ||
| optional/logging/clusterLogServiceAccountInfrastructureBinding.yaml | ||
| required/registry/catalog-source.yaml | ||
| required/registry/idms-operator.yaml | ||
| required/registry/idms-release.yaml | ||
| required/registry/itms-generic.yaml | ||
| required/registry/itms-release.yaml | ||
| required/registry/operator-hub.yaml | ||
| required/gitops/addPluginsPolicy.yaml | ||
| required/gitops/app-project.yaml | ||
| required/gitops/argocd-application.yaml | ||
| required/gitops/argocd-ssh-known-hosts-cm.yaml | ||
| required/gitops/argocd-tls-certs-cm.yaml | ||
| required/gitops/clusterrolebinding.yaml | ||
| required/gitops/clusterrole.yaml | ||
| required/gitops/gitopsNS.yaml | ||
| required/gitops/gitopsOperatorGroup.yaml | ||
| required/gitops/gitopsSubscription.yaml | ||
| required/gitops/kustomization.yaml | ||
| required/gitops/ztp-installation/app-project.yaml | ||
| required/gitops/ztp-installation/clusters-app.yaml | ||
| required/gitops/ztp-installation/gitops-cluster-rolebinding.yaml | ||
| required/gitops/ztp-installation/gitops-policy-rolebinding.yaml | ||
| required/gitops/ztp-installation/kustomization.yaml | ||
| required/gitops/ztp-installation/policies-app-project.yaml | ||
| required/gitops/ztp-installation/policies-app.yaml | ||
| required/gitops/ztp-repo.yaml | ||
| optional/cert-manager/certManagerClusterIssuer.yaml | ||
| optional/cert-manager/certManagerNS.yaml | ||
| optional/cert-manager/certManagerOperatorgroup.yaml | ||
| optional/cert-manager/certManagerSubscription.yaml | ||
| optional/cert-manager/consoleCertificate.yaml | ||
| optional/cert-manager/downloadsCertificate.yaml | ||
| optional/cert-manager/oauthServiceCertificate.yaml | ||
| optional/backup-recovery/backupSchedule.yaml | ||
| optional/backup-recovery/dataProtectionApplication.yaml | ||
| optional/backup-recovery/objectBucketClaim.yaml | ||
| optional/backup-recovery/policy-backup.yaml | ||
| optional/backup-recovery/restore.yaml | ||
| optional/odf-internal/odfReady.yaml | ||
| required/acm/acmPerfSearch.yaml | ||
| required/acm/thanosSecretPolicy.yaml | ||
|
|
||
| # ArgoCD files | ||
| kustomization.yaml | ||
| optional/lso/kustomization.yaml | ||
| optional/odf-internal/kustomization.yaml | ||
| required/talm/kustomization.yaml | ||
| required/acm/kustomization.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have 2 areas that do the same check (here and telco-ran), maybe we should consider putting more of the logic in a shared helper script instead of copying it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be implemented in a follow-up PR as discussed.