diff --git a/api/v1alpha/networkinterface_schema_test.go b/api/v1alpha/networkinterface_schema_test.go
new file mode 100644
index 00000000..6394a255
--- /dev/null
+++ b/api/v1alpha/networkinterface_schema_test.go
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+
+package v1alpha_test
+
+import (
+ "context"
+ "fmt"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ networkingv1alpha "go.datum.net/network-services-operator/api/v1alpha"
+)
+
+func physicalInterfaceSpec() networkingv1alpha.NetworkInterfaceSpec {
+ return networkingv1alpha.NetworkInterfaceSpec{
+ Network: networkingv1alpha.LocalNetworkRef{Name: "app"},
+ AttachmentMode: networkingv1alpha.NetworkInterfaceAttachmentModePhysical,
+ AttachmentPoint: &networkingv1alpha.NetworkInterfaceAttachmentPoint{
+ MACAddress: "00:00:5e:00:53:01",
+ Switch: "rack-a1-tor-1",
+ Port: "Ethernet1/12",
+ },
+ }
+}
+
+func TestPhysicalInterfaceAdmission(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaces")
+ ctx := context.Background()
+
+ tests := []struct {
+ name string
+ mutate func(*networkingv1alpha.NetworkInterfaceSpec)
+ valid bool
+ }{
+ {name: "physical with an attachment point", valid: true},
+ {name: "boot purpose and private isolation", valid: true, mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationPrivate
+ }},
+ {name: "physical without an attachment point", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.AttachmentPoint = nil
+ }},
+ {name: "attachment point on the default mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.AttachmentMode = ""
+ }},
+ {name: "purpose on another mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.AttachmentMode = networkingv1alpha.NetworkInterfaceAttachmentModeNetns
+ spec.AttachmentPoint = nil
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ }},
+ {name: "isolation on another mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.AttachmentMode = networkingv1alpha.NetworkInterfaceAttachmentModeHypervisor
+ spec.AttachmentPoint = nil
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationShared
+ }},
+ }
+
+ for i, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ iface := &networkingv1alpha.NetworkInterface{
+ ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("create-%d", i), Namespace: "default"},
+ Spec: physicalInterfaceSpec(),
+ }
+ if tt.mutate != nil {
+ tt.mutate(&iface.Spec)
+ }
+ err := k8sClient.Create(ctx, iface)
+ if tt.valid {
+ require.NoError(t, err)
+ return
+ }
+ require.Error(t, err)
+ })
+ }
+}
+
+func TestPhysicalInterfaceFieldsAreImmutable(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaces")
+ ctx := context.Background()
+
+ tests := []struct {
+ name string
+ mutate func(*networkingv1alpha.NetworkInterfaceSpec)
+ }{
+ {name: "change the port", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.AttachmentPoint.Port = "Ethernet1/13"
+ }},
+ {name: "set the purpose", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ }},
+ {name: "set the isolation", mutate: func(spec *networkingv1alpha.NetworkInterfaceSpec) {
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationPrivate
+ }},
+ }
+
+ for i, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ iface := &networkingv1alpha.NetworkInterface{
+ ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("update-%d", i), Namespace: "default"},
+ Spec: physicalInterfaceSpec(),
+ }
+ require.NoError(t, k8sClient.Create(ctx, iface))
+
+ tt.mutate(&iface.Spec)
+ require.Error(t, k8sClient.Update(ctx, iface))
+ })
+ }
+}
+
+// The operator changes an existing interface's MTU, claim and mode, so the new
+// rules must leave interfaces that carry none of the physical fields alone.
+func TestExistingInterfacesStillUpdate(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaces")
+ ctx := context.Background()
+
+ iface := &networkingv1alpha.NetworkInterface{
+ ObjectMeta: metav1.ObjectMeta{Name: "existing", Namespace: "default"},
+ Spec: networkingv1alpha.NetworkInterfaceSpec{Network: networkingv1alpha.LocalNetworkRef{Name: "app"}},
+ }
+ require.NoError(t, k8sClient.Create(ctx, iface))
+
+ iface.Spec.MTU = 1400
+ iface.Spec.AttachmentMode = networkingv1alpha.NetworkInterfaceAttachmentModeHypervisor
+ iface.Spec.ClaimRef = &networkingv1alpha.NetworkInterfaceClaimRef{Name: "web-0-eth0"}
+ require.NoError(t, k8sClient.Update(ctx, iface))
+}
diff --git a/api/v1alpha/networkinterface_types.go b/api/v1alpha/networkinterface_types.go
index 0e7aa774..aec67817 100644
--- a/api/v1alpha/networkinterface_types.go
+++ b/api/v1alpha/networkinterface_types.go
@@ -37,7 +37,7 @@ const (
// by the consumer, carried by the operator, and acted on by whoever realizes
// the interface.
//
-// +kubebuilder:validation:Enum=Netns;Hypervisor;HypervisorDeclared
+// +kubebuilder:validation:Enum=Netns;Hypervisor;HypervisorDeclared;Physical
type NetworkInterfaceAttachmentMode string
const (
@@ -58,6 +58,69 @@ const (
// hypervisor directly. A guest whose hypervisor reads no node state needs
// this mode.
NetworkInterfaceAttachmentModeHypervisorDeclared NetworkInterfaceAttachmentMode = "HypervisorDeclared"
+
+ // NetworkInterfaceAttachmentModePhysical means the interface is a physical
+ // NIC that reaches its network through the switch port it is cabled to.
+ // There is no node, container or hypervisor, and the claim names the port
+ // in its attachment point.
+ NetworkInterfaceAttachmentModePhysical NetworkInterfaceAttachmentMode = "Physical"
+)
+
+// NetworkInterfaceAttachmentPoint names the physical NIC and the switch port it
+// is cabled to. The provider that writes the claim reads it from its own
+// inventory, and the operator copies it without checking it.
+type NetworkInterfaceAttachmentPoint struct {
+ // macAddress is the NIC's MAC address, as six colon-separated hexadecimal
+ // pairs.
+ //
+ // +kubebuilder:validation:Required
+ // +kubebuilder:validation:Pattern=`^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$`
+ MACAddress string `json:"macAddress"`
+
+ // switch is the switch the NIC is cabled to, in the name network operations
+ // uses for it.
+ //
+ // +kubebuilder:validation:Required
+ // +kubebuilder:validation:MinLength=1
+ // +kubebuilder:validation:MaxLength=253
+ Switch string `json:"switch"`
+
+ // port is the switch port the NIC is cabled to, in the name network
+ // operations uses for it. It may hold characters a Kubernetes name cannot,
+ // such as the slash in Ethernet1/12.
+ //
+ // +kubebuilder:validation:Required
+ // +kubebuilder:validation:MinLength=1
+ // +kubebuilder:validation:MaxLength=253
+ Port string `json:"port"`
+}
+
+// NetworkInterfacePurpose sets what a physical claim is for.
+//
+// +kubebuilder:validation:Enum=Boot
+type NetworkInterfacePurpose string
+
+const (
+ // NetworkInterfacePurposeBoot marks a claim that attaches its port to a
+ // boot network for as long as the claim exists, ahead of any other claim on
+ // the port.
+ NetworkInterfacePurposeBoot NetworkInterfacePurpose = "Boot"
+)
+
+// NetworkInterfaceIsolation sets whether a physical port shares its network's
+// segment with the network's other members.
+//
+// +kubebuilder:validation:Enum=Private;Shared
+type NetworkInterfaceIsolation string
+
+const (
+ // NetworkInterfaceIsolationPrivate puts the port in a segment of its own on
+ // the network, reaching the network's gateway and no other member.
+ NetworkInterfaceIsolationPrivate NetworkInterfaceIsolation = "Private"
+
+ // NetworkInterfaceIsolationShared puts the port in the network's shared
+ // segment, reaching every other member.
+ NetworkInterfaceIsolationShared NetworkInterfaceIsolation = "Shared"
)
// NetworkInterfacePhase reports whether an interface is held by a claim.
@@ -303,6 +366,13 @@ type NetworkInterfaceAttachmentRef struct {
// NetworkInterfaceSpec defines the desired state of NetworkInterface. It is
// written by the operator when a claim is fulfilled, and it carries everything
// a provider needs to configure a NIC without reading any other resource.
+//
+// +kubebuilder:validation:XValidation:message="attachmentPoint is immutable and cannot be set, changed, or cleared after creation",rule="has(self.attachmentPoint) == has(oldSelf.attachmentPoint) && (!has(self.attachmentPoint) || self.attachmentPoint == oldSelf.attachmentPoint)"
+// +kubebuilder:validation:XValidation:message="purpose is immutable and cannot be set, changed, or cleared after creation",rule="has(self.purpose) == has(oldSelf.purpose) && (!has(self.purpose) || self.purpose == oldSelf.purpose)"
+// +kubebuilder:validation:XValidation:message="isolation is immutable and cannot be set, changed, or cleared after creation",rule="has(self.isolation) == has(oldSelf.isolation) && (!has(self.isolation) || self.isolation == oldSelf.isolation)"
+// +kubebuilder:validation:XValidation:message="attachmentPoint is required for attachmentMode Physical and not allowed for any other mode",rule="has(self.attachmentPoint) == (has(self.attachmentMode) && self.attachmentMode == 'Physical')"
+// +kubebuilder:validation:XValidation:message="purpose is only allowed for attachmentMode Physical",rule="!has(self.purpose) || (has(self.attachmentMode) && self.attachmentMode == 'Physical')"
+// +kubebuilder:validation:XValidation:message="isolation is only allowed for attachmentMode Physical",rule="!has(self.isolation) || (has(self.attachmentMode) && self.attachmentMode == 'Physical')"
type NetworkInterfaceSpec struct {
// network is the network this interface belongs to, in the same namespace as
// the interface. It comes from the claim and does not change.
@@ -339,6 +409,25 @@ type NetworkInterfaceSpec struct {
// +kubebuilder:default="Netns"
AttachmentMode NetworkInterfaceAttachmentMode `json:"attachmentMode,omitempty"`
+ // attachmentPoint is the physical NIC and switch port a Physical interface
+ // reaches its network through. It comes from the claim and is absent for
+ // every other mode.
+ //
+ // +kubebuilder:validation:Optional
+ AttachmentPoint *NetworkInterfaceAttachmentPoint `json:"attachmentPoint,omitempty"`
+
+ // purpose is what a Physical interface is for. It comes from the claim.
+ //
+ // +kubebuilder:validation:Optional
+ Purpose NetworkInterfacePurpose `json:"purpose,omitempty"`
+
+ // isolation is whether a Physical interface's port shares its network's
+ // segment. It comes from the claim. Left unset, a boot interface is private
+ // and any other is shared.
+ //
+ // +kubebuilder:validation:Optional
+ Isolation NetworkInterfaceIsolation `json:"isolation,omitempty"`
+
// mtu is the MTU, in bytes, the interface must be configured with. It is
// resolved from the network, so a provider never has to read the network to
// configure the NIC.
diff --git a/api/v1alpha/networkinterfaceclaim_schema_test.go b/api/v1alpha/networkinterfaceclaim_schema_test.go
new file mode 100644
index 00000000..cc788ae7
--- /dev/null
+++ b/api/v1alpha/networkinterfaceclaim_schema_test.go
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+
+package v1alpha_test
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/runtime"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+ "sigs.k8s.io/controller-runtime/pkg/envtest"
+ "sigs.k8s.io/yaml"
+
+ networkingv1alpha "go.datum.net/network-services-operator/api/v1alpha"
+)
+
+func startSchemaEnv(t *testing.T, crdName string) client.Client {
+ t.Helper()
+ if os.Getenv("KUBEBUILDER_ASSETS") == "" {
+ t.Skip("envtest assets are required")
+ }
+
+ data, err := os.ReadFile(filepath.Join("..", "..", "config", "crd", "bases", "networking.datumapis.com_"+crdName+".yaml"))
+ require.NoError(t, err)
+ var crd apiextensionsv1.CustomResourceDefinition
+ require.NoError(t, yaml.Unmarshal(data, &crd))
+
+ env := &envtest.Environment{CRDs: []*apiextensionsv1.CustomResourceDefinition{&crd}}
+ cfg, err := env.Start()
+ require.NoError(t, err)
+ t.Cleanup(func() { require.NoError(t, env.Stop()) })
+
+ scheme := runtime.NewScheme()
+ require.NoError(t, networkingv1alpha.AddToScheme(scheme))
+ k8sClient, err := client.New(cfg, client.Options{Scheme: scheme})
+ require.NoError(t, err)
+ return k8sClient
+}
+
+func physicalClaimSpec() networkingv1alpha.NetworkInterfaceClaimSpec {
+ return networkingv1alpha.NetworkInterfaceClaimSpec{
+ Network: networkingv1alpha.LocalNetworkRef{Name: "app"},
+ AttachmentMode: networkingv1alpha.NetworkInterfaceAttachmentModePhysical,
+ AttachmentPoint: &networkingv1alpha.NetworkInterfaceAttachmentPoint{
+ MACAddress: "00:00:5e:00:53:01",
+ Switch: "rack-a1-tor-1",
+ Port: "Ethernet1/12",
+ },
+ }
+}
+
+func TestPhysicalClaimAdmission(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaceclaims")
+ ctx := context.Background()
+
+ tests := []struct {
+ name string
+ mutate func(*networkingv1alpha.NetworkInterfaceClaimSpec)
+ valid bool
+ }{
+ {name: "physical with an attachment point", valid: true},
+ {name: "boot purpose and private isolation", valid: true, mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationPrivate
+ }},
+ {name: "shared isolation", valid: true, mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationShared
+ }},
+ {name: "upper-case MAC address", valid: true, mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.MACAddress = "00:00:5E:00:53:0A"
+ }},
+ {name: "physical without an attachment point", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint = nil
+ }},
+ {name: "attachment point on another mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentMode = networkingv1alpha.NetworkInterfaceAttachmentModeHypervisor
+ }},
+ {name: "attachment point on the default mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentMode = ""
+ }},
+ {name: "purpose on another mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentMode = networkingv1alpha.NetworkInterfaceAttachmentModeNetns
+ spec.AttachmentPoint = nil
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ }},
+ {name: "isolation on another mode", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentMode = networkingv1alpha.NetworkInterfaceAttachmentModeNetns
+ spec.AttachmentPoint = nil
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationPrivate
+ }},
+ {name: "unknown purpose", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Purpose = "Install"
+ }},
+ {name: "unknown isolation", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = "Isolated"
+ }},
+ {name: "MAC address with five pairs", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.MACAddress = "00:00:5e:00:53"
+ }},
+ {name: "MAC address with dashes", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.MACAddress = "00-00-5e-00-53-01"
+ }},
+ {name: "empty switch", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.Switch = ""
+ }},
+ {name: "empty port", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.Port = ""
+ }},
+ }
+
+ for i, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ claim := &networkingv1alpha.NetworkInterfaceClaim{
+ ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("create-%d", i), Namespace: "default"},
+ Spec: physicalClaimSpec(),
+ }
+ if tt.mutate != nil {
+ tt.mutate(&claim.Spec)
+ }
+ err := k8sClient.Create(ctx, claim)
+ if tt.valid {
+ require.NoError(t, err)
+ return
+ }
+ require.Error(t, err)
+ })
+ }
+}
+
+func TestPhysicalClaimFieldsAreImmutable(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaceclaims")
+ ctx := context.Background()
+
+ tests := []struct {
+ name string
+ start func(*networkingv1alpha.NetworkInterfaceClaimSpec)
+ mutate func(*networkingv1alpha.NetworkInterfaceClaimSpec)
+ }{
+ {name: "change the port", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.Port = "Ethernet1/13"
+ }},
+ {name: "change the MAC address", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.AttachmentPoint.MACAddress = "00:00:5e:00:53:02"
+ }},
+ {name: "set the purpose", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ }},
+ {name: "clear the purpose", start: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Purpose = networkingv1alpha.NetworkInterfacePurposeBoot
+ }, mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Purpose = ""
+ }},
+ {name: "set the isolation", mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationShared
+ }},
+ {name: "change the isolation", start: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationPrivate
+ }, mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationShared
+ }},
+ {name: "clear the isolation", start: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = networkingv1alpha.NetworkInterfaceIsolationPrivate
+ }, mutate: func(spec *networkingv1alpha.NetworkInterfaceClaimSpec) {
+ spec.Isolation = ""
+ }},
+ }
+
+ for i, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ claim := &networkingv1alpha.NetworkInterfaceClaim{
+ ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("update-%d", i), Namespace: "default"},
+ Spec: physicalClaimSpec(),
+ }
+ if tt.start != nil {
+ tt.start(&claim.Spec)
+ }
+ require.NoError(t, k8sClient.Create(ctx, claim))
+
+ tt.mutate(&claim.Spec)
+ require.Error(t, k8sClient.Update(ctx, claim))
+ })
+ }
+}
+
+// A provider compares the claim it reads back with the claim it wrote, so a
+// default written by the server would read as a conflict.
+func TestPhysicalClaimFieldsHaveNoServerDefaults(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaceclaims")
+ ctx := context.Background()
+
+ for name, spec := range map[string]networkingv1alpha.NetworkInterfaceClaimSpec{
+ "physical": physicalClaimSpec(),
+ "netns": {Network: networkingv1alpha.LocalNetworkRef{Name: "app"}},
+ } {
+ t.Run(name, func(t *testing.T) {
+ claim := &networkingv1alpha.NetworkInterfaceClaim{
+ ObjectMeta: metav1.ObjectMeta{Name: "defaults-" + name, Namespace: "default"},
+ Spec: spec,
+ }
+ require.NoError(t, k8sClient.Create(ctx, claim))
+
+ var stored networkingv1alpha.NetworkInterfaceClaim
+ require.NoError(t, k8sClient.Get(ctx, client.ObjectKeyFromObject(claim), &stored))
+ require.Empty(t, stored.Spec.Purpose)
+ require.Empty(t, stored.Spec.Isolation)
+ require.Equal(t, spec.AttachmentPoint, stored.Spec.AttachmentPoint)
+ })
+ }
+}
+
+// Claims stored before the physical fields existed carry none of them, and
+// must still accept the updates the operator and compute make.
+func TestExistingClaimsStillUpdate(t *testing.T) {
+ k8sClient := startSchemaEnv(t, "networkinterfaceclaims")
+ ctx := context.Background()
+
+ claim := &networkingv1alpha.NetworkInterfaceClaim{
+ ObjectMeta: metav1.ObjectMeta{Name: "existing", Namespace: "default"},
+ Spec: networkingv1alpha.NetworkInterfaceClaimSpec{Network: networkingv1alpha.LocalNetworkRef{Name: "app"}},
+ }
+ require.NoError(t, k8sClient.Create(ctx, claim))
+
+ claim.Labels = map[string]string{"example.com/touched": "true"}
+ claim.Spec.Egress = &networkingv1alpha.NetworkInterfaceClaimEgress{
+ Internet: &networkingv1alpha.NetworkInterfaceClaimInternetEgress{Mode: networkingv1alpha.NetworkInterfaceClaimInternetEgressInherit},
+ }
+ require.NoError(t, k8sClient.Update(ctx, claim))
+}
diff --git a/api/v1alpha/networkinterfaceclaim_types.go b/api/v1alpha/networkinterfaceclaim_types.go
index 954fd7d5..d0a9b48d 100644
--- a/api/v1alpha/networkinterfaceclaim_types.go
+++ b/api/v1alpha/networkinterfaceclaim_types.go
@@ -77,6 +77,11 @@ const (
// The platform provisions it with the project, so its absence says the
// control plane is not bootstrapped rather than that it is slow to appear.
NetworkInterfaceClaimReasonProjectNamespaceNotFound = "ProjectNamespaceNotFound"
+
+ // NetworkInterfaceClaimReasonPhysicalAttachmentUnsupported means the claim
+ // asks for a physical attachment, which this operator does not bind yet.
+ // Nothing is allocated for it.
+ NetworkInterfaceClaimReasonPhysicalAttachmentUnsupported = "PhysicalAttachmentUnsupported"
)
// NetworkInterfaceAddressRequest asks for one address beyond the ones the
@@ -106,6 +111,12 @@ type NetworkInterfaceAddressRequest struct {
//
// +kubebuilder:validation:XValidation:message="networkInterfaceName is immutable and cannot be set, changed, or cleared after creation",rule="has(self.networkInterfaceName) == has(oldSelf.networkInterfaceName) && (!has(self.networkInterfaceName) || self.networkInterfaceName == oldSelf.networkInterfaceName)"
// +kubebuilder:validation:XValidation:message="addresses is immutable and cannot be set, changed, or cleared after creation",rule="has(self.addresses) == has(oldSelf.addresses) && (!has(self.addresses) || self.addresses == oldSelf.addresses)"
+// +kubebuilder:validation:XValidation:message="attachmentPoint is immutable and cannot be set, changed, or cleared after creation",rule="has(self.attachmentPoint) == has(oldSelf.attachmentPoint) && (!has(self.attachmentPoint) || self.attachmentPoint == oldSelf.attachmentPoint)"
+// +kubebuilder:validation:XValidation:message="purpose is immutable and cannot be set, changed, or cleared after creation",rule="has(self.purpose) == has(oldSelf.purpose) && (!has(self.purpose) || self.purpose == oldSelf.purpose)"
+// +kubebuilder:validation:XValidation:message="isolation is immutable and cannot be set, changed, or cleared after creation",rule="has(self.isolation) == has(oldSelf.isolation) && (!has(self.isolation) || self.isolation == oldSelf.isolation)"
+// +kubebuilder:validation:XValidation:message="attachmentPoint is required for attachmentMode Physical and not allowed for any other mode",rule="has(self.attachmentPoint) == (has(self.attachmentMode) && self.attachmentMode == 'Physical')"
+// +kubebuilder:validation:XValidation:message="purpose is only allowed for attachmentMode Physical",rule="!has(self.purpose) || (has(self.attachmentMode) && self.attachmentMode == 'Physical')"
+// +kubebuilder:validation:XValidation:message="isolation is only allowed for attachmentMode Physical",rule="!has(self.isolation) || (has(self.attachmentMode) && self.attachmentMode == 'Physical')"
type NetworkInterfaceClaimSpec struct {
// network is the network the interface attaches to. The network must already
// exist in the same namespace as the claim.
@@ -137,6 +148,8 @@ type NetworkInterfaceClaimSpec struct {
// virtual machine or microVM guest needs. HypervisorDeclared also hands it
// to a hypervisor, and additionally has the realizer state the device to
// that hypervisor instead of letting it discover the device from the node.
+ // Physical is a physical NIC that reaches its network through the switch
+ // port named in attachmentPoint.
//
// It is copied to the bound interface and never interpreted here. Whoever
// realizes the interface decides what each mode means on its data plane.
@@ -148,6 +161,37 @@ type NetworkInterfaceClaimSpec struct {
// +kubebuilder:validation:XValidation:message="attachmentMode is immutable and cannot be changed after creation",rule="self == oldSelf"
AttachmentMode NetworkInterfaceAttachmentMode `json:"attachmentMode,omitempty"`
+ // attachmentPoint is the physical NIC and the switch port it is cabled to.
+ // It is required for attachmentMode Physical and not allowed for any other
+ // mode. It is copied to the bound interface and never checked against any
+ // inventory, so only a provider writes it.
+ //
+ // Immutable. A server recabled to another port needs a new claim.
+ //
+ // +kubebuilder:validation:Optional
+ AttachmentPoint *NetworkInterfaceAttachmentPoint `json:"attachmentPoint,omitempty"`
+
+ // purpose is what a Physical claim is for. Boot attaches the port to a
+ // boot network for as long as the claim exists, ahead of any other claim on
+ // the port. Left unset, the claim attaches the port to its network whenever
+ // no boot claim names the port.
+ //
+ // Only allowed for attachmentMode Physical. Immutable.
+ //
+ // +kubebuilder:validation:Optional
+ Purpose NetworkInterfacePurpose `json:"purpose,omitempty"`
+
+ // isolation is whether a Physical claim's port shares its network's segment
+ // with the network's other members. Private gives the port a segment of its
+ // own that reaches only the network's gateway. Shared joins the network's
+ // shared segment. Left unset, a boot claim is private and any other claim is
+ // shared; nothing is written back to the claim.
+ //
+ // Only allowed for attachmentMode Physical. Immutable.
+ //
+ // +kubebuilder:validation:Optional
+ Isolation NetworkInterfaceIsolation `json:"isolation,omitempty"`
+
// ipFamilies are the address families the interface must carry, in priority
// order. List [IPv6, IPv4] for a dual-stack interface. The first family
// listed holds the interface's primary address, which is the one reported in
diff --git a/api/v1alpha/zz_generated.deepcopy.go b/api/v1alpha/zz_generated.deepcopy.go
index 77bca37a..4941bc39 100644
--- a/api/v1alpha/zz_generated.deepcopy.go
+++ b/api/v1alpha/zz_generated.deepcopy.go
@@ -1598,6 +1598,21 @@ func (in *NetworkInterfaceAddressRequest) DeepCopy() *NetworkInterfaceAddressReq
return out
}
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *NetworkInterfaceAttachmentPoint) DeepCopyInto(out *NetworkInterfaceAttachmentPoint) {
+ *out = *in
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkInterfaceAttachmentPoint.
+func (in *NetworkInterfaceAttachmentPoint) DeepCopy() *NetworkInterfaceAttachmentPoint {
+ if in == nil {
+ return nil
+ }
+ out := new(NetworkInterfaceAttachmentPoint)
+ in.DeepCopyInto(out)
+ return out
+}
+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NetworkInterfaceAttachmentRef) DeepCopyInto(out *NetworkInterfaceAttachmentRef) {
*out = *in
@@ -1726,6 +1741,11 @@ func (in *NetworkInterfaceClaimRef) DeepCopy() *NetworkInterfaceClaimRef {
func (in *NetworkInterfaceClaimSpec) DeepCopyInto(out *NetworkInterfaceClaimSpec) {
*out = *in
out.Network = in.Network
+ if in.AttachmentPoint != nil {
+ in, out := &in.AttachmentPoint, &out.AttachmentPoint
+ *out = new(NetworkInterfaceAttachmentPoint)
+ **out = **in
+ }
if in.IPFamilies != nil {
in, out := &in.IPFamilies, &out.IPFamilies
*out = make([]IPFamily, len(*in))
@@ -1898,6 +1918,11 @@ func (in *NetworkInterfaceSpec) DeepCopyInto(out *NetworkInterfaceSpec) {
*out = new(NetworkInterfaceClaimRef)
**out = **in
}
+ if in.AttachmentPoint != nil {
+ in, out := &in.AttachmentPoint, &out.AttachmentPoint
+ *out = new(NetworkInterfaceAttachmentPoint)
+ **out = **in
+ }
if in.Addresses != nil {
in, out := &in.Addresses, &out.Addresses
*out = make([]NetworkInterfaceAddress, len(*in))
diff --git a/config/crd/bases/networking.datumapis.com_networkinterfaceclaims.yaml b/config/crd/bases/networking.datumapis.com_networkinterfaceclaims.yaml
index 44d659b8..50d20720 100644
--- a/config/crd/bases/networking.datumapis.com_networkinterfaceclaims.yaml
+++ b/config/crd/bases/networking.datumapis.com_networkinterfaceclaims.yaml
@@ -117,6 +117,8 @@ spec:
virtual machine or microVM guest needs. HypervisorDeclared also hands it
to a hypervisor, and additionally has the realizer state the device to
that hypervisor instead of letting it discover the device from the node.
+ Physical is a physical NIC that reaches its network through the switch
+ port named in attachmentPoint.
It is copied to the bound interface and never interpreted here. Whoever
realizes the interface decides what each mode means on its data plane.
@@ -126,11 +128,47 @@ spec:
- Netns
- Hypervisor
- HypervisorDeclared
+ - Physical
type: string
x-kubernetes-validations:
- message: attachmentMode is immutable and cannot be changed after
creation
rule: self == oldSelf
+ attachmentPoint:
+ description: |-
+ attachmentPoint is the physical NIC and the switch port it is cabled to.
+ It is required for attachmentMode Physical and not allowed for any other
+ mode. It is copied to the bound interface and never checked against any
+ inventory, so only a provider writes it.
+
+ Immutable. A server recabled to another port needs a new claim.
+ properties:
+ macAddress:
+ description: |-
+ macAddress is the NIC's MAC address, as six colon-separated hexadecimal
+ pairs.
+ pattern: ^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$
+ type: string
+ port:
+ description: |-
+ port is the switch port the NIC is cabled to, in the name network
+ operations uses for it. It may hold characters a Kubernetes name cannot,
+ such as the slash in Ethernet1/12.
+ maxLength: 253
+ minLength: 1
+ type: string
+ switch:
+ description: |-
+ switch is the switch the NIC is cabled to, in the name network operations
+ uses for it.
+ maxLength: 253
+ minLength: 1
+ type: string
+ required:
+ - macAddress
+ - port
+ - switch
+ type: object
egress:
default:
internet:
@@ -205,6 +243,19 @@ spec:
rule: self.all(f, self.exists_one(g, g == f))
- message: ipFamilies is immutable and cannot be changed after creation
rule: self == oldSelf
+ isolation:
+ description: |-
+ isolation is whether a Physical claim's port shares its network's segment
+ with the network's other members. Private gives the port a segment of its
+ own that reaches only the network's gateway. Shared joins the network's
+ shared segment. Left unset, a boot claim is private and any other claim is
+ shared; nothing is written back to the claim.
+
+ Only allowed for attachmentMode Physical. Immutable.
+ enum:
+ - Private
+ - Shared
+ type: string
network:
description: |-
network is the network the interface attaches to. The network must already
@@ -238,6 +289,17 @@ spec:
maxLength: 253
minLength: 1
type: string
+ purpose:
+ description: |-
+ purpose is what a Physical claim is for. Boot attaches the port to a
+ boot network for as long as the claim exists, ahead of any other claim on
+ the port. Left unset, the claim attaches the port to its network whenever
+ no boot claim names the port.
+
+ Only allowed for attachmentMode Physical. Immutable.
+ enum:
+ - Boot
+ type: string
reclaimPolicy:
default: Delete
description: |-
@@ -282,6 +344,28 @@ spec:
after creation
rule: has(self.addresses) == has(oldSelf.addresses) && (!has(self.addresses)
|| self.addresses == oldSelf.addresses)
+ - message: attachmentPoint is immutable and cannot be set, changed, or
+ cleared after creation
+ rule: has(self.attachmentPoint) == has(oldSelf.attachmentPoint) && (!has(self.attachmentPoint)
+ || self.attachmentPoint == oldSelf.attachmentPoint)
+ - message: purpose is immutable and cannot be set, changed, or cleared
+ after creation
+ rule: has(self.purpose) == has(oldSelf.purpose) && (!has(self.purpose)
+ || self.purpose == oldSelf.purpose)
+ - message: isolation is immutable and cannot be set, changed, or cleared
+ after creation
+ rule: has(self.isolation) == has(oldSelf.isolation) && (!has(self.isolation)
+ || self.isolation == oldSelf.isolation)
+ - message: attachmentPoint is required for attachmentMode Physical and
+ not allowed for any other mode
+ rule: has(self.attachmentPoint) == (has(self.attachmentMode) && self.attachmentMode
+ == 'Physical')
+ - message: purpose is only allowed for attachmentMode Physical
+ rule: '!has(self.purpose) || (has(self.attachmentMode) && self.attachmentMode
+ == ''Physical'')'
+ - message: isolation is only allowed for attachmentMode Physical
+ rule: '!has(self.isolation) || (has(self.attachmentMode) && self.attachmentMode
+ == ''Physical'')'
status:
default:
conditions:
diff --git a/config/crd/bases/networking.datumapis.com_networkinterfaces.yaml b/config/crd/bases/networking.datumapis.com_networkinterfaces.yaml
index dba16ddc..8a306c42 100644
--- a/config/crd/bases/networking.datumapis.com_networkinterfaces.yaml
+++ b/config/crd/bases/networking.datumapis.com_networkinterfaces.yaml
@@ -157,7 +157,40 @@ spec:
- Netns
- Hypervisor
- HypervisorDeclared
+ - Physical
type: string
+ attachmentPoint:
+ description: |-
+ attachmentPoint is the physical NIC and switch port a Physical interface
+ reaches its network through. It comes from the claim and is absent for
+ every other mode.
+ properties:
+ macAddress:
+ description: |-
+ macAddress is the NIC's MAC address, as six colon-separated hexadecimal
+ pairs.
+ pattern: ^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$
+ type: string
+ port:
+ description: |-
+ port is the switch port the NIC is cabled to, in the name network
+ operations uses for it. It may hold characters a Kubernetes name cannot,
+ such as the slash in Ethernet1/12.
+ maxLength: 253
+ minLength: 1
+ type: string
+ switch:
+ description: |-
+ switch is the switch the NIC is cabled to, in the name network operations
+ uses for it.
+ maxLength: 253
+ minLength: 1
+ type: string
+ required:
+ - macAddress
+ - port
+ - switch
+ type: object
claimRef:
description: |-
claimRef is the claim currently holding this interface. It is empty while a
@@ -261,6 +294,15 @@ spec:
maxLength: 15
minLength: 1
type: string
+ isolation:
+ description: |-
+ isolation is whether a Physical interface's port shares its network's
+ segment. It comes from the claim. Left unset, a boot interface is private
+ and any other is shared.
+ enum:
+ - Private
+ - Shared
+ type: string
mtu:
description: |-
mtu is the MTU, in bytes, the interface must be configured with. It is
@@ -284,6 +326,12 @@ spec:
x-kubernetes-validations:
- message: network is immutable and cannot be changed after creation
rule: self == oldSelf
+ purpose:
+ description: purpose is what a Physical interface is for. It comes
+ from the claim.
+ enum:
+ - Boot
+ type: string
reclaimPolicy:
default: Delete
description: |-
@@ -297,6 +345,29 @@ spec:
required:
- network
type: object
+ x-kubernetes-validations:
+ - message: attachmentPoint is immutable and cannot be set, changed, or
+ cleared after creation
+ rule: has(self.attachmentPoint) == has(oldSelf.attachmentPoint) && (!has(self.attachmentPoint)
+ || self.attachmentPoint == oldSelf.attachmentPoint)
+ - message: purpose is immutable and cannot be set, changed, or cleared
+ after creation
+ rule: has(self.purpose) == has(oldSelf.purpose) && (!has(self.purpose)
+ || self.purpose == oldSelf.purpose)
+ - message: isolation is immutable and cannot be set, changed, or cleared
+ after creation
+ rule: has(self.isolation) == has(oldSelf.isolation) && (!has(self.isolation)
+ || self.isolation == oldSelf.isolation)
+ - message: attachmentPoint is required for attachmentMode Physical and
+ not allowed for any other mode
+ rule: has(self.attachmentPoint) == (has(self.attachmentMode) && self.attachmentMode
+ == 'Physical')
+ - message: purpose is only allowed for attachmentMode Physical
+ rule: '!has(self.purpose) || (has(self.attachmentMode) && self.attachmentMode
+ == ''Physical'')'
+ - message: isolation is only allowed for attachmentMode Physical
+ rule: '!has(self.isolation) || (has(self.attachmentMode) && self.attachmentMode
+ == ''Physical'')'
status:
default:
conditions:
diff --git a/docs/api/networkinterfaceclaims.md b/docs/api/networkinterfaceclaims.md
index 9abb41a9..1c70619a 100644
--- a/docs/api/networkinterfaceclaims.md
+++ b/docs/api/networkinterfaceclaims.md
@@ -74,7 +74,7 @@ it. To change one of those fields, delete the claim and create a new one,
accepting that the workload gets new addresses unless the interface is
retained.
- Validations:
| Name | +Type | +Description | +Required | +
|---|---|---|---|
| macAddress | +string | +
+ macAddress is the NIC's MAC address, as six colon-separated hexadecimal
+pairs. + |
+ true | +
| port | +string | +
+ port is the switch port the NIC is cabled to, in the name network
+operations uses for it. It may hold characters a Kubernetes name cannot,
+such as the slash in Ethernet1/12. + |
+ true | +
| switch | +string | +
+ switch is the switch the NIC is cabled to, in the name network operations
+uses for it. + |
+ true | +
| Name | +Type | +Description | +Required | +
|---|---|---|---|
| macAddress | +string | +
+ macAddress is the NIC's MAC address, as six colon-separated hexadecimal
+pairs. + |
+ true | +
| port | +string | +
+ port is the switch port the NIC is cabled to, in the name network
+operations uses for it. It may hold characters a Kubernetes name cannot,
+such as the slash in Ethernet1/12. + |
+ true | +
| switch | +string | +
+ switch is the switch the NIC is cabled to, in the name network operations
+uses for it. + |
+ true | +