Skip to content
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

Run framework tests on OCM PRs #216

Merged
merged 2 commits into from
Mar 21, 2024
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: 14 additions & 0 deletions .github/workflows/framework-kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Framework

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
pull_request:
branches:
- main

jobs:
fw-kind-tests:
name: KinD
uses: stolostron/governance-policy-framework/.github/workflows/kind.yml@main
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ GOOS = $(shell go env GOOS)
TESTARGS_DEFAULT := -v
TESTARGS ?= $(TESTARGS_DEFAULT)
CONTROLLER_NAME = $(shell cat COMPONENT_NAME 2> /dev/null)
CONTROLLER_NAMESPACE ?= open-cluster-management-agent-addon
# Handle KinD configuration
MANAGED_CLUSTER_SUFFIX ?=
MANAGED_CLUSTER_NAME ?= managed$(MANAGED_CLUSTER_SUFFIX)
WATCH_NAMESPACE ?= $(MANAGED_CLUSTER_NAME)
KIND_NAME ?= test-$(MANAGED_CLUSTER_NAME)
KIND_CLUSTER_NAME ?= kind-$(KIND_NAME)
KIND_NAMESPACE ?= $(CONTROLLER_NAMESPACE)
KIND_NAMESPACE ?= open-cluster-management-agent-addon
# Test coverage threshold
export COVERAGE_MIN ?= 75
COVERAGE_E2E_OUT ?= coverage_e2e.out
Expand Down Expand Up @@ -101,7 +100,7 @@ deploy: generate-operator-yaml create-ns

.PHONY: create-ns
create-ns:
-@kubectl create namespace $(CONTROLLER_NAMESPACE)
-@kubectl create namespace $(KIND_NAMESPACE)
-@kubectl create namespace $(WATCH_NAMESPACE)

# Run against the current locally configured Kubernetes cluster
Expand Down Expand Up @@ -162,15 +161,31 @@ kind-deploy-controller: generate-operator-yaml install-resources deploy
.PHONY: deploy-controller
deploy-controller: kind-deploy-controller

HOSTED ?= none

.PHONY: kind-deploy-controller-dev
kind-deploy-controller-dev: kind-deploy-controller build-images
kind-deploy-controller-dev:
if [ "$(HOSTED)" = "hosted" ]; then\
$(MAKE) kind-deploy-controller-dev-addon ;\
else\
$(MAKE) kind-deploy-controller-dev-normal ;\
fi

.PHONY: kind-deploy-controller-dev-normal
kind-deploy-controller-dev-normal: kind-deploy-controller
@echo Pushing image to KinD cluster
kind load docker-image $(REGISTRY)/$(IMG):$(TAG) --name $(KIND_NAME)
@echo "Patch deployment image"
kubectl patch deployment $(IMG) -n $(KIND_NAMESPACE) -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"$(IMG)\",\"imagePullPolicy\":\"Never\"}]}}}}"
kubectl patch deployment $(IMG) -n $(KIND_NAMESPACE) -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"$(IMG)\",\"image\":\"$(REGISTRY)/$(IMG):$(TAG)\"}]}}}}"
kubectl rollout status -n $(KIND_NAMESPACE) deployment $(IMG) --timeout=180s

.PHONY: kind-deploy-controller-dev-addon
kind-deploy-controller-dev-addon:
kind load docker-image $(REGISTRY)/$(IMG):$(TAG) --name $(KIND_NAME)
kubectl annotate -n $(subst -hosted,,$(KIND_NAMESPACE)) --overwrite managedclusteraddon config-policy-controller\
addon.open-cluster-management.io/values='{"global":{"imagePullPolicy": "Never", "imageOverrides":{"config_policy_controller": "$(REGISTRY)/$(IMG):$(TAG)"}}}'

# Specify KIND_VERSION to indicate the version tag of the KinD image
.PHONY: kind-create-cluster
kind-create-cluster:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ to learn how to get involved.
```
- Deploy controller to a cluster

The controller is deployed to a namespace defined in `CONTROLLER_NAMESPACE` and monitors the namepace defined in `WATCH_NAMESPACE` for `ConfigurationPolicy` resources.
The controller is deployed to a namespace defined in `KIND_NAMESPACE` and monitors the namepace defined in `WATCH_NAMESPACE` for `ConfigurationPolicy` resources.

1. Deploy the controller and related resources
```bash
Expand All @@ -143,7 +143,7 @@ to learn how to get involved.

The deployment namespaces are configurable with:
```bash
export CONTROLLER_NAMESPACE='' # (defaults to 'open-cluster-management-agent-addon')
export KIND_NAMESPACE='' # (defaults to 'open-cluster-management-agent-addon')
export WATCH_NAMESPACE='' # (defaults to 'managed')
```
**NOTE:** Please be aware of the community's [deployment images](https://github.com/open-cluster-management-io/community#deployment-images) special note.
Expand Down