Skip to content
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
13 changes: 13 additions & 0 deletions internal/controller/networkinterface_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ const (
// The NAD is the allocation record for that identifier.
LabelVPCAttachment = "cloud.datumapis.com/vpc-attachment"

// AnnotationHostInterface records the host device this attachment will get,
// on the NAD, at the moment the NAD is written. The name is derived from the
// VPC and the attachment identifier, so it is known here — well before the
// CNI ADD that creates the device. A runtime that must name the device when
// it asks for an interface, rather than learn it from the ADD result, has
// nowhere else to read it in time. galactic writes the same key during ADD
// from the same inputs, so the two always agree.
AnnotationHostInterface = "k8s.v1.cni.cncf.io/host-interface"

// ConditionTypePrepared reports that the data plane's pre-Pod artifacts exist.
// Unlike Programmed, which only becomes true at CNI ADD, it is safe to gate
// Pod creation on. network-services-operator is adding the type in parallel.
Expand Down Expand Up @@ -213,6 +222,10 @@ func (r *NetworkInterfaceReconciler) reconcileNAD(
}
nad.Labels[LabelVPC] = vpc.Status.VPC
nad.Labels[LabelVPCAttachment] = attachmentID
if nad.Annotations == nil {
nad.Annotations = map[string]string{}
}
nad.Annotations[AnnotationHostInterface] = galactic.HostInterfaceName(vpc.Status.VPC, attachmentID)
nad.Spec.Config = config
return controllerutil.SetControllerReference(attachment, nad, r.Scheme)
}); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions internal/controller/networkinterface_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ func TestAttachmentModeFallsBackToTheCell(t *testing.T) {
}

// Only the declared mode asks the tap plugin to describe the device.
// TestHostInterfaceAnnotationKey pins the annotation key this controller writes
// on the NAD. The key is a contract with the data plane: galactic writes the
// same one during CNI ADD, and a runtime reads it to learn its host device.
// Renaming it here alone would leave that runtime with nothing to read, and
// nothing else in this repository would fail.
func TestHostInterfaceAnnotationKey(t *testing.T) {
const want = "k8s.v1.cni.cncf.io/host-interface"
if AnnotationHostInterface != want {
t.Errorf("AnnotationHostInterface = %q, want %q", AnnotationHostInterface, want)
}
}

func TestDeclaresDevice(t *testing.T) {
if declaresDevice(cloudv1alpha1.VPCAttachmentInterfaceModeHypervisor) {
t.Error("a discovered hypervisor attachment must not ask for a description")
Expand Down
Loading