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

Revert static ips #908

Merged
merged 9 commits into from
May 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
3 changes: 0 additions & 3 deletions operator/config/crd/bases/forklift.konveyor.io_plans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ spec:
description: Preserve the CPU model and flags the VM runs with in
its oVirt cluster.
type: boolean
preserveStaticIPs:
description: Preserve static IPs of VMs in vSphere (Windows only)
type: boolean
provider:
description: Providers.
properties:
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/forklift/v1beta1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ type PlanSpec struct {
Archived bool `json:"archived,omitempty"`
// Preserve the CPU model and flags the VM runs with in its oVirt cluster.
PreserveClusterCPUModel bool `json:"preserveClusterCpuModel,omitempty"`
// Preserve static IPs of VMs in vSphere (Windows only)
PreserveStaticIPs bool `json:"preserveStaticIPs,omitempty"`
}

// Find a planned VM.
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/plan/adapter/base/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ type Validator interface {
WarmMigration() bool
// Validate that no more than one of a VM's networks is mapped to the pod network.
PodNetwork(vmRef ref.Ref) (bool, error)
// Validate that we have information about static IPs for every virtual NIC
StaticIPs(vmRef ref.Ref) (bool, error)
}

// DestinationClient API.
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller/plan/adapter/ocp/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,3 @@ func (r *Validator) NetworksMapped(vmRef ref.Ref) (ok bool, err error) {
func (r *Validator) DirectStorage(vmRef ref.Ref) (bool, error) {
return true, nil
}

// NO-OP
func (r *Validator) StaticIPs(vmRef ref.Ref) (bool, error) {
return true, nil
}
6 changes: 0 additions & 6 deletions pkg/controller/plan/adapter/openstack/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,3 @@ func (r *Validator) PodNetwork(vmRef ref.Ref) (ok bool, err error) {
func (r *Validator) DirectStorage(vmRef ref.Ref) (bool, error) {
return true, nil
}

// NO-OP
func (r *Validator) StaticIPs(vmRef ref.Ref) (bool, error) {
// the guest operating system is not modified during the migration so static IPs should be preserved
return true, nil
}
5 changes: 0 additions & 5 deletions pkg/controller/plan/adapter/ova/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,3 @@ func (r *Validator) MaintenanceMode(vmRef ref.Ref) (ok bool, err error) {
func (r *Validator) DirectStorage(vmRef ref.Ref) (bool, error) {
return true, nil
}

// NO-OP
func (r *Validator) StaticIPs(vmRef ref.Ref) (bool, error) {
return true, nil
}
6 changes: 0 additions & 6 deletions pkg/controller/plan/adapter/ovirt/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,3 @@ func (r *Validator) MaintenanceMode(_ ref.Ref) (ok bool, err error) {
ok = true
return
}

// NO-OP
func (r *Validator) StaticIPs(vmRef ref.Ref) (bool, error) {
// the guest operating system is not modified during the migration so static IPs should be preserved
return true, nil
}
29 changes: 1 addition & 28 deletions pkg/controller/plan/adapter/vsphere/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "vsphere",
Expand Down Expand Up @@ -43,30 +43,3 @@ go_library(
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
],
)

go_test(
name = "vsphere_test",
srcs = [
"builder_test.go",
"validator_test.go",
"vsphere_suite_test.go",
],
embed = [":vsphere"],
deps = [
"//pkg/apis/forklift/v1beta1",
"//pkg/apis/forklift/v1beta1/plan",
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/context",
"//pkg/controller/provider/model/vsphere",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/vsphere",
"//pkg/lib/logging",
"//vendor/github.com/onsi/ginkgo/v2:ginkgo",
"//vendor/github.com/onsi/gomega",
"//vendor/github.com/vmware/govmomi/vim25/types",
"//vendor/k8s.io/api/apps/v1:apps",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
"//vendor/k8s.io/apimachinery/pkg/runtime",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client/fake",
],
)
31 changes: 1 addition & 30 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const (
DefaultWindows = "win10"
DefaultLinux = "rhel8.1"
Unknown = "unknown"
WindowsPrefix = "win"
)

// Annotations
Expand Down Expand Up @@ -184,11 +183,6 @@ func (r *Builder) PodEnvironment(vmRef ref.Ref, sourceSecret *core.Secret) (env
return
}

macsToIps := ""
if r.Plan.Spec.PreserveStaticIPs {
macsToIps = r.mapMacStaticIps(vm)
}

libvirtURL, fingerprint, err := r.getSourceDetails(vm, sourceSecret)
if err != nil {
return
Expand All @@ -215,32 +209,9 @@ func (r *Builder) PodEnvironment(vmRef ref.Ref, sourceSecret *core.Secret) (env
Value: fingerprint,
},
)
if macsToIps != "" {
env = append(env, core.EnvVar{
Name: "V2V_staticIPs",
Value: macsToIps,
})
}
return
}

func (r *Builder) mapMacStaticIps(vm *model.VM) string {
if !isWindows(vm) {
return ""
}
configurations := []string{}
for _, guestNetwork := range vm.GuestNetworks {
if guestNetwork.Origin == string(types.NetIpConfigInfoIpAddressOriginManual) {
configurations = append(configurations, fmt.Sprintf("%s:ip:%s", guestNetwork.MAC, guestNetwork.IP))
}
}
return strings.Join(configurations, "_")
}

func isWindows(vm *model.VM) bool {
return strings.Contains(vm.GuestID, WindowsPrefix) || strings.Contains(vm.GuestName, WindowsPrefix)
}

func (r *Builder) getSourceDetails(vm *model.VM, sourceSecret *core.Secret) (libvirtURL liburl.URL, fingerprint string, err error) {
host, err := r.host(vm.Host)
if err != nil {
Expand Down Expand Up @@ -729,7 +700,7 @@ func (r *Builder) TemplateLabels(vmRef ref.Ref) (labels map[string]string, err e
os = osMap[vm.GuestID]
} else if strings.Contains(vm.GuestName, "linux") || strings.Contains(vm.GuestName, "rhel") {
os = DefaultLinux
} else if strings.Contains(vm.GuestName, WindowsPrefix) {
} else if strings.Contains(vm.GuestName, "win") {
os = DefaultWindows
} else {
os = Unknown
Expand Down
68 changes: 0 additions & 68 deletions pkg/controller/plan/adapter/vsphere/builder_test.go

This file was deleted.

31 changes: 0 additions & 31 deletions pkg/controller/plan/adapter/vsphere/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,3 @@ func (r *Validator) MaintenanceMode(vmRef ref.Ref) (ok bool, err error) {
func (r *Validator) DirectStorage(vmRef ref.Ref) (bool, error) {
return true, nil
}

// Validate that we have information about static IPs for every virtual NIC
func (r *Validator) StaticIPs(vmRef ref.Ref) (ok bool, err error) {
if !r.plan.Spec.PreserveStaticIPs {
return true, nil
}
vm := &model.Workload{}
err = r.inventory.Find(vm, vmRef)
if err != nil {
err = liberr.Wrap(err, "vm", vmRef)
return
}
if !isWindows(&vm.VM) {
return true, nil
}

for _, nic := range vm.NICs {
found := false
for _, guestNetwork := range vm.GuestNetworks {
if nic.MAC == guestNetwork.MAC {
found = true
break
}
}
if !found {
return
}
}
ok = true
return
}
120 changes: 0 additions & 120 deletions pkg/controller/plan/adapter/vsphere/validator_test.go

This file was deleted.

Loading
Loading