forked from kubernetes-sigs/cluster-api-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 56
OCPCLOUD-3513: add a tool to generate manifests-summary #616
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
Open
hongkailiu
wants to merge
1
commit into
openshift:main
Choose a base branch
from
hongkailiu:manifests-summary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if [[ -z "$MANIFESTS_FILE" ]]; then | ||
| echo "The variable MANIFESTS_FILE must set." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z "$MANIFESTS_SUMMARY_FILE" ]]; then | ||
| echo "The variable MANIFESTS_SUMMARY_FILE must set." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command -v yq >/dev/null 2>&1 ; then | ||
| echo "Command yq is not available. See https://github.com/kislyuk/yq for more information." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| TMP_DIR=$(mktemp -d) | ||
|
|
||
| if [[ ! -d "$TMP_DIR" ]]; then | ||
| echo "Could not create temporary directory" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| trap 'rm -rf "$TMP_DIR"' EXIT | ||
|
|
||
| PROFILE="${PROFILE:-default}" | ||
|
|
||
| echo "The variable MANIFESTS_FILE=${MANIFESTS_FILE}" | ||
| echo "The variable MANIFESTS_SUMMARY_FILE=${MANIFESTS_SUMMARY_FILE}" | ||
| echo "The variable PROFILE=${PROFILE}" | ||
|
|
||
| TMP_LIST_FILE="$TMP_DIR/list.yaml" | ||
| TMP_RESULT_FILE="$TMP_DIR/result.yaml" | ||
|
|
||
| yq -s . "${MANIFESTS_FILE}" | yq 'map({apiVersion: .apiVersion, kind: .kind, name: .metadata.name, namespace: .metadata.namespace})' | yq -y 'map(with_entries(select(.value != null))) | sort_by(.kind, .apiVersion, .namespace, .name)' > "${TMP_LIST_FILE}" | ||
|
|
||
| yq -y --indentless-lists --arg key "$PROFILE" --argjson value "$(yq . "${TMP_LIST_FILE}")" '.[$key] = $value' "${MANIFESTS_SUMMARY_FILE}" > "${TMP_RESULT_FILE}" | ||
|
|
||
| mv "${TMP_RESULT_FILE}" "${MANIFESTS_SUMMARY_FILE}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| default: | ||
| - apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| name: capa-manager-role | ||
| - apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| name: capa-manager-rolebinding | ||
| - apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| name: awsclustercontrolleridentities.infrastructure.cluster.x-k8s.io | ||
| - apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| name: awsclusters.infrastructure.cluster.x-k8s.io | ||
| - apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| name: awsmachines.infrastructure.cluster.x-k8s.io | ||
| - apiVersion: apiextensions.k8s.io/v1 | ||
| kind: CustomResourceDefinition | ||
| name: awsmachinetemplates.infrastructure.cluster.x-k8s.io | ||
| - apiVersion: apps/v1 | ||
| kind: Deployment | ||
| name: capa-controller-manager | ||
| namespace: openshift-cluster-api | ||
| - apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: MutatingWebhookConfiguration | ||
| name: capa-mutating-webhook-configuration | ||
| - apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| name: capa-leader-elect-role | ||
| namespace: openshift-cluster-api | ||
| - apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| name: capa-leader-elect-rolebinding | ||
| namespace: openshift-cluster-api | ||
| - apiVersion: v1 | ||
| kind: Service | ||
| name: capa-metrics-service | ||
| namespace: openshift-cluster-api | ||
| - apiVersion: v1 | ||
| kind: Service | ||
| name: capa-webhook-service | ||
| namespace: openshift-cluster-api | ||
| - apiVersion: v1 | ||
| kind: ServiceAccount | ||
| name: capa-controller-manager | ||
| namespace: openshift-cluster-api | ||
| - apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicy | ||
| name: openshift-cluster-api-protect-awscluster | ||
| - apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicyBinding | ||
| name: openshift-cluster-api-protect-awscluster | ||
| - apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingWebhookConfiguration | ||
| name: capa-validating-webhook-configuration | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I like the output!
But I wonder if we can avoid defining a new go module to do this.
Could we leverage existing tools like yq/jq or similar to generate this? Thanks!
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.
I got the impression that GoLang is alright too.
Moreover, the tools for GoLang are already used in Makefile
cluster-api-provider-aws/openshift/Makefile
Lines 16 to 18 in 90f95c2
go getvsgo run: what is the difference?Just to a confirmation before switching.
You want to implement the same function with Shell + yq/jq, correct?
Let me try it and get back to you.
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.
It has
go runtoo.cluster-api-provider-aws/openshift/Makefile
Line 6 in 90f95c2
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.
Switched to "Shell + yq/jq" implementation.
Uh oh!
There was an error while loading. Please reload this page.
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.
https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-api-provider-aws/616/pull-ci-openshift-cluster-api-provider-aws-main-verify/2074620784856272896#1:build-log.txt%3A55
yqseems not available.If we want to go to that direction, we might need to install them here.
https://github.com/openshift/release/blob/122318671d7f0555f9ea6efeb652da885dbb0f69/ci-operator/config/openshift/cluster-api-provider-aws/openshift-cluster-api-provider-aws-main.yaml#L35
jqis easy whileyqmight be non-trivial.