-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Adding initiall support for OVA migration
Signed-off-by: Bella Khizgiyaev <[email protected]>
- Loading branch information
Showing
50 changed files
with
3,688 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
Oops, something went wrong.