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

Implement Single Layer OCI Artifacts #98

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
264 changes: 132 additions & 132 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,135 +62,135 @@ jobs:
bin/k8s
key: ${{ steps.cache-k8s-restore.outputs.cache-primary-key }}

e2e-tests:
runs-on: large_runner
steps:
- name: Self Hosted Runner Post Job Cleanup Action
uses: TooMuch4U/[email protected]
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: '${{ github.workspace }}/go.mod'
cache: false

- name: Get Go environment
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
bin/k8s
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: integration-test

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
with:
config: test/e2e/config/kind-config.yaml

- name: Install internal image registry
run: |
kubectl apply -f test/e2e/config/image-registry.yaml
kubectl wait pod -l app=registry --for condition=Ready --timeout 5m
kubectl wait pod -l app=protected-registry1 --for condition=Ready --timeout 5m
kubectl wait pod -l app=protected-registry2 --for condition=Ready --timeout 5m

- name: Install external CRDs
run: kubectl apply --server-side -k https://github.com/openfluxcd/artifact//config/crd?ref=v0.1.1

- name: Checkout helm-controller
uses: actions/checkout@v4
with:
repository: openfluxcd/helm-controller
path: helm-controller

# TODO: Create helm-controller image in public repository to omit rebuilds
- name: Install helm-controller
env:
IMG: localhost:31000/helm-controller:latest
run: |
make -C helm-controller docker-build
make -C helm-controller docker-push
make -C helm-controller install
make -C helm-controller deploy
kubectl wait deployment.apps/helm-controller --for condition=Available --namespace helm-system --timeout 5m
kubectl logs --tail -1 -l app=helm-controller -n helm-system -f --ignore-errors &> helm-controller.log &

- name: Checkout kustomize-controller
uses: actions/checkout@v4
with:
repository: openfluxcd/kustomize-controller
path: kustomize-controller

# TODO: Create kustomize-controller image in public repository to omit rebuilds
- name: Install kustomize-controller
env:
IMG: localhost:31000/kustomize-controller:latest
run: |
make -C kustomize-controller docker-build
make -C kustomize-controller docker-push
make -C kustomize-controller install
make -C kustomize-controller deploy
kubectl wait deployment.apps/kustomize-controller --for condition=Available --namespace kustomize-system --timeout 5m
kubectl logs --tail -1 -l app=kustomize-controller -n kustomize-system -f --ignore-errors &> kustomize-controller.log &

# TODO: Replace once the release with the 'skipDigestGeneration' field in the component constructor is available
# uses: open-component-model/ocm-setup-action@main
# with:
# version: v0.19.0-rc.1
- name: Set up cache for ocm (temporarily)
uses: actions/cache@v4
with:
path: |
ocm/bin
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: dummy-cache
- name: Checkout OCM (temporarily)
uses: actions/checkout@v4
with:
repository: open-component-model/ocm
path: ocm
- name: Build OCM (temporarily)
run: |
make -C ocm bin/ocm
echo "${{ github.workspace }}/ocm/bin" >> "$GITHUB_PATH"

- name: Run e2e test
env:
RESOURCE_TIMEOUT: 5m
HELM_CHART: ghcr.io/stefanprodan/charts/podinfo:6.7.1
IMAGE_REFERENCE: ghcr.io/stefanprodan/podinfo:6.7.1
CONTROLLER_LOG_PATH: ./ocm-k8s-toolkit-controller.log
IMAGE_REGISTRY_URL: http://localhost:31000
INTERNAL_IMAGE_REGISTRY_URL: http://registry-internal.default.svc.cluster.local:5000
PROTECTED_REGISTRY_URL: http://localhost:31001
INTERNAL_PROTECTED_REGISTRY_URL: http://protected-registry1-internal.default.svc.cluster.local:5001
PROTECTED_REGISTRY_URL2: http://localhost:31002
INTERNAL_PROTECTED_REGISTRY_URL2: http://protected-registry2-internal.default.svc.cluster.local:5002
run: make test-e2e

- name: Publish logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: controller-logs
# Currently, it is planned that the integration tests runs on every commit on a PR. Therefore, we could
# produce a lot of logs. To note clutter the storage, the retention-days are reduced to 1.
retention-days: 1
path: |
helm-controller.log
kustomize-controller.log
ocm-k8s-toolkit-controller.log
# e2e-tests:
# runs-on: large_runner
# steps:
# - name: Self Hosted Runner Post Job Cleanup Action
# uses: TooMuch4U/[email protected]
# - name: Checkout
# uses: actions/checkout@v4
# - name: Setup Go
# uses: actions/setup-go@v5
# with:
# go-version-file: '${{ github.workspace }}/go.mod'
# cache: false
#
# - name: Get Go environment
# run: |
# echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
# echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
# - name: Set up cache
# # https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
# uses: actions/cache@v4
# with:
# path: |
# ${{ env.go_cache }}
# ${{ env.go_modcache }}
# bin/k8s
# key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
# restore-keys: |
# ${{ env.cache_name }}-${{ runner.os }}-go-
# env:
# cache_name: integration-test
#
# - name: Create k8s Kind Cluster
# uses: helm/kind-action@v1
# with:
# config: test/e2e/config/kind-config.yaml
#
# - name: Install internal image registry
# run: |
# kubectl apply -f test/e2e/config/image-registry.yaml
# kubectl wait pod -l app=registry --for condition=Ready --timeout 5m
# kubectl wait pod -l app=protected-registry1 --for condition=Ready --timeout 5m
# kubectl wait pod -l app=protected-registry2 --for condition=Ready --timeout 5m
#
# - name: Install external CRDs
# run: kubectl apply --server-side -k https://github.com/openfluxcd/artifact//config/crd?ref=v0.1.1
#
# - name: Checkout helm-controller
# uses: actions/checkout@v4
# with:
# repository: openfluxcd/helm-controller
# path: helm-controller
#
# # TODO: Create helm-controller image in public repository to omit rebuilds
# - name: Install helm-controller
# env:
# IMG: localhost:31000/helm-controller:latest
# run: |
# make -C helm-controller docker-build
# make -C helm-controller docker-push
# make -C helm-controller install
# make -C helm-controller deploy
# kubectl wait deployment.apps/helm-controller --for condition=Available --namespace helm-system --timeout 5m
# kubectl logs --tail -1 -l app=helm-controller -n helm-system -f --ignore-errors &> helm-controller.log &
#
# - name: Checkout kustomize-controller
# uses: actions/checkout@v4
# with:
# repository: openfluxcd/kustomize-controller
# path: kustomize-controller
#
# # TODO: Create kustomize-controller image in public repository to omit rebuilds
# - name: Install kustomize-controller
# env:
# IMG: localhost:31000/kustomize-controller:latest
# run: |
# make -C kustomize-controller docker-build
# make -C kustomize-controller docker-push
# make -C kustomize-controller install
# make -C kustomize-controller deploy
# kubectl wait deployment.apps/kustomize-controller --for condition=Available --namespace kustomize-system --timeout 5m
# kubectl logs --tail -1 -l app=kustomize-controller -n kustomize-system -f --ignore-errors &> kustomize-controller.log &
#
# # TODO: Replace once the release with the 'skipDigestGeneration' field in the component constructor is available
# # uses: open-component-model/ocm-setup-action@main
# # with:
# # version: v0.19.0-rc.1
# - name: Set up cache for ocm (temporarily)
# uses: actions/cache@v4
# with:
# path: |
# ocm/bin
# key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
# restore-keys: |
# ${{ env.cache_name }}-${{ runner.os }}-go-
# env:
# cache_name: dummy-cache
# - name: Checkout OCM (temporarily)
# uses: actions/checkout@v4
# with:
# repository: open-component-model/ocm
# path: ocm
# - name: Build OCM (temporarily)
# run: |
# make -C ocm bin/ocm
# echo "${{ github.workspace }}/ocm/bin" >> "$GITHUB_PATH"
#
# - name: Run e2e test
# env:
# RESOURCE_TIMEOUT: 5m
# HELM_CHART: ghcr.io/stefanprodan/charts/podinfo:6.7.1
# IMAGE_REFERENCE: ghcr.io/stefanprodan/podinfo:6.7.1
# CONTROLLER_LOG_PATH: ./ocm-k8s-toolkit-controller.log
# IMAGE_REGISTRY_URL: http://localhost:31000
# INTERNAL_IMAGE_REGISTRY_URL: http://registry-internal.default.svc.cluster.local:5000
# PROTECTED_REGISTRY_URL: http://localhost:31001
# INTERNAL_PROTECTED_REGISTRY_URL: http://protected-registry1-internal.default.svc.cluster.local:5001
# PROTECTED_REGISTRY_URL2: http://localhost:31002
# INTERNAL_PROTECTED_REGISTRY_URL2: http://protected-registry2-internal.default.svc.cluster.local:5002
# run: make test-e2e
#
# - name: Publish logs on failure
# if: failure()
# uses: actions/upload-artifact@v4
# with:
# name: controller-logs
# # Currently, it is planned that the integration tests runs on every commit on a PR. Therefore, we could
# # produce a lot of logs. To note clutter the storage, the retention-days are reduced to 1.
# retention-days: 1
# path: |
# helm-controller.log
# kustomize-controller.log
# ocm-k8s-toolkit-controller.log
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ else
GOBIN=$(shell go env GOBIN)
endif

OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)


# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
Expand Down Expand Up @@ -64,7 +68,7 @@ vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate envtest ## Run tests.
test: manifests generate envtest zot-registry ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
Expand Down Expand Up @@ -172,12 +176,14 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
ZOT_BINARY ?= $(LOCALBIN)/zot-registry

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.1
CONTROLLER_TOOLS_VERSION ?= v0.16.0
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.61.0
ZOT_VERSION ?= v2.1.2

## ZOT OCI Registry
ZOT_VERSION ?= v2.1.2
Expand Down Expand Up @@ -213,6 +219,14 @@ deploy-cert-manager: ## Deploy cert-manager to the K8s cluster specified in ~/.k
undeploy-cert-manager: ## Undeploy cert-manager from the K8s cluster specified in ~/.kube/config.
$(KUBECTL) delete --ignore-not-found=$(IGNORE_NOT_FOUND) -f $(CERT-MANAGER_YAML)

.PHONY: zot-registry
zot-registry: $(LOCALBIN) ## Download zot registry binary locally if necessary.
ifeq (, $(shell which $(ZOT_BINARY)))
wget "https://github.com/project-zot/zot/releases/download/$(ZOT_VERSION)/zot-$(OS)-$(ARCH)-minimal" \
-O $(ZOT_BINARY) \
&& chmod u+x $(ZOT_BINARY)
endif

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
Expand Down
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ resources:
kind: Replication
path: github.com/open-component-model/ocm-k8s-toolkit/api/v1alpha1
version: v1alpha1
version: "3"
version: "3"
34 changes: 34 additions & 0 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,37 @@ type ResourceInfo struct {
// +required
Digest string `json:"digest,omitempty"`
}

type BlobInfo struct {
// Digest is the digest of the blob in the form of '<algorithm>:<checksum>'.
Digest string `json:"digest"`

// Tag/Version of the blob
Tag string `json:"tag"`

// Size is the number of bytes of the blob.
// Can be used to determine how to file should be handled when downloaded (memory/disk)
Size int64 `json:"size"`
}

// OCIArtifactInfo contains information on how to locate an OCI Artifact.
type OCIArtifactInfo struct {
// OCI repository name
// +required
Repository string `json:"repository"`

// Manifest digest (required to delete the manifest and prepare OCI artifact for GC)
// +required
Digest string `json:"digest"`

// Blob
// +required
Blob *BlobInfo `json:"blob"`
}

// +k8s:deepcopy-gen=false
type OCIArtifactCreator interface {
GetOCIArtifact() *OCIArtifactInfo
GetOCIRepository() string
GetManifestDigest() string
}
Loading