Skip to content

Commit

Permalink
Add install-tools and local-env rules to Makefiles (redhat-developer#…
Browse files Browse the repository at this point in the history
…1280)

If required tool version is found on the host, then it will be linked
into the ./bin folder. Otherwise, it will be downloaded.

Signed-off-by: Francesco Ilario <[email protected]>

Signed-off-by: Francesco Ilario <[email protected]>
  • Loading branch information
filariow authored and web-flow committed Oct 24, 2022
1 parent 480d9d1 commit 642c05c
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 54 deletions.
52 changes: 46 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,76 @@ put us into an unreleasable state
* End to end, i.e. acceptance tests
* Unit tests:
* Coverage should remain the same or increase


## Configure your local environment

To compile and execute the Service Binding Operator, you must have on your machine the following dependencies:

* Git
* Go
* Python3
* Make
* Docker

Other dependencies are needed, but you can install them locally using the make rule `install-tools`.
This rule will download into the local `./bin` folder all the missing tools needed to work with this repo.
So, to install the dependencies locally and configure your shell to use them, use the following commands:

```
make install-tools
eval $(make local-env)
```

If not present, the following dependencies will be downloaded:

* minikube
* opm
* mockgen
* kubectl-slice
* yq
* kustomize
* controller-gen
* gen-mocks
* operator-sdk
* kubectl
* helm

## Running Acceptance Tests

1. Set KUBECONFIG for both minikube and acceptance tests (it will be generated at minikube's start if it does not exist):
1. Install dependencies

```
make install-tools
eval $(make local-env)
```

2. Set KUBECONFIG for both minikube and acceptance tests (it will be generated at minikube's start if it does not exist):

```
export KUBECONFIG=/tmp/minikubeconfig
```

2. Start minikube:
3. Start minikube:

```
./hack/start-minikube.sh
```

3. Enable olm on minikube:
4. Enable olm on minikube:


```
minikube addons enable olm
```

4. Deploy operator to the minikube cluster
5. Deploy operator to the minikube cluster

```
eval $(minikube docker-env)
make deploy OPERATOR_REPO_REF=$(minikube ip):5000/sbo
```

5. Execute all acceptance tests tagged with `@dev` using `kubectl` CLI:
6. Execute all acceptance tests tagged with `@dev` using `kubectl` CLI:

```
make test-acceptance TEST_ACCEPTANCE_TAGS="@dev" TEST_ACCEPTANCE_START_SBO=remote TEST_ACCEPTANCE_CLI=kubectl
Expand Down
10 changes: 5 additions & 5 deletions make/acceptance.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ OLM_NAMESPACE ?=

# Testing setup
.PHONY: deploy-test-3rd-party-crds
deploy-test-3rd-party-crds:
$(Q)kubectl --namespace $(TEST_NAMESPACE) apply -f ./test/third-party-crds/
deploy-test-3rd-party-crds: kubectl
$(Q)$(KUBECTL) --namespace $(TEST_NAMESPACE) apply -f ./test/third-party-crds/

.PHONY: create-test-namespace
create-test-namespace:
$(Q)kubectl get namespace $(TEST_NAMESPACE) || kubectl create namespace $(TEST_NAMESPACE)
create-test-namespace: kubectl
$(Q)$(KUBECTL) get namespace $(TEST_NAMESPACE) || $(KUBECTL) create namespace $(TEST_NAMESPACE)

.PHONY: test-setup
test-setup: test-cleanup create-test-namespace deploy-test-3rd-party-crds
Expand Down Expand Up @@ -100,4 +100,4 @@ collect-kube-resources:
-$(Q)OUTPUT_PATH=$(TEST_ACCEPTANCE_RESOURCES_DIR) \
OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) \
OLM_NAMESPACE=$(OLM_NAMESPACE) \
$(HACK_DIR)/collect-kube-resources.sh
$(HACK_DIR)/collect-kube-resources.sh
14 changes: 7 additions & 7 deletions make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ manifests: controller-gen

.PHONY: bundle
# Generate bundle manifests and metadata, then validate generated files.
bundle: manifests kustomize yq kubectl-slice push-image
# operator-sdk generate kustomize manifests -q
bundle: manifests kustomize yq kubectl-slice operator-sdk push-image
# $(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_REPO_REF)@$(OPERATOR_IMAGE_SHA_REF)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(YQ) e -i '.metadata.annotations.containerImage="$(OPERATOR_REPO_REF)@$(OPERATOR_IMAGE_SHA_REF)"' bundle/manifests/service-binding-operator.clusterserviceversion.yaml
# this is needed because operator-sdk 1.16 filters out aggregated cluster role and the accompanied binding
# this is needed because $(OPERATOR_SDK) 1.16 filters out aggregated cluster role and the accompanied binding
$(KUSTOMIZE) build config/manifests | $(YQ) e 'select((.kind == "ClusterRole" and .metadata.name == "service-binding-controller-role") or (.kind == "ClusterRoleBinding" and .metadata.name == "service-binding-controller-rolebinding"))' - | $(KUBECTL_SLICE) -o bundle/manifests -t '{{.metadata.name}}_{{.apiVersion | replace "/" "_"}}_{{.kind | lower}}.yaml'
operator-sdk bundle validate ./bundle --select-optional name=operatorhub
$(OPERATOR_SDK) bundle validate ./bundle --select-optional name=operatorhub

.PHONY: registry-login
registry-login:
Expand All @@ -52,9 +52,9 @@ bundle-image: bundle
$(CONTAINER_RUNTIME) build -f bundle.Dockerfile -t $(OPERATOR_BUNDLE_IMAGE_REF) .

.PHONY: push-bundle-image
push-bundle-image: bundle-image registry-login
push-bundle-image: bundle-image registry-login operator-sdk
$(Q)$(CONTAINER_RUNTIME) push $(OPERATOR_BUNDLE_IMAGE_REF)
$(Q)operator-sdk bundle validate --select-optional name=operatorhub -b $(CONTAINER_RUNTIME) $(OPERATOR_BUNDLE_IMAGE_REF)
$(Q)$(OPERATOR_SDK) bundle validate --select-optional name=operatorhub -b $(CONTAINER_RUNTIME) $(OPERATOR_BUNDLE_IMAGE_REF)

.PHONY: index-image
index-image: opm push-bundle-image
Expand Down
Loading

0 comments on commit 642c05c

Please sign in to comment.