Skip to content

Commit

Permalink
Merge pull request #1262 from fhaftmann/mac-address-from-annotation
Browse files Browse the repository at this point in the history
✨ Enable mac address retrieved from annotations
  • Loading branch information
metal3-io-bot authored Oct 17, 2023
2 parents 429a4e9 + 6f0c29e commit 9e5cf69
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 82 deletions.
14 changes: 14 additions & 0 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ func (src *Metal3DataTemplate) ConvertTo(dstRaw conversion.Hub) error {
}
}
if dst.Spec.NetworkData != nil && restored.Spec.NetworkData != nil {
for k := range dst.Spec.NetworkData.Links.Ethernets {
dst.Spec.NetworkData.Links.Ethernets[k].MACAddress = restored.Spec.NetworkData.Links.Ethernets[k].MACAddress
}
for k := range dst.Spec.NetworkData.Links.Vlans {
dst.Spec.NetworkData.Links.Vlans[k].MACAddress = restored.Spec.NetworkData.Links.Vlans[k].MACAddress
}
for k := range dst.Spec.NetworkData.Links.Bonds {
dst.Spec.NetworkData.Links.Bonds[k].MACAddress = restored.Spec.NetworkData.Links.Bonds[k].MACAddress
}
for k := range dst.Spec.NetworkData.Networks.IPv4 {
dst.Spec.NetworkData.Networks.IPv4[k].FromPoolRef = restored.Spec.NetworkData.Networks.IPv4[k].FromPoolRef
}
Expand All @@ -219,6 +228,11 @@ func (dst *Metal3DataTemplate) ConvertFrom(srcRaw conversion.Hub) error {
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta1_NetworkLinkEthernetMac_To_v1alpha5_NetworkLinkEthernetMac(in *v1beta1.NetworkLinkEthernetMac, out *NetworkLinkEthernetMac, s apiconversion.Scope) error {
// fromAnnotation was added with v1betaX.
return autoConvert_v1beta1_NetworkLinkEthernetMac_To_v1alpha5_NetworkLinkEthernetMac(in, out, s)
}

func Convert_v1beta1_NetworkDataIPv6_To_v1alpha5_NetworkDataIPv6(in *v1beta1.NetworkDataIPv6, out *NetworkDataIPv6, s apiconversion.Scope) error {
// fromPoolRef was added with v1beta1.
return autoConvert_v1beta1_NetworkDataIPv6_To_v1alpha5_NetworkDataIPv6(in, out, s)
Expand Down
124 changes: 104 additions & 20 deletions api/v1alpha5/zz_generated.conversion.go

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

15 changes: 15 additions & 0 deletions api/v1beta1/metal3datatemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ type MetaData struct {
FromAnnotations []MetaDataFromAnnotation `json:"fromAnnotations,omitempty"`
}

// NetworkLinkEthernetMacFromAnnotation contains the information to fetch an annotation
// content, if the label does not exist, it is rendered as empty string.
type NetworkLinkEthernetMacFromAnnotation struct {
// +kubebuilder:validation:Enum=machine;metal3machine;baremetalhost
// Object is the type of the object from which we retrieve the name
Object string `json:"object"`
// Annotation is the key of the Annotation to fetch
Annotation string `json:"annotation"`
}

// NetworkLinkEthernetMac represents the Mac address content.
type NetworkLinkEthernetMac struct {
// String contains the MAC address given as a string
Expand All @@ -201,6 +211,11 @@ type NetworkLinkEthernetMac struct {
// Introspection details from which to fetch the MAC address
// +optional
FromHostInterface *string `json:"fromHostInterface,omitempty"`

// FromAnnotation references an object Annotation to retrieve the
// MAC address from
// +optional
FromAnnotation *NetworkLinkEthernetMacFromAnnotation `json:"fromAnnotation,omitempty"`
}

// NetworkDataLinkEthernet represents an ethernet link object.
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta1/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 9e5cf69

Please sign in to comment.