Skip to content

Changes to the run-e2e-kind.sh locally #290

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

Merged
merged 8 commits into from
Apr 5, 2023
Merged
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
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VERSION_FILE=./CONTROLLER_VERSION
RELEASE_VER=v$(shell $(CAT_CMD) $(VERSION_FILE))
CURRENT_DIR=$(shell pwd)
GIT_BRANCH:=$(shell git symbolic-ref --short HEAD 2>&1 | grep -v fatal)
LOCAL_BUILD_ARGS ?= -race
# Reset branch name if this a Travis CI environment
ifneq ($(strip $(TRAVIS_BRANCH)),)
GIT_BRANCH:=${TRAVIS_BRANCH}
Expand All @@ -23,9 +24,10 @@ TAG:=${TAG}${RELEASE_VER}

.PHONY: print-global-variables

# Build the controler executalbe for use in docker image build
mcad-controller: init generate-code
$(info Compiling controller)
CGO_ENABLED=0 GOARCH=amd64 go build -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/
CGO_ENABLED=0 GOOS="linux" go build -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/

print-global-variables:
$(info "---")
Expand Down Expand Up @@ -54,15 +56,15 @@ generate-code:
$(info Generating deepcopy...)
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/controller/v1beta1/ -O zz_generated.deepcopy

images: verify-tag-name
images: verify-tag-name mcad-controller
$(info List executable directory)
$(info repo id: ${git_repository_id})
$(info branch: ${GIT_BRANCH})
ls -l ${CURRENT_DIR}/_output/bin
$(info Build the docker image)
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/deployment/Dockerfile.both ${CURRENT_DIR}/_output/bin

images-podman: verify-tag-name
images-podman: verify-tag-name mcad-controller
$(info List executable directory)
$(info repo id: ${git_repository_id})
$(info branch: ${GIT_BRANCH})
Expand Down Expand Up @@ -106,6 +108,12 @@ mcad-controller-private: init generate-code
$(info Compiling controller)
CGO_ENABLED=0 GOARCH=amd64 GOPRIVATE=github.ibm.com/* go build -tags private -modfile ./private.mod -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/

# Build the controller executable for use on the local host and using local build args
# the default for local build args is `-race` to turn race detection
mcad-controller-local: init generate-code
$(info Compiling controller)
go build ${LOCAL_BUILD_ARGS} -o ${BIN_DIR}/mcad-controller-local ./cmd/kar-controllers/

coverage:
# KUBE_COVER=y hack/make-rules/test.sh $(WHAT) $(TESTS)

Expand Down
192 changes: 135 additions & 57 deletions doc/build/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ To build `Multi-Cluster-App-Deployer`, a running Docker environment must be avai
Clone this repo in your local environment:

__Option 1__: Clone this github project to your local machine via HTTPS
```

```bash
$ git clone https://github.com/project-codeflare/multi-cluster-app-dispatcher.git
Cloning into 'multi-cluster-app-dispatcher'...
Checking connectivity... done.
Expand All @@ -22,90 +23,167 @@ $
```

__Option 2__: Clone this github project to your local machine via SSH
```

```bash
$ git clone git@github.com:project-codeflare/multi-cluster-app-dispatcher.git
Cloning into 'multi-cluster-app-dispatcher'...
Checking connectivity... done.
Checking out files: 100% (####/####), done.
$

```

### Additional software needed

To build the controller and to run the end to end tests locally you will need to have the following software installed:

* `Go` (version 1.16) -- the controller will compile and run with later versions, but currently supported version is 1.16
* `kind` (version 0.11) -- later versions will work fine
* `kubectl`
* `helm` - version 3.0 or later
* `make`

On MacOS you will need to have `readlink` executable installed (`brew install coreutils`)

## 2. Building the Multi-Cluster-App-Deployer Controller

### Build the Executable

Run the build script `build.sh`:
```
$ cd multi-cluster-app-dispatcher/deployment/
From the root directory of the repository, you may build only the executable, or you can build the image directly.

To to build the executable, execute:

$ ./build.sh
```bash
#build for linux OS and for use inside docker image
multi-cluster-app-dispatcher $ make mcad-controller
...
+ cd ..
+ make generate-code
Compiling deepcopy-gen
Generating deepcopy
Compiling deepcopy-gen...
Generating deepcopy...
go build -o _output/bin/deepcopy-gen ./cmd/deepcopy-gen/
_output/bin/deepcopy-gen -i ./pkg/apis/controller/v1beta1/ -O zz_generated.deepcopy
+ make kar-controller
_output/bin/deepcopy-gen -i ./pkg/apis/controller/v1beta1/ -O zz_generated.deepcopy
Compiling controller
CGO_ENABLED=0 GOOS="linux" go build -o _output/bin/mcad-controller ./cmd/kar-controllers/

#build for local testing purposes, by default enable the race conditions detector
multi-cluster-app-dispatcher $ make mcad-controller-local
...
mkdir -p _output/bin
CGO_ENABLED=0 GOARCH=amd64 go build -o _output/bin/kar-controllers ./cmd/kar-controllers/
$
Compiling deepcopy-gen...
Generating deepcopy...
go build -o _output/bin/deepcopy-gen ./cmd/deepcopy-gen/
_output/bin/deepcopy-gen -i ./pkg/apis/controller/v1beta1/ -O zz_generated.deepcopy
Compiling controller
go build -race -o _output/bin/mcad-controller-local ./cmd/kar-controllers/
```

Ensure the executables: `deepcopy-gen`, `mcad-controllers` are created in the target output directory:
```
$ ls ../_output/bin/
deepcopy-gen mcad-controller
$
Ensure the executables: `deepcopy-gen` and `mcad-controllers` are created in the target output directory:

```bash
multi-cluster-app-dispatcher $ ls _output/bin
deepcopy-gen mcad-controller
```

### Build the Multi-Cluster-App-Dispatcher Image

Run the image build script `image.sh`:
If you want to run the end to end tests locally, you will need to have the docker daemon running on your workstation, and build the image using docker. Images can also be build using podman for deployment of the MCAD controller on remote clusters.

```
$ ./image.sh
...
+ make images
Changed to executable directory
Build the docker image
cd ./_output/bin
docker build --no-cache --tag mcad-controller:v1.14 ...
Sending build context to Docker daemon 122.7MB
Step 1/7 : From ubuntu:18.04
---> ea4c82dcd15a
Step 2/7 : ADD mcad-controller /usr/local/bin
---> 674cefbce55a
...
---> 911c7c82b5ee
Step 7/7 : WORKDIR /usr/local/bin
---> Running in f2db4649e7a6
Removing intermediate container f2db4649e7a6
---> 1dbf126976cf
Successfully built 1dbf126976cf
Successfully tagged mcad-controller:v1.14
$
```
From the root directory of the repository:

Note the *image name* and *image tag* from the image build script (`./image.sh`) above. For example the *image name* and *image tag* built after running the example above is `mcad-controller:v1.14`. List the Docker images to ensure the image exists.
```bash
# With docker daemon running
multi-cluster-app-dispatcher % make images

....

# output from a local branch, MacOS build, local file names replaced with XXXXXXXXXX
"---"
"MAKE GLOBAL VARIABLES:"
" "BIN_DIR="_output/bin"
" "GIT_BRANCH="local_e2e_test"
" "RELEASE_VER="v1.29.55"
" "TAG="local_e2e_test-v1.29.55"
"---"
# Check for invalid tag name
t=local_e2e_test-v1.29.55 && [ ${#t} -le 128 ] || { echo "Target name $t has 128 or more chars"; false; }
mkdir -p _output/bin
Compiling deepcopy-gen...
Generating deepcopy...
go build -o _output/bin/deepcopy-gen ./cmd/deepcopy-gen/
_output/bin/deepcopy-gen -i ./pkg/apis/controller/v1beta1/ -O zz_generated.deepcopy
Compiling controller
CGO_ENABLED=0 GOOS="linux" go build -o _output/bin/mcad-controller ./cmd/kar-controllers/
List executable directory
repo id:
branch: local_e2e_test
Build the docker image
ls -l XXXXXXXXXXXX/multi-cluster-app-dispatcher/_output/bin
total 268768
-rwxr-xr-x 1 XXXXX staff 8238498 Apr 4 12:46 deepcopy-gen
-rwxr-xr-x 1 XXXXX staff 57584808 Apr 4 12:47 mcad-controller
docker build --quiet --no-cache --tag mcad-controller:local_e2e_test-v1.29.55 -f XXXXXXXX/multi-cluster-app-dispatcher/deployment/Dockerfile.both XXXXXX/multi-cluster-app-dispatcher/_output/bin
sha256:3b4f314b06674f6b52d6a5d77ad1d3d9cebf8fa94a9f80026b02813689c3289d

#Using podman
make images-podman

....

# output from a local branch, MacOS build, local file names replaced with XXXXXXXXXX
"---"
"MAKE GLOBAL VARIABLES:"
" "BIN_DIR="_output/bin"
" "GIT_BRANCH="local_e2e_test"
" "RELEASE_VER="v1.29.55"
" "TAG="local_e2e_test-v1.29.55"
"---"
# Check for invalid tag name
t=local_e2e_test-v1.29.55 && [ ${#t} -le 128 ] || { echo "Target name $t has 128 or more chars"; false; }
mkdir -p _output/bin
Compiling deepcopy-gen...
Generating deepcopy...
go build -o _output/bin/deepcopy-gen ./cmd/deepcopy-gen/
_output/bin/deepcopy-gen -i ./pkg/apis/controller/v1beta1/ -O zz_generated.deepcopy
Compiling controller
CGO_ENABLED=0 GOOS="linux" go build -o _output/bin/mcad-controller ./cmd/kar-controllers/
List executable directory
repo id:
branch: local_e2e_test
Build the docker image
ls -l XXXXXXXXXX/multi-cluster-app-dispatcher/_output/bin
total 128568
-rwxr-xr-x 1 XXXXXXXX staff 8238498 Apr 4 12:53 deepcopy-gen
-rwxr-xr-x 1 XXXXXXXX staff 57584808 Apr 4 12:53 mcad-controller
podman build --quiet --no-cache --tag mcad-controller:local_e2e_test-v1.29.55 -f XXXXXXXXXX/multi-cluster-app-dispatcher/deployment/Dockerfile.both XXXXXXXXXX/multi-cluster-app-dispatcher/_output/bin
7553c702e5238920f44cba7303d1ff111aca1722e7e3ed4d49afbafa165fc3e3
```
$ docker images mcad-controller
REPOSITORY TAG IMAGE ID CREATED SIZE
mcad-controller v.1.14 1dbf126976cf 11 minutes ago 272MB
$
```

### Push the Multi-Cluster-App-Dispatcher Image to an Image Repository
The following example assumes an available `<repository>/mcad-controller` on [Docker Hub](https://hub.docker.com)
```
$ docker login
$ docker push <respository>/mcad-controller:v1.14

The following example assumes an available `<repository>/mcad-controller` on [Docker Hub](https://hub.docker.com) and using image version `v1.14`

```bash
docker login
docker push <respository>/mcad-controller:v1.14
```

The same can be done with [Quay](quay.io)
```
$ docker login quay.io
$ docker push <quay_respository>/mcad-controller:v1.14

```bash
docker login quay.io
docker push <quay_respository>/mcad-controller:v1.14
```

Refer to [deployment](../deploy/deployment.md) on how to deploy the `multi-cluster-app-dispatcher` as a controller in Kubernetes.

## 3. Running e2e tests locally

When running e2e tests, is recommended you restrict the `docker` daemon [cpu and memory resources](https://docs.docker.com/config/containers/resource_constraints/). The recomended settings are:

* CPU: 2
* Memory: 8 GB

From the root directory of the repository:

```bash
# With docker daemon running
multi-cluster-app-dispatcher % make run-e2e:
```
4 changes: 2 additions & 2 deletions hack/e2e-kind-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# this config file contains all config fields with comments
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
# 1 control plane node and 3 workers
# 1 control plane node and 1 workers
nodes:
# the control plane node config
- role: control-plane
# kubernetes version 1.20.7 from kind v0.11.0
image: kindest/node:v1.20.7@sha256:e645428988191fc824529fd0bb5c94244c12401cf5f5ea3bd875eb0a787f0fe9
# the three workers
# the worker
- role: worker
# kubernetes version 1.20.7 from kind v0.11.0
image: kindest/node:v1.20.7@sha256:e645428988191fc824529fd0bb5c94244c12401cf5f5ea3bd875eb0a787f0fe9
Loading