Skip to content

Commit

Permalink
MGMT-8356: Deploy assisted-service and its components to kind cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and danmanor committed Jun 18, 2024
1 parent f961a0d commit c345228
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 165 deletions.
112 changes: 62 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ else
UPDATE_IMAGE=update-minimal
endif

ifdef SUBSYSTEM_LOCAL_REGISTRY
UPDATE_LOCAL_SERVICE=_update-private-registry-image
LOCAL_SERVICE_IMAGE=${SUBSYSTEM_LOCAL_REGISTRY}/assisted-service:${ASSISTED_TAG}
IMAGE_PULL_POLICY=--image-pull-policy Always
else
IMAGE_PULL_POLICY=--image-pull-policy IfNotPresent
UPDATE_LOCAL_SERVICE=_update-local-k8s-image
LOCAL_SERVICE_IMAGE=${SERVICE}
endif

CONTAINER_BUILD_PARAMS = --network=host --label git_revision=${GIT_REVISION} ${CONTAINER_BUILD_EXTRA_PARAMS}

MUST_GATHER_IMAGES := $(or ${MUST_GATHER_IMAGES}, $(shell (tr -d '\n\t ' < ${ROOT_DIR}/data/default_must_gather_versions.json)))
Expand Down Expand Up @@ -101,6 +91,9 @@ DISABLE_TLS := $(or ${DISABLE_TLS},false)
ENABLE_ORG_TENANCY := $(or ${ENABLE_ORG_TENANCY},False)
ALLOW_CONVERGED_FLOW := $(or ${ALLOW_CONVERGED_FLOW}, false)
ENABLE_ORG_BASED_FEATURE_GATES := $(or ${ENABLE_ORG_BASED_FEATURE_GATES},False)
KIND_EXPERIMENTAL_PROVIDER=podman
SUBSYSTEM_LOCAL_SERVICE=localhost/assisted-service:latest
SUBSYSTEM_LOCAL_IMAGE_ARCHIVE=build/assisted_service_image.tar

ifeq ($(DISABLE_TLS),true)
DISABLE_TLS_CMD := --disable-tls
Expand Down Expand Up @@ -238,16 +231,18 @@ update-debug-minimal:

update-image: $(UPDATE_IMAGE)

_update-private-registry-image: update-image
$(CONTAINER_COMMAND) tag $(SERVICE) $(LOCAL_SERVICE_IMAGE)
$(CONTAINER_COMMAND) push $(PUSH_FLAGS) $(LOCAL_SERVICE_IMAGE)

_update-local-k8s-image:
# Temporary hack that updates the local k8s(e.g minikube) with the latest image.
# Should be replaced after installing a local registry
./hack/update_local_image.sh

update-local-image: $(UPDATE_LOCAL_SERVICE)
load-image: create-hub-cluster
rm -f $(SUBSYSTEM_LOCAL_IMAGE_ARCHIVE) || true
@if [ -z ${SUBSYSTEM_SERVICE_IMAGE} ]; then \
echo "Building and using local assisted-service image..."; \
$(MAKE) update-image SERVICE=$(SUBSYSTEM_LOCAL_SERVICE); \
else \
echo "Using image from ${SUBSYSTEM_SERVICE_IMAGE}..."; \
$(CONTAINER_COMMAND) pull ${SUBSYSTEM_SERVICE_IMAGE}; \
$(CONTAINER_COMMAND) tag ${SUBSYSTEM_SERVICE_IMAGE} $(SUBSYSTEM_LOCAL_SERVICE); \
fi
$(CONTAINER_COMMAND) save -o $(SUBSYSTEM_LOCAL_IMAGE_ARCHIVE) $(SUBSYSTEM_LOCAL_SERVICE)
./hack/kind/kind.sh load_kind_image $(SUBSYSTEM_LOCAL_IMAGE_ARCHIVE) assisted-installer-kind

build-image: update-minimal

Expand Down Expand Up @@ -380,30 +375,35 @@ create-ocp-manifests:
export HW_REQUIREMENTS="$(subst ",\", $(shell cat $(ROOT_DIR)/data/default_hw_requirements.json | tr -d "\n\t "))" && \
$(MAKE) deploy-postgres deploy-ocm-secret deploy-s3-secret deploy-service deploy-ui

ci-deploy-for-subsystem: _verify_cluster generate-keys
export TEST_FLAGS=--subsystem-test && export AUTH_TYPE="rhsso" && export DUMMY_IGNITION=${DUMMY_IGNITION} && \
export IPV6_SUPPORT="True" && export ENABLE_ORG_TENANCY="True" && export ENABLE_ORG_BASED_FEATURE_GATES="True" && \
export RELEASE_SOURCES='$(or ${RELEASE_SOURCES},${DEFAULT_RELEASE_SOURCES})' && \
$(MAKE) deploy-wiremock deploy-all
ci-deploy-for-subsystem: deploy-test

patch-service: _verify_cluster update-local-image
patch-service: _verify_cluster
$(MAKE) load-image
ifdef DEBUG_SERVICE
$(KUBECTL) patch deployment assisted-service --type json -p='[{"op": "add", "path": "/spec/template/spec/containers/0/ports/-", "value": {"containerPort": 40000}}]'
$(KUBECTL) patch service assisted-service --type json -p='[{"op": "add", "path": "/spec/ports/-", value: {"name": "assisted-service-debug", "port": 40000, "protocol": "TCP", "targetPort": 40000}}]'
$(KUBECTL) patch deployment assisted-service --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
endif
$(call restart_service_pods)

deploy-test: _verify_cluster generate-keys update-local-image
deploy-test: _verify_cluster generate-keys
-$(KUBECTL) delete deployments.apps assisted-service &> /dev/null
export SERVICE=${LOCAL_SERVICE_IMAGE} && export TEST_FLAGS=--subsystem-test && \
export TEST_FLAGS=--subsystem-test && \
export AUTH_TYPE="rhsso" && export DUMMY_IGNITION="True" && \
export IPV6_SUPPORT="True" && ENABLE_ORG_TENANCY="True" && ENABLE_ORG_BASED_FEATURE_GATES="True" && \
export RELEASE_SOURCES='$(or ${RELEASE_SOURCES},${DEFAULT_RELEASE_SOURCES})' && \
$(MAKE) deploy-wiremock deploy-all

# An alias for the deploy-test target
deploy-service-for-subsystem-test: deploy-test
# execute on the host, without skipper
deploy-service-for-subsystem-test: create-hub-cluster load-image
skipper $(MAKE) deploy-test TARGET=kind SERVICE=$(SUBSYSTEM_LOCAL_SERVICE) IP=$(shell ip route get 1 | sed 's/^.*src \([^ ]*\).*$$/\1/;q')
@if [ $(ENABLE_KUBE_API) == "true" ]; then \
echo "Deploying assisted-service for subsystem tests in kube-api mode..."; \
TARGET=kind skipper make enable-kube-api-for-subsystem; \
fi

destroy-kind-cluster:
./hack/kind/kind.sh delete

# $SERVICE is built with docker. If we want the latest version of $SERVICE
# we need to pull it from the docker daemon before deploy-onprem.
Expand All @@ -417,34 +417,43 @@ deploy-onprem:

deploy-on-openshift-ci:
export PERSISTENT_STORAGE="False" && export TARGET='oc' && export GENERATE_CRD='false' && unset GOFLAGS && \
$(MAKE) ci-deploy-for-subsystem
$(MAKE) deploy-test
oc get pods

########
# Test #
########

subsystem-run: test subsystem-clean

subsystem-run-kube-api: enable-kube-api-for-subsystem test-kube-api subsystem-clean

test:
$(MAKE) _run_subsystem_test AUTH_TYPE=rhsso ENABLE_ORG_TENANCY=true ENABLE_ORG_BASED_FEATURE_GATES=true

test-kube-api:
$(MAKE) _run_subsystem_test AUTH_TYPE=local ENABLE_KUBE_API=true FOCUS="$(or ${FOCUS},kube-api)"
$(MAKE) _run_subsystem_test AUTH_TYPE=local FOCUS="$(or ${FOCUS},kube-api)"

# An alias for the test target
subsystem-test: test
# execute on the host, without skipper
subsystem-test:
TARGET=kind skipper $(MAKE) test

# An alias for the test-kube-api target
subsystem-test-kube-api: test-kube-api
# execute on the host, without skipper
subsystem-test-kube-api:
TARGET=kind skipper $(MAKE) test-kube-api

_run_subsystem_test:
INVENTORY=$(shell $(call get_service_host_port,assisted-service) | sed 's/http:\/\///g') \
DB_HOST=$(shell $(call get_service_host_port,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 1) \
DB_PORT=$(shell $(call get_service_host_port,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 2) \
OCM_HOST=$(shell $(call get_service_host_port,wiremock) | sed 's/http:\/\///g') \
@if [ $(TARGET) == "kind" ]; then \
assisted_service_url="localhost:8090"; \
db_host="localhost"; \
db_port="5432"; \
ocm_host="localhost:8070"; \
else \
assisted_service_url="$(shell $(call get_service_host_port,assisted-service) | sed 's/http:\/\///g')"; \
db_host="$(shell $(call get_service_host_port,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 1)"; \
db_port="$(shell $(call get_service_host_port,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 2)"; \
ocm_host="$(shell $(call get_service_host_port,wiremock) | sed 's/http:\/\///g')"; \
fi; \
INVENTORY=$$assisted_service_url \
DB_HOST=$$db_host \
DB_PORT=$$db_port \
OCM_HOST=$$ocm_host \
TEST_TOKEN="$(shell cat $(BUILD_FOLDER)/auth-tokenString)" \
TEST_TOKEN_2="$(shell cat $(BUILD_FOLDER)/auth-tokenString2)" \
TEST_TOKEN_ADMIN="$(shell cat $(BUILD_FOLDER)/auth-tokenAdminString)" \
Expand All @@ -461,9 +470,6 @@ enable-kube-api-for-subsystem: $(BUILD_FOLDER)

deploy-wiremock: deploy-namespace
python3 ./tools/deploy_wiremock.py --target $(TARGET) --namespace "$(NAMESPACE)"
timeout 5m ./hack/wait_for_wiremock.sh
OCM_URL=$$(kubectl get service wiremock -n $(NAMESPACE) -ojson | jq --from-file ./hack/k8s_service_host_port.jq --raw-output); \
export OCM_URL && go run ./hack/add_wiremock_stubs.go

deploy-olm: deploy-namespace
python3 ./tools/deploy_olm.py --target $(TARGET)
Expand Down Expand Up @@ -535,6 +541,15 @@ test-on-openshift-ci:
export TARGET='oc' && unset GOFLAGS && \
$(MAKE) test FOCUS="[minimal-set]"

install-kind-if-needed:
./hack/kind/kind.sh install

delete-kind-cluster:
kind delete cluster

create-hub-cluster:
./hack/kind/kind.sh create

#########
# Clean #
#########
Expand All @@ -545,9 +560,6 @@ clean:
-rm -rf $(BUILD_FOLDER) $(REPORTS)
-rm -rf bundle*

subsystem-clean:
-$(KUBECTL) get pod -o name | grep createimage | xargs -r $(KUBECTL) delete --force --grace-period=0 1> /dev/null || true

clear-deployment:
-python3 ./tools/clear_deployment.py --delete-namespace $(APPLY_NAMESPACE) --delete-pvc $(DELETE_PVC) --namespace "$(NAMESPACE)" --target "$(TARGET)" || true

Expand Down
1 change: 1 addition & 0 deletions deploy/assisted-image-service-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
port: 8080
protocol: TCP
targetPort: 8080
nodePort: 30001
selector:
app: assisted-image-service
type: LoadBalancer
1 change: 1 addition & 0 deletions deploy/assisted-service-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
port: 8090
protocol: TCP
targetPort: 8090
nodePort: 30000
selector:
app: assisted-service
type: LoadBalancer
Expand Down
2 changes: 2 additions & 0 deletions deploy/postgres/postgres-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ spec:
type: LoadBalancer
ports:
- port: 5432
targetPort: 5432
nodePort: 30003
selector:
app: postgres
status:
Expand Down
6 changes: 5 additions & 1 deletion deploy/wiremock/wiremock-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ spec:
spec:
type: LoadBalancer
ports:
- port: 8080
- name: assisted-image-service
port: 8080
protocol: TCP
targetPort: 8080
nodePort: 30002
selector:
app: wiremock
status:
Expand Down
108 changes: 39 additions & 69 deletions docs/dev/running-test.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,73 @@
# How to run Assisted-service subsystem tests
# Running Assisted-service Subsystem Tests on Kubernetes

There are two "flavors" of subsystem tests:
## Overview

* subsystem tests for the service deployed in REST-API mode
* subsystem tests for the service deployed in kube-api mode
This document details the steps required to run subsystem tests for the Assisted-service deployed in two modes:
- REST-API mode
- Kube-API mode

Assisted-service subsystem tests require that you first deploy the
assisted-service on a k8s cluster (e.g. minikube).
## Deployment for Subsystem Tests

This document will explain how you can easily deploy the service in preperation
for subsystem tests, and also how to run the tests themselves.
Assisted-service components will be deployed in a Kind cluster using the Podman provider.
`podman` and `kind` and `skipper` executables must be available in the $PATH.
you can install kind by running:

The subsystem tests themselves are located in the
[subsystem](https://github.com/openshift/assisted-service/tree/master/subsystem)
directory, but they are launched via `make` targets in the Makefile at the root
of this repository.

## Service deployment

This section will show you how you can deploy the assisted installer to
a minikube cluster in preperation for subsystem tests.
```bash
make install-kind-if-needed
```
which will install `kind` latest version if it is not present.

### minikube
## Deploying Components

First we must prepare the minikube cluster -
To deploy in REST-API mode, run:

```bash
# Optionally delete the existing minikube cluster:
# minikube delete
make deploy-service-for-subsystem-test
```

# Clean remains of any networks created by minikube
podman network rm minikube || true
To deploy kube-api mode, run:

# Start minikube
minikube start --insecure-registry=$(hostname --ip):5000 --driver=podman --addons dashboard --force
```bash
ENABLE_KUBE_API=true make deploy-service-for-subsystem-test
```

# enable the registry addon using quay.io images (to overcome docker-hub's rate-limiter)
minikube addons enable registry --images="Registry=quay.io/libpod/registry:2.8"
Optionally the following environment variables can be exported:

# Make the registry addon accessible locally:
nohup kubectl port-forward svc/registry --address 0.0.0.0 5000:80 -n kube-system &>/dev/null &
export LOCAL_SUBSYSTEM_REGISTRY=$(hostname --ip):5000
* `SUBSYSTEM_SERVICE_IMAGE` - Specify external image to use for assisted-service.
* `FOCUS="install_cluster"` - An optional flag used for [focused specs](https://onsi.github.io/ginkgo/#focused-specs) with regular expression.
* `SKIP="install_cluster"` - An optional flag to skip scopes with regular expressions.
* `VERBOSE=true` - An optional flag to print verbosed data.

echo "Waiting for registry to become ready..."
while ! curl --location $LOCAL_SUBSYSTEM_REGISTRY; do
sleep 10
echo "kubectl registry service tunnel at port 5000 is not available yet, retrying..."
echo "If this persists, try running the kubectl port-forward command above without"
echo "nohup, /dev/null redirection and the background job & operator and see if there"
echo "are any errors"
done
## Running the tests

# Make a tunnel to make minikube services reachable (the command will ask for root password):
nohup minikube tunnel &>/dev/null &
```
When the components are already deployed, you can run the tests as many times as you like:

Now that the cluster is prepared, we can deploy the service -

To deploy the service in REST-API mode, run:
To test in REST-API mode, run:

```bash
skipper make deploy-service-for-subsystem-test
make subsystem-test
```

To deploy the service in kube-api mode, run:
To test kube-api mode, run:

```bash
ENABLE_KUBE_API=true skipper make deploy-service-for-subsystem-test
skipper make enable-kube-api-for-subsystem
make subsystem-test-kube-api
```

## Running the subsystem tests
## Quick Update and Test

To run the REST-API subsystem tests, run:
To quickly update the service and run tests after making code changes, use:

```bash
skipper make subsystem-test
make patch-service
```

To run the kube-api subsystem tests, run:
This command builds a new service image, pushes it to the container registry, and triggers a rollout of the updated service Deployment.

```bash
skipper make subsystem-test-kube-api
```
## Cleanup

Optionally the following environment variables can be exported:

* `FOCUS="install_cluster"` - An optional flag used for [focused specs](https://onsi.github.io/ginkgo/#focused-specs) with regular expression.
* `SKIP="install_cluster"` - An optional flag to skip scopes with regular expressions.
* `VERBOSE=true` - An optional flag to print verbosed data.

## Update service for the subsystem tests

If you are making changes to the service's code and don't want to go through
the slow steps above once again, you can simply run this command instead:
to Destroy the cluster, run:

```bash
skipper make patch-service
destroy-kind-cluster
```

It will build and push a new image of the service to the container registry,
then trigger a rollout of the service Deployment.
Loading

0 comments on commit c345228

Please sign in to comment.