Skip to content
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

[HOLD] 🌱 cleanup/registry #3323

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
31 changes: 15 additions & 16 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,20 @@ jobs:
# Build the OLM image and save it as an artifact
build:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.vars.outputs.sha }}
steps:
# checkout code and setup go
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
# build binaries and image for e2e test (includes experimental features)
- name: Build controller image
run: make e2e-build
- name: Save image
run: docker save quay.io/operator-framework/olm:local -o olm-image.tar
- name: Upload Docker image as artifact
- name: Build OLM Image
run: make e2e-build save-image
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: olm-image.tar
path: olm-image.tar
name: docker-images
path: "*.tar.gz"

# Run e2e tests in parallel jobs
# Take olm image from the previous stage
Expand All @@ -53,14 +49,17 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

# load the olm image
- name: Load OLM Docker image
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: olm-image.tar
path: .
- run: docker load < olm-image.tar
name: docker-images
path: images/
- name: Load Docker images
run: |
for image in images/*.tar.gz; do
echo "Loading image $image"
docker load -i $image
done

# set e2e environment variables
# Set ginkgo output and parallelism
Expand All @@ -87,7 +86,7 @@ jobs:
KIND_CLUSTER_NAME="kind-olmv0-${i}" \
KIND_CREATE_OPTS="--kubeconfig=${E2E_KUBECONFIG_ROOT}/kubeconfig-${i}" \
HELM_INSTALL_OPTS="--kubeconfig ${E2E_KUBECONFIG_ROOT}/kubeconfig-${i}" \
make kind-create deploy;
make kind-create load-test-images deploy;
done

# run non-flakes if matrix-id is not 'flakes'
Expand Down
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export CONFIGMAP_SERVER_IMAGE ?= quay.io/operator-framework/configmap-operator-r

PKG := github.com/operator-framework/operator-lifecycle-manager
IMAGE_REPO ?= quay.io/operator-framework/olm
IMAGE_TAG ?= "dev"
IMAGE_TAG ?= "local"

# Go build settings #

Expand Down Expand Up @@ -102,8 +102,8 @@ KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -p path $(KUBE_MINOR).x)

# Kind node image tags are in the format x.y.z we pin to version x.y.0 because patch releases and node images
# are not guaranteed to be available when a new version of the kube apis is released
KIND_CLUSTER_IMAGE := kindest/node:v$(KUBE_MINOR).0
KIND_CLUSTER_NAME ?= kind-olmv0
export KIND_CLUSTER_IMAGE := kindest/node:v$(KUBE_MINOR).0
export KIND_CLUSTER_NAME ?= kind-olmv0

# Targets #
# Disable -j flag for make
Expand Down Expand Up @@ -145,9 +145,20 @@ image: export GOOS = linux
image: clean build #HELP Build image image for linux on host architecture
docker build -t $(IMAGE_REPO):$(IMAGE_TAG) -f Dockerfile bin

.PHONY: save-image
TARGZ_FILE ?= olm-image.tar.gz
save-image:
docker save $(IMAGE_REPO):$(IMAGE_TAG) | gzip > "$(TARGZ_FILE)"


.PHONE: build-e2e-fixture-images
build-e2e-fixture-images: #HELP Build images for e2e testing
./scripts/e2e_test_fixtures.sh

.PHONY: e2e-build
# the e2e and experimental_metrics tags are required to get e2e tests to pass
# search the code for go:build e2e or go:build experimental_metrics to see where these tags are used

e2e-build: export GO_BUILD_TAGS += e2e experimental_metrics #HELP Build image for e2e testing
e2e-build: IMAGE_TAG = local
e2e-build: image
Expand Down Expand Up @@ -207,13 +218,18 @@ kind-clean: $(KIND) #HELP Delete kind cluster $KIND_CLUSTER_NAME (default: kind-

.PHONY: kind-create
kind-create: kind-clean #HELP Create a new kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0)
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_CLUSTER_IMAGE) $(KIND_CREATE_OPTS)
./scripts/kind_with_registry.sh
$(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME)

.PHONY: load-test-images
export REGISTRY ?= localhost:5001
load-test-images: #HELP Load the OLM images into the kind cluster's registry
./scripts/e2e_test_fixtures.sh --push-to="$(REGISTRY)"

.PHONY: deploy
OLM_IMAGE := quay.io/operator-framework/olm:local
OLM_IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG)
deploy: $(KIND) $(HELM) #HELP Deploy OLM to kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) using $OLM_IMAGE (default: quay.io/operator-framework/olm:local)
$(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME); \
$(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME)
$(HELM) upgrade --install olm deploy/chart \
--set debug=true \
--set olm.image.ref=$(OLM_IMAGE) \
Expand Down
19 changes: 0 additions & 19 deletions scripts/build_test_images.sh

This file was deleted.

30 changes: 30 additions & 0 deletions scripts/e2e_test_fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

KIND=${KIND:-kind}
CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-docker}

# Default values
OPERATOR_REGISTRY_VERSION="${OPERATOR_REGISTRY_VERSION:-$(go list -m github.com/operator-framework/operator-registry | cut -d" " -f2 | sed 's/^v//')}"
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind-olmv0}"
REGISTRY="${REGISTRY:-localhost:5001}"

# Fixtures
# Note: the following catalogs reference bundles stored in quay.io/olmtest
INDEX_V1="${REGISTRY}/busybox-dependencies-index:1.0.0-with-ListBundles-method-${OPM_VERSION}"
INDEX_V2="${REGISTRY}/busybox-dependencies-index:2.0.0-with-ListBundles-method-${OPM_VERSION}"
TEST_CATALOG_IMAGE="${REGISTRY}/test-catalog:e2e"

## Build
${CONTAINER_RUNTIME} build -t "${INDEX_V1}" --build-arg="OPM_VERSION=v${OPERATOR_REGISTRY_VERSION}" -f ./test/images/busybox-index/index.Dockerfile ./test/images/busybox-index/indexv1
${CONTAINER_RUNTIME} build -t "${INDEX_V2}" --build-arg="OPM_VERSION=v${OPERATOR_REGISTRY_VERSION}" -f ./test/images/busybox-index/index.Dockerfile ./test/images/busybox-index/indexv2

# The following catalog used for e2e tests related to serving an extracted registry
# See catalog_e2e_test.go
# let's just reuse one of the other catalogs for this - the tests don't care about the content
# only that a catalog's content can be extracted and served by a different container
${CONTAINER_RUNTIME} tag "${INDEX_V2}" "${TEST_CATALOG_IMAGE}"

### Push
${CONTAINER_RUNTIME} push "${INDEX_V1}"
${CONTAINER_RUNTIME} push "${INDEX_V2}"
${CONTAINER_RUNTIME} push "${TEST_CATALOG_IMAGE}"
77 changes: 77 additions & 0 deletions scripts/kind_with_registry.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as a sanity check, this works consistently on both Mac and Linux boxes for standing up a local registry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question. I don't have a Mac 😬 - works on linux XD
Would you mind giving it a spin?

make e2e-build kind-create load-test-images deploy e2e

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

borrowed a mac (M1) can confirm deployment works and e2e runs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but I found an issue I missed (making sure the kind cluster uses the right node image) - addressed

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh
set -o errexit
set -x

. ".bingo/variables.env"

# Original source: https://kind.sigs.k8s.io/docs/user/local-registry/
KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-kind-olmv0}
KIND=${KIND:-kind}
DOCKER=${DOCKER:-docker}
KUBECTL=${KUBECTL:-kubectl}

# 1. Create registry container unless it already exists
reg_name='kind-registry'
reg_port='5001'
if [ "$(${DOCKER} inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
${DOCKER} run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \
registry:2
fi

# 2. Create kind cluster with containerd registry config dir enabled
# TODO: kind will eventually enable this by default and this patch will
# be unnecessary.
#
# See:
# https://github.com/kubernetes-sigs/kind/issues/2875
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
if [ -n "${KIND_CLUSTER_IMAGE}" ]; then
KIND_IMAGE="--image=${KIND_CLUSTER_IMAGE}"
fi
cat <<EOF | ${KIND} create cluster --name="${KIND_CLUSTER_NAME}" "${KIND_IMAGE}" ${KIND_CREATE_OPTS} --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
EOF

# 3. Add the registry config to the nodes
#
# This is necessary because localhost resolves to loopback addresses that are
# network-namespace local.
# In other words: localhost in the container is not localhost on the host.
#
# We want a consistent name that works from both ends, so we tell containerd to
# alias localhost:${reg_port} to the registry container when pulling images
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
for node in $(${KIND} --name="${KIND_CLUSTER_NAME}" get nodes); do
${DOCKER} exec "${node}" mkdir -p "${REGISTRY_DIR}"
cat <<EOF | ${DOCKER} exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
[host."http://${reg_name}:5000"]
EOF
done

# 4. Connect the registry to the cluster network
# This allows kind to bootstrap the network but ensures they're on the same network
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi

# 5. Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
${KIND} export kubeconfig --name="${KIND_CLUSTER_NAME}"
cat <<EOF | ${KUBECTL} apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF
11 changes: 6 additions & 5 deletions test/e2e/catalog_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
c operatorclient.ClientInterface
crc versioned.Interface
packageserverClient *packageserverclientset.Clientset
testCatalogImage string
)

BeforeEach(func() {
Expand All @@ -67,6 +68,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
c = ctx.Ctx().KubeClient()
crc = ctx.Ctx().OperatorClient()
packageserverClient = packageserverclientset.NewForConfigOrDie(ctx.Ctx().RESTConfig())
testCatalogImage = fmt.Sprintf("%s/test-catalog:e2e", testClusterRegistry)
})

AfterEach(func() {
Expand Down Expand Up @@ -704,7 +706,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
},
Spec: v1alpha1.CatalogSourceSpec{
SourceType: v1alpha1.SourceTypeGrpc,
Image: communityOperatorsImage,
Image: testCatalogImage,
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
SecurityContextConfig: v1alpha1.Restricted,
},
Expand Down Expand Up @@ -764,7 +766,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
},
Spec: v1alpha1.CatalogSourceSpec{
SourceType: v1alpha1.SourceTypeGrpc,
Image: communityOperatorsImage,
Image: testCatalogImage,
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
SecurityContextConfig: v1alpha1.Restricted,
ExtractContent: &v1alpha1.ExtractContentConfig{
Expand Down Expand Up @@ -1075,7 +1077,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
},
Spec: v1alpha1.CatalogSourceSpec{
SourceType: v1alpha1.SourceTypeGrpc,
Image: catSrcImage + ":1.0.0-with-ListBundles-method",
Image: fmt.Sprintf("%s:1.0.0-with-ListBundles-method", catSrcImage),
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
SecurityContextConfig: v1alpha1.Restricted,
},
Expand Down Expand Up @@ -1126,8 +1128,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
if err != nil {
return err
}
existingSource.Spec.Image = catSrcImage + ":2.0.0-with-ListBundles-method"

existingSource.Spec.Image = fmt.Sprintf("%s:2.0.0-with-ListBundles-method", catSrcImage)
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), existingSource, metav1.UpdateOptions{})
return err
}).Should(Succeed())
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ var (
catalogNamespace = flag.String(
"catalogNamespace", "", "namespace where the global catalog content is stored")

communityOperators = flag.String(
"communityOperators",
"quay.io/operatorhubio/catalog:latest",
"reference to upstream-community-operators image",
)

dummyImage = flag.String(
"dummyImage",
"bitnami/nginx:latest",
Expand All @@ -62,6 +56,12 @@ var (
"configures where to find the testdata directory",
)

clusterRegistry = flag.String(
"cluster-registry",
"localhost:5001",
"set cluster registry url (default: localhost:5001)",
)

kubeconfigRootDir = flag.String(
"kubeconfig-root",
"",
Expand All @@ -71,11 +71,11 @@ var (
"Note that this flag will override the kubeconfig flag.",
)

testdataDir = ""
testNamespace = ""
operatorNamespace = ""
communityOperatorsImage = ""
globalCatalogNamespace = ""
testdataDir = ""
testNamespace = ""
operatorNamespace = ""
globalCatalogNamespace = ""
testClusterRegistry = ""
)

func TestEndToEnd(t *testing.T) {
Expand Down Expand Up @@ -104,9 +104,9 @@ var _ = BeforeSuite(func() {

testNamespace = *namespace
operatorNamespace = *olmNamespace
communityOperatorsImage = *communityOperators
globalCatalogNamespace = *catalogNamespace
testdataDir = *testdataPath
testClusterRegistry = *clusterRegistry
deprovision = ctx.MustProvision(ctx.Ctx())
ctx.MustInstall(ctx.Ctx())

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ func catalogSourceRegistryPodSynced() func(catalog *operatorsv1alpha1.CatalogSou
state = connState.LastObservedState
}
if state != lastState {
fmt.Printf("waiting %s for catalog pod %s/%s to be available (for sync) - %s\n", time.Since(lastTime), catalog.GetNamespace(), catalog.GetName(), state)
ctx.Ctx().Logf("waiting %s for catalog pod %s/%s to be available (for sync) - %s\n", time.Since(lastTime), catalog.GetNamespace(), catalog.GetName(), state)
lastState = state
lastTime = time.Now()
}
if registry != nil && connState != nil && !connState.LastConnectTime.IsZero() && connState.LastObservedState == "READY" {
fmt.Printf("probing catalog %s pod with address %s\n", catalog.GetName(), registry.Address())
ctx.Ctx().Logf("probing catalog %s pod with address %s\n", catalog.GetName(), registry.Address())
return registryPodHealthy(registry.Address())
}
return false
Expand Down
16 changes: 16 additions & 0 deletions test/images/busybox-index/index.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The base image is expected to contain
# /bin/opm (with a serve subcommand) and /bin/grpc_health_probe
ARG OPM_VERSION=latest
FROM quay.io/operator-framework/opm:${OPM_VERSION}

# Set DC-specific label for the location of the DC root directory
# in the image
LABEL operators.operatorframework.io.index.configs.v1=/configs

# Copy declarative config root into image at /configs and pre-populate serve cache
COPY /configs /configs
RUN ["/bin/opm", "serve", "/configs", "--cache-dir=/tmp/cache", "--cache-only"]

# Configure the entrypoint and command
ENTRYPOINT ["/bin/opm"]
CMD ["serve", "/configs", "--cache-dir=/tmp/cache"]
2 changes: 2 additions & 0 deletions test/images/busybox-index/indexv1/configs/.indexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/expected_all.json
..*
Loading
Loading