MetalLB Builders
MetalLB Builders - MetalLB Resource Constructors
The metallb package provides strongly-typed constructor functions for creating MetalLB Kubernetes resources. These are the low-level building blocks used by Kure’s higher-level stack and workflow packages.
Overview
Each config-struct builder takes a configuration struct and returns a populated MetalLB custom resource. The builders handle API version and kind metadata, letting you focus on the resource specification.
Constructors
Every kind this package registers has a generated Create<Kind> wrapper in zz_generated_create.go, produced from the scheme by pkg/kubernetes/internal/gen (make gen-builders, checked by make check-builders in CI). A wrapper delegates to kubernetes.Create[T] and emits TypeMeta and identity only: no default, no label, no spec value. Namespaced kinds take (name, namespace), cluster-scoped kinds take (name). The upstream struct is the construction API; set spec fields directly or through the admissible Set*/Add* sugar below.
obj := metallb.CreateIPAddressPool("my-pool", "metallb-system")The config-struct builders (metallb.IPAddressPool(&metallb.IPAddressPoolConfig{...})) are a separate, opinionated layer on top of the same upstream types; they are unchanged by the generated constructors. The hand-written Create* helpers for spec fragments that remain in this package are legacy and are removed by the prune work item of the builder-contract epic.
See the Kubernetes Builders page for the full builder contract: construction, sugar admission classes, purity and the release-1 migration ledger.
Supported Resources
IP Address Pools
import "github.com/go-kure/kure/pkg/kubernetes/metallb"
pool := metallb.IPAddressPool(&metallb.IPAddressPoolConfig{
Name: "my-pool",
Namespace: "metallb-system",
Addresses: []string{"192.168.1.0/24", "10.0.0.0/16"},
})BGP Peers
peer := metallb.BGPPeer(&metallb.BGPPeerConfig{
Name: "my-peer",
Namespace: "metallb-system",
MyASN: 64500,
ASN: 64501,
Address: "10.0.0.1",
Port: 179,
})BGP Advertisements
advert := metallb.BGPAdvertisement(&metallb.BGPAdvertisementConfig{
Name: "my-advert",
Namespace: "metallb-system",
IPAddressPools: []string{"my-pool"},
Peers: []string{"my-peer"},
Communities: []string{"65535:65282"},
LocalPref: 100,
})L2 Advertisements
l2 := metallb.L2Advertisement(&metallb.L2AdvertisementConfig{
Name: "my-l2",
Namespace: "metallb-system",
IPAddressPools: []string{"my-pool"},
Interfaces: []string{"eth0"},
})BFD Profiles
detectMult := uint32(3)
bfd := metallb.BFDProfile(&metallb.BFDProfileConfig{
Name: "my-bfd",
Namespace: "metallb-system",
DetectMultiplier: &detectMult,
})Modifier Functions
Update existing resources:
// Replace full spec
pool.Spec = newSpec
peer.Spec = newSpec
// Plain fields are assigned directly — there is no Set<Kind><Field> helper
peer.Spec.Port = 1179
// Slice fields keep an appender, and pointer fields a setter
metallb.AddIPAddressPoolAddress(pool, "172.16.0.0/12")
metallb.AddBGPAdvertisementPeer(advert, "peer-2")
metallb.AddL2AdvertisementInterface(l2, "eth1")
metallb.SetIPAddressPoolAutoAssign(pool, false)The helpers are void. A nil object is a programming error and panics, like every other builder in this family.
Related Packages
- kubernetes - Core Kubernetes resource builders
- fluxcd - FluxCD resource builders