Skip to content

Commit

Permalink
create a downstream bundle with make command (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
maskarb authored Mar 18, 2024
1 parent caec017 commit 212f944
Show file tree
Hide file tree
Showing 15 changed files with 1,791 additions and 81 deletions.
57 changes: 48 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IMAGE_TAG_BASE ?= quay.io/project-koku/koku-metrics-operator
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
PREVIOUS_BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(PREVIOUS_VERSION)
CATALOG_IMG ?= quay.io/project-koku/kmc-test-catalog:v$(VERSION)
DOWNSTREAM_IMAGE_TAG ?= registry-proxy.engineering.redhat.com/rh-osbs/costmanagement-metrics-operator:$(VERSION)

# Image URL to use all building/pushing image targets
IMG ?= quay.io/project-koku/koku-metrics-operator:v$(VERSION)
Expand Down Expand Up @@ -288,7 +289,7 @@ bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metada
ifdef NAMESPACE
$(YQ) -i '.metadata.namespace = "$(NAMESPACE)"' bundle/manifests/koku-metrics-operator.clusterserviceversion.yaml
endif
scripts/update_bundle_dockerfile.py
sed -i '' '/^COPY / s/bundle\///g' bundle.Dockerfile

cp -r ./bundle/ koku-metrics-operator/$(VERSION)/
cp bundle.Dockerfile koku-metrics-operator/$(VERSION)/Dockerfile
Expand Down Expand Up @@ -322,28 +323,66 @@ bundle-deploy-cleanup: operator-sdk ## Delete the entirety of the deployed bundl
##@ Generate downstream file changes

#### Updates code for downstream release
REMOVE_FILES = koku-metrics-operator/
REMOVE_FILES = koku-metrics-operator/ config/scorecard/
UPSTREAM_LOWERCASE = koku
UPSTREAM_UPPERCASE = Koku
DOWNSTREAM_LOWERCASE = costmanagement
DOWNSTREAM_UPPERCASE = CostManagement
.PHONY: downstream
downstream: ## Generate the code changes necessary for the downstream image.
downstream: operator-sdk ## Generate the code changes necessary for the downstream image.
rm -rf $(REMOVE_FILES)
# sed replace everything but the Makefile
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec sed -i -- 's/$(UPSTREAM_UPPERCASE)/$(DOWNSTREAM_UPPERCASE)/g' {} +
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec sed -i -- 's/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec sed -i '' 's/$(UPSTREAM_UPPERCASE)/$(DOWNSTREAM_UPPERCASE)/g' {} +
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec sed -i '' 's/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +

- LC_ALL=C find internal/* -type f -exec sed -i '' '/^\/\/ +kubebuilder:rbac:groups/ s/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +
# fix the cert
- sed -i -- 's/ca-certificates.crt/ca-bundle.crt/g' internal/crhchttp/http_cloud_dot_redhat.go
- sed -i -- 's/isCertified bool = false/isCertified bool = true/g' internal/packaging/packaging.go
- sed -i '' 's/ca-certificates.crt/ca-bundle.crt/g' internal/crhchttp/http_cloud_dot_redhat.go
- sed -i '' 's/isCertified bool = false/isCertified bool = true/g' internal/packaging/packaging.go
# clean up the other files
- git clean -fx
# - git clean -fx
# mv the sample to the correctly named file
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec rename -f -- 's/$(UPSTREAM_UPPERCASE)/$(DOWNSTREAM_UPPERCASE)/g' {} +
- LC_ALL=C find api/v1beta1 config/* docs/* -type f -exec rename -f -- 's/$(UPSTREAM_LOWERCASE)/$(DOWNSTREAM_LOWERCASE)/g' {} +
$(MAKE) generate

$(YQ) -i '.projectName = "costmanagement-metrics-operator"' PROJECT
$(YQ) -i '.resources.[0].group = "costmanagement-metrics-cfg"' PROJECT
$(YQ) -i '.resources.[0].kind = "CostManagementMetricsConfig"' PROJECT
$(YQ) -i 'del(.resources[] | select(. == "../scorecard"))' config/manifests/kustomization.yaml

$(MAKE) manifests

rm -rf ./bundle costmanagement-metrics-operator/$(VERSION)/

$(OPERATOR_SDK) generate kustomize manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=$(DOWNSTREAM_IMAGE_TAG)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle --overwrite --version $(VERSION) --default-channel=stable --channels=stable

$(YQ) -i '.annotations."com.redhat.openshift.versions" = "$(MIN_OCP_VERSION)"' bundle/metadata/annotations.yaml
$(YQ) -i '(.annotations."com.redhat.openshift.versions" | key) head_comment="OpenShift specific annotations."' bundle/metadata/annotations.yaml

$(YQ) -i '.metadata.annotations.repository = "https://github.com/project-koku/koku-metrics-operator"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.metadata.annotations.certified = "true"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.metadata.annotations.support = "Red Hat"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.metadata.annotations."operators.openshift.io/valid-subscription" = "[\"OpenShift Kubernetes Engine\", \"OpenShift Container Platform\", \"OpenShift Platform Plus\"]"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.metadata.annotations.containerImage = "$(DOWNSTREAM_IMAGE_TAG)"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.spec.install.spec.deployments.[0].spec.template.spec.containers.[0].command = ["/usr/bin/costmanagement-metrics-operator"]' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.spec.description |= load_str("docs/csv-description.md")' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.spec.displayName = "Cost Management Metrics Operator"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.spec.minKubeVersion = "$(MIN_KUBE_VERSION)"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml
$(YQ) -i '.spec.replaces = "costmanagement-metrics-operator.$(PREVIOUS_VERSION)"' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml

sed -i '' 's/CostManagement Metrics Operator/Cost Management Metrics Operator/g' bundle/manifests/costmanagement-metrics-operator.clusterserviceversion.yaml

# scripts/update_bundle_dockerfile.py
cat downstream-assets/bundle.Dockerfile.txt >> bundle.Dockerfile
sed -i '' '/^COPY / s/bundle\///g' bundle.Dockerfile
sed -i '' 's/MIN_OCP_VERSION/$(MIN_OCP_VERSION)/g' bundle.Dockerfile
sed -i '' 's/REPLACE_VERSION/$(VERSION)/g' bundle.Dockerfile

cp -r ./bundle/ costmanagement-metrics-operator/$(VERSION)/
cp bundle.Dockerfile costmanagement-metrics-operator/$(VERSION)/Dockerfile

##@ Build Dependencies

## Location to install dependencies to
Expand Down
6 changes: 3 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ layout:
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
projectName: koku-metrics-operator
projectName: costmanagement-metrics-operator
repo: github.com/project-koku/koku-metrics-operator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openshift.io
group: koku-metrics-cfg
kind: KokuMetricsConfig
group: costmanagement-metrics-cfg
kind: CostManagementMetricsConfig
path: github.com/project-koku/koku-metrics-operator/api/v1beta1
version: v1beta1
version: "3"
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: CostManagementMetricsConfig is the Schema for the costmanagementmetricsconfig API
displayName: CostManagement Metrics Config
- description: CostManagementMetricsConfig is the Schema for the costmanagementmetricsconfig
API
displayName: Cost Management Metrics Config
kind: CostManagementMetricsConfig
name: costmanagementmetricsconfigs.costmanagement-metrics-cfg.openshift.io
version: v1beta1
Expand Down
5 changes: 2 additions & 3 deletions config/manifests/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
resources:
- ../default
- ../samples
- ../scorecard
- ../default
- ../samples
10 changes: 5 additions & 5 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: manager-role
namespace: koku-metrics-operator
namespace: costmanagement-metrics-operator
rules:
- apiGroups:
- apps
Expand Down Expand Up @@ -79,9 +79,9 @@ rules:
- update
- watch
- apiGroups:
- koku-metrics-cfg.openshift.io
- costmanagement-metrics-cfg.openshift.io
resources:
- kokumetricsconfigs
- costmanagementmetricsconfigs
verbs:
- create
- delete
Expand All @@ -91,9 +91,9 @@ rules:
- update
- watch
- apiGroups:
- koku-metrics-cfg.openshift.io
- costmanagement-metrics-cfg.openshift.io
resources:
- kokumetricsconfigs/status
- costmanagementmetricsconfigs/status
verbs:
- get
- patch
Expand Down
7 changes: 0 additions & 7 deletions config/scorecard/bases/config.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions config/scorecard/kustomization.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions config/scorecard/patches/basic.config.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions config/scorecard/patches/olm.config.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions costmanagement-metrics-operator/3.2.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM scratch

# Core bundle labels.
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=costmanagement-metrics-operator
LABEL operators.operatorframework.io.bundle.channels.v1=stable
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.33.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4

# Copy files to locations specified by labels.
COPY manifests /manifests/
COPY metadata /metadata/

# Openshift specific labels
LABEL io.k8s.display-name='Cost Management Metrics Operator'
LABEL io.k8s.description='Component required to gather metrics from Prometheus, package and upload them to the cost management service in the cloud. The operator can work in clusters connected to the Internet and air-gapped (with additional configuration and steps)'
LABEL io.openshift.build.commit.id=REPLACE_REF
LABEL io.openshift.build.commit.url=https://github.com/project-koku/koku-metrics-operator/commit/REPLACE_REF
LABEL io.openshift.build.source-location=https://github.com/project-koku/koku-metrics-operator
LABEL io.openshift.maintainer.component='Cost Management Metrics Operator'
LABEL io.openshift.maintainer.product='OpenShift Container Platform'
LABEL io.openshift.tags=openshift
LABEL com.redhat.component=costmanagement-metrics-operator-bundle-container
LABEL com.redhat.delivery.appregistry=false
LABEL com.redhat.delivery.operator.bundle=true
LABEL com.redhat.openshift.versions='v4.12'
LABEL name=openshift/costmanagement-metrics-operator-bundle
LABEL maintainer='<costmanagement@redhat.com>'
LABEL summary='Operator required to upload metrics data to the cost management service in console.redhat.com.'
LABEL version=3.2.1
Loading

0 comments on commit 212f944

Please sign in to comment.