Skip to content

Commit

Permalink
Merge pull request #67 from Nordix/fix_e2e_pkg_build
Browse files Browse the repository at this point in the history
Use local porch pkg build for e2e tests
  • Loading branch information
efiacor authored Jun 13, 2024
2 parents bf6b2ba + 181f7f4 commit 9fd76cc
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/porch-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
with:
cluster_name: kind
- name: Build Images and Deploy porch kpt pkg
run: IMAGE_REPO=porch-kind IMAGE_TAG=${GITHUB_SHA:0:8} make run-in-kind-kpt
run: IMAGE_REPO=porch-kind IMAGE_TAG=${GITHUB_SHA:0:8} make run-in-kind
- name: Sleep for 15 seconds
run: sleep 15s
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/porchctl-cli-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
cluster_name: kind
- name: Build Images and Deploy porch kpt pkg
run: IMAGE_REPO=porch-kind IMAGE_TAG=${GITHUB_SHA:0:8} make run-in-kind-kpt
run: IMAGE_REPO=porch-kind IMAGE_TAG=${GITHUB_SHA:0:8} make run-in-kind
- name: porchctl e2e test
run: E2E=1 go test -v -timeout 20m ${GITHUB_WORKSPACE}/test/e2e/cli
- name: Export porch server logs
Expand Down
91 changes: 19 additions & 72 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
MYGOBIN := $(shell go env GOPATH)/bin
BUILDDIR=$(CURDIR)/.build
CACHEDIR=$(CURDIR)/.cache
DEPLOYCONFIGDIR=$(BUILDDIR)/deploy
DEPLOYKPTCONFIGDIR=$(DEPLOYCONFIGDIR)/kpt_pkgs
DEPLOYCONFIG_NO_SA_DIR=$(BUILDDIR)/deploy-no-sa
DEPLOYPORCHCONFIGDIR=$(BUILDDIR)/deploy
DEPLOYKPTCONFIGDIR=$(BUILDDIR)/kpt_pkgs
KPTDIR=$(abspath $(CURDIR)/..)

# This includes the following targets:
Expand All @@ -29,16 +28,6 @@ include default-go.mk
# This includes the 'help' target that prints out all targets with their descriptions organized by categories
include default-help.mk

# GCP project to use for development

ifeq ($(GCP_PROJECT_ID),)
ifeq ($(shell command -v gcloud > /dev/null 2>&1; echo $$?), 0)
export GCP_PROJECT_ID=$(shell gcloud config get-value project)
else
export GCP_PROJECT_ID=pure-faculty-367518
endif
endif

export IMAGE_REPO ?= docker.io/nephio
export USER ?= nephio

Expand All @@ -63,7 +52,7 @@ SKIP_IMG_BUILD ?= false
# Only enable a subset of reconcilers in porch controllers by default. Use the RECONCILERS
# env variable to specify a specific list of reconcilers or use
# RECONCILERS=* to enable all known reconcilers.
ALL_RECONCILERS="packagevariants,packagevariantsets,fleetsyncs"
ALL_RECONCILERS="packagevariants,packagevariantsets"
ifndef RECONCILERS
ENABLED_RECONCILERS="packagevariants,packagevariantsets"
else
Expand Down Expand Up @@ -166,7 +155,7 @@ test-e2e:

.PHONY: test-e2e-clean
test-e2e-clean:
./scripts/clean-kind-only-e2e-test.sh
./scripts/clean-kind-only-e2e-test.sh

.PHONY: configure-git
configure-git:
Expand Down Expand Up @@ -247,89 +236,47 @@ apply-dev-config:
# TODO: Replace with kpt function
cat config/samples/deployment-repository.yaml | sed -e s/example-google-project-id/${GCP_PROJECT_ID}/g | kubectl apply -f -


.PHONY: deployment-config
deployment-config:
rm -rf $(DEPLOYCONFIGDIR) || true
mkdir -p $(DEPLOYCONFIGDIR)
mkdir -p $(DEPLOYPORCHCONFIGDIR)
find $(DEPLOYPORCHCONFIGDIR) ! -name 'resourcegroup.yaml' -type f -exec rm -f {} +
./scripts/create-deployment-blueprint.sh \
--destination "$(DEPLOYCONFIGDIR)" \
--destination "$(DEPLOYPORCHCONFIGDIR)" \
--server-image "$(IMAGE_REPO)/$(PORCH_SERVER_IMAGE):$(IMAGE_TAG)" \
--controllers-image "$(IMAGE_REPO)/$(PORCH_CONTROLLERS_IMAGE):$(IMAGE_TAG)" \
--function-image "$(IMAGE_REPO)/$(PORCH_FUNCTION_RUNNER_IMAGE):$(IMAGE_TAG)" \
--wrapper-server-image "$(IMAGE_REPO)/$(PORCH_WRAPPER_SERVER_IMAGE):$(IMAGE_TAG)" \
--enabled-reconcilers "$(ENABLED_RECONCILERS)" \
--project "$(GCP_PROJECT_ID)"
--enabled-reconcilers "$(ENABLED_RECONCILERS)"

.PHONY: deploy
deploy: deployment-config
kubectl apply -R -f $(DEPLOYCONFIGDIR)
kubectl apply -R -f $(DEPLOYPORCHCONFIGDIR)

.PHONY: push-and-deploy
push-and-deploy: push-images deploy

# Builds deployment config without configuring GCP workload identity for
# Porch server. This is sufficient for working with GitHub repositories.
# Workload identity is currently required for Porch to integrate with GCP
# Container and Artifact Registries; for those use cases, use the make
# targets without the `-no-sa` suffix (i.e. `deployment-config`,
# `push-and-deploy` etc.)
.PHONY: deployment-config-no-sa
deployment-config-no-sa:
mkdir -p $(DEPLOYCONFIG_NO_SA_DIR)
find $(DEPLOYCONFIG_NO_SA_DIR) ! -name 'resourcegroup.yaml' -type f -exec rm -f {} +
./scripts/create-deployment-blueprint.sh \
--destination "$(DEPLOYCONFIG_NO_SA_DIR)" \
--server-image "$(IMAGE_REPO)/$(PORCH_SERVER_IMAGE):$(IMAGE_TAG)" \
--controllers-image "$(IMAGE_REPO)/$(PORCH_CONTROLLERS_IMAGE):$(IMAGE_TAG)" \
--function-image "$(IMAGE_REPO)/$(PORCH_FUNCTION_RUNNER_IMAGE):$(IMAGE_TAG)" \
--wrapper-server-image "$(IMAGE_REPO)/$(PORCH_WRAPPER_SERVER_IMAGE):$(IMAGE_TAG)" \
--enabled-reconcilers "$(ENABLED_RECONCILERS)"

.PHONY: deploy-no-sa
deploy-no-sa: deployment-config-no-sa
kubectl apply -R -f $(DEPLOYCONFIG_NO_SA_DIR)

.PHONY: push-and-deploy-no-sa
push-and-deploy-no-sa: push-images deploy-no-sa

KIND_CONTEXT_NAME ?= kind

.PHONY: run-in-kind
run-in-kind: IMAGE_REPO=porch-kind
run-in-kind:
make build-images
ifeq ($(SKIP_IMG_BUILD), false)
make build-images;
endif
kind load docker-image $(IMAGE_REPO)/$(PORCH_SERVER_IMAGE):${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image $(IMAGE_REPO)/$(PORCH_CONTROLLERS_IMAGE):${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image $(IMAGE_REPO)/$(PORCH_FUNCTION_RUNNER_IMAGE):${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image $(IMAGE_REPO)/$(PORCH_WRAPPER_SERVER_IMAGE):${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image $(IMAGE_REPO)/$(TEST_GIT_SERVER_IMAGE):${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
make deployment-config
KUBECONFIG=$(KUBECONFIG) kubectl apply --wait --recursive --filename $(DEPLOYCONFIGDIR)
KUBECONFIG=$(KUBECONFIG) kubectl rollout status deployment function-runner --namespace porch-system
KUBECONFIG=$(KUBECONFIG) kubectl rollout status deployment porch-controllers --namespace porch-system
KUBECONFIG=$(KUBECONFIG) kubectl rollout status deployment porch-server --namespace porch-system

.PHONY: deployment-config-kpt
deployment-config-kpt:
rm -rf $(DEPLOYKPTCONFIGDIR) || true
mkdir -p $(DEPLOYKPTCONFIGDIR)
./scripts/create-deployment-kpt.sh \
--destination $(DEPLOYKPTCONFIGDIR) \
--server-image "$(IMAGE_REPO)/$(PORCH_SERVER_IMAGE):$(IMAGE_TAG)" \
--controllers-image "$(IMAGE_REPO)/$(PORCH_CONTROLLERS_IMAGE):$(IMAGE_TAG)" \
--function-image "$(IMAGE_REPO)/$(PORCH_FUNCTION_RUNNER_IMAGE):$(IMAGE_TAG)" \
--wrapper-server-image "$(IMAGE_REPO)/$(PORCH_WRAPPER_SERVER_IMAGE):$(IMAGE_TAG)" \
--test-git-server-image "$(IMAGE_REPO)/$(TEST_GIT_SERVER_IMAGE):${IMAGE_TAG}" \
--enabled-reconcilers "$(ENABLED_RECONCILERS)" \
--kind-context "$(KIND_CONTEXT_NAME)"
kpt fn render $(DEPLOYPORCHCONFIGDIR)
kpt live init $(DEPLOYPORCHCONFIGDIR) || true
kpt live apply --inventory-policy=adopt $(DEPLOYPORCHCONFIGDIR)
kubectl rollout status deployment function-runner --namespace porch-system
kubectl rollout status deployment porch-controllers --namespace porch-system
kubectl rollout status deployment porch-server --namespace porch-system

.PHONY: run-in-kind-kpt
run-in-kind-kpt: IMAGE_REPO=porch-kind
run-in-kind-kpt:
ifeq ($(SKIP_IMG_BUILD), false)
make build-images;
endif
make deployment-config-kpt

PKG=gitea-dev
.PHONY: deploy-gitea-dev-pkg
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/1-namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions deployments/porch/2-function-runner.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@ spec:
serviceAccountName: porch-fn-runner
containers:
- name: function-runner
image: gcr.io/example-google-project-id/porch-function-runner:latest
image: docker.io/nephio/porch-function-runner:latest
imagePullPolicy: IfNotPresent
command:
- /server
Expand All @@ -46,7 +46,7 @@ spec:
- --pod-namespace=porch-fn-system
env:
- name: WRAPPER_SERVER_IMAGE
value: gcr.io/example-google-project-id/porch-wrapper-server:latest
value: docker.io/nephio/porch-wrapper-server:latest
ports:
- containerPort: 9445
# Add grpc readiness probe to ensure the cache is ready
Expand Down
4 changes: 2 additions & 2 deletions deployments/porch/3-porch-server.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +45,7 @@ spec:
containers:
- name: porch-server
# Update image to the image of your porch apiserver build.
image: gcr.io/example-google-project-id/porch-server:latest
image: docker.io/nephio/porch-server:latest
imagePullPolicy: IfNotPresent
resources:
requests:
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/4-apiservice.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/5-rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/6-rbac-bind.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/7-auth-reader.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/8-auth-delegator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions deployments/porch/9-controllers.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,7 @@ spec:
containers:
- name: porch-controllers
# Update to the image of your porch-controllers build.
image: gcr.io/example-google-project-id/porch-controllers:latest
image: docker.io/nephio/porch-controllers:latest
env:
- name: GCP_PROJECT_ID
value: example-google-project-id
- name: EXAMPLE_ENV
value: "true"
5 changes: 2 additions & 3 deletions docs/running-porch-in-kind-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Docker image load bug on v25.0.0 Use v24.0.7
4. [The go programming language](https://go.dev/doc/install)
5. [kind](https://kind.sigs.k8s.io/docs/user/quick-start#installation)
6. [kpt-cli](https://kpt.dev/installation/kpt-cli)
7. [yq](https://github.com/mikefarah/yq/#install)

## Create a default kind cluster

Expand All @@ -32,7 +31,7 @@ export KUBECONFIG=~/.kube/kind-dev-config
Clone the [porch project](https://github.com/nephio-project/porch.git) from Github onto your environment using whatever cloning process for development your organization recommends.
Here, we assume Porch is cloned into a directory called `porch`.

We will now use the make target `run-in-kind-kpt` to build the images and re deploy the porch deployments to use them.
We will now use the make target `run-in-kind` to build the images and re deploy the porch deployments to use them.

Here, we pass the following vars to the make target:

Expand All @@ -45,7 +44,7 @@ Here, we pass the following vars to the make target:
```
cd porch
make run-in-kind-kpt IMAGE_TAG='test' KUBECONFIG='/home/ubuntu/.kube/config' KIND_CONTEXT_NAME='dev'
make run-in-kind IMAGE_TAG='test' KUBECONFIG='/home/ubuntu/.kube/config' KIND_CONTEXT_NAME='dev'
```
This will build the porch images locally with the given tag, load them in to the kind docker ctr, update the [porch kpt pkg](https://github.com/nephio-project/catalog/tree/main/nephio/core/porch) to use those images and deploy the pkg to the cluster.

Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/porch-development-environment/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ kubectl wait --namespace gitea statefulset gitea \

############################################
h1 Create git repos in gitea
curl -k -H "content-type: application/json" "http://nephio:secret@${gitea_ip}:3000/api/v1/user/repos" --data "{\"name\":\"$git_repo_name\"}"
curl -v -k -H "content-type: application/json" "http://nephio:secret@localhost:3000/api/v1/user/repos" --data "{\"name\":\"$git_repo_name\"}"
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
git clone "http://nephio:secret@${gitea_ip}:3000/nephio/$git_repo_name"
git clone "http://nephio:secret@localhost:3000/nephio/$git_repo_name"
cd "$git_repo_name"
if ! git rev-parse -q --verify refs/remotes/origin/main >/dev/null; then
echo "Add main branch to git repo:"
Expand Down Expand Up @@ -146,8 +146,8 @@ fi
############################################
h1 Install all porch components, except porch-server
cd "${git_root}"
make deployment-config-no-sa
cd .build/deploy-no-sa
make deployment-config
cd .build/deploy
# expose function-runner to local processes
kpt fn eval \
--image gcr.io/kpt-fn/starlark:v0.5.0 \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/bluekeyes/go-gitdiff v0.6.1
github.com/bytecodealliance/wasmtime-go v0.39.0
github.com/cpuguy83/go-md2man/v2 v2.0.2
github.com/fsnotify/fsnotify v1.7.0
github.com/go-errors/errors v1.4.2
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.12.0
Expand Down Expand Up @@ -100,7 +101,6 @@ require (
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logr/logr v1.4.1 // indirect
Expand Down
13 changes: 2 additions & 11 deletions scripts/clean-kind-only-e2e-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright 2022 The kpt and Nephio Authors
# Copyright 2022-2024 The kpt and Nephio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,16 +27,7 @@ kubeconfig_file="$(mktemp)"
kind delete cluster --name "$kind_cluster" || true
kind create cluster --name "$kind_cluster"
kind get kubeconfig --name "$kind_cluster" > "$kubeconfig_file"
make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME="$kind_cluster" KUBECONFIG="$kubeconfig_file"
for deployment in porch-controllers porch-server function-runner; do
kubectl rollout status deployment $deployment --namespace porch-system
kubectl wait --namespace porch-system deploy $deployment \
--for=condition=available \
--timeout=90s
done
kubectl wait --namespace porch-system pod --selector=app=function-runner \
--for=condition=ready \
--timeout=90s
make run-in-kind IMAGE_TAG='test' KIND_CONTEXT_NAME="$kind_cluster" KUBECONFIG="$kubeconfig_file"

sleep 20

Expand Down
Loading

0 comments on commit 9fd76cc

Please sign in to comment.