Skip to content

Commit

Permalink
Makefile targets to deploy/undeploy forklift
Browse files Browse the repository at this point in the history
Add targets to deploy/undeploy forklift to different
environments. Currently supported:

* OpenShift/OKD
* CRC
* Minikube
* Kind

Targets to install CRC, Minikube and Kind are also provided

Signed-off-by: Miguel Martín <mmartinv@redhat.com>
  • Loading branch information
mmartinv committed Jul 11, 2023
1 parent f6305c4 commit 360a02a
Show file tree
Hide file tree
Showing 23 changed files with 1,199 additions and 7 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build --action_env=VERSION=2.5.0
build --action_env=NAMESPACE=konveyor-forklift
build --action_env=CHANNELS=development
build --action_env=DEFAULT_CHANNEL=development
build --action_env=OPM_OPTS

## Images which should be installed
build --action_env=CONTROLLER_IMAGE=quay.io/kubev2v/forklift-controller:latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ tools/tilt/tilt-settings.json
# bazel build artifacts
bazel-*
.bazeldnf

# deploy env
hack/deploy/**/deploy.env
179 changes: 172 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,41 @@ GOPATH ?= `go env GOPATH`
GOBIN ?= $(GOPATH)/bin
GO111MODULE = auto

CONTAINER_CMD ?= $(shell command -v podman)

CONTAINER_RUNTIME ?=

ifeq ($(CONTAINER_RUNTIME),)
CONTAINER_CMD ?= $(shell type -P podman)
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD := $(shell command -v docker)
CONTAINER_CMD := $(shell type -P docker)
endif
CONTAINER_RUNTIME=$(shell basename $(CONTAINER_CMD))
else
CONTAINER_CMD := $(shell type -P $(CONTAINER_RUNTIME))
endif

REGISTRY ?= quay.io
# TODO remove REGISTRY_ORG check once the changes are merged in forkliftci
ifneq (,$(REGISTRY_ORG))
ifeq (,$(REGISTRY_ORG))
REGISTRY_ORG = $(REGISTRY_ORG)
endif
endif
REGISTRY_ORG ?= kubev2v
REGISTRY_TAG ?= devel

VERSION ?= 2.5.0
NAMESPACE ?= konveyor-forklift
OPERATOR_NAME ?= forklift-operator
CHANNELS ?= development
DEFAULT_CHANNEL ?= development
CATALOG_NAMESPACE ?= konveyor-forklift
CATALOG_NAME ?= forklift-catalog
CATALOG_DISPLAY_NAME ?= Konveyor Forklift
CATALOG_PUBLISHER ?= Community

# Use OPM_OPTS="--use-http" when using a non HTTPS registry
# Use OPM_OPTS="--skip-tls-verify" when using an HTTPS registry with self-signed certificate
OPM_OPTS ?=

# By default use the controller gen installed by the
Expand Down Expand Up @@ -109,10 +129,6 @@ run: generate fmt vet
install: manifests kubectl
$(KUBECTL) apply -k operator/config/crds

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kubectl
$(KUBECTL) apply -k operator/config/default

# Generate manifests e.g. CRD, Webhooks
manifests: controller-gen
$(CONTROLLER_GEN) crd rbac:roleName=manager-role webhook paths="./pkg/apis/..." output:dir=operator/config/crd/bases
Expand Down Expand Up @@ -235,7 +251,7 @@ build-operator-index-image: check_container_runtmime
--action_env VERSION=$(VERSION) \
--action_env CHANNELS=$(CHANNELS) \
--action_env DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) \
--action_env OPT_OPTS=$(OPM_OPTS) \
--action_env OPM_OPTS=$(OPM_OPTS) \
--action_env REGISTRY=$(REGISTRY) \
--action_env REGISTRY_TAG=$(REGISTRY_TAG) \
--action_env REGISTRY_ORG=$(REGISTRY_ORG)
Expand Down Expand Up @@ -312,3 +328,152 @@ $(DEFAULT_CONTROLLER_GEN):
kubectl: $(KUBECTL)
$(DEFAULT_KUBECTL):
curl -L https://dl.k8s.io/release/v1.25.10/bin/linux/amd64/kubectl -o $(GOBIN)/kubectl && chmod +x $(GOBIN)/kubectl

# The directory where the 'crc' binary will be installed (this path
# will be added to the PATH variable). (default: ${HOME}/.local/bin)
CRC_BIN_DIR ?=
# Number of CPUS for CRC. By default all of the available CPUs will
# be used
CRC_CPUS ?= 8
# Memory for CRC in MB. (default: 16384)
CRC_MEM ?= 16384
# Disk size in GB. (default: 100)
CRC_DISK ?= 100
# Select openshift/okd installation type (default: okd)
CRC_PRESET ?= okd
# Pull secret file. If not provided it will be requested at
# installation time by the script
CRC_PULL_SECRET_FILE ?=
# Bundle to deploy. If not specified the default bundle will be
# installed. OKD default bundle doesn't work for now because of
# expired certificates so the installation script will temporarily
# overwrite it with:
# docker://quay.io/crcont/okd-bundle:4.13.0-0.okd-2023-06-04-080300
CRC_BUNDLE ?=
# Use the integrated CRC registry instead of local one. (default: '')
# Non empty variable is considered as true.
CRC_USE_INTEGRATED_REGISTRY ?=

install-crc:
ROOTLESS=$(ROOTLESS) \
CRC_BIN_DIR=$(CRC_BIN_DIR) \
CRC_CPUS=$(CRC_CPUS) \
CRC_MEM=$(CRC_MEM) \
CRC_DISK=$(CRC_DISK) \
CRC_PRESET=$(CRC_PRESET) \
CRC_PULL_SECRET_FILE=$(CRC_PULL_SECRET_FILE) \
CRC_BUNDLE=$(CRC_BUNDLE) \
CRC_USE_INTEGRATED_REGISTRY=$(CRC_USE_INTEGRATED_REGISTRY) \
./hack/installation/crc.sh;
eval `crc oc-env`; \
oc new-project "${REGISTRY_ORG}"

uninstall-crc:
crc delete -f

# Driver: kvm2, docker or podman.
MINIKUBE_DRIVER ?= $(CONTAINER_RUNTIME)
MINIKUBE_CPUS ?= max
MINIKUBE_MEMORY ?= 16384
MINIKUBE_ADDONS ?= olm,kubevirt
MINIKUBE_USE_INTEGRATED_REGISTRY ?=

install-minikube:
ROOTLESS=$(ROOTLESS) \
MINIKUBE_DRIVER=$(MINIKUBE_DRIVER) \
MINIKUBE_CPUS=$(MINIKUBE_CPUS) \
MINIKUBE_MEMORY=$(MINIKUBE_MEMORY) \
MINIKUBE_ADDONS=$(MINIKUBE_ADDONS) \
MINIKUBE_USE_INTEGRATED_REGISTRY=$(MINIKUBE_USE_INTEGRATED_REGISTRY) \
./hack/installation/minikube.sh

uninstall-minikube: uninstall-local-registry
minikube delete

ROOTLESS ?= true
# Kind version to install (default: v0.15.0)
KIND_VERSION ?= v0.15.0
# Kind operator Livecycle Manager version (default: v.0.25.0)
OLM_VERSION ?= v0.25.0
# Kind cert manager operator version (default: v1.12.2)
CERT_MANAGER_VERSION ?= v1.12.2

install-kind: install-local-registry
ROOTLESS=$(ROOTLESS) \
KIND_VERSION=$(KIND_VERSION) \
OLM_VERSION=$(OLM_VERSION) \
CERT_MANAGER_VERSION=$(CERT_MANAGER_VERSION) \
./hack/installation/kind.sh; \
[ $(CONTAINER_RUNTIME) != "podman" ] || export KIND_EXPERIMENTAL_PROVIDER="podman"; kind export kubeconfig --name forklift

uninstall-kind: uninstall-local-registry
[ $(CONTAINER_RUNTIME) != "podman" ] || export KIND_EXPERIMENTAL_PROVIDER="podman"; kind delete clusters forklift

define DEPLOYMENT_VARS
OPERATOR_NAMESPACE=$(NAMESPACE)
OPERATOR_NAME=$(OPERATOR_NAME)
SUBSCRIPTION_CHANNEL=$(CHANNELS)
CATALOG_NAMESPACE=$(CATALOG_NAMESPACE)
CATALOG_NAME=$(CATALOG_NAME)
CATALOG_DISPLAY_NAME=$(CATALOG_DISPLAY_NAME)
CATALOG_IMAGE=$(OPERATOR_INDEX_IMAGE)
CATALOG_PUBLISHER=$(CATALOG_PUBLISHER)
REGISTRY_ORG=$(REGISTRY_ORG)
endef
export DEPLOYMENT_VARS

# Deploy the operator and create a forklift controller in the configured Kubernetes cluster in ~/.kube/config
deploy: kubectl
@echo -n "- Deploying to OKD: "
@$(KUBECTL) get clusterrole system:image-puller &>/dev/null; OKD=$$?; \
if [ $${OKD} -eq 0 ]; then echo "yes"; else echo "no"; fi; \
echo "- Creating env files."; \
for i in operator forklift rolebinding/{catalog,operator,default}; do \
echo "$$DEPLOYMENT_VARS" > hack/deploy/$${i}/deploy.env; \
done; \
echo "- Creating the operator namespace: $(NAMESPACE)"; \
$(KUBECTL) get namespace $(NAMESPACE) &>/dev/null || $(KUBECTL) create namespace $(NAMESPACE); \
$(KUBECTL) get namespace $(CATALOG_NAMESPACE) &>/dev/null || $(KUBECTL) create namespace $(CATALOG_NAMESPACE); \
$(KUBECTL) get namespace $(REGISTRY_ORG) &>/dev/null || $(KUBECTL) create namespace $(REGISTRY_ORG); \
echo "- Creating the CatalogSource, OperatorGroup and the Subscription manifests"; \
$(KUBECTL) apply -k hack/deploy/operator ; \
if [ $$OKD -eq 0 ]; then \
echo "- Creating the required RoleBindings for the deployment"; \
$(KUBECTL) apply -k hack/deploy/rolebinding/default; \
$(KUBECTL) apply -k hack/deploy/rolebinding/catalog ; \
fi; \
echo -n "- Waiting for the operator to be installed"; \
until $(KUBECTL) -n $(NAMESPACE) get clusterserviceversion $(OPERATOR_NAME).v$(VERSION) &>/dev/null; do \
sleep 1; echo -n "."; \
done; \
echo; \
if [ $$OKD -eq 0 ]; then \
echo "- Applying required role bindings"; \
$(KUBECTL) apply -k hack/deploy/rolebinding/operator; \
fi; \
$(KUBECTL) -n $(NAMESPACE) wait --timeout=60s --for=jsonpath=.status.phase=Succeeded clusterserviceversion $(OPERATOR_NAME).v$(VERSION); \
echo "- Creating the Forklift Controller"; \
$(KUBECTL) apply -k hack/deploy/forklift; \
echo "Done!"

undeploy: kubectl
@echo "- Removing the operator namespace: $(NAMESPACE)"
@$(KUBECTL) get namespace $(NAMESPACE) -o name 2>/dev/null | xargs -r $(KUBECTL) delete ;
@echo "- Removing the CatalogSource"
@$(KUBECTL) get catalogsource -n $(CATALOG_NAMESPACE) -o name $(CATALOG_NAME) 2>/dev/null | xargs -r $(KUBECTL) -n $(CATALOG_NAMESPACE) delete;
@echo "- Removing the Operator"
@$(KUBECTL) get operator $(OPERATOR_NAME).$(NAMESPACE) -o name 2>/dev/null | xargs -r $(KUBECTL) delete;
@echo "- Removing the Webhooks"
@$(KUBECTL) get mutatingwebhookconfiguration forklift-api -o name 2>/dev/null | xargs -r $(KUBECTL) delete;
@$(KUBECTL) get validatingwebhookconfiguration forklift-api -o name 2>/dev/null | xargs -r $(KUBECTL) delete;
@echo "- Removing the ConsolePlugin"
@$(KUBECTL) get consoleplugin forklift-console-plugin -o name 2>/dev/null | xargs -r $(KUBECTL) delete;
@echo "- Removing the OAuthClient"
@$(KUBECTL) get oauthclient forklift-ui -o name 2>/dev/null | xargs -r $(KUBECTL) delete;
@echo "- Removing the CRDs"
@$(KUBECTL) get crd -l operators.coreos.com/forklift-operator.konveyor-forklift -o name 2>/dev/null | xargs -r $(KUBECTL) delete;
@echo "- Removing the RoleBindings"
@for ROLE_BINDING in forklift-{default,operator,controller,api,catalog,catalog-default} ; do \
$(KUBECTL) -n $(REGISTRY_ORG) get rolebinding $${ROLE_BINDING} -o name 2>/dev/null | xargs -r $(KUBECTL) -n $(REGISTRY_ORG) delete ; \
done;
@echo "Done!"
22 changes: 22 additions & 0 deletions hack/deploy/forklift/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources/forkliftcontroller.yaml
configMapGenerator:
- behavior: create
envs:
- deploy.env
name: forklift-controller-env
replacements:
- source:
fieldPath: data.OPERATOR_NAMESPACE
kind: ConfigMap
name: forklift-controller-env
version: v1
targets:
- fieldPaths:
- metadata.namespace
select:
group: forklift.konveyor.io
kind: ForkliftController
version: v1beta1
6 changes: 6 additions & 0 deletions hack/deploy/forklift/resources/forkliftcontroller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: forklift.konveyor.io/v1beta1
kind: ForkliftController
metadata:
name: forklift-controller
namespace: OPERATOR_NAMESPACE_PLACEHOLDER
spec: {}
135 changes: 135 additions & 0 deletions hack/deploy/operator/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources/catalogsource.yaml
- resources/operatorgroup.yaml
- resources/subscription.yaml
configMapGenerator:
- behavior: create
envs:
- deploy.env
name: forklift-operator-env
replacements:
- source:
fieldPath: data.OPERATOR_NAMESPACE
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- metadata.namespace
- spec.targetNamespaces.0
select:
group: operators.coreos.com
kind: OperatorGroup
name: migration
version: v1
- fieldPaths:
- metadata.namespace
select:
group: operators.coreos.com
kind: Subscription
version: v1alpha1
- fieldPaths:
- metadata.namespace
select:
group: forklift.konveyor.io
kind: ForkliftController
version: v1beta1
- source:
fieldPath: data.OPERATOR_NAME
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- metadata.name
- spec.name
select:
group: operators.coreos.com
kind: Subscription
version: v1alpha1
- source:
fieldPath: data.CATALOG_NAMESPACE
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- metadata.namespace
select:
group: operators.coreos.com
kind: CatalogSource
version: v1alpha1
- fieldPaths:
- spec.sourceNamespace
select:
group: operators.coreos.com
kind: Subscription
version: v1alpha1
- source:
fieldPath: data.CATALOG_NAME
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- metadata.name
select:
group: operators.coreos.com
kind: CatalogSource
version: v1alpha1
- fieldPaths:
- spec.source
select:
group: operators.coreos.com
kind: Subscription
version: v1alpha1
- source:
fieldPath: data.CATALOG_IMAGE
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- spec.image
select:
group: operators.coreos.com
kind: CatalogSource
version: v1alpha1
- source:
fieldPath: data.CATALOG_DISPLAY_NAME
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- spec.displayName
select:
group: operators.coreos.com
kind: CatalogSource
version: v1alpha1
- source:
fieldPath: data.CATALOG_PUBLISHER
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- spec.publisher
select:
group: operators.coreos.com
kind: CatalogSource
version: v1alpha1
- source:
fieldPath: data.SUBSCRIPTION_CHANNEL
kind: ConfigMap
name: forklift-operator-env
version: v1
targets:
- fieldPaths:
- spec.channel
select:
group: operators.coreos.com
kind: Subscription
version: v1alpha1
Loading

0 comments on commit 360a02a

Please sign in to comment.