Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion openshift/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ include provider-version.mk
MANIFESTS_GEN := go run ./vendor/github.com/openshift/cluster-capi-operator/manifests-gen/

.PHONY: verify
verify: verify-ocp-manifests
verify: verify-ocp-manifests verify-manifests-summary

.PHONY: verify-%
verify-%: ## Ensure no diff after running some other target
$(MAKE) $*
./verify-diff.sh

MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

.PHONY: manifests-summary
manifests-summary:
MANIFESTS_FILE="$(MAKEFILE_DIR)capi-operator-manifests/default/manifests.yaml" MANIFESTS_SUMMARY_FILE="$(MAKEFILE_DIR)manifests-summary.yaml" ./generate-manifests-summary.sh

.PHONY: update-manifests-gen
update-manifests-gen:
cd tools && go get github.com/openshift/cluster-capi-operator/manifests-gen && go mod tidy && go mod vendor
Expand Down
42 changes: 42 additions & 0 deletions openshift/generate-manifests-summary.sh
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}"
55 changes: 55 additions & 0 deletions openshift/manifests-summary.yaml
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
Comment on lines +1 to +22

Copy link
Copy Markdown
Member

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!

Copy link
Copy Markdown
Member Author

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

.PHONY: update-manifests-gen
update-manifests-gen:
cd tools && go get github.com/openshift/cluster-capi-operator/manifests-gen && go mod tidy && go mod vendor

go get vs go 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has go run too.

MANIFESTS_GEN := go run ./vendor/github.com/openshift/cluster-capi-operator/manifests-gen/

Copy link
Copy Markdown
Member Author

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.

@hongkailiu hongkailiu Jul 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading