From 75074350ef94355eef59b641f67ba239d9199eec Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Tue, 19 Aug 2025 04:22:37 -0400 Subject: [PATCH] Adjust generate-yamls.sh due to pkg/embeddedyamls/yamls.go removal ...from submariner-operator in lieu of using Go embed functionality. The charts project needs to obtain the RBAC and CRD yaml files from the submariner, submariner-operator and mcs-api projects. To achieve this, define a simple Go file that statically references the packages containing the desired embed.go and yaml files. The generate-yamls.sh script uses 'go mod' commands to create the go.mod file and vendor directory, which also downloads the yaml files. Signed-off-by: Tom Pantelis --- .gitignore | 4 +- extract-yamls | 21 -------- generate-yamls.sh | 105 ++++++++++++++++++++++------------------ yamls/generate-yamls.go | 38 +++++++++++++++ 4 files changed, 100 insertions(+), 68 deletions(-) delete mode 100755 extract-yamls create mode 100644 yamls/generate-yamls.go diff --git a/.gitignore b/.gitignore index 4d3e0cc..c44f785 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,9 @@ Makefile.dapper Makefile.shipyard Dockerfile.* helm_repo -yamls +yamls/go.mod +yamls/go.sum +yamls/vendor submariner-k8s-broker/crds/crd.yaml submariner-k8s-broker/templates/_role.tpl submariner-operator/crds/crd.yaml diff --git a/extract-yamls b/extract-yamls deleted file mode 100755 index fecee5c..0000000 --- a/extract-yamls +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/awk -f - -# Start of a file entry -/= `/ { - outfile = gensub("_yaml$", ".yaml", "1", $1) - print "Writing " outfile - firstline = substr($0, index($0, "`") + 1) - if (firstline !~ "^---") - firstline = "---\n"firstline - print firstline > outfile - next -} - -/^`$/ { - outfile = "" - next -} - -outfile != "" { - print >> outfile -} diff --git a/generate-yamls.sh b/generate-yamls.sh index 9dc36ef..7292b79 100755 --- a/generate-yamls.sh +++ b/generate-yamls.sh @@ -10,81 +10,94 @@ GLOBALNET_RBAC_YAML=submariner-operator/templates/globalnet-rbac.yaml SERVICE_DISC_RBAC_YAML=submariner-operator/templates/service-discovery-rbac.yaml OPENSHIFT_MONITORING_YAML=submariner-operator/templates/openshift-monitoring-rbac.yaml +YAMLS_BASE=yamls/vendor +SUBM_CRDS=${YAMLS_BASE}/github.com/submariner-io/submariner/deploy/crds +OPERATOR_CRDS=${YAMLS_BASE}/github.com/submariner-io/submariner-operator/deploy/crds +MCS_CRDS=${YAMLS_BASE}/sigs.k8s.io/mcs-api/config/crd +BROKER=${YAMLS_BASE}/github.com/submariner-io/submariner-operator/config/broker/broker-client +RBAC_BASE=${YAMLS_BASE}/github.com/submariner-io/submariner-operator/config/rbac +OPENSHIFT=${YAMLS_BASE}/github.com/submariner-io/submariner-operator/config/openshift + function add_service_acct_ns() { sed -i '/- kind: ServiceAccount/a \ \ \ \ namespace: {{ .Release.Namespace }}' $1 } -mkdir -p yamls cd yamls -curl -L https://raw.githubusercontent.com/submariner-io/submariner-operator/refs/heads/$1/pkg/embeddedyamls/yamls.go | ../extract-yamls -cd - +rm go.mod || true +go mod init +go get github.com/submariner-io/submariner-operator@$1 +go mod tidy +go mod vendor +cd .. # Generate the CRDs for the broker chart mkdir -p submariner-k8s-broker/crds -cat yamls/Deploy_submariner_crds_submariner_io_endpoints.yaml \ - yamls/Deploy_submariner_crds_submariner_io_clusters.yaml \ - yamls/Deploy_submariner_crds_submariner_io_gateways.yaml \ - yamls/Deploy_mcsapi_crds_multicluster_x_k8s_io_serviceexports.yaml \ - yamls/Deploy_mcsapi_crds_multicluster_x_k8s_io_serviceimports.yaml > submariner-k8s-broker/crds/crd.yaml +cat ${SUBM_CRDS}/submariner.io_endpoints.yaml \ + ${SUBM_CRDS}/submariner.io_clusters.yaml \ + ${SUBM_CRDS}/submariner.io_gateways.yaml > submariner-k8s-broker/crds/crd.yaml +echo '---' >> submariner-k8s-broker/crds/crd.yaml +cat ${MCS_CRDS}/multicluster.x-k8s.io_serviceexports.yaml >> submariner-k8s-broker/crds/crd.yaml +echo '---' >> submariner-k8s-broker/crds/crd.yaml +cat ${MCS_CRDS}/multicluster.x-k8s.io_serviceimports.yaml >> submariner-k8s-broker/crds/crd.yaml # Generate the client role yaml for the broker chart echo '{{- define "broker-role" -}}' > ${BROKER_ROLE_TPL} -cat yamls/Config_broker_broker_client_role.yaml >> ${BROKER_ROLE_TPL} +cat ${BROKER}/role.yaml >> ${BROKER_ROLE_TPL} echo '{{- end -}}' >> ${BROKER_ROLE_TPL} sed -i -e 's/name:.*/name: {{ template "submariner-k8s-broker.fullname" \. }}-cluster/' ${BROKER_ROLE_TPL} # Generate the CRDs for the operator chart mkdir -p submariner-operator/crds -cat yamls/Deploy_crds_submariner_io_submariners.yaml \ - yamls/Deploy_crds_submariner_io_servicediscoveries.yaml \ - yamls/Deploy_crds_submariner_io_brokers.yaml > submariner-operator/crds/crd.yaml +cat ${OPERATOR_CRDS}/submariner.io_submariners.yaml \ + ${OPERATOR_CRDS}/submariner.io_servicediscoveries.yaml \ + ${OPERATOR_CRDS}/submariner.io_brokers.yaml > submariner-operator/crds/crd.yaml # Generate the operator RBAC yaml for the operator chart -add_service_acct_ns yamls/Config_rbac_submariner_operator_cluster_role_binding.yaml -cat yamls/Config_rbac_submariner_operator_service_account.yaml \ - yamls/Config_rbac_submariner_operator_role.yaml \ - yamls/Config_rbac_submariner_operator_role_binding.yaml \ - yamls/Config_rbac_submariner_operator_cluster_role.yaml \ - yamls/Config_rbac_submariner_operator_cluster_role_binding.yaml > ${OPERATOR_RBAC_YAML} +add_service_acct_ns ${RBAC_BASE}/submariner-operator/cluster_role_binding.yaml +cat ${RBAC_BASE}/submariner-operator/service_account.yaml \ + ${RBAC_BASE}/submariner-operator/role.yaml \ + ${RBAC_BASE}/submariner-operator/role_binding.yaml \ + ${RBAC_BASE}/submariner-operator/cluster_role.yaml \ + ${RBAC_BASE}/submariner-operator/cluster_role_binding.yaml > ${OPERATOR_RBAC_YAML} # Generate the gateway RBAC yaml for the operator chart -add_service_acct_ns yamls/Config_rbac_submariner_gateway_cluster_role_binding.yaml -cat yamls/Config_rbac_submariner_gateway_service_account.yaml \ - yamls/Config_rbac_submariner_gateway_role.yaml \ - yamls/Config_rbac_submariner_gateway_role_binding.yaml \ - yamls/Config_rbac_submariner_gateway_cluster_role.yaml \ - yamls/Config_rbac_submariner_gateway_cluster_role_binding.yaml > ${GATEWAY_RBAC_YAML} +add_service_acct_ns ${RBAC_BASE}/submariner-gateway/cluster_role_binding.yaml +cat ${RBAC_BASE}/submariner-gateway/service_account.yaml \ + ${RBAC_BASE}/submariner-gateway/role.yaml \ + ${RBAC_BASE}/submariner-gateway/role_binding.yaml \ + ${RBAC_BASE}/submariner-gateway/cluster_role.yaml \ + ${RBAC_BASE}/submariner-gateway/cluster_role_binding.yaml > ${GATEWAY_RBAC_YAML} # Generate the routeagent RBAC yaml for the operator chart -add_service_acct_ns yamls/Config_rbac_submariner_route_agent_cluster_role_binding.yaml -cat yamls/Config_rbac_submariner_route_agent_service_account.yaml \ - yamls/Config_rbac_submariner_route_agent_role.yaml \ - yamls/Config_rbac_submariner_route_agent_role_binding.yaml \ - yamls/Config_rbac_submariner_route_agent_cluster_role.yaml \ - yamls/Config_rbac_submariner_route_agent_cluster_role_binding.yaml > ${ROUTE_AGENT_RBAC_YAML} +add_service_acct_ns ${RBAC_BASE}/submariner-route-agent/cluster_role_binding.yaml +cat ${RBAC_BASE}/submariner-route-agent/service_account.yaml \ + ${RBAC_BASE}/submariner-route-agent/role.yaml \ + ${RBAC_BASE}/submariner-route-agent/role_binding.yaml \ + ${RBAC_BASE}/submariner-route-agent/cluster_role.yaml \ + ${RBAC_BASE}/submariner-route-agent/cluster_role_binding.yaml > ${ROUTE_AGENT_RBAC_YAML} # Generate the globalnet RBAC yaml for the operator chart echo '{{- if .Values.broker.globalnet }}' > ${GLOBALNET_RBAC_YAML} -add_service_acct_ns yamls/Config_rbac_submariner_globalnet_cluster_role_binding.yaml -cat yamls/Config_rbac_submariner_globalnet_service_account.yaml \ - yamls/Config_rbac_submariner_globalnet_role.yaml \ - yamls/Config_rbac_submariner_globalnet_role_binding.yaml \ - yamls/Config_rbac_submariner_globalnet_cluster_role.yaml \ - yamls/Config_rbac_submariner_globalnet_cluster_role_binding.yaml >> ${GLOBALNET_RBAC_YAML} +add_service_acct_ns ${RBAC_BASE}/submariner-globalnet/cluster_role_binding.yaml +cat ${RBAC_BASE}/submariner-globalnet/service_account.yaml \ + ${RBAC_BASE}/submariner-globalnet/role.yaml \ + ${RBAC_BASE}/submariner-globalnet/role_binding.yaml \ + ${RBAC_BASE}/submariner-globalnet/cluster_role.yaml \ + ${RBAC_BASE}/submariner-globalnet/cluster_role_binding.yaml >> ${GLOBALNET_RBAC_YAML} echo '{{- end -}}' >> ${GLOBALNET_RBAC_YAML} # Generate the service discovery RBAC yaml for the operator chart echo '{{- if .Values.submariner.serviceDiscovery }}' > ${SERVICE_DISC_RBAC_YAML} -add_service_acct_ns yamls/Config_rbac_lighthouse_agent_cluster_role_binding.yaml -add_service_acct_ns yamls/Config_rbac_lighthouse_coredns_cluster_role_binding.yaml -cat yamls/Config_rbac_lighthouse_agent_service_account.yaml \ - yamls/Config_rbac_lighthouse_agent_cluster_role.yaml \ - yamls/Config_rbac_lighthouse_agent_cluster_role_binding.yaml \ - yamls/Config_rbac_lighthouse_coredns_service_account.yaml \ - yamls/Config_rbac_lighthouse_coredns_cluster_role.yaml \ - yamls/Config_rbac_lighthouse_coredns_cluster_role_binding.yaml >> ${SERVICE_DISC_RBAC_YAML} +add_service_acct_ns ${RBAC_BASE}/lighthouse-agent/cluster_role_binding.yaml +add_service_acct_ns ${RBAC_BASE}/lighthouse-coredns/cluster_role_binding.yaml +cat ${RBAC_BASE}/lighthouse-agent/service_account.yaml \ + ${RBAC_BASE}/lighthouse-agent/cluster_role.yaml \ + ${RBAC_BASE}/lighthouse-agent/cluster_role_binding.yaml \ + ${RBAC_BASE}/lighthouse-coredns/service_account.yaml \ + ${RBAC_BASE}/lighthouse-coredns/cluster_role.yaml \ + ${RBAC_BASE}/lighthouse-coredns/cluster_role_binding.yaml >> ${SERVICE_DISC_RBAC_YAML} echo '{{- end -}}' >> ${SERVICE_DISC_RBAC_YAML} # Generate the openshift monitoring rbac yaml for the operator chart -cat yamls/Config_openshift_rbac_submariner_metrics_reader_role.yaml \ - yamls/Config_openshift_rbac_submariner_metrics_reader_role_binding.yaml > ${OPENSHIFT_MONITORING_YAML} +cat ${OPENSHIFT}/rbac/submariner-metrics-reader/role.yaml \ + ${OPENSHIFT}/rbac/submariner-metrics-reader/role_binding.yaml > ${OPENSHIFT_MONITORING_YAML} diff --git a/yamls/generate-yamls.go b/yamls/generate-yamls.go new file mode 100644 index 0000000..0603c69 --- /dev/null +++ b/yamls/generate-yamls.go @@ -0,0 +1,38 @@ +//go:build yamls + +/* +SPDX-License-Identifier: Apache-2.0 + +Copyright Contributors to the Submariner project. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Place any runtime dependencies as imports in this file. +// Go modules will be forced to download and install them. + +package yamls + +import ( + _ "github.com/submariner-io/submariner-operator/config/broker/broker-client" + _ "github.com/submariner-io/submariner-operator/config/openshift/rbac/submariner-metrics-reader" + _ "github.com/submariner-io/submariner-operator/config/rbac/submariner-gateway" + _ "github.com/submariner-io/submariner-operator/config/rbac/submariner-globalnet" + _ "github.com/submariner-io/submariner-operator/config/rbac/submariner-operator" + _ "github.com/submariner-io/submariner-operator/config/rbac/submariner-route-agent" + _ "github.com/submariner-io/submariner-operator/config/rbac/lighthouse-agent" + _ "github.com/submariner-io/submariner-operator/config/rbac/lighthouse-coredns" + _ "github.com/submariner-io/submariner-operator/deploy/crds" + _ "github.com/submariner-io/submariner/deploy/crds" + _ "sigs.k8s.io/mcs-api/config/crd" +)