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

Use templates for deploy-on-kind and use envconfig for configuration #186

Merged
merged 1 commit into from
Mar 20, 2025
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@ jobs:
- name: Checkout the code
uses: actions/checkout@v2

- name: Setup oc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this part of Makefile? We tried to have Makefile as reusable as possible, so even all dependecies are isntalled in Makefile

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this approach may not be the best for supporting different operating systems and environments. Requiring the oc command to be pre-installed seems like a reasonable approach, similar to how we handle kubectl.
However, if you still think it's necessary to install oc, I can add an installation step for Linux systems in case oc isn’t already installed.
Additionally, I’m adding an environment variable OC to allow flexibility in changing the executor path if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change this in a different PR

uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4"

- name: Set env variables
run: |
export "REGISTRY_IP=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+')"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -12,5 +12,4 @@ examples/config.yaml
/tmp/
cover.out
/docker-config/
deploy/k8s/migration-planner.yaml
deploy/k8s/vcsim.yaml
123 changes: 85 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -8,15 +8,19 @@ TIMEOUT ?= 30m
VERBOSE ?= false
MIGRATION_PLANNER_AGENT_IMAGE ?= quay.io/kubev2v/migration-planner-agent
MIGRATION_PLANNER_API_IMAGE ?= quay.io/kubev2v/migration-planner-api
MIGRATION_PLANNER_API_IMAGE_TAG ?= latest
MIGRATION_PLANNER_API_IMAGE_PULL_POLICY ?= Always
MIGRATION_PLANNER_UI_IMAGE ?= quay.io/kubev2v/migration-planner-ui
MIGRATION_PLANNER_UI_IMAGE_TAG ?= latest
MIGRATION_PLANNER_NAMESPACE ?= assisted-migration
MIGRATION_PLANNER_REPLICAS ?= 1
PERSISTENT_DISK_DEVICE ?= /dev/sda
INSECURE_REGISTRY ?= true
INSECURE_REGISTRY ?= "true"
REGISTRY_TAG ?= latest
DOWNLOAD_RHCOS ?= true
KUBECTL ?= kubectl
IFACE ?= eth0
GREP ?= grep
PODMAN ?= podman
DOCKER_CONF ?= $(CURDIR)/docker-config
DOCKER_AUTH_FILE ?= ${DOCKER_CONF}/auth.json
@@ -55,7 +59,7 @@ help:
@echo " clean: clean up all containers and volumes"

GOBIN = $(shell pwd)/bin
GINKGO = $(GOBIN)/ginkgo
GINKGO ?= $(GOBIN)/ginkgo
ginkgo: ## Download ginkgo locally if necessary.
ifeq (, $(shell which ginkgo 2> /dev/null))
go install -v github.com/onsi/ginkgo/v2/[email protected]
@@ -136,50 +140,93 @@ push-agent-container: migration-planner-agent-container quay-login

push-containers: push-api-container push-agent-container

deploy-on-kind:
sed "s|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|g; \
s|@INSECURE_REGISTRY@|$(INSECURE_REGISTRY)|g; \
s|@MIGRATION_PLANNER_API_IMAGE_PULL_POLICY@|$(MIGRATION_PLANNER_API_IMAGE_PULL_POLICY)|g; \
s|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g; \
s|@PERSISTENT_DISK_DEVICE@|$(PERSISTENT_DISK_DEVICE)|g" \
deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f 'deploy/k8s/*-service.yaml'
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f 'deploy/k8s/*-secret.yaml'
config_server=$$(ip addr show ${IFACE}| grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
migration_planner_image_url=$$(ip addr show ${IFACE}| grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
$(KUBECTL) create secret generic migration-planner-secret -n "${MIGRATION_PLANNER_NAMESPACE}" --from-literal=migration_planner_image_url=http://$$migration_planner_image_url --from-literal=config_server=http://$$config_server:7443 --from-literal=config_server_ui=https://$$config_server_ui/migrate/wizard || true
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f deploy/k8s/

deploy-on-openshift:
sed "s|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|g; \
s|@INSECURE_REGISTRY@|$(INSECURE_REGISTRY)|g; \
s|@MIGRATION_PLANNER_API_IMAGE_PULL_POLICY@|$(MIGRATION_PLANNER_API_IMAGE_PULL_POLICY)|g; \
s|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g; \
s|@PERSISTENT_DISK_DEVICE@|$(PERSISTENT_DISK_DEVICE)|g" \
deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
sed 's|@MIGRATION_PLANNER_UI_IMAGE@|$(MIGRATION_PLANNER_UI_IMAGE)|g' deploy/k8s/migration-planner-ui.yaml.template > deploy/k8s/migration-planner-ui.yaml
ls deploy/k8s | awk '/secret|service/' | xargs -I {} oc apply -n ${MIGRATION_PLANNER_NAMESPACE} -f deploy/k8s/{}
oc create route edge planner --service=migration-planner-ui -n ${MIGRATION_PLANNER_NAMESPACE} || true
oc expose service migration-planner-agent -n ${MIGRATION_PLANNER_NAMESPACE} --name planner-agent || true
oc expose service migration-planner-image -n ${MIGRATION_PLANNER_NAMESPACE} --name planner-image || true
config_server=$$(oc get route planner-agent -o jsonpath='{.spec.host}'); \
migration_planner_image_url=$$(oc get route planner-image -o jsonpath='{.spec.host}'); \
config_server_ui=$$(oc get route planner -o jsonpath='{.spec.host}'); \
oc create secret generic migration-planner-secret -n ${MIGRATION_PLANNER_NAMESPACE} --from-literal=migration_planner_image_url=http://$$migration_planner_image_url --from-literal=config_server=http://$$config_server --from-literal=config_server_ui=https://$$config_server_ui/migrate/wizard || true
ls deploy/k8s | awk '! /secret|service|template/' | xargs -I {} oc apply -n ${MIGRATION_PLANNER_NAMESPACE} -f deploy/k8s/{}
@openshift_base_url=$$(oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
openshift_project=$$(oc project -q); \
echo "*** Deploy Migration Planner on Openshift. Project: $${openshift_project}, Base URL: $${openshift_base_url} ***";\
oc process -f deploy/templates/postgres-template.yml | oc apply -f -; \
oc process -f deploy/templates/service-template.yml \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_AGENT_IMAGE=$(MIGRATION_PLANNER_AGENT_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=${MIGRATION_PLANNER_REPLICAS} \
-p IMAGE_TAG=$(MIGRATION_PLANNER_API_IMAGE_TAG) \
-p MIGRATION_PLANNER_URL=http://planner-agent-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_UI_URL=http://planner-ui-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_IMAGE_URL=http://planner-image-$${openshift_project}.apps.$${openshift_base_url} \
| oc apply -f -; \
oc process -f https://raw.githubusercontent.com/kubev2v/migration-planner-ui/refs/heads/main/deploy/templates/ui-template.yml \
-p MIGRATION_PLANNER_UI_IMAGE=$(MIGRATION_PLANNER_UI_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p IMAGE_TAG=$(MIGRATION_PLANNER_UI_IMAGE_TAG) \
| oc apply -f -; \
oc expose service migration-planner-agent --name planner-agent; \
oc expose service migration-planner-ui --name planner-ui; \
oc expose service migration-planner-image --name planner-image; \
echo "*** Migration Planner has been deployed successfully on Openshift ***"; \
echo "*** Open UI: http://planner-ui-$${openshift_project}.apps.$${openshift_base_url}"

delete-from-openshift:
@openshift_base_url=$$(oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
openshift_project=$$(oc project -q); \
echo "*** Delete Migration Planner from Openshift. Project: $${openshift_project}, Base URL: $${openshift_base_url} ***"; \
oc process -f https://raw.githubusercontent.com/kubev2v/migration-planner-ui/refs/heads/main/deploy/templates/ui-template.yml \
-p MIGRATION_PLANNER_UI_IMAGE=$(MIGRATION_PLANNER_UI_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p IMAGE_TAG=$(MIGRATION_PLANNER_UI_IMAGE_TAG) \
| oc delete -f -; \
openshift_base_url=$$(oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
openshift_project=$$(oc project -q); \
oc process -f deploy/templates/service-template.yml \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_AGENT_IMAGE=$(MIGRATION_PLANNER_AGENT_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p IMAGE_TAG=$(MIGRATION_PLANNER_API_IMAGE_TAG) \
-p MIGRATION_PLANNER_URL=http://planner-agent-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_UI_URL=http://planner-ui-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_IMAGE_URL=http://planner-image-$${openshift_project}.apps.$${openshift_base_url} \
| oc delete -f -; \
oc process -f deploy/templates/postgres-template.yml | oc delete -f -; \
oc delete route planner-agent planner-ui planner-image; \
echo "*** Migration Planner has been deleted successfully from Openshift ***"

deploy-on-kind:
@inet_ip=$$(ip addr show ${IFACE} | $(GREP) -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
echo "*** Deploy Migration Planner on Kind. Namespace: $${MIGRATION_PLANNER_NAMESPACE}, inet_ip: $${inet_ip}, PERSISTENT_DISK_DEVICE: $${PERSISTENT_DISK_DEVICE} ***"; \
oc process --local -f deploy/templates/postgres-template.yml | $(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/service-template.yml \
-p MIGRATION_PLANNER_URL=http://$${inet_ip}:7443 \
-p MIGRATION_PLANNER_UI_URL=http://$${inet_ip}:3333 \
-p MIGRATION_PLANNER_IMAGE_URL=http://$${inet_ip}:11443 \
-p MIGRATION_PLANNER_API_IMAGE_PULL_POLICY=Never \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_AGENT_IMAGE=$(MIGRATION_PLANNER_AGENT_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p PERSISTENT_DISK_DEVICE=$(PERSISTENT_DISK_DEVICE) \
-p INSECURE_REGISTRY=$(INSECURE_REGISTRY) \
| $(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
echo "*** Migration Planner has been deployed successfully on Kind ***"

delete-from-kind:
inet_ip=$$(ip addr show ${IFACE} | $(GREP) -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
oc process --local -f deploy/templates/service-template.yml \
-p MIGRATION_PLANNER_URL=http://$${inet_ip}:7443 \
-p MIGRATION_PLANNER_UI_URL=http://$${inet_ip}:3333 \
-p MIGRATION_PLANNER_IMAGE_URL=http://$${inet_ip}:11443 \
-p MIGRATION_PLANNER_API_IMAGE_PULL_POLICY=Never \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_AGENT_IMAGE=$(MIGRATION_PLANNER_AGENT_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p PERSISTENT_DISK_DEVICE=$(PERSISTENT_DISK_DEVICE) \
-p INSECURE_REGISTRY=$(INSECURE_REGISTRY) \
| $(KUBECTL) delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/postgres-template.yml | $(KUBECTL) delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f -

deploy-local-obs:
@podman play kube --network host deploy/observability.yml

undeploy-local-obs:
@podman kube down deploy/observability.yml

undeploy-on-openshift:
oc delete route planner || true
oc delete route planner-agent || true
oc delete secret migration-planner-secret || true
oc delete -f deploy/k8s || true

bin:
mkdir -p bin

6 changes: 1 addition & 5 deletions cmd/planner-api/migrate.go
Original file line number Diff line number Diff line change
@@ -18,11 +18,7 @@ var migrateCmd = &cobra.Command{
undo := zap.ReplaceGlobals(logger)
defer undo()

if configFile == "" {
configFile = config.ConfigFile()
}

cfg, err := config.Load(configFile)
cfg, err := config.New()
if err != nil {
zap.S().Fatalf("reading configuration: %v", err)
}
5 changes: 1 addition & 4 deletions cmd/planner-api/run.go
Original file line number Diff line number Diff line change
@@ -29,10 +29,7 @@ var runCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
defer zap.S().Info("API service stopped")

if configFile == "" {
configFile = config.ConfigFile()
}
cfg, err := config.LoadOrGenerate(configFile)
cfg, err := config.New()
if err != nil {
zap.S().Fatalf("reading configuration: %v", err)
}
17 changes: 0 additions & 17 deletions deploy/k8s/migration-planner-agent-service.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions deploy/k8s/migration-planner-image-service.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions deploy/k8s/migration-planner-service.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions deploy/k8s/migration-planner-ui-service.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions deploy/k8s/migration-planner-ui.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions deploy/k8s/migration-planner-ui.yaml.template

This file was deleted.

75 changes: 0 additions & 75 deletions deploy/k8s/migration-planner.yaml.template

This file was deleted.

Loading