Skip to content

Commit

Permalink
NetworkInterface support
Browse files Browse the repository at this point in the history
Signed-off-by: vaspahomov <[email protected]>
  • Loading branch information
vaspahomov committed Jun 23, 2021
1 parent 1baed27 commit e6e9620
Show file tree
Hide file tree
Showing 14 changed files with 1,325 additions and 0 deletions.
65 changes: 65 additions & 0 deletions apis/network/v1alpha3/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ func SubnetID() reference.ExtractValueFn {
}
}

// PublicIPAddressID extracts status.ID from the supplied managed resource, which must be
// a PublicIPAddress.
func PublicIPAddressID() reference.ExtractValueFn {
return func(mg resource.Managed) string {
s, ok := mg.(*PublicIPAddress)
if !ok {
return ""
}
return s.Status.ID
}
}

// ResolveReferences of this VirtualNetwork
func (mg *VirtualNetwork) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)
Expand Down Expand Up @@ -116,3 +128,56 @@ func (mg *PublicIPAddress) ResolveReferences(ctx context.Context, c client.Reade

return nil
}

// ResolveReferences of this PublicIPAddress
func (mg *NetworkInterface) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// Resolve spec.resourceGroupName
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ResourceGroupName,
Reference: mg.Spec.ResourceGroupNameRef,
Selector: mg.Spec.ResourceGroupNameSelector,
To: reference.To{Managed: &v1alpha3.ResourceGroup{}, List: &v1alpha3.ResourceGroupList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.resourceGroupName")
}
mg.Spec.ResourceGroupName = rsp.ResolvedValue
mg.Spec.ResourceGroupNameRef = rsp.ResolvedReference

// Resolve spec.properties.interfaceIPConfigurations[].publicIPAddress
for i, iface := range mg.Spec.NetworkInterfaceFormat.IPConfigurations {
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: iface.PublicIPAddressID,
Reference: iface.PublicIPAddressIDRef,
Selector: iface.PublicIPAddressIDSelector,
To: reference.To{Managed: &PublicIPAddress{}, List: &PublicIPAddressList{}},
Extract: PublicIPAddressID(),
})
if err != nil {
return errors.Wrap(err, "spec.properties.interfaceIPConfigurations[].publicIPAddress")
}
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].PublicIPAddressID = rsp.ResolvedValue
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].PublicIPAddressIDRef = rsp.ResolvedReference
}

// Resolve spec.properties.interfaceIPConfigurations[].subnet
for i, iface := range mg.Spec.NetworkInterfaceFormat.IPConfigurations {
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: iface.SubnetID,
Reference: iface.SubnetIDRef,
Selector: iface.SubnetIDSelector,
To: reference.To{Managed: &Subnet{}, List: &SubnetList{}},
Extract: SubnetID(),
})
if err != nil {
return errors.Wrap(err, "spec.properties.interfaceIPConfigurations[].subnet")
}
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].SubnetID = rsp.ResolvedValue
mg.Spec.NetworkInterfaceFormat.IPConfigurations[i].SubnetIDRef = rsp.ResolvedReference
}

return nil
}
9 changes: 9 additions & 0 deletions apis/network/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ var (
PublicIPAddressGroupVersionKind = SchemeGroupVersion.WithKind(PublicIPAddressKind)
)

// PublicIpAddress type metadata.
var (
NetworkInterfaceKind = reflect.TypeOf(NetworkInterface{}).Name()
NetworkInterfaceGroupKind = schema.GroupKind{Group: Group, Kind: NetworkInterfaceKind}.String()
NetworkInterfaceKindAPIVersion = NetworkInterfaceKind + "." + SchemeGroupVersion.String()
NetworkInterfaceGroupVersionKind = SchemeGroupVersion.WithKind(NetworkInterfaceKind)
)

func init() {
SchemeBuilder.Register(&VirtualNetwork{}, &VirtualNetworkList{})
SchemeBuilder.Register(&Subnet{}, &SubnetList{})
SchemeBuilder.Register(&PublicIPAddress{}, &PublicIPAddressList{})
SchemeBuilder.Register(&NetworkInterface{}, &NetworkInterfaceList{})
}
106 changes: 106 additions & 0 deletions apis/network/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,109 @@ type PublicIPAddressList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []PublicIPAddress `json:"items"`
}

// A NetworkInterfaceSpec defines the desired state of a NetworkInterface.
type NetworkInterfaceSpec struct {
xpv1.ResourceSpec `json:",inline"`

// ResourceGroupName - Name of the Public IP address's resource group.
ResourceGroupName string `json:"resourceGroupName,omitempty"`

// ResourceGroupNameRef - A reference to the the Public IP address's resource
// group.
ResourceGroupNameRef *xpv1.Reference `json:"resourceGroupNameRef,omitempty"`

// ResourceGroupNameSelector - Select a reference to the the Public IP address's
// resource group.
ResourceGroupNameSelector *xpv1.Selector `json:"resourceGroupNameSelector,omitempty"`

// NetworkInterfaceFormat - Properties of the NetworkInterface.
NetworkInterfaceFormat NetworkInterfaceFormat `json:"properties"`

// Tags - Resource tags.
// +optional
Tags map[string]*string `json:"tags,omitempty"`
}

// NetworkInterfaceFormat defines properties of the NetworkInterface.
type NetworkInterfaceFormat struct {
// Location - Resource location.
Location string `json:"location"`

// IPConfigurations - A list of IPConfigurations of the network interface.
IPConfigurations []*InterfaceIPConfiguration `json:"iPConfigurations"`
}

// A NetworkInterfaceStatus represents the observed state of a NetworkInterface.
type NetworkInterfaceStatus struct {
xpv1.ResourceStatus `json:",inline"`

// State of this PublicIPAddress.
State string `json:"state,omitempty"`

// A Message providing detail about the state of this PublicIPAddress, if any.
Message string `json:"message,omitempty"`

// Etag - A unique string that changes whenever the resource is updated.
Etag string `json:"etag,omitempty"`

// ID of this PublicIPAddress.
ID string `json:"id,omitempty"`
}

// +kubebuilder:object:root=true

// A NetworkInterface is a managed resource that represents an Azure NetworkInterface.
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="STATE",type="string",JSONPath=".status.state"
// +kubebuilder:printcolumn:name="LOCATION",type="string",JSONPath=".spec.properties.location"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
type NetworkInterface struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NetworkInterfaceSpec `json:"spec"`
Status NetworkInterfaceStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// NetworkInterfaceList contains a list of NetworkInterface items
type NetworkInterfaceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NetworkInterface `json:"items"`
}

// InterfaceIPConfiguration defines properties of a service endpoint.
type InterfaceIPConfiguration struct {
Name string `json:"name"`

// PublicIPAddressID - Name of the Network Interface's Public IP address.
PublicIPAddressID string `json:"publicIPAddressID,omitempty"`

// PublicIPAddressIDRef - A reference to the the Network Interface's Public IP address.
PublicIPAddressIDRef *xpv1.Reference `json:"publicIPAddressIDRef,omitempty"`

// PublicIPAddressIDSelector - Select a reference to the Network Interface's Public IP address.
PublicIPAddressIDSelector *xpv1.Selector `json:"publicIPAddressIDSelector,omitempty"`

// SubnetID - Name of the Network Interface's Subnet.
SubnetID string `json:"subnetID,omitempty"`

// SubnetIDRef - A reference to the the Network Interface's Subnet.
SubnetIDRef *xpv1.Reference `json:"subnetIDRef,omitempty"`

// SubnetIDSelector - Select a reference to the Network Interface's Subnet.
SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"`

// Primary - Gets whether this is a primary customer address on the network interface.
Primary bool `json:"primary,omitempty"`

// ProvisioningState - The provisioning state of the resource.
// +optional
ProvisioningState string `json:"provisioningState,omitempty"`
}
178 changes: 178 additions & 0 deletions apis/network/v1alpha3/zz_generated.deepcopy.go

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

Loading

0 comments on commit e6e9620

Please sign in to comment.