Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkInterface support #269

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
86 changes: 86 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 @@ -95,3 +107,77 @@ func (mg *Subnet) ResolveReferences(ctx context.Context, c client.Reader) error

return nil
}

// ResolveReferences of this PublicIPAddress
func (mg *PublicIPAddress) 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

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
}
18 changes: 18 additions & 0 deletions apis/network/v1alpha3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,25 @@ var (
SubnetGroupVersionKind = SchemeGroupVersion.WithKind(SubnetKind)
)

// PublicIpAddress type metadata.
var (
PublicIPAddressKind = reflect.TypeOf(PublicIPAddress{}).Name()
PublicIPAddressGroupKind = schema.GroupKind{Group: Group, Kind: PublicIPAddressKind}.String()
PublicIPAddressKindAPIVersion = PublicIPAddressKind + "." + SchemeGroupVersion.String()
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{})
}
228 changes: 228 additions & 0 deletions apis/network/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,231 @@ type SubnetList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Subnet `json:"items"`
}

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

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

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

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

// PublicIPAddressFormat - Properties of the PublicIPAddress.
// +kubebuilder:validation:Required
PublicIPAddressFormat PublicIPAddressFormat `json:"properties"`

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

// PublicIPAddressFormat defines properties of the PublicIPAddress.
type PublicIPAddressFormat struct {
// PublicIPAllocationMethod - The public IP address allocation method. Possible values include: 'Static', 'Dynamic'
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=Static;Dynamic
PublicIPAllocationMethod string `json:"allocationMethod"`

// PublicIPAllocationMethod - The public IP address version. Possible values include: 'IPV4', 'IPV6'
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=IPV4;IPV6
PublicIPAddressVersion string `json:"version"`

// Location - Resource location.
// +optional
Location *string `json:"location,omitempty"`

// SKU of PublicIPAddress
// +optional
SKU *SKU `json:"sku,omitempty"`
}

// SKU of PublicIPAddress
type SKU struct {
// Name - Name of sku. Possible values include: ['Standard', 'Basic']
// +kubebuilder:validation:Enum=Standard;Basic
Name string `json:"name,omitempty"`
}

// A PublicIPAddressStatus represents the observed state of a PublicIPAddress.
type PublicIPAddressStatus 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"`

// Address - A string identifying address of PublicIPAddress resource
Address string `json:"address"`
}

// +kubebuilder:object:root=true

// A PublicIPAddress is a managed resource that represents an Azure PublicIPAddress.
// +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="ADDRESS",type="string",JSONPath=".status.address"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,azure}
type PublicIPAddress struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PublicIPAddressSpec `json:"spec"`
Status PublicIPAddressStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// PublicIPAddressList contains a list of PublicIPAddress items
type PublicIPAddressList struct {
metav1.TypeMeta `json:",inline"`
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.
// +immutable
ResourceGroupName string `json:"resourceGroupName,omitempty"`
vaspahomov marked this conversation as resolved.
Show resolved Hide resolved

// ResourceGroupNameRef - A reference to the the Public IP address's resource
// group.
// +immutable
// +optional
ResourceGroupNameRef *xpv1.Reference `json:"resourceGroupNameRef,omitempty"`
vaspahomov marked this conversation as resolved.
Show resolved Hide resolved

// ResourceGroupNameSelector - Select a reference to the the Public IP address's
// resource group.
// +optional
ResourceGroupNameSelector *xpv1.Selector `json:"resourceGroupNameSelector,omitempty"`
vaspahomov marked this conversation as resolved.
Show resolved Hide resolved

// NetworkInterfaceFormat - Properties of the NetworkInterface.
// +kubebuilder:validation:Required
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.
// +kubebuilder:validation:Required
Location string `json:"location"`
vaspahomov marked this conversation as resolved.
Show resolved Hide resolved

// IPConfigurations - A list of IPConfigurations of the network interface.
// +kubebuilder:validation:Required
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 - name of InterfaceIPConfiguration
// +kubebuilder:validation:Required
Name string `json:"name"`
vaspahomov marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

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

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

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

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

// ProvisioningState - The provisioning state of the resource.
// +optional
ProvisioningState *string `json:"provisioningState,omitempty"`
}
Loading