Skip to content

Commit 7d5bf45

Browse files
committed
Use templates for deploy-on-kind and use envconfig for configuration
* Add script to convert template to manifest file, include changing the params to right values * Use the autogenerated manifst for kind deployment * Rewrite deploy and delete operation to use the template files (both Openshift and Kind) * Change configuration file to be created using envconfig library * Add --platform=linux/amd64 to support running on macOS * Add GREP environment variable to allow changing executer on macOS Signed-off-by: Nir Argaman <[email protected]>
1 parent 8e795d8 commit 7d5bf45

31 files changed

+356
-516
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ examples/config.yaml
1212
/tmp/
1313
cover.out
1414
/docker-config/
15-
deploy/k8s/migration-planner.yaml
15+
deploy/templates/service-template-values
16+
deploy/templates/service-manifest.yml
17+
deploy/templates/ui-template-values
18+
deploy/templates/postgres-manifest.yml

Containerfile.agent

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN mkdir /app/www && \
66
tar xf /tmp/agent-latest.tgz -C /app/www
77

88
# Builder container
9-
FROM registry.access.redhat.com/ubi9/go-toolset as builder
9+
FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/go-toolset as builder
1010

1111
WORKDIR /app
1212
COPY go.mod go.sum ./

Containerfile.api

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Builder container
2-
FROM registry.access.redhat.com/ubi9/go-toolset as builder
2+
FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/go-toolset as builder
33

44
WORKDIR /app
55

@@ -11,7 +11,7 @@ COPY . .
1111
USER 0
1212
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o /planner-api cmd/planner-api/*.go
1313

14-
FROM registry.access.redhat.com/ubi9/ubi-minimal
14+
FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/ubi-minimal
1515

1616
WORKDIR /app
1717

Makefile

+70-37
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ REGISTRY_TAG ?= latest
1717
DOWNLOAD_RHCOS ?= true
1818
KUBECTL ?= kubectl
1919
IFACE ?= eth0
20+
GREP ?= grep
2021
PODMAN ?= podman
2122
DOCKER_CONF ?= $(CURDIR)/docker-config
2223
DOCKER_AUTH_FILE ?= ${DOCKER_CONF}/auth.json
@@ -139,50 +140,82 @@ push-containers: push-api-container push-agent-container
139140
deploy-vsphere-simulator:
140141
$(KUBECTL) apply -f 'deploy/k8s/vcsim.yaml'
141142

142-
deploy-on-kind:
143-
sed "s|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|g; \
144-
s|@INSECURE_REGISTRY@|$(INSECURE_REGISTRY)|g; \
145-
s|@MIGRATION_PLANNER_API_IMAGE_PULL_POLICY@|$(MIGRATION_PLANNER_API_IMAGE_PULL_POLICY)|g; \
146-
s|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g; \
147-
s|@PERSISTENT_DISK_DEVICE@|$(PERSISTENT_DISK_DEVICE)|g" \
148-
deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
149-
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f 'deploy/k8s/*-service.yaml'
150-
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f 'deploy/k8s/*-secret.yaml'
151-
config_server=$$(ip addr show ${IFACE}| grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
152-
migration_planner_image_url=$$(ip addr show ${IFACE}| grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
153-
$(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
154-
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f deploy/k8s/
155-
156-
deploy-on-openshift:
157-
sed "s|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|g; \
158-
s|@INSECURE_REGISTRY@|$(INSECURE_REGISTRY)|g; \
159-
s|@MIGRATION_PLANNER_API_IMAGE_PULL_POLICY@|$(MIGRATION_PLANNER_API_IMAGE_PULL_POLICY)|g; \
160-
s|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g; \
161-
s|@PERSISTENT_DISK_DEVICE@|$(PERSISTENT_DISK_DEVICE)|g" \
162-
deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
163-
sed 's|@MIGRATION_PLANNER_UI_IMAGE@|$(MIGRATION_PLANNER_UI_IMAGE)|g' deploy/k8s/migration-planner-ui.yaml.template > deploy/k8s/migration-planner-ui.yaml
164-
ls deploy/k8s | awk '/secret|service/' | xargs -I {} oc apply -n ${MIGRATION_PLANNER_NAMESPACE} -f deploy/k8s/{}
165-
oc create route edge planner --service=migration-planner-ui -n ${MIGRATION_PLANNER_NAMESPACE} || true
166-
oc expose service migration-planner-agent -n ${MIGRATION_PLANNER_NAMESPACE} --name planner-agent || true
167-
oc expose service migration-planner-image -n ${MIGRATION_PLANNER_NAMESPACE} --name planner-image || true
168-
config_server=$$(oc get route planner-agent -o jsonpath='{.spec.host}'); \
169-
migration_planner_image_url=$$(oc get route planner-image -o jsonpath='{.spec.host}'); \
170-
config_server_ui=$$(oc get route planner -o jsonpath='{.spec.host}'); \
171-
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
172-
ls deploy/k8s | awk '! /secret|service|template/' | xargs -I {} oc apply -n ${MIGRATION_PLANNER_NAMESPACE} -f deploy/k8s/{}
143+
define service_template_values
144+
MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE)\n
145+
MIGRATION_PLANNER_AGENT_IMAGE=$(MIGRATION_PLANNER_AGENT_IMAGE)\n
146+
MIGRATION_PLANNER_REPLICAS=1\n
147+
IMAGE_TAG=latest\n
148+
endef
149+
export service_template_values
150+
151+
deploy/templates/service-template-values:
152+
@echo $$service_template_values > deploy/templates/service-template-values
153+
154+
define ui_template_values
155+
MIGRATION_PLANNER_UI_IMAGE=$(MIGRATION_PLANNER_UI_IMAGE)\n
156+
MIGRATION_PLANNER_REPLICAS=1\n
157+
IMAGE_TAG=latest\n
158+
endef
159+
export ui_template_values
160+
161+
deploy/templates/ui-template-values:
162+
@echo $$ui_template_values > deploy/templates/ui-template-values
163+
164+
165+
deploy-on-openshift: deploy/templates/service-template-values deploy/templates/ui-template-values
166+
# Deploy api resources
167+
oc process -f deploy/templates/postgres-template.yml | oc apply -f -
168+
openshift_base_url := $(shell oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
169+
openshift_project := $(shell oc project -q); \
170+
oc process -f deploy/templates/service-template.yml --param-file deploy/templates/service-template-values \
171+
-p MIGRATION_PLANNER_URL=http://planner-agent-$(openshift_project).apps.$(openshift_base_url) \
172+
-p MIGRATION_PLANNER_UI_URL=http://planner-ui-$(openshift_project).apps.$(openshift_base_url) \
173+
-p MIGRATION_PLANNER_IMAGE_URL=http://planner-image-$(openshift_project).apps.$(openshift_base_url) \
174+
| oc apply -f -
175+
# Deploy UI resources
176+
oc process -f https://raw.githubusercontent.com/nirarg/migration-planner-ui/refs/heads/template-change/deploy/templates/ui-template.yml \
177+
--param-file deploy/templates/ui-template-values | oc apply -f -
178+
# Create Route
179+
oc expose service migration-planner-agent --name planner-agent
180+
oc expose service migration-planner-ui --name planner-ui
181+
oc expose service migration-planner-image --name planner-image
182+
183+
delete-from-openshift: deploy/templates/service-template-values deploy/templates/ui-template-values
184+
oc process -f https://raw.githubusercontent.com/nirarg/migration-planner-ui/refs/heads/template-change/deploy/templates/ui-template.yml \
185+
--param-file deploy/templates/ui-template-values | oc delete -f -
186+
oc process -f deploy/templates/service-template.yml --param-file deploy/templates/service-template-values \
187+
-p MIGRATION_PLANNER_URL="empty" \
188+
-p MIGRATION_PLANNER_UI_URL="empty" \
189+
| oc delete -f -
190+
oc process -f deploy/templates/postgres-template.yml | oc delete -f -
191+
oc delete route planner-agent planner-ui
192+
193+
deploy-on-kind: deploy/templates/service-template-values deploy/templates/ui-template-values
194+
@deploy/templates/convert_template_to_manifests.sh deploy/templates/postgres-template.yml deploy/templates/postgres-manifest.yml; \
195+
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f deploy/templates/postgres-manifest.yml; \
196+
@inet_ip=$$(ip addr show ${IFACE} | $(GREP) -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
197+
deploy/templates/convert_template_to_manifests.sh deploy/templates/service-template.yml deploy/templates/service-manifest.yml deploy/templates/service-template-values \
198+
-p MIGRATION_PLANNER_URL=http://$${inet_ip}:7443 \
199+
-p MIGRATION_PLANNER_UI_URL=http://$${inet_ip}:3333 \
200+
-p MIGRATION_PLANNER_IMAGE_URL=http://$${inet_ip}:11443; \
201+
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f deploy/templates/service-manifest.yml
202+
203+
delete-from-kind: deploy/templates/service-template-values deploy/templates/ui-template-values
204+
@inet_ip=$$(ip addr show ${IFACE} | $(GREP) -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
205+
deploy/templates/convert_template_to_manifests.sh deploy/templates/service-template.yml deploy/templates/service-manifest.yml deploy/templates/service-template-values \
206+
-p MIGRATION_PLANNER_URL=http://$${inet_ip}:7443 \
207+
-p MIGRATION_PLANNER_UI_URL=http://$${inet_ip}:3333 \
208+
-p MIGRATION_PLANNER_IMAGE_URL=http://$${inet_ip}:11443; \
209+
$(KUBECTL) delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f deploy/templates/service-manifest.yml; \
210+
deploy/templates/convert_template_to_manifests.sh deploy/templates/postgres-template.yml deploy/templates/postgres-manifest.yml; \
211+
$(KUBECTL) apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f deploy/templates/postgres-manifest.yml
173212

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

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

180-
undeploy-on-openshift:
181-
oc delete route planner || true
182-
oc delete route planner-agent || true
183-
oc delete secret migration-planner-secret || true
184-
oc delete -f deploy/k8s || true
185-
186219
bin:
187220
mkdir -p bin
188221

cmd/planner-api/migrate.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ var migrateCmd = &cobra.Command{
1818
undo := zap.ReplaceGlobals(logger)
1919
defer undo()
2020

21-
if configFile == "" {
22-
configFile = config.ConfigFile()
23-
}
24-
25-
cfg, err := config.Load(configFile)
21+
cfg, err := config.New()
2622
if err != nil {
2723
zap.S().Fatalf("reading configuration: %v", err)
2824
}

cmd/planner-api/run.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ var runCmd = &cobra.Command{
2828
RunE: func(cmd *cobra.Command, args []string) error {
2929
defer zap.S().Info("API service stopped")
3030

31-
if configFile == "" {
32-
configFile = config.ConfigFile()
33-
}
34-
cfg, err := config.LoadOrGenerate(configFile)
31+
cfg, err := config.New()
3532
if err != nil {
3633
zap.S().Fatalf("reading configuration: %v", err)
3734
}

deploy/k8s/migration-planner-agent-service.yaml

-17
This file was deleted.

deploy/k8s/migration-planner-image-service.yaml

-17
This file was deleted.

deploy/k8s/migration-planner-service.yaml

-17
This file was deleted.

deploy/k8s/migration-planner-ui-service.yaml

-12
This file was deleted.

deploy/k8s/migration-planner-ui.yaml

-21
This file was deleted.

deploy/k8s/migration-planner-ui.yaml.template

-21
This file was deleted.

deploy/k8s/migration-planner.yaml.template

-75
This file was deleted.

0 commit comments

Comments
 (0)