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

Add end to end tests #51

Merged
merged 1 commit into from
Oct 27, 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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rhcos-live.x86_64.iso
**/*iso
10 changes: 10 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5

- name: Setup libvirt
run: |
sudo apt update
sudo apt install libvirt-dev

- name: Prepare
run: |
make generate
Expand All @@ -36,6 +41,11 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Setup libvirt
run: |
sudo apt update
sudo apt install libvirt-dev

- name: Run golangci-lint
uses: golangci/[email protected]
with:
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Run e2e test

on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
env:
MIGRATION_PLANNER_API_IMAGE: "custom/migration-planner-api"
MIGRATION_PLANNER_API_IMAGE_PULL_POLICY: "Never"
PODMAN: "docker"

steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true

- name: Checkout the code
uses: actions/checkout@v2

- name: Set env variables
run: |
export "REGISTRY_IP=$(ip addr show eth0 | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+')"
echo "REGISTRY_IP=${REGISTRY_IP}" >> $GITHUB_ENV
echo "MIGRATION_PLANNER_AGENT_IMAGE=${REGISTRY_IP}:5000/agent" >> $GITHUB_ENV
echo "INSECURE_REGISTRY=${REGISTRY_IP}:5000" >> $GITHUB_ENV

- name: Ignore insecure registry
run: |
cat << EOF > daemon.json
{
"insecure-registries" : [ "${INSECURE_REGISTRY}" ]
}
EOF
sudo mv daemon.json /etc/docker/daemon.json
sudo systemctl daemon-reload
sudo systemctl restart docker

- name: Install kubectl
uses: azure/setup-kubectl@v4

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
with:
cluster_name: kind

- name: Setup libvirt
run: |
sudo apt update
sudo apt install sshpass libvirt-dev libvirt-daemon libvirt-daemon-system
sudo systemctl restart libvirtd

- name: Deploy vcsim
run: |
kubectl create deployment vcsim --image=docker.io/vmware/vcsim
kubectl wait --for=condition=Ready pods --all --timeout=240s
kubectl port-forward --address 0.0.0.0 deploy/vcsim 8989:8989 &

- name: Deploy registry
run: |
kubectl create deployment registry --image=docker.io/registry
kubectl wait --for=condition=Ready pods --all --timeout=240s
kubectl port-forward --address 0.0.0.0 deploy/registry 5000:5000 &

- name: Build assisted-migration containers
run: |
make migration-planner-agent-container MIGRATION_PLANNER_AGENT_IMAGE=$MIGRATION_PLANNER_AGENT_IMAGE
make migration-planner-api-container MIGRATION_PLANNER_API_IMAGE=$MIGRATION_PLANNER_API_IMAGE
docker push $MIGRATION_PLANNER_AGENT_IMAGE
kind load docker-image $MIGRATION_PLANNER_API_IMAGE
docker rmi $MIGRATION_PLANNER_API_IMAGE

- name: Deploy assisted-migration
run: |
make deploy-on-kind MIGRATION_PLANNER_API_IMAGE=$MIGRATION_PLANNER_API_IMAGE MIGRATION_PLANNER_AGENT_IMAGE=$MIGRATION_PLANNER_AGENT_IMAGE MIGRATION_PLANNER_API_IMAGE_PULL_POLICY=$MIGRATION_PLANNER_API_IMAGE_PULL_POLICY INSECURE_REGISTRY=$INSECURE_REGISTRY
kubectl wait --for=condition=Ready pods --all --timeout=240s
kubectl port-forward --address 0.0.0.0 service/migration-planner-agent 7443:7443 &
kubectl port-forward --address 0.0.0.0 service/migration-planner 3443:3443 &

- name: Run test
run: |
sudo make integration-test PLANNER_IP=${REGISTRY_IP}
26 changes: 21 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ 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_PULL_POLICY ?= Always
MIGRATION_PLANNER_UI_IMAGE ?= quay.io/kubev2v/migration-planner-ui
INSECURE_REGISTRY ?=
DOWNLOAD_RHCOS ?= true
KUBECTL ?= kubectl
IFACE ?= eth0
PODMAN ?= podman

SOURCE_GIT_TAG ?=$(shell git describe --always --long --tags --abbrev=7 --match 'v[0-9]*' || echo 'v0.0.0-unknown-$(SOURCE_GIT_COMMIT)')
SOURCE_GIT_TREE_STATE ?=$(shell ( ( [ ! -d ".git/" ] || git diff --quiet ) && echo 'clean' ) || echo 'dirty')
Expand Down Expand Up @@ -69,6 +74,9 @@ ifeq ($(DOWNLOAD_RHCOS), true)
curl --silent -C - -O https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live.x86_64.iso
endif

integration-test: ginkgo
$(GINKGO) -focus=$(FOCUS) run test/e2e

build: bin image
go build -buildvcs=false $(GO_BUILD_FLAGS) -o $(GOBIN) ./cmd/...

Expand All @@ -78,10 +86,10 @@ build-api: bin

# rebuild container only on source changes
bin/.migration-planner-agent-container: bin Containerfile.agent go.mod go.sum $(GO_FILES)
podman build -f Containerfile.agent -t $(MIGRATION_PLANNER_AGENT_IMAGE):latest
$(PODMAN) build . -f Containerfile.agent -t $(MIGRATION_PLANNER_AGENT_IMAGE):latest

bin/.migration-planner-api-container: bin Containerfile.api go.mod go.sum $(GO_FILES)
podman build -f Containerfile.api -t $(MIGRATION_PLANNER_API_IMAGE):latest
$(PODMAN) build . -f Containerfile.api -t $(MIGRATION_PLANNER_API_IMAGE):latest

migration-planner-api-container: bin/.migration-planner-api-container
migration-planner-agent-container: bin/.migration-planner-agent-container
Expand All @@ -91,11 +99,19 @@ build-containers: migration-planner-api-container migration-planner-agent-contai
.PHONY: build-containers

push-containers: build-containers
podman push $(MIGRATION_PLANNER_API_IMAGE):latest
podman push $(MIGRATION_PLANNER_AGENT_IMAGE):latest
$(PODMAN) push $(MIGRATION_PLANNER_API_IMAGE):latest
$(PODMAN) push $(MIGRATION_PLANNER_AGENT_IMAGE):latest

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' deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
$(KUBECTL) apply -f 'deploy/k8s/*-service.yaml'
$(KUBECTL) apply -f 'deploy/k8s/*-secret.yaml'
@config_server=$$(ip addr show ${IFACE}| grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
$(KUBECTL) create secret generic migration-planner-secret --from-literal=config_server=http://$$config_server:7443 || true
$(KUBECTL) apply -f deploy/k8s/

deploy-on-openshift:
sed 's|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g' deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
sed 's|@MIGRATION_PLANNER_AGENT_IMAGE@|$(MIGRATION_PLANNER_AGENT_IMAGE)|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' 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
oc apply -f 'deploy/k8s/*-service.yaml'
oc apply -f 'deploy/k8s/*-secret.yaml'
Expand Down
9 changes: 9 additions & 0 deletions data/ignition.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ storage:
group:
name: core
files:
{{if .InsecureRegistry}}
- path: /etc/containers/registries.conf.d/myregistry.conf
overwrite: true
contents:
inline: |
[[registry]]
location = "{{.InsecureRegistry}}"
insecure = true
{{end}}
- path: /etc/ssh/sshd_config.d/40-rhcos-defaults.conf
overwrite: true
contents:
Expand Down
7 changes: 6 additions & 1 deletion deploy/k8s/migration-planner.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
cpu: 300m
memory: 400Mi
image: @MIGRATION_PLANNER_API_IMAGE@
imagePullPolicy: Always
imagePullPolicy: @MIGRATION_PLANNER_API_IMAGE_PULL_POLICY@
ports:
- containerPort: 3443
livenessProbe:
Expand All @@ -36,6 +36,11 @@ spec:
secretKeyRef:
name: migration-planner-secret
key: config_server
- name: MIGRATION_PLANNER_AGENT_IMAGE
value: @MIGRATION_PLANNER_AGENT_IMAGE@
- name: INSECURE_REGISTRY
value: @INSECURE_REGISTRY@
volumeMounts:
volumeMounts:
- name: migration-planner-config
mountPath: "/.migration-planner/config.yaml"
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ require (
github.com/go-chi/render v1.0.3
github.com/google/uuid v1.6.0
github.com/konveyor/forklift-controller v0.0.0-20221102112227-e73b65a01cda
github.com/libvirt/libvirt-go v7.4.0+incompatible
github.com/lthibault/jitterbug v2.0.0+incompatible
github.com/oapi-codegen/nethttp-middleware v1.0.2
github.com/oapi-codegen/runtime v1.1.1
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.32.0
github.com/openshift/assisted-image-service v0.0.0-20240827125623-ad5c4b36a817
Expand Down Expand Up @@ -50,6 +52,7 @@ require (
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/cors v1.3.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand Down Expand Up @@ -94,6 +97,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/openshift/api v0.0.0-20230613151523-ba04973d3ed1 // indirect
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pborman/uuid v1.2.1 // indirect
Expand Down Expand Up @@ -125,6 +129,7 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ github.com/kubev2v/forklift v0.0.0-20240729073638-8978e272380e/go.mod h1:1jmlC7L
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/libvirt/libvirt-go v7.4.0+incompatible h1:crnSLkwPqCdXtg6jib/FxBG/hweAc/3Wxth1AehCXL4=
github.com/libvirt/libvirt-go v7.4.0+incompatible/go.mod h1:34zsnB4iGeOv7Byj6qotuW8Ya4v4Tr43ttjz/F0wjLE=
github.com/lthibault/jitterbug v2.0.0+incompatible h1:qouq51IKzlMx25+15jbxhC/d79YyTj0q6XFoptNqaUw=
github.com/lthibault/jitterbug v2.0.0+incompatible/go.mod h1:2l7akWd27PScEs6YkjyUVj/8hKgNhbbQ3KiJgJtlf6o=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down Expand Up @@ -461,6 +463,7 @@ golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
Expand Down
5 changes: 5 additions & 0 deletions internal/image/ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type IgnitionData struct {
SshKey string
PlannerService string
MigrationPlannerAgentImage string
InsecureRegistry string
}

type Image interface {
Expand Down Expand Up @@ -128,6 +129,10 @@ func (o *Ova) generateIgnition() (string, error) {
MigrationPlannerAgentImage: util.GetEnv("MIGRATION_PLANNER_AGENT_IMAGE", "quay.io/kubev2v/migration-planner-agent"),
}

if insecureRegistry := os.Getenv("INSECURE_REGISTRY"); insecureRegistry != "" {
ignData.InsecureRegistry = insecureRegistry
}

var buf bytes.Buffer
t, err := template.New("ignition.template").ParseFiles("data/ignition.template")
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Running integration tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

The integration tests are executed against deployed `planner-api`. The planner api can be deployed
as container or running as binary.

## Requiremets

```
dnf install -y libvirt-devel
sudo usermod -a -G libvirt $USER
```

Running planner api, either as container or binary:
```
bin/planner-api
```

## Executing tests
```
PLANNER_IP=1.2.3.4 make integration-tests
```
34 changes: 34 additions & 0 deletions test/e2e/data/vm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<domain type='kvm'>
<name>coreos-vm</name>
<memory unit='MiB'>4096</memory>
<vcpu placement='static'>2</vcpu>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/coreos/stable"/>
</libosinfo:libosinfo>
</metadata>
<os>
<type arch='x86_64' machine='pc-q35-6.2'>hvm</type>
<boot dev='cdrom'/>
</os>
<cpu mode='host-passthrough' check='none' migratable='on'/>
<features>
<acpi/>
<apic/>
</features>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/tmp/agent.iso'/>
<target dev='sda' bus='sata'/>
<readonly/>
</disk>
<interface type='network'>
<source network='default'/>
<model type='virtio'/>
</interface>
<graphics type='vnc' port='-1'/>
<console type='pty'/>
</devices>
</domain>
Loading
Loading