Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit b963747

Browse files
committed
NetworkInterface support
Signed-off-by: vaspahomov <vas2142553@gmail.com>
1 parent 1baed27 commit b963747

14 files changed

Lines changed: 1329 additions & 0 deletions

File tree

apis/network/v1alpha3/referencers.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ func SubnetID() reference.ExtractValueFn {
4040
}
4141
}
4242

43+
// PublicIPAddressID extracts status.ID from the supplied managed resource, which must be
44+
// a PublicIPAddress.
45+
func PublicIPAddressID() reference.ExtractValueFn {
46+
return func(mg resource.Managed) string {
47+
s, ok := mg.(*PublicIPAddress)
48+
if !ok {
49+
return ""
50+
}
51+
return s.Status.ID
52+
}
53+
}
54+
4355
// ResolveReferences of this VirtualNetwork
4456
func (mg *VirtualNetwork) ResolveReferences(ctx context.Context, c client.Reader) error {
4557
r := reference.NewAPIResolver(c, mg)
@@ -116,3 +128,56 @@ func (mg *PublicIPAddress) ResolveReferences(ctx context.Context, c client.Reade
116128

117129
return nil
118130
}
131+
132+
// ResolveReferences of this PublicIPAddress
133+
func (mg *NetworkInterface) ResolveReferences(ctx context.Context, c client.Reader) error {
134+
r := reference.NewAPIResolver(c, mg)
135+
136+
// Resolve spec.resourceGroupName
137+
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
138+
CurrentValue: mg.Spec.ResourceGroupName,
139+
Reference: mg.Spec.ResourceGroupNameRef,
140+
Selector: mg.Spec.ResourceGroupNameSelector,
141+
To: reference.To{Managed: &v1alpha3.ResourceGroup{}, List: &v1alpha3.ResourceGroupList{}},
142+
Extract: reference.ExternalName(),
143+
})
144+
if err != nil {
145+
return errors.Wrap(err, "spec.resourceGroupName")
146+
}
147+
mg.Spec.ResourceGroupName = rsp.ResolvedValue
148+
mg.Spec.ResourceGroupNameRef = rsp.ResolvedReference
149+
150+
// Resolve spec.properties.interfaceIPConfigurations[].publicIPAddress
151+
for i, iface := range mg.Spec.NetworkInterfaceFormat.IPConfigurations {
152+
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
153+
CurrentValue: iface.PublicIPAddressID,
154+
Reference: iface.PublicIPAddressIDRef,
155+
Selector: iface.PublicIPAddressIDSelector,
156+
To: reference.To{Managed: &PublicIPAddress{}, List: &PublicIPAddressList{}},
157+
Extract: PublicIPAddressID(),
158+
})
159+
if err != nil {
160+
return errors.Wrap(err, "spec.properties.interfaceIPConfigurations[].publicIPAddress")
161+
}
162+
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].PublicIPAddressID = rsp.ResolvedValue
163+
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].PublicIPAddressIDRef = rsp.ResolvedReference
164+
}
165+
166+
// Resolve spec.properties.interfaceIPConfigurations[].subnet
167+
for i, iface := range mg.Spec.NetworkInterfaceFormat.IPConfigurations {
168+
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
169+
CurrentValue: iface.SubnetID,
170+
Reference: iface.SubnetIDRef,
171+
Selector: iface.SubnetIDSelector,
172+
To: reference.To{Managed: &Subnet{}, List: &SubnetList{}},
173+
Extract: SubnetID(),
174+
})
175+
if err != nil {
176+
return errors.Wrap(err, "spec.properties.interfaceIPConfigurations[].subnet")
177+
}
178+
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].SubnetID = rsp.ResolvedValue
179+
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].SubnetIDRef = rsp.ResolvedReference
180+
}
181+
182+
return nil
183+
}

apis/network/v1alpha3/register.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,17 @@ var (
6161
PublicIPAddressGroupVersionKind = SchemeGroupVersion.WithKind(PublicIPAddressKind)
6262
)
6363

64+
// PublicIpAddress type metadata.
65+
var (
66+
NetworkInterfaceKind = reflect.TypeOf(NetworkInterface{}).Name()
67+
NetworkInterfaceGroupKind = schema.GroupKind{Group: Group, Kind: NetworkInterfaceKind}.String()
68+
NetworkInterfaceKindAPIVersion = NetworkInterfaceKind + "." + SchemeGroupVersion.String()
69+
NetworkInterfaceGroupVersionKind = SchemeGroupVersion.WithKind(NetworkInterfaceKind)
70+
)
71+
6472
func init() {
6573
SchemeBuilder.Register(&VirtualNetwork{}, &VirtualNetworkList{})
6674
SchemeBuilder.Register(&Subnet{}, &SubnetList{})
6775
SchemeBuilder.Register(&PublicIPAddress{}, &PublicIPAddressList{})
76+
SchemeBuilder.Register(&NetworkInterface{}, &NetworkInterfaceList{})
6877
}

apis/network/v1alpha3/types.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,109 @@ type PublicIPAddressList struct {
318318
metav1.ListMeta `json:"metadata,omitempty"`
319319
Items []PublicIPAddress `json:"items"`
320320
}
321+
322+
// A NetworkInterfaceSpec defines the desired state of a NetworkInterface.
323+
type NetworkInterfaceSpec struct {
324+
xpv1.ResourceSpec `json:",inline"`
325+
326+
// ResourceGroupName - Name of the Public IP address's resource group.
327+
ResourceGroupName string `json:"resourceGroupName,omitempty"`
328+
329+
// ResourceGroupNameRef - A reference to the the Public IP address's resource
330+
// group.
331+
ResourceGroupNameRef *xpv1.Reference `json:"resourceGroupNameRef,omitempty"`
332+
333+
// ResourceGroupNameSelector - Select a reference to the the Public IP address's
334+
// resource group.
335+
ResourceGroupNameSelector *xpv1.Selector `json:"resourceGroupNameSelector,omitempty"`
336+
337+
// NetworkInterfaceFormat - Properties of the NetworkInterface.
338+
NetworkInterfaceFormat NetworkInterfaceFormat `json:"properties"`
339+
340+
// Tags - Resource tags.
341+
// +optional
342+
Tags map[string]*string `json:"tags,omitempty"`
343+
}
344+
345+
// NetworkInterfaceFormat defines properties of the NetworkInterface.
346+
type NetworkInterfaceFormat struct {
347+
// Location - Resource location.
348+
Location string `json:"location"`
349+
350+
// IPConfigurations - A list of IPConfigurations of the network interface.
351+
IPConfigurations []*InterfaceIPConfiguration `json:"iPConfigurations"`
352+
}
353+
354+
// A NetworkInterfaceStatus represents the observed state of a NetworkInterface.
355+
type NetworkInterfaceStatus struct {
356+
xpv1.ResourceStatus `json:",inline"`
357+
358+
// State of this PublicIPAddress.
359+
State string `json:"state,omitempty"`
360+
361+
// A Message providing detail about the state of this PublicIPAddress, if any.
362+
Message string `json:"message,omitempty"`
363+
364+
// Etag - A unique string that changes whenever the resource is updated.
365+
Etag string `json:"etag,omitempty"`
366+
367+
// ID of this PublicIPAddress.
368+
ID string `json:"id,omitempty"`
369+
}
370+
371+
// +kubebuilder:object:root=true
372+
373+
// A NetworkInterface is a managed resource that represents an Azure NetworkInterface.
374+
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
375+
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
376+
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.state"
377+
// +kubebuilder:printcolumn:name="LOCATION",type="string",JSONPath=".spec.properties.location"
378+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
379+
// +kubebuilder:subresource:status
380+
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
381+
type NetworkInterface struct {
382+
metav1.TypeMeta `json:",inline"`
383+
metav1.ObjectMeta `json:"metadata,omitempty"`
384+
385+
Spec NetworkInterfaceSpec `json:"spec"`
386+
Status NetworkInterfaceStatus `json:"status,omitempty"`
387+
}
388+
389+
// +kubebuilder:object:root=true
390+
391+
// NetworkInterfaceList contains a list of NetworkInterface items
392+
type NetworkInterfaceList struct {
393+
metav1.TypeMeta `json:",inline"`
394+
metav1.ListMeta `json:"metadata,omitempty"`
395+
Items []NetworkInterface `json:"items"`
396+
}
397+
398+
// InterfaceIPConfiguration defines properties of a service endpoint.
399+
type InterfaceIPConfiguration struct {
400+
Name string `json:"name"`
401+
402+
// PublicIPAddressID - ID of the Network Interface's Public IP address.
403+
PublicIPAddressID string `json:"publicIPAddressID,omitempty"`
404+
405+
// PublicIPAddressIDRef - A reference to the the Network Interface's Public IP address.
406+
PublicIPAddressIDRef *xpv1.Reference `json:"publicIPAddressIDRef,omitempty"`
407+
408+
// PublicIPAddressIDSelector - Select a reference to the Network Interface's Public IP address.
409+
PublicIPAddressIDSelector *xpv1.Selector `json:"publicIPAddressIDSelector,omitempty"`
410+
411+
// SubnetID - Name of the Network Interface's Subnet.
412+
SubnetID string `json:"subnetID,omitempty"`
413+
414+
// SubnetIDRef - A reference to the the Network Interface's Subnet.
415+
SubnetIDRef *xpv1.Reference `json:"subnetIDRef,omitempty"`
416+
417+
// SubnetIDSelector - Select a reference to the Network Interface's Subnet.
418+
SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"`
419+
420+
// Primary - Gets whether this is a primary customer address on the network interface.
421+
Primary bool `json:"primary,omitempty"`
422+
423+
// ProvisioningState - The provisioning state of the resource.
424+
// +optional
425+
ProvisioningState string `json:"provisioningState,omitempty"`
426+
}

apis/network/v1alpha3/zz_generated.deepcopy.go

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)