Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/controller/evacuation"
"github.com/deckhouse/virtualization-controller/pkg/controller/indexer"
"github.com/deckhouse/virtualization-controller/pkg/controller/livemigration"
"github.com/deckhouse/virtualization-controller/pkg/controller/migrationiface"
mc "github.com/deckhouse/virtualization-controller/pkg/controller/moduleconfig"
mcapi "github.com/deckhouse/virtualization-controller/pkg/controller/moduleconfig/api"
"github.com/deckhouse/virtualization-controller/pkg/controller/nodeusbdevice"
Expand Down Expand Up @@ -96,6 +97,8 @@ const (

SdnEnabledEnv = "SDN_ENABLED"
clusterUUIDEnv = "CLUSTER_UUID"

migrationSystemNetworkNameEnv = "MIGRATION_SYSTEM_NETWORK_NAME"
)

func main() {
Expand Down Expand Up @@ -390,6 +393,12 @@ func main() {
os.Exit(1)
}

migrationIfaceLogger := logger.NewControllerLogger(migrationiface.ControllerName, logLevel, logOutput, logDebugVerbosity, logDebugControllerList)
if _, err = migrationiface.NewController(ctx, mgr, migrationIfaceLogger, os.Getenv(migrationSystemNetworkNameEnv)); err != nil {
log.Error(err.Error())
os.Exit(1)
}

resourceSliceLogger := logger.NewControllerLogger(resourceslice.ControllerName, logLevel, logOutput, logDebugVerbosity, logDebugControllerList)
if _, err = resourceslice.NewController(ctx, mgr, resourceSliceLogger); err != nil {
log.Error(err.Error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ const (
// AnnNetworksStatus is the annotation for view current network configuration into Pod.
AnnNetworksStatus = "network.deckhouse.io/networks-status"

// AnnMigrationIface names the kernel interface that virt-handler binds
// live-migration traffic to. Written on Nodes by the migrationiface
// controller from a SystemNetwork CR (sdn module); read by virt-handler
// on startup.
AnnMigrationIface = AnnAPIGroupV + "/migration-iface"

// AnnVirtualDiskOriginalAnnotations is the annotation for storing original VirtualDisk annotations.
AnnVirtualDiskOriginalAnnotations = AnnAPIGroupV + "/vd-original-annotations"
// AnnVirtualDiskOriginalLabels is the annotation for storing original VirtualDisk labels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const (

IndexFieldResourceSliceByPoolName = "spec.pool.name"
IndexFieldResourceSliceByDriver = "spec.driver"

IndexFieldSNNNIAByNodeName = "snnnia.status.nodeName"
IndexFieldSNNNIABySystemNetworkName = "snnnia.spec.systemNetworkName"
)

var IndexGetters = []IndexGetter{
Expand Down Expand Up @@ -114,6 +117,11 @@ var IndexGettersUSB = []IndexGetter{
IndexResourceSliceByDriver,
}

var IndexGettersSDN = []IndexGetter{
IndexSNNNIAByNodeName,
IndexSNNNIABySystemNetworkName,
}

type IndexGetter func() (obj client.Object, field string, extractValue client.IndexerFunc)

func IndexALL(ctx context.Context, mgr manager.Manager) error {
Expand All @@ -126,6 +134,15 @@ func IndexALL(ctx context.Context, mgr manager.Manager) error {
}
}

if featuregates.Default().Enabled(featuregates.SDN) {
for _, fn := range IndexGettersSDN {
obj, field, indexFunc := fn()
if err := mgr.GetFieldIndexer().IndexField(ctx, obj, field, indexFunc); err != nil {
return err
}
}
}

for _, fn := range IndexGetters {
obj, field, indexFunc := fn()
if err := mgr.GetFieldIndexer().IndexField(ctx, obj, field, indexFunc); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2026 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package indexer

import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var snnniaGVK = schema.GroupVersionKind{
Group: "network.deckhouse.io",
Version: "v1alpha1",
Kind: "SystemNetworkNodeNetworkInterfaceAttachment",
}

func snnniaSeed() client.Object {
u := &unstructured.Unstructured{}
u.SetGroupVersionKind(snnniaGVK)
return u
}

func snnniaIndexer(path ...string) client.IndexerFunc {
return func(o client.Object) []string {
u, ok := o.(*unstructured.Unstructured)
if !ok || u == nil {
return nil
}
v, _, _ := unstructured.NestedString(u.Object, path...)
if v == "" {
return nil
}
return []string{v}
}
}

func IndexSNNNIAByNodeName() (client.Object, string, client.IndexerFunc) {
return snnniaSeed(), IndexFieldSNNNIAByNodeName, snnniaIndexer("status", "nodeName")
}

func IndexSNNNIABySystemNetworkName() (client.Object, string, client.IndexerFunc) {
return snnniaSeed(), IndexFieldSNNNIABySystemNetworkName, snnniaIndexer("spec", "systemNetworkName")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2026 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package migrationiface annotates each Node with the kernel interface name
// of a dedicated live-migration network, resolved from sdn's
// SystemNetworkNodeNetworkInterfaceAttachment + NodeNetworkInterface.
// virt-handler reads the annotation (see pkg/common/annotations.AnnMigrationIface)
// at startup to bind migration traffic to that interface.
package migrationiface

import (
"context"
"time"

"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/deckhouse/deckhouse/pkg/log"
"github.com/deckhouse/virtualization-controller/pkg/featuregates"
"github.com/deckhouse/virtualization-controller/pkg/logger"
)

const ControllerName = "migrationiface-controller"

func NewController(
ctx context.Context,
mgr manager.Manager,
log *log.Logger,
systemNetworkName string,
) (controller.Controller, error) {
if !featuregates.Default().Enabled(featuregates.SDN) {
log.Info("SDN feature gate is disabled, migrationiface controller is disabled")
return nil, nil
}
if systemNetworkName == "" {
log.Info("MIGRATION_SYSTEM_NETWORK_NAME is empty, migrationiface controller is disabled")
return nil, nil
}

r := NewReconciler(mgr.GetClient(), systemNetworkName, log)

c, err := controller.New(ControllerName, mgr, controller.Options{
Reconciler: r,
RecoverPanic: ptr.To(true),
LogConstructor: logger.NewConstructor(log),
CacheSyncTimeout: 10 * time.Minute,
})
if err != nil {
return nil, err
}

if err = r.SetupController(ctx, mgr, c); err != nil {
return nil, err
}

log.Info("Initialized migrationiface controller", "systemNetwork", systemNetworkName)
return c, nil
}
Loading
Loading