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
10 changes: 10 additions & 0 deletions api/v1alpha/networkinterface_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ type NetworkInterfaceStatus struct {
// +kubebuilder:validation:Optional
VPC string `json:"vpc,omitempty"`

// vlanID is the VLAN a Physical interface's network arrives on at its
// switch port. The physical realizer reports it no later than Prepared, so
// once Prepared is true an absent vlanID means the network arrives
// untagged.
//
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=4094
VLANID *int32 `json:"vlanID,omitempty"`

// conditions report the current state of the interface. Allocated means every
// address is held. Prepared means the data plane is ready for a workload to
// consume it. Programmed means the data plane carries the addresses.
Expand Down
29 changes: 29 additions & 0 deletions api/v1alpha/networkinterfaceclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ const (
// port's SwitchPortHold to see what holds it.
NetworkInterfaceClaimReasonAttachmentPointHeld = "AttachmentPointHeld"

// NetworkInterfaceClaimReasonPortChanging means the physical realizer is
// changing what the claim's switch port carries, so the port is between
// states until the realizer reads it back.
NetworkInterfaceClaimReasonPortChanging = "PortChanging"

// NetworkInterfaceClaimReasonBootAttachmentActive means a boot claim holds
// the claim's switch port, so the port carries the boot network and not
// this claim's network until the boot claim is deleted. The claim keeps
// its addresses meanwhile.
NetworkInterfaceClaimReasonBootAttachmentActive = "BootAttachmentActive"

// NetworkInterfaceClaimReasonPortCarriesNetwork means the switch port
// carries the claim's network, as read back from the switch.
NetworkInterfaceClaimReasonPortCarriesNetwork = "PortCarriesNetwork"

// NetworkInterfaceClaimReasonAttachmentPointAccepted means the physical
// realizer accepted the claim's switch port and can build its segment.
NetworkInterfaceClaimReasonAttachmentPointAccepted = "AttachmentPointAccepted"

// NetworkInterfaceClaimReasonAwaitingDetach means a physical claim is being
// deleted and the realizer has not yet taken its network off the switch
// port, so its addresses stay held.
Expand Down Expand Up @@ -356,6 +375,16 @@ type NetworkInterfaceClaimStatus struct {
// +kubebuilder:validation:Optional
ExternalAddresses []NetworkInterfaceExternalAddress `json:"externalAddresses,omitempty"`

// vlanID is the VLAN a Physical claim's network arrives on at its switch
// port, copied from the bound interface's status by the physical realizer.
// Once Prepared is true an absent vlanID means the network arrives
// untagged.
//
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=4094
VLANID *int32 `json:"vlanID,omitempty"`

// conditions report the current state of the claim. Wait on Ready, which is
// true once the claim is bound, its addresses are allocated, the data plane
// is prepared for a workload, and the data plane carries the addresses.
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,16 @@ spec:
required:
- name
type: object
vlanID:
description: |-
vlanID is the VLAN a Physical claim's network arrives on at its switch
port, copied from the bound interface's status by the physical realizer.
Once Prepared is true an absent vlanID means the network arrives
untagged.
format: int32
maximum: 4094
minimum: 1
type: integer
type: object
required:
- spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@ spec:
- Available
- Bound
type: string
vlanID:
description: |-
vlanID is the VLAN a Physical interface's network arrives on at its
switch port. The physical realizer reports it no later than Prepared, so
once Prepared is true an absent vlanID means the network arrives
untagged.
format: int32
maximum: 4094
minimum: 1
type: integer
vpc:
description: |-
vpc is the base62 identifier of the VPC backing this network in this
Expand Down
14 changes: 14 additions & 0 deletions docs/api/networkinterfaceclaims.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,20 @@ namespace. Read it to reach fields the claim does not repeat, such as the
MTU and the data-plane attachment.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>vlanID</b></td>
<td>integer</td>
<td>
vlanID is the VLAN a Physical claim's network arrives on at its switch
port, copied from the bound interface's status by the physical realizer.
Once Prepared is true an absent vlanID means the network arrives
untagged.<br/>
<br/>
<i>Format</i>: int32<br/>
<i>Minimum</i>: 1<br/>
<i>Maximum</i>: 4094<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down
14 changes: 14 additions & 0 deletions docs/api/networkinterfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,20 @@ addresses with no claim bound.<br/>
<i>Enum</i>: Available, Bound<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>vlanID</b></td>
<td>integer</td>
<td>
vlanID is the VLAN a Physical interface's network arrives on at its
switch port. The physical realizer reports it no later than Prepared, so
once Prepared is true an absent vlanID means the network arrives
untagged.<br/>
<br/>
<i>Format</i>: int32<br/>
<i>Minimum</i>: 1<br/>
<i>Maximum</i>: 4094<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>vpc</b></td>
<td>string</td>
Expand Down
13 changes: 13 additions & 0 deletions internal/cmd/cell/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"go.datum.net/network-services-operator/internal/configwatch"
"go.datum.net/network-services-operator/internal/controller"
galacticcontroller "go.datum.net/network-services-operator/internal/galactic/controller"
"go.datum.net/network-services-operator/internal/physicalrealizer"
)

const leaderElectionID = "6a7d51cc.datumapis.com-cell"
Expand Down Expand Up @@ -364,6 +365,18 @@ func controllerRegistrations(
}},
)
}
if serverConfig.PhysicalRealizer.Enabled {
registrations = append(registrations, namedSetup{physicalrealizer.ControllerName, func() (bool, error) {
setupLog.Error(nil, "THE PHYSICAL REALIZER IS THE SIMULATED TEST REALIZER: no switch is changed, "+
"and every physical claim it reports programmed is fake. Never enable it in a real cell.",
"driver", serverConfig.PhysicalRealizer.Driver)
return true, (&physicalrealizer.Reconciler{
Client: mgr.GetLocalManager().GetClient(),
APIReader: mgr.GetLocalManager().GetAPIReader(),
Driver: physicalrealizer.NewSimulatedSwitch(),
}).SetupWithManager(mgr.GetLocalManager())
}})
}
registrations = append(registrations,
namedSetup{"networkinterfaceclaim", func() (bool, error) {
return true, (&controller.NetworkInterfaceClaimReconciler{
Expand Down
28 changes: 28 additions & 0 deletions internal/cmd/cell/cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,31 @@ func TestInternalDNSDisabledNeedsNoHubOrDNSAPIs(t *testing.T) {
}
t.Fatal("DNS registration not found")
}

func TestThePhysicalRealizerRunsOnlyWhenEnabled(t *testing.T) {
for _, tt := range []struct {
name string
enabled bool
}{
{name: "default"},
{name: "enabled", enabled: true},
} {
t.Run(tt.name, func(t *testing.T) {
cfg := config.CellControllerManager{}
if tt.enabled {
cfg.PhysicalRealizer = config.PhysicalRealizerConfig{
Enabled: true, Driver: config.PhysicalRealizerDriverSimulated,
}
}
registered := slices.ContainsFunc(controllerRegistrations(nil, cfg, nil, nil), func(r namedSetup) bool {
return r.name == "physical-realizer"
})
if registered != tt.enabled {
t.Errorf("physical realizer registered = %t, want %t", registered, tt.enabled)
}
})
}
if slices.Contains(ControllerNames(), "physical-realizer") {
t.Error("the default cell lists the physical realizer among its controllers")
}
}
19 changes: 19 additions & 0 deletions internal/config/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ type CellControllerManager struct {
// cell's Galactic gateways. It is disabled unless explicitly enabled, and
// needs galactic.enabled.
NetworkLoadBalancer NetworkLoadBalancerCellConfig `json:"networkLoadBalancer,omitempty"`

// PhysicalRealizer runs the test realizer for physical interfaces, which
// programs a simulated switch from the cell's switch port holds. It is
// for tests only and is disabled unless explicitly enabled.
PhysicalRealizer PhysicalRealizerConfig `json:"physicalRealizer,omitempty"`
}

const PhysicalRealizerDriverSimulated = "simulated"

// +k8s:deepcopy-gen=true

type PhysicalRealizerConfig struct {
Enabled bool `json:"enabled,omitempty"`

// Driver is the switch the realizer programs. Only simulated exists.
Driver string `json:"driver,omitempty"`
}

// +k8s:deepcopy-gen=true
Expand Down Expand Up @@ -154,6 +170,9 @@ func (c *CellControllerManager) Validate() error {
if err := validateHostOnlyPorts(c.Galactic.HypervisorHostOnlyPorts); err != nil {
return fmt.Errorf("galactic.hypervisorHostOnlyPorts: %w", err)
}
if c.PhysicalRealizer.Enabled && c.PhysicalRealizer.Driver != PhysicalRealizerDriverSimulated {
return fmt.Errorf("physicalRealizer.driver must be %s", PhysicalRealizerDriverSimulated)
}
return nil
}

Expand Down
46 changes: 46 additions & 0 deletions internal/config/cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ func TestCellControllerManager_Validate(t *testing.T) {
},
wantSub: "networkLoadBalancer.ipv4VIPs needs networkLoadBalancer.enabled",
},
{
name: "simulated physical realizer",
mutate: func(c *CellControllerManager) {
c.PhysicalRealizer = PhysicalRealizerConfig{Enabled: true, Driver: PhysicalRealizerDriverSimulated}
},
},
{
name: "physical realizer without a driver",
mutate: func(c *CellControllerManager) {
c.PhysicalRealizer.Enabled = true
},
wantSub: "physicalRealizer.driver must be simulated",
},
{
name: "physical realizer driver while disabled",
mutate: func(c *CellControllerManager) {
c.PhysicalRealizer.Driver = "switch-example"
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -172,6 +191,33 @@ location:
}
}

func TestThePhysicalRealizerIsOffUnlessConfigured(t *testing.T) {
base := `apiVersion: apiserver.config.datumapis.com/v1alpha1
kind: CellControllerManager
ipam:
kubeconfigPath: /etc/ipam-cluster/kubeconfig
federation:
kubeconfigPath: /etc/kubernetes/federation/auth/kubeconfig
`
var cfg CellControllerManager
decodeInto(t, []byte(base), &cfg)
if cfg.PhysicalRealizer.Enabled {
t.Fatal("the physical realizer is enabled by default")
}

var enabled CellControllerManager
decodeInto(t, []byte(base+`physicalRealizer:
enabled: true
driver: simulated
`), &enabled)
if err := enabled.Validate(); err != nil {
t.Fatalf("expected the config to validate, got %v", err)
}
if !enabled.PhysicalRealizer.Enabled || enabled.PhysicalRealizer.Driver != PhysicalRealizerDriverSimulated {
t.Errorf("expected the physical realizer to decode, got %+v", enabled.PhysicalRealizer)
}
}

func TestDecodeCellControllerManager_RejectsControlPlaneFields(t *testing.T) {
data := []byte(`apiVersion: apiserver.config.datumapis.com/v1alpha1
kind: CellControllerManager
Expand Down
16 changes: 16 additions & 0 deletions internal/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/controller/networkinterface_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ func projectedInterface(source *networkingv1alpha.NetworkInterface, location str
Status: networkingv1alpha.NetworkInterfaceStatus{
DNS: source.Status.DNS.DeepCopy(),
Phase: source.Status.Phase,
VLANID: copyVLANID(source.Status.VLANID),
Conditions: append([]metav1.Condition(nil), source.Status.Conditions...),
},
}

return projection
}

func copyVLANID(vlan *int32) *int32 {
if vlan == nil {
return nil
}
copied := *vlan
return &copied
}

func projectionLabels(source *networkingv1alpha.NetworkInterface, location string) map[string]string {
labels := map[string]string{}
for key, value := range source.Labels {
Expand Down
12 changes: 12 additions & 0 deletions internal/controller/networkinterface_projection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ func TestProjectedInterfaceReportsDNSSettings(t *testing.T) {
require.Equal(t, "fd53::53", source.Status.DNS.Nameservers[0], "the projection must own its DNS settings")
}

func TestProjectedInterfaceReportsTheVLANItsNetworkArrivesOn(t *testing.T) {
vlan := int32(100)
source := &networkingv1alpha.NetworkInterface{Status: networkingv1alpha.NetworkInterfaceStatus{VLANID: &vlan}}

projection := projectedInterface(source, "ord-1")
require.Equal(t, &vlan, projection.Status.VLANID, "a tagged network must not read as untagged on the copy")
*projection.Status.VLANID = 200
require.Equal(t, int32(100), vlan, "the projection must own its VLAN")

require.Nil(t, projectedInterface(&networkingv1alpha.NetworkInterface{}, "ord-1").Status.VLANID)
}

func TestCopyDropsWhatOnlyMeansSomethingOnTheCell(t *testing.T) {
v := newVisibility(t)
v.interfaceOnCell()
Expand Down
Loading
Loading