Skip to content

Commit

Permalink
e2e refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeey committed Aug 7, 2020
1 parent e224c15 commit 4a90916
Show file tree
Hide file tree
Showing 40 changed files with 1,221 additions and 1,257 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.project
output
_output
apiserver.local.config
.api_violation.report
generate_exes
Expand All @@ -9,4 +10,6 @@ generate_files
acm-agent
acm-controller
acm-proxyserver
acm-webhook
acm-webhook
registration-operator
e2e.test
110 changes: 69 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,108 @@ include $(addprefix ./vendor/github.com/openshift/build-machinery-go/make/, \
lib/tmp.mk \
)

# Image URL to use all building/pushing image targets;
# Use your own docker registry and image name for dev/test by overridding the IMG and REGISTRY environment variable.
IMG ?= multicloud-manager
REGISTRY ?= quay.io/open-cluster-management
# Tools for deploy
KUBECONFIG ?= ./.kubeconfig
KUBECTL?=kubectl
KUSTOMIZE?=$(PERMANENT_TMP_GOPATH)/bin/kustomize
KUSTOMIZE_VERSION?=v3.5.4
KUSTOMIZE_ARCHIVE_NAME?=kustomize_$(KUSTOMIZE_VERSION)_$(GOHOSTOS)_$(GOHOSTARCH).tar.gz
kustomize_dir:=$(dir $(KUSTOMIZE))

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"
# Image URL to use all building/pushing image targets;
IMAGE ?= multicloud-manager
IMAGE_REGISTRY ?= quay.io/open-cluster-management
IMAGE_TAG ?= latest
IMAGE_NAME ?= $(IMAGE_REGISTRY)/$(IMAGE):$(IMAGE_TAG)

# Keep an existing GOPATH, make a private one if it is undefined
# GOPATH_DEFAULT := $(PWD)/.go
# export GOPATH ?= $(GOPATH_DEFAULT)
TESTARGS_DEFAULT := "-v"
export TESTARGS ?= $(TESTARGS_DEFAULT)
# KUBEBUILDER for unit test
export KUBEBUILDER_ASSETS ?=$(shell pwd)/$(PERMANENT_TMP_GOPATH)/kubebuilder/bin

TYPES_FILES = $(shell find pkg/apis -name types.go)
K8S_VERSION ?=1.16.4
KB_TOOLS_ARCHIVE_NAME :=kubebuilder-tools-$(K8S_VERSION)-$(GOHOSTOS)-$(GOHOSTARCH).tar.gz
KB_TOOLS_ARCHIVE_PATH := $(PERMANENT_TMP_GOPATH)/$(KB_TOOLS_ARCHIVE_NAME)

# Add packages to do unit test
GO_TEST_PACKAGES :=./pkg/...

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"

# This will call a macro called "build-image" which will generate image specific targets based on the parameters:
# $0 - macro name
# $1 - target suffix
# $2 - Dockerfile path
# $3 - context directory for image build
# It will generate target "image-$(1)" for building the image and binding it as a prerequisite to target "images".
$(call build-image,$(IMG),$(REGISTRY)/$(IMG),./Dockerfile,.)


.PHONY: fmt lint test coverage build images build-push-images
$(call build-image,$(IMAGE),$(IMAGE_REGISTRY)/$(IMAGE),./Dockerfile,.)

# GITHUB_USER containing '@' char must be escaped with '%40'
GITHUB_USER := $(shell echo $(GITHUB_USER) | sed 's/@/%40/g')
GITHUB_TOKEN ?=
test-unit: ensure-kubebuilder

include test/e2e/Makefile.e2e.mk
deploy-hub:
deploy/managedcluster/hub/install.sh

############################################################
# test section
############################################################
deploy-klusterlet:
deploy/managedcluster/klusterlet/install.sh

test:
@go test ${TESTARGS} $(shell go list ./... | grep -v /test/)
deploy-acm-foundation-hub: ensure-kustomize
cp deploy/prod/hub/kustomization.yaml deploy/prod/hub/kustomization.yaml.tmp
cd deploy/prod/hub && ../../../$(KUSTOMIZE) edit set image ko://github.com/open-cluster-management/multicloud-operators-foundation/cmd/acm-controller=$(IMAGE_NAME)
cd deploy/prod/hub && ../../../$(KUSTOMIZE) edit set image ko://github.com/open-cluster-management/multicloud-operators-foundation/cmd/acm-proxyserver=$(IMAGE_NAME)
$(KUSTOMIZE) build deploy/prod/hub | $(KUBECTL) apply -f -
mv deploy/prod/hub/kustomization.yaml.tmp deploy/prod/hub/kustomization.yaml

############################################################
# e2e test section
############################################################
deploy-acm-foundation-agent: ensure-kustomize
cp deploy/prod/klusterlet/kustomization.yaml deploy/prod/klusterlet/kustomization.yaml.tmp
cd deploy/prod/klusterlet && ../../../$(KUSTOMIZE) edit set image ko://github.com/open-cluster-management/multicloud-operators-foundation/cmd/acm-agent=$(IMAGE_NAME)
$(KUSTOMIZE) build deploy/prod/klusterlet | $(KUBECTL) apply -f -
mv deploy/prod/klusterlet/kustomization.yaml.tmp deploy/prod/klusterlet/kustomization.yaml

e2e-test: run-all-e2e-test
build-e2e:
go test -c ./test/e2e

############################################################
# coverage section
############################################################

############################################################
# This section contains the code generation stuff
############################################################
test-e2e: build-e2e deploy-hub deploy-klusterlet deploy-acm-foundation-hub deploy-acm-foundation-agent
./e2e.test -test.v -ginkgo.v

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
manifests: ensure-controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./pkg/apis/action/v1beta1" output:crd:artifacts:config=deploy/dev/hub/resources/crds
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./pkg/apis/view/v1beta1" output:crd:artifacts:config=deploy/dev/hub/resources/crds
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./pkg/apis/cluster/v1beta1" output:crd:artifacts:config=deploy/dev/hub/resources/crds
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./pkg/apis/inventory/v1alpha1" output:crd:artifacts:config=deploy/dev/hub/resources/crds

# Generate code
generate: controller-gen
generate: ensure-controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/custom-boilerplate.go.txt" paths="./pkg/apis/action/v1beta1"
$(CONTROLLER_GEN) object:headerFile="hack/custom-boilerplate.go.txt" paths="./pkg/apis/view/v1beta1"
$(CONTROLLER_GEN) object:headerFile="hack/custom-boilerplate.go.txt" paths="./pkg/apis/inventory/v1alpha1"
$(CONTROLLER_GEN) object:headerFile="hack/custom-boilerplate.go.txt" paths="./pkg/apis/cluster/v1beta1"
$(CONTROLLER_GEN) object:headerFile="hack/custom-boilerplate.go.txt" paths="./pkg/apis/conditions"

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
# Ensure kubebuilder
ensure-kubebuilder:
ifeq "" "$(wildcard $(KUBEBUILDER_ASSETS))"
$(info Downloading kube-apiserver into '$(KUBEBUILDER_ASSETS)')
mkdir -p '$(KUBEBUILDER_ASSETS)'
curl -s -f -L https://storage.googleapis.com/kubebuilder-tools/$(KB_TOOLS_ARCHIVE_NAME) -o '$(KB_TOOLS_ARCHIVE_PATH)'
tar -C '$(KUBEBUILDER_ASSETS)' --strip-components=2 -zvxf '$(KB_TOOLS_ARCHIVE_PATH)'
else
$(info Using existing kube-apiserver from "$(KUBEBUILDER_ASSETS)")
endif

# Ensure kustomize
ensure-kustomize:
ifeq "" "$(wildcard $(KUSTOMIZE))"
$(info Installing kustomize into '$(KUSTOMIZE)')
mkdir -p '$(kustomize_dir)'
curl -s -f -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$(KUSTOMIZE_VERSION)/$(KUSTOMIZE_ARCHIVE_NAME) -o '$(kustomize_dir)$(KUSTOMIZE_ARCHIVE_NAME)'
tar -C '$(kustomize_dir)' -zvxf '$(kustomize_dir)$(KUSTOMIZE_ARCHIVE_NAME)'
chmod +x '$(KUSTOMIZE)';
else
$(info Using existing kustomize from "$(KUSTOMIZE)")
endif

# Ensure controller-gen
ensure-controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
Expand Down
38 changes: 5 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Run the following after cloning/pulling/making a change.
make build
```

make build will build all the binaries in output directory.
make build will build all the binaries in current directory.

### Prerequisites

Expand All @@ -44,7 +44,7 @@ Need to install ManagedCluster before deploy ACM Foundation.
1. Install Cluster Mananger on Hub cluster.

```sh
bash deploy/managedcluster/hub/install.sh
make deploy-hub
```

2. Install Klusterlet On Managed cluster.
Expand All @@ -53,7 +53,7 @@ Need to install ManagedCluster before deploy ACM Foundation.
2. Install Klusterlet.

```sh
bash deploy/managedcluster/klusterlet/install.sh
make deploy-klusterlet
```

3. Approve CSR on Hub cluster.
Expand All @@ -73,48 +73,20 @@ Need to install ManagedCluster before deploy ACM Foundation.

### Deploy ACM Foundation from quay.io

You can use `kustomize` to deploy ACM Foundation with the following step.

Install `kustomize`, you can use

```sh
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash mv kustomize /usr/local/bin/
```

More info please see: [kustomize](https://github.com/kubernetes-sigs/kustomize/blob/master/docs/INSTALL.md)

1. Install on hub cluster

Config image repo and image pull secret in `deploy/prod/hub/kustomization.yaml`

- Change image repo and image tag in `images` section
- Change `<AUTH INFO>` with your image repo login info in `secretGenerator` section. It looks like:

```json
{"auths":{"https://quay.io/open-cluster-management/multicloud-manager":{"username":"<USER NAME>","password":"<TOKEN>/","auth":"<BASE64 ENACODE <USER:TOKEN>>"}}}
```

Deploy hub components

```sh
kustomize build deploy/prod/hub | kubectl apply -f -
make deploy-acm-foundation-hub
```

2. Install on managed cluster

Config image repo and image pull secret info in `deploy/prod/klusterlet/kustomization.yaml`

- Change image repo and image tag in `images` section
- Change `<AUTH INFO>` with your image repo login info in `secretGenerator` section. It looks like:

```json
{"auths":{"https://quay.io/open-cluster-management/multicloud-manager":{"username":"<USER NAME>","password":"<TOKEN>/","auth":"<BASE64 ENACODE <USER:TOKEN>>"}}}
```

Deploy klusterlet components

```sh
kustomize build deploy/prod/klusterlet | kubectl apply -f -
make deploy-acm-foundation-agent
```

### Deploy for development environment
Expand Down
13 changes: 0 additions & 13 deletions build/bin/user_setup

This file was deleted.

136 changes: 0 additions & 136 deletions build/install-managedcluster.sh

This file was deleted.

Loading

0 comments on commit 4a90916

Please sign in to comment.