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
7 changes: 7 additions & 0 deletions api/v1alpha/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ type InstanceNetworkInterfaceStatus struct {
// +kubebuilder:validation:Optional
Name string `json:"name,omitempty"`

// The NetworkInterface bound to this entry, in the instance's namespace. An
// infrastructure provider follows it to configure the NIC, so it never has to
// derive the name of the claim that produced it.
//
// +kubebuilder:validation:Optional
NetworkInterfaceRef *networkingv1alpha.LocalNetworkInterfaceRef `json:"networkInterfaceRef,omitempty"`

// The addresses the interface holds inside its network, each with its prefix
// length and, once the location has a subnet, its gateway.
//
Expand Down
5 changes: 5 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.

14 changes: 14 additions & 0 deletions config/base/crd/bases/compute.datumapis.com_instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,20 @@ spec:
The name of the interface this entry reports on, matching the name in the
instance's spec.
type: string
networkInterfaceRef:
description: |-
The NetworkInterface bound to this entry, in the instance's namespace. An
infrastructure provider follows it to configure the NIC, so it never has to
derive the name of the claim that produced it.
properties:
name:
description: name is the network interface name.
maxLength: 253
minLength: 1
type: string
required:
- name
type: object
type: object
type: array
suspended:
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/networkinterfaceclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func instanceNetworkInterfaceStatus(
return status
}

// Published so a provider reads the interface without deriving the claim name.
if ref := claim.Status.NetworkInterfaceRef; ref != nil {
status.NetworkInterfaceRef = ref.DeepCopy()
}

for _, address := range claim.Status.Addresses {
status.Addresses = append(status.Addresses, computev1alpha.InstanceNetworkInterfaceAddress{
Family: address.Family,
Expand Down
49 changes: 49 additions & 0 deletions internal/controller/networkinterfaceclaim_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,52 @@ func TestCheckForNetworkCreationFailure_SurfacesClaimRejection(t *testing.T) {
require.NoError(t, err)
assert.False(t, failed)
}

// TestInstancePublishesTheBoundNetworkInterface pins the reference a provider
// follows. Without it a provider has to rebuild the claim name from compute's
// own convention, which is private and changes without notice.
func TestInstancePublishesTheBoundNetworkInterface(t *testing.T) {
t.Parallel()

instance := newClaimTestInstance(claimTestDeployment+"-0",
computev1alpha.InstanceNetworkInterface{
Network: networkingv1alpha.NetworkRef{Name: claimTestNetwork},
Name: defaultInterfaceName,
})

claim := &networkingv1alpha.NetworkInterfaceClaim{
ObjectMeta: metav1.ObjectMeta{Name: instance.Name + "-eth0", Namespace: claimTestNamespace},
Status: networkingv1alpha.NetworkInterfaceClaimStatus{
NetworkInterfaceRef: &networkingv1alpha.LocalNetworkInterfaceRef{Name: "nic-4f2a9c1e"},
Addresses: []networkingv1alpha.NetworkInterfaceAddress{
{Family: networkingv1alpha.IPv4Protocol, Address: claimTestAddressCIDR, Primary: true},
},
Conditions: []metav1.Condition{
claimCondition(networkingv1alpha.NetworkInterfaceClaimBound, metav1.ConditionTrue, "Bound"),
claimCondition(networkingv1alpha.NetworkInterfaceClaimAllocated, metav1.ConditionTrue, "Allocated"),
},
},
}

cl := fake.NewClientBuilder().
WithScheme(newClaimTestScheme()).
WithObjects(instance, claim).
Build()

r := &InstanceReconciler{NetworkingEnabled: true}
changed, err := r.reconcileNetworkInterfaceStatus(context.Background(), cl, instance)
require.NoError(t, err)
require.True(t, changed)

require.Len(t, instance.Status.NetworkInterfaces, 1)
published := instance.Status.NetworkInterfaces[0]
require.NotNil(t, published.NetworkInterfaceRef,
"a provider reads the interface through this reference")
assert.Equal(t, "nic-4f2a9c1e", published.NetworkInterfaceRef.Name)

// An unbound claim publishes no reference rather than an empty one.
unbound := instanceNetworkInterfaceStatus(defaultInterfaceName,
&networkingv1alpha.NetworkInterfaceClaim{})
assert.Nil(t, unbound.NetworkInterfaceRef)
assert.Nil(t, instanceNetworkInterfaceStatus(defaultInterfaceName, nil).NetworkInterfaceRef)
}
Loading