From 7cab1bdb587a46163e26313385b15e09927b41f1 Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Sun, 21 Jun 2026 18:05:15 +0200 Subject: [PATCH] Remove unused olm-bundle module Signed-off-by: Erik Godding Boye --- modules/olm-bundle/00_mod.mk | 101 ----------- modules/olm-bundle/01_mod.mk | 143 --------------- modules/olm-bundle/base/PROJECT | 5 - modules/olm-bundle/base/bundle/README.md | 79 --------- modules/olm-bundle/olm-to-oci/go.mod | 20 --- modules/olm-bundle/olm-to-oci/go.sum | 40 ----- modules/olm-bundle/olm-to-oci/main.go | 210 ----------------------- modules/olm-bundle/yamlfmt.yaml | 5 - 8 files changed, 603 deletions(-) delete mode 100644 modules/olm-bundle/00_mod.mk delete mode 100644 modules/olm-bundle/01_mod.mk delete mode 100644 modules/olm-bundle/base/PROJECT delete mode 100644 modules/olm-bundle/base/bundle/README.md delete mode 100644 modules/olm-bundle/olm-to-oci/go.mod delete mode 100644 modules/olm-bundle/olm-to-oci/go.sum delete mode 100644 modules/olm-bundle/olm-to-oci/main.go delete mode 100644 modules/olm-bundle/yamlfmt.yaml diff --git a/modules/olm-bundle/00_mod.mk b/modules/olm-bundle/00_mod.mk deleted file mode 100644 index 9263aeb3..00000000 --- a/modules/olm-bundle/00_mod.mk +++ /dev/null @@ -1,101 +0,0 @@ -# Copyright 2024 The cert-manager Authors. -# -# 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. - -# Utility functions -fatal_if_undefined = $(if $(findstring undefined,$(origin $1)),$(error $1 is not set)) - -# Utility variables -current_makefile := $(lastword $(MAKEFILE_LIST)) -current_makefile_directory := $(dir $(current_makefile)) -olm_base_dir := $(current_makefile_directory)/base - -ifdef deploy_name -# Name of the project, this goes in the PROJECT file as well as getting used. -# $(deploy_name) is usually a sane default for this value -olm_project_name ?= $(deploy_name) -endif - -$(call fatal_if_undefined,olm_project_name) - -# Minimum openshift version we support -olm_openshift_version ?= v4.6 - -# A mapping of git repos to push to when publishing, OLMs are published by PRing -# into a Red Hat repo. -# -# For example, to publish to the certified-operators repos you may do this: -# olm_publish_repos += redhat-openshift-ecosystem/certified-operators=jetstack/certified-operators -# -# Where the value on the left is the repo to PR into, and the one on the right is -# where to push the changes to PR from -olm_publish_repos ?= - -# Project ID is the components ID if publishing to the Red Hat certified operators -# program -olm_project_id ?= - -# Used for handling auto-upgrade, the version that this release is replacing -olm_replaces_version ?= $(shell git describe --tags --always --match='v*' --abbrev=0 --exclude $(VERSION)) - -# OLMs are built as images, so can be pushed to image registries. We default the -# tag to the version. -# -# If you wish to push to an OCI registry this can be done by setting -# oci_olm_image_name to the name of the repository -oci_olm_image_tag ?= $(VERSION) - -# When publishing a certified operator you must submit a preflight scan, this -# variable maps images to the IDs to use when submitting preflight scan results -# For example: -# preflight_container_project_ids += registry.venafi.cloud/public/venafi-images/vcp-operator=123456abcdef123456abcde -# -# If left unset, no scans will be submitted -preflight_container_project_ids ?= - -# The example directory is used to find CRD examples, this is used to create the -# alm-examples annotation in the clusterserviceversion - -# Base directory for OLM bundle -olm_bundle_base := bundle -olm_manifests_base := $(olm_bundle_base)/manifests -olm_metadata_base := $(olm_bundle_base)/metadata -olm_scorecard_base := $(olm_bundle_base)/tests/scorecard -olm_example_directory ?= $(olm_bundle_base)/examples - -# Some files are optional, so we use wildcard to not error if they do not exist -olm_clusterserviceversion_path ?= $(olm_manifests_base)/$(deploy_name).clusterserviceversion.yaml -olm_additional_manifests ?= $(filter-out $(olm_clusterserviceversion_path),$(wildcard $(olm_manifests_base)/*.yaml)) -olm_annotations_path ?= $(wildcard $(olm_metadata_base)/annotations.yaml) -olm_scorecard_config_path ?= $(wildcard $(olm_scorecard_base)/config.yaml) -olm_icon_path ?= $(wildcard $(olm_bundle_base)/icon.png) -olm_helm_value_path ?= $(wildcard $(olm_bundle_base)/values.yaml $(olm_bundle_base)/values.yml) - -# Validate -$(call fatal_if_undefined,oci_olm_image_tag) - -# Add OLM as a push target to the oci-publish module -ifdef oci_olm_image_name -push_names += olm -endif - -oci_digest_path_olm := $(bin_dir)/scratch/image/oci-layout-olm.$(oci_olm_image_tag).digests -oci_layout_path_olm := $(bin_dir)/scratch/image/oci-layout-olm.$(oci_olm_image_tag) - -.PHONY: generate-olm-project -generate-olm-project: | $$(NEEDS_YQ) - cp -r $(olm_base_dir)/. ./ - $(YQ) -i '.projectName = "$(deploy_name)"' PROJECT - -shared_generate_targets += generate-olm-project - diff --git a/modules/olm-bundle/01_mod.mk b/modules/olm-bundle/01_mod.mk deleted file mode 100644 index 405b9fc0..00000000 --- a/modules/olm-bundle/01_mod.mk +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright 2024 The cert-manager Authors. -# -# 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. - -# Utility variables -current_makefile = $(lastword $(MAKEFILE_LIST)) -current_makefile_directory = $(dir $(current_makefile)) -yamlfmt_config := $(current_makefile_directory)/yamlfmt.yaml -comma := , - -base64_wrapped := base64 -w76 -ifeq ($(HOST_OS),darwin) - base64_wrapped := base64 -b76 -endif - -# Utility functions -for_each_kv = $(foreach item,$2,$(eval $(call $1,$(word 1,$(subst =, ,$(item))),$(word 2,$(subst =, ,$(item)))))) -fatal_if_undefined = $(if $(findstring undefined,$(origin $1)),$(error $1 is not set)) - -# Build up config -olm_bundle_dir := $(bin_dir)/scratch/olm/bundle-$(oci_olm_image_tag) - -# Build the olm-to-oci tool -olm_to_oci_dir := $(current_makefile_directory:/=)/olm-to-oci -OLM-TO-OCI := $(CURDIR)/$(bin_dir)/tools/olm-to-oci -NEEDS_OLM-TO-OCI := $(bin_dir)/tools/olm-to-oci -$(NEEDS_OLM-TO-OCI): $(wildcard $(olm_to_oci_dir)/*.go) | $(NEEDS_GO) - cd $(olm_to_oci_dir) && GOWORK=off GOBIN=$(CURDIR)/$(dir $@) $(GO) install . - -# Get all example files -olm_examples := $(wildcard $(olm_example_directory)/*.yaml) - -.PHONY: olm-bundle -olm-bundle: $(helm_chart_archive) $(olm_clusterserviceversion_path) | $(NEEDS_HELM) $(NEEDS_YQ) $(NEEDS_OPERATOR-SDK) $(NEEDS_YAMLFMT) - rm -rf $(olm_bundle_dir) $(oci_layout_path_olm) $(oci_digest_path_olm) - mkdir -p $(olm_bundle_dir) - cd $(olm_bundle_dir) && $(HELM) template $(addprefix --values=,$(abspath $(olm_helm_value_path))) $(olm_project_name) $(CURDIR)/$(helm_chart_archive) |\ - $(YQ) 'del(.metadata.annotations["helm.sh/resource-policy"])' |\ - $(YQ) 'del(.metadata.labels["app.kubernetes.io/managed-by"])' |\ - $(YQ) 'del(.metadata.labels["app.kubernetes.io/version"])' |\ - $(YQ) 'del(.metadata.labels["helm.sh/chart"])' |\ - $(YQ) 'del(.metadata.creationTimestamp)' |\ - $(YQ) - $(abspath $(olm_clusterserviceversion_path)) $(abspath $(olm_examples)) $(abspath $(olm_additional_manifests)) |\ - $(OPERATOR-SDK) generate bundle --output-dir . --package $(olm_project_name) --version $(VERSION:v%=%) - - @# Set the previous version in the replaces field, this is required for auto-upgrade to work - $(YQ) -i '.spec.replaces = "$(olm_project_name).$(olm_replaces_version)"' $(olm_bundle_dir)/manifests/$(olm_project_name).clusterserviceversion.yaml - - @# Set the container image annotation - $(YQ) -i '.metadata.annotations.containerImage = .spec.install.spec.deployments[0].spec.template.spec.containers[0].image' $(olm_bundle_dir)/manifests/$(olm_project_name).clusterserviceversion.yaml - $(YQ) -i '.spec.relatedImages = [ .spec.install.spec.deployments[].spec.template.spec.containers[] | {"name": .name, "image": .image} ]' $(olm_bundle_dir)/manifests/$(olm_project_name).clusterserviceversion.yaml - - @# Set the supported OS/Arches based on $(oci_platforms) - $(YQ) -i --string-interpolation '. * ("$(oci_platforms)" | [ split(",").[] | split("/") | ["operatorframework.io/os.\(.[0])", "operatorframework.io/arch.\(.[1])"] ] | [ .[][] ] | unique | .[] as $$item ireduce({}; . * {"metadata": {"labels": {$$item: "supported"}}}))' $(olm_bundle_dir)/manifests/$(olm_project_name).clusterserviceversion.yaml - - @# Set the openshift version - $(YQ) -i '.annotations."com.redhat.openshift.versions"="$(olm_openshift_version)"' $(olm_bundle_dir)/metadata/annotations.yaml - - @# Merge in custom annotations - $(YQ) eval-all -i '. as $$item ireduce ({}; . * $$item )' $(olm_bundle_dir)/metadata/annotations.yaml $(olm_annotations_path) - - @# Copy in scorecard config - $(if $(olm_scorecard_config_path),mkdir -p $(olm_bundle_dir)/tests/scorecard && cp $(olm_scorecard_config_path) $(olm_bundle_dir)/tests/scorecard/config.yaml) - - @# Set the displayName and description of CRDs - $(YQ) eval-all -i '.spec.customresourcedefinitions.owned = [ select(.kind == "CustomResourceDefinition") | {"kind": .spec.names.kind$(comma) "name": .metadata.name$(comma) "displayName": .spec.names.kind$(comma) "version": (.spec.versions[] | select(.storage == true) | .name)$(comma)"description": (.spec.versions[] | select(.storage == true) | .schema.openAPIV3Schema.description)} ] | select(fi == 0)' $(olm_bundle_dir)/manifests/$(olm_project_name).clusterserviceversion.yaml $(olm_bundle_dir)/manifests/*.yaml - - @# Use folded style for long lines (lines cannot be longer than 180) - for file in $$(find $(olm_bundle_dir) -name "*.yaml"); do yq -i '(.. | select(tag == "!!str" and ([split("\n") | .[] | length | select(. > 150)] | length) != 0)) |= . style="folded"' $$file; done - - @# Set the icon in the clusterserviceversion - $(if $(olm_icon_path),$(YQ) -i '.spec.icon = [{"mediatype": "image/png"$(comma) "base64data": load_str("'<(cat $(olm_icon_path) | $(base64_wrapped))'")}]' $(olm_bundle_dir)/manifests/$(olm_project_name).clusterserviceversion.yaml) - - @# Run through yamlfmt - $(YAMLFMT) -conf $(yamlfmt_config) $(olm_bundle_dir)/**/*.yaml - - @# Remove the bundle dockerfile - rm -f $(olm_bundle_dir)/bundle.Dockerfile - -.PHONY: oci-build-olm -## Generate OCI directory for OLM bundle -## @category [shared] Build -oci-build-olm: olm-bundle | $(NEEDS_OLM-TO-OCI) - $(OLM-TO-OCI) $(olm_bundle_dir) $(oci_layout_path_olm) - -# $1 upstream repo -# $2 fork -define olm_publish_targets -.PHONY: olm-publish-$(subst /,-,$1) -olm-publish-$(subst /,-,$1): olm-bundle | $(NEEDS_GH) $(NEEDS_YQ) $(bin_dir)/scratch - rm -rf $(bin_dir)/scratch/git/$2 - mkdir -p $(bin_dir)/scratch/git/$(dir $2) - $(GH) repo clone $2 $(bin_dir)/scratch/git/$2 - cd $(bin_dir)/scratch/git/$2 && \ - git checkout -B $(VERSION) && \ - mkdir -p operators/$(olm_project_name) && \ - cp -r $(abspath $(olm_bundle_dir)) operators/$(olm_project_name)/$(VERSION) && \ - git add operators/$(olm_project_name)/$(VERSION) && \ - touch operators/$(olm_project_name)/ci.yaml && \ - $(if $(and $(findstring redhat-openshift-ecosystem/certified-operators,$1),$(olm_project_id)), \ - $(YQ) -i '.cert_project_id = "$(olm_project_id)"' operators/$(olm_project_name)/ci.yaml &&) \ - $(YQ) -i '.updateGraph = "semver-mode"' operators/$(olm_project_name)/ci.yaml && \ - git add operators/$(olm_project_name)/ci.yaml && \ - git commit -m "operator $(olm_project_name) ($(VERSION))" && \ - git -c "credential.helper=!$(GH) auth git-credential" push -f origin $(VERSION) && \ - { $(GH) pr create --repo $1 --head $(firstword $(subst /, ,$2)):$(VERSION) --title "operator $(olm_project_name) ($(VERSION))" --body "Release of $(olm_project_name) - $(VERSION)" ||:; } - -olm-publish: olm-publish-$(subst /,-,$1) -endef - -$(call for_each_kv,olm_publish_targets,$(olm_publish_repos)) - -.PHONY: olm-publish -## Publish the OLM bundle to an upstream repo, the GH_TOKEN environment variable -## is required to exist -## @category [shared] Publish -olm-publish: - -.PHONY: preflight-scan -## Scan the published image using preflight -## @category [shared] Publish -preflight-scan: - -define preflight_scan_targets -.PHONY: preflight-scan-$1 -preflight-scan-$1: | $$(NEEDS_PREFLIGHT) - $$(call fatal_if_undefined,PYXIS_API_TOKEN) - $$(PREFLIGHT) check container --submit --certification-component-id $2 --pyxis-api-token $$(PYXIS_API_TOKEN) $(firstword $(filter $1:%,$(foreach build_name,$(build_names),$(addsuffix :$(oci_$(build_name)_image_tag),$(oci_$(build_name)_image_name))))) - -preflight-scan: preflight-scan-$1 -endef - -$(call for_each_kv,preflight_scan_targets,$(preflight_container_project_ids)) diff --git a/modules/olm-bundle/base/PROJECT b/modules/olm-bundle/base/PROJECT deleted file mode 100644 index 586d4d29..00000000 --- a/modules/olm-bundle/base/PROJECT +++ /dev/null @@ -1,5 +0,0 @@ -projectName: placeholder -version: "3" -plugins: - manifests.sdk.operatorframework.io/v2: {} - scorecard.sdk.operatorframework.io/v2: {} \ No newline at end of file diff --git a/modules/olm-bundle/base/bundle/README.md b/modules/olm-bundle/base/bundle/README.md deleted file mode 100644 index 7f6f47d4..00000000 --- a/modules/olm-bundle/base/bundle/README.md +++ /dev/null @@ -1,79 +0,0 @@ -# OLM Bundle - -This is the boilerplate for the OLM bundle, it contains the config that is used -to generate an OLM bundle. - -## Bundle generation - -The OLM bundle is generated using the existing Helm chart in the repo. The chart -is build then ran through `helm template`, optionally using a values file for -specific configuration. - -The manifests produced by `helm template` are merged with a -`clusterresourceversion.yaml` file and run through the -`operator-sdk generate bundle` command. - -Additional mutations are then applied for convenience, for example adding the -`containerImage` annotation based of the generated manifests. - -## Layout - -The bundle directory is laid out in the rough structure of the final OLM bundle. -The files in the folder are used as a basis for generating the OLM bundle and -will not appear in the final bundle exactly as written. - -``` -bundle/ -├─ manifests/ -│ ├─ $(deploy_name).clusterresourceversion.yaml [required] -│ └─ additional yaml files [optional] -│ metadata/ -│ └─ annotations.yaml [optional] -│ tests/ -│ └─ scorecard/ -│ └─ config.yaml [optional] -│ examples/ -│ └─ example yaml files [optional] -├─ icon.png [optional] -├─ values.yaml [optional] -└─ README.md -``` - -### `bundle/manifests/$(deploy_name).clusterresourceversion.yaml` - -This file us used as the basis for the final ClusterResourceVersion, it should -not contain any Kubernetes resources as these are added during the bundle -generation process. - -The file should contain descriptions and metadata relating to the bundle only. - -### `bundle/metadata/annotations.yaml` - -This optional file is merged with the generated `annotations.yaml` file. This is -a way for adding additional annotations to the bundle. - -### `bundle/tests/scorecard/config.yaml` - -The scorecard config for testing the bundle, see -https://sdk.operatorframework.io/docs/testing-operators/scorecard/ for more -information. - -### `bundle/icon.png` - -The icon used when the bundle appears on listings. This functionally the same as -defining `.spec.icon.base64data` in the clusterresourceversion file, but as this -field is often very large it makes sense to have it as a separate file. - -### `bundle/values.yaml` - -The values used when `Helm` is used to generate the bundle manifests. This -allows the bundle to have specific config defaults. - -### `bundle/examples/*.yaml` - -Any examples to include in the OLM bundle, the examples are used when listed on operator-hub. You can have a maximum of -one example per CRD. - -### `bundle/README.md` - -This file. \ No newline at end of file diff --git a/modules/olm-bundle/olm-to-oci/go.mod b/modules/olm-bundle/olm-to-oci/go.mod deleted file mode 100644 index 2986cf55..00000000 --- a/modules/olm-bundle/olm-to-oci/go.mod +++ /dev/null @@ -1,20 +0,0 @@ -module olm-to-oci - -go 1.25.7 - -require ( - github.com/google/go-containerregistry v0.21.7 - gopkg.in/yaml.v3 v3.0.1 -) - -require ( - github.com/docker/cli v29.5.3+incompatible // indirect - github.com/docker/docker-credential-helpers v0.9.3 // indirect - github.com/klauspost/compress v1.18.6 // indirect - github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.1.1 // indirect - github.com/sirupsen/logrus v1.9.4 // indirect - golang.org/x/sync v0.21.0 // indirect - golang.org/x/sys v0.46.0 // indirect - gotest.tools/v3 v3.5.2 // indirect -) diff --git a/modules/olm-bundle/olm-to-oci/go.sum b/modules/olm-bundle/olm-to-oci/go.sum deleted file mode 100644 index 03e250e0..00000000 --- a/modules/olm-bundle/olm-to-oci/go.sum +++ /dev/null @@ -1,40 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/cli v29.4.3+incompatible h1:u+UliYm2J/rYrIh2FqHQg32neRG8GjbvNuwQRTzGspU= -github.com/docker/cli v29.4.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= -github.com/docker/cli v29.5.3+incompatible h1:nbEFfz774vBwQ5KRYv7c/AghjReqnGISvrRhzjV0evs= -github.com/docker/cli v29.5.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= -github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8= -github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/go-containerregistry v0.21.6 h1:T+yqQIlJXKrM98Om4DlW3GoWQAmhZuLMwoDOvVrtiUM= -github.com/google/go-containerregistry v0.21.6/go.mod h1:U7MMSBIJynke2MVQrQk19NP9k/uQsGz/h0amIFSHMbo= -github.com/google/go-containerregistry v0.21.7 h1:/vPFuVXDjtFREsVArW+0h1CIl5urnOhzei4X2DMW9IU= -github.com/google/go-containerregistry v0.21.7/go.mod h1:kjSbt7/zMsKLWfnHrIvKvhXHUw91jbe9DNjPPJ32gXE= -github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao= -github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= -github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= -github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= -github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= -github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= -golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= -golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM= -golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= -golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= -golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= -golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= -gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= diff --git a/modules/olm-bundle/olm-to-oci/main.go b/modules/olm-bundle/olm-to-oci/main.go deleted file mode 100644 index 5dae0b6e..00000000 --- a/modules/olm-bundle/olm-to-oci/main.go +++ /dev/null @@ -1,210 +0,0 @@ -/* -Copyright 2024 The cert-manager Authors. - -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. -*/ - -package main - -import ( - "archive/tar" - "bytes" - "flag" - "fmt" - "io" - "io/fs" - "os" - "path/filepath" - - "github.com/google/go-containerregistry/pkg/crane" - cranev1 "github.com/google/go-containerregistry/pkg/v1" - "github.com/google/go-containerregistry/pkg/v1/empty" - "github.com/google/go-containerregistry/pkg/v1/mutate" - "github.com/google/go-containerregistry/pkg/v1/tarball" - yaml "gopkg.in/yaml.v3" -) - -func main() { - // Create function to describe usage - flag.Usage = func() { - fmt.Fprintf(os.Stderr, "%s bundle-path oci-path\n\n", os.Args[0]) - fmt.Fprintf(os.Stderr, "Converts the provided OLM bundle into an OCI directory.\n\n") - flag.PrintDefaults() - } - - // Parse flags, we actually have no flags, but this adds `-help`, which is nice - flag.Parse() - - // Validate we have the correct number of arguments - args := flag.Args() - if len(args) < 2 { - flag.Usage() - os.Exit(1) - } - - bundle := args[0] - oci := args[1] - - image, err := buildImage(bundle) - if err != nil { - fmt.Fprintf(os.Stderr, "Could not build image from bundle: %s", err) - os.Exit(1) - } - - err = crane.SaveOCI(image, oci) - if err != nil { - fmt.Fprintf(os.Stderr, "Could not save OCI directory: %s", err) - os.Exit(1) - } - - digest, err := image.Digest() - if err != nil { - fmt.Fprintf(os.Stderr, "Could not get image digest: %s", err) - os.Exit(1) - } - - err = os.WriteFile(oci+".digests", []byte(digest.String()), 0600) - if err != nil { - fmt.Fprintf(os.Stderr, "Could not save OCI digests: %s", err) - os.Exit(1) - } -} - -// buildImage constructs an image from the provided bundle directory -func buildImage(bundle string) (cranev1.Image, error) { - layer, err := loadLayer(bundle) - if err != nil { - return nil, err - } - - image, err := mutate.AppendLayers(empty.Image, layer) - if err != nil { - return nil, err - } - - annotations, err := loadAnnotations(bundle) - if err != nil { - return nil, err - } - - image, err = mutate.Config(image, cranev1.Config{Labels: annotations}) - if err != nil { - return nil, err - } - - return image, nil -} - -// loadLayer will create an image layer from the bundle directory -func loadLayer(bundle string) (cranev1.Layer, error) { - // Create buffer and tarball writer that will fill the buffer - var buffer bytes.Buffer - tw := tar.NewWriter(&buffer) - - // Walk the all the files in the bundle, only keep directories and yaml - // files - err := filepath.Walk(bundle, func(target string, info fs.FileInfo, err error) error { - if err != nil { - return err - } - - // Generate tar header - this is not actually used as a smaller header - // with reproducible values is used, but some of the values are - // copied from here - header, err := tar.FileInfoHeader(info, info.Name()) - if err != nil { - return err - } - - // Generate a relative name so the tarball does not have the full - // path - name, err := filepath.Rel(bundle, target) - if err != nil { - return err - } - - // If the path is not directory or a yaml file, skip it - if !info.IsDir() { - if ext := filepath.Ext(name); ext != "yaml" && ext != "yml" { - return nil - } - } - - // Write simplified header, this removes all fields that would cause - // the build to be non-reproducible (like modtime for example) - err = tw.WriteHeader(&tar.Header{ - Typeflag: header.Typeflag, - Name: name, - Mode: header.Mode, - Linkname: header.Linkname, - Size: header.Size, - }) - - if err != nil { - return err - } - - // Write the file contents to the tarball - if !info.IsDir() { - file, err := os.Open(target) - if err != nil { - return err - } - - defer file.Close() - - _, err = io.Copy(tw, file) - if err != nil { - return err - } - } - - return nil - }) - - if err != nil { - return nil, err - } - - // Flush the writer to the buffer - if err := tw.Close(); err != nil { - return nil, err - } - - // Return layer from tarball - data := buffer.Bytes() - return tarball.LayerFromOpener(func() (io.ReadCloser, error) { - return io.NopCloser(bytes.NewReader(data)), nil - }) -} - -// loadAnnotations reads the bundles annotations from metadata/annotations.yaml -func loadAnnotations(bundle string) (map[string]string, error) { - type Annotations struct { - Annotations map[string]string `yaml:"annotations"` - } - - path := filepath.Join(bundle, "metadata", "annotations.yaml") - - data, err := os.ReadFile(path) - if err != nil { - return nil, err - } - - var annotations Annotations - if err := yaml.Unmarshal(data, &annotations); err != nil { - return nil, err - } - - return annotations.Annotations, nil -} diff --git a/modules/olm-bundle/yamlfmt.yaml b/modules/olm-bundle/yamlfmt.yaml deleted file mode 100644 index 0c4a06f5..00000000 --- a/modules/olm-bundle/yamlfmt.yaml +++ /dev/null @@ -1,5 +0,0 @@ -doublestar: true -formatter: - type: basic - include_document_start: true - max_line_length: 150 \ No newline at end of file