Skip to content

Commit

Permalink
WIP: Adding initiall support for OVA migration
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy authored and ahadas committed Jul 17, 2023
1 parent 1557a58 commit f9b2897
Show file tree
Hide file tree
Showing 50 changed files with 3,688 additions and 2 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ build --action_env=POPULATOR_CONTROLLER_IMAGE=quay.io/kubev2v/populator-controll
build --action_env=OPENSTACK_POPULATOR_IMAGE=quay.io/kubev2v/openstack-populator:latest
build --action_env=OVIRT_POPULATOR_IMAGE=quay.io/kubev2v/ovirt-populator:latest
build --action_env=OPERATOR_IMAGE=quay.io/kubev2v/forklift-operator:latest
build --action_env=OVA_PROVIDER_SERVER_IMAGE=quay.io/kubev2v/forklift-ova-provider-server:latest

# Appliance build
# container_run_and_extract() does not work inside Podman and Docker
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ OVIRT_POPULATOR_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/ovirt-populator:$(REGISTRY_
OPENSTACK_POPULATOR_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/openstack-populator:$(REGISTRY_TAG)
OVA_PROVIDER_SERVER_IMAGE ?= $(REGISTRY)/$(REGISTRY_ORG)/ova-provider-server:$(REGISTRY_TAG)


### External images
MUST_GATHER_IMAGE ?= quay.io/kubev2v/forklift-must-gather:latest
MUST_GATHER_API_IMAGE ?= quay.io/kubev2v/forklift-must-gather-api:latest
Expand Down Expand Up @@ -241,6 +242,7 @@ build-operator-bundle-image: check_container_runtime
--action_env OPENSTACK_POPULATOR_IMAGE=$(OPENSTACK_POPULATOR_IMAGE)\
--action_env OVA_PROVIDER_SERVER_IMAGE=$(OVA_PROVIDER_SERVER_IMAGE)


push-operator-bundle-image: build-operator-bundle-image
$(CONTAINER_CMD) tag bazel/operator:forklift-operator-bundle-image $(OPERATOR_BUNDLE_IMAGE)
$(CONTAINER_CMD) push $(OPERATOR_BUNDLE_IMAGE)
Expand Down Expand Up @@ -292,6 +294,7 @@ build-ova-provider-server-image: check_container_runtime
push-ova-provider-server-image: build-ova-provider-server-image
$(CONTAINER_CMD) push $(OVA_PROVIDER_SERVER_IMAGE)


build-all-images: build-api-image \
build-controller-image \
build-validation-image \
Expand All @@ -305,6 +308,7 @@ build-all-images: build-api-image \
build-openstack-populator-image\
build-ova-provider-server-image


push-all-images: push-api-image \
push-controller-image \
push-validation-image \
Expand All @@ -318,6 +322,7 @@ push-all-images: push-api-image \
push-openstack-populator-image\
push-ova-provider-server-image


.PHONY: check_container_runtime
check_container_runtime:
@if [ ! -x "$(CONTAINER_CMD)" ]; then \
Expand Down
2 changes: 2 additions & 0 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ spec:
value: ${OVIRT_POPULATOR_IMAGE}
- name: OPENSTACK_POPULATOR_IMAGE
value: ${OPENSTACK_POPULATOR_IMAGE}
- name: OVA_PROVIDER_SERVER_IMAGE
value: ${OVA_PROVIDER_SERVER_IMAGE}
livenessProbe:
httpGet:
path: /healthz
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/forklift/v1beta1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ const (
OVirt ProviderType = "ovirt"
// OpenStack
OpenStack ProviderType = "openstack"
// OVA
Ova ProviderType = "ova"
)

var ProviderTypes = []ProviderType{
OpenShift,
VSphere,
OVirt,
OpenStack,
Ova,
}

func (t ProviderType) String() string {
Expand Down Expand Up @@ -164,5 +167,5 @@ func (p *Provider) HasReconciled() bool {

// This provider requires VM guest conversion.
func (p *Provider) RequiresConversion() bool {
return p.Type() == VSphere
return p.Type() == VSphere || p.Type() == Ova
}
1 change: 1 addition & 0 deletions pkg/controller/host/handler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/host/handler/ocp",
"//pkg/controller/host/handler/openstack",
"//pkg/controller/host/handler/ova",
"//pkg/controller/host/handler/ovirt",
"//pkg/controller/host/handler/vsphere",
"//pkg/controller/watch/handler",
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/host/handler/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/host/handler/ocp"
"github.com/konveyor/forklift-controller/pkg/controller/host/handler/openstack"
"github.com/konveyor/forklift-controller/pkg/controller/host/handler/ova"
"github.com/konveyor/forklift-controller/pkg/controller/host/handler/ovirt"
"github.com/konveyor/forklift-controller/pkg/controller/host/handler/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
Expand Down Expand Up @@ -47,6 +48,11 @@ func New(
client,
channel,
provider)
case api.Ova:
h, err = ova.New(
client,
channel,
provider)
default:
err = liberr.New("provider not supported.")
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/controller/host/handler/ova/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "ova",
srcs = [
"doc.go",
"handler.go",
],
importpath = "github.com/konveyor/forklift-controller/pkg/controller/host/handler/ova",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/watch/handler",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
"//vendor/sigs.k8s.io/controller-runtime/pkg/event",
],
)
22 changes: 22 additions & 0 deletions pkg/controller/host/handler/ova/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ova

import (
api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
)

// Handler factory.
func New(
client client.Client,
channel chan event.GenericEvent,
provider *api.Provider) (h *Handler, err error) {
//
b, err := handler.New(client, channel, provider)
if err != nil {
return
}
h = &Handler{Handler: b}
return
}
15 changes: 15 additions & 0 deletions pkg/controller/host/handler/ova/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ova

import (
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
)

// Provider watch event handler.
type Handler struct {
*handler.Handler
}

// Ensure watch on hosts.
func (r *Handler) Watch(watch *handler.WatchManager) (err error) {
return
}
22 changes: 22 additions & 0 deletions pkg/controller/map/storage/handler/ova/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "ova",
srcs = [
"doc.go",
"handler.go",
],
importpath = "github.com/konveyor/forklift-controller/pkg/controller/map/storage/handler/ova",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/provider/web/ova",
"//pkg/controller/watch/handler",
"//pkg/lib/error",
"//pkg/lib/inventory/web",
"//pkg/lib/logging",
"//vendor/golang.org/x/net/context",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
"//vendor/sigs.k8s.io/controller-runtime/pkg/event",
],
)
22 changes: 22 additions & 0 deletions pkg/controller/map/storage/handler/ova/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ova

import (
api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
)

// Handler factory.
func New(
client client.Client,
channel chan event.GenericEvent,
provider *api.Provider) (h *Handler, err error) {
//
b, err := handler.New(client, channel, provider)
if err != nil {
return
}
h = &Handler{Handler: b}
return
}
116 changes: 116 additions & 0 deletions pkg/controller/map/storage/handler/ova/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package ova

import (
"path"
"strings"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ova"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"sigs.k8s.io/controller-runtime/pkg/event"
)

// Package logger.
var log = logging.WithName("storageMap|ova")

// Provider watch event handler.
type Handler struct {
*handler.Handler
}

// Ensure watch on Disk.
func (r *Handler) Watch(watch *handler.WatchManager) (err error) {
w, err := watch.Ensure(
r.Provider(),
&ova.Disk{},
r)
if err != nil {
return
}

log.Info(
"Inventory watch ensured.",
"provider",
path.Join(
r.Provider().Namespace,
r.Provider().Name),
"watch",
w.ID())

return
}

// Resource created.
func (r *Handler) Created(e libweb.Event) {
if ds, cast := e.Resource.(*ova.Disk); cast {
r.changed(ds)
}
}

// Resource created.
func (r *Handler) Updated(e libweb.Event) {
if ds, cast := e.Resource.(*ova.Disk); cast {
updated := e.Updated.(*ova.Disk)
if updated.Path != ds.Path {
r.changed(ds, updated)
}
}
}

// Resource deleted.
func (r *Handler) Deleted(e libweb.Event) {
if ds, cast := e.Resource.(*ova.Disk); cast {
r.changed(ds)
}
}

// Storage changed.
// Find all of the StorageMap CRs the reference both the
// provider and the changed storage domain and enqueue reconcile events.
func (r *Handler) changed(models ...*ova.Disk) {
log.V(3).Info(
"Storage domain changed.",
"id",
models[0].ID)
list := api.StorageMapList{}
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
return
}
for i := range list.Items {
mp := &list.Items[i]
ref := mp.Spec.Provider.Source
if !r.MatchProvider(ref) {
continue
}
referenced := false
for _, pair := range mp.Spec.Map {
ref := pair.Source
for _, ds := range models {
if ref.ID == ds.ID || strings.HasSuffix(ds.Path, ref.Name) {
referenced = true
break
}
}
if referenced {
break
}
}
if referenced {
log.V(3).Info(
"Queue reconcile event.",
"map",
path.Join(
mp.Namespace,
mp.Name))
r.Enqueue(event.GenericEvent{
Object: mp,
})
}
}
}
1 change: 1 addition & 0 deletions pkg/controller/plan/handler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/plan/handler/ocp",
"//pkg/controller/plan/handler/openstack",
"//pkg/controller/plan/handler/ova",
"//pkg/controller/plan/handler/ovirt",
"//pkg/controller/plan/handler/vsphere",
"//pkg/controller/watch/handler",
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/plan/handler/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/plan/handler/ocp"
"github.com/konveyor/forklift-controller/pkg/controller/plan/handler/openstack"
"github.com/konveyor/forklift-controller/pkg/controller/plan/handler/ova"
"github.com/konveyor/forklift-controller/pkg/controller/plan/handler/ovirt"
"github.com/konveyor/forklift-controller/pkg/controller/plan/handler/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
Expand Down Expand Up @@ -47,6 +48,11 @@ func New(
client,
channel,
provider)
case api.Ova:
h, err = ova.New(
client,
channel,
provider)
default:
err = liberr.New("provider not supported.")
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/plan/handler/ova/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "ova",
srcs = [
"doc.go",
"handler.go",
],
importpath = "github.com/konveyor/forklift-controller/pkg/controller/plan/handler/ova",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/provider/web/ova",
"//pkg/controller/watch/handler",
"//pkg/lib/error",
"//pkg/lib/inventory/web",
"//pkg/lib/logging",
"//vendor/golang.org/x/net/context",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
"//vendor/sigs.k8s.io/controller-runtime/pkg/event",
],
)
Loading

0 comments on commit f9b2897

Please sign in to comment.