diff --git a/Makefile b/Makefile index ac0b7a1..ea09d02 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ GITVERSION := $(shell git describe --long --all) BUILDDATE := $(shell date -Iseconds) VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD)) -CONTROLLER_TOOLS_VERSION ?= v0.21.0 +CONTROLLER_TOOLS_VERSION ?= v0.22.0 LOCALBIN ?= $(shell pwd)/bin CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest diff --git a/api/v2/types_firewall.go b/api/v2/types_firewall.go index c8cf401..93af717 100644 --- a/api/v2/types_firewall.go +++ b/api/v2/types_firewall.go @@ -152,6 +152,10 @@ type FirewallStatus struct { // The information is used by the firewall-controller in order to reconcile this firewall. // See .spec.networks. FirewallNetworks []FirewallNetwork `json:"firewallNetworks,omitempty"` + // Nics connected to the switches + Nics []Nic `json:"nics,omitempty"` + // VPN configuration + VPN *VPN `json:"vpn,omitempty"` // Conditions contain the latest available observations of a firewall's current state. Conditions Conditions `json:"conditions"` // Phase describes the firewall phase at the current time. @@ -254,15 +258,37 @@ type FirewallNetwork struct { // IPs are the ip addresses used in this network. IPs []string `json:"ips,omitempty"` // Nat specifies whether the outgoing traffic is natted or not. + // Deprecated will be superseded by NATTypeV2 Nat *bool `json:"nat"` // NetworkID is the id of this network. NetworkID *string `json:"networkID"` // NetworkType is the type of this network. + // Deprecated will be superseded by NetworkTypeV2 NetworkType *string `json:"networkType"` // Prefixes are the network prefixes of this network. Prefixes []string `json:"prefixes,omitempty"` // Vrf is vrf id of this network. Vrf *int64 `json:"vrf"` + // Project of this network + Project *string `json:"project,omitempty"` + // NetworkTypeV2 is the type of this network. + NetworkTypeV2 *string `json:"networkTypeV2,omitempty"` + // NATTypeV2 is the nat type of this network. + NATTypeV2 *string `json:"natTypeV2,omitempty"` +} + +// Nic contains details of a network interface of this firewall. +type Nic struct { + // Mac the macaddress of this interface. + Mac string `json:"mac,omitempty"` + // Name of this interface. + Name string `json:"name,omitempty"` +} + +// VPN Configuration of the firewall +type VPN struct { + // Address of VPN control plane. + ControlPlaneAddress string `json:"control_plane_address,omitempty"` } // FirewallList contains a list of firewalls diff --git a/api/v2/zz_generated.deepcopy.go b/api/v2/zz_generated.deepcopy.go index 393c86c..ad36609 100644 --- a/api/v2/zz_generated.deepcopy.go +++ b/api/v2/zz_generated.deepcopy.go @@ -495,6 +495,21 @@ func (in *FirewallNetwork) DeepCopyInto(out *FirewallNetwork) { *out = new(int64) **out = **in } + if in.Project != nil { + in, out := &in.Project, &out.Project + *out = new(string) + **out = **in + } + if in.NetworkTypeV2 != nil { + in, out := &in.NetworkTypeV2, &out.NetworkTypeV2 + *out = new(string) + **out = **in + } + if in.NATTypeV2 != nil { + in, out := &in.NATTypeV2, &out.NATTypeV2 + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirewallNetwork. @@ -719,6 +734,11 @@ func (in *FirewallStatus) DeepCopyInto(out *FirewallStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Nics != nil { + in, out := &in.Nics, &out.Nics + *out = make([]Nic, len(*in)) + copy(*out, *in) + } if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make(Conditions, len(*in)) @@ -853,6 +873,21 @@ func (in *MachineStatus) DeepCopy() *MachineStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Nic) DeepCopyInto(out *Nic) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Nic. +func (in *Nic) DeepCopy() *Nic { + if in == nil { + return nil + } + out := new(Nic) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RateLimit) DeepCopyInto(out *RateLimit) { *out = *in diff --git a/config/crds/firewall.metal-stack.io_firewalldeployments.yaml b/config/crds/firewall.metal-stack.io_firewalldeployments.yaml index 411bf6a..11341b6 100644 --- a/config/crds/firewall.metal-stack.io_firewalldeployments.yaml +++ b/config/crds/firewall.metal-stack.io_firewalldeployments.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.20.0 + controller-gen.kubebuilder.io/version: v0.22.0 name: firewalldeployments.firewall.metal-stack.io spec: group: firewall.metal-stack.io diff --git a/config/crds/firewall.metal-stack.io_firewallmonitors.yaml b/config/crds/firewall.metal-stack.io_firewallmonitors.yaml index 637536b..664664d 100644 --- a/config/crds/firewall.metal-stack.io_firewallmonitors.yaml +++ b/config/crds/firewall.metal-stack.io_firewallmonitors.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.20.0 + controller-gen.kubebuilder.io/version: v0.22.0 name: firewallmonitors.firewall.metal-stack.io spec: group: firewall.metal-stack.io diff --git a/config/crds/firewall.metal-stack.io_firewalls.yaml b/config/crds/firewall.metal-stack.io_firewalls.yaml index 6087ab1..1017d78 100644 --- a/config/crds/firewall.metal-stack.io_firewalls.yaml +++ b/config/crds/firewall.metal-stack.io_firewalls.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.20.0 + controller-gen.kubebuilder.io/version: v0.22.0 name: firewalls.firewall.metal-stack.io spec: group: firewall.metal-stack.io @@ -311,20 +311,32 @@ spec: type: string type: array nat: - description: Nat specifies whether the outgoing traffic is natted - or not. + description: |- + Nat specifies whether the outgoing traffic is natted or not. + Deprecated will be superseded by NATTypeV2 type: boolean + natTypeV2: + description: NATTypeV2 is the nat type of this network. + type: string networkID: description: NetworkID is the id of this network. type: string networkType: - description: NetworkType is the type of this network. + description: |- + NetworkType is the type of this network. + Deprecated will be superseded by NetworkTypeV2 + type: string + networkTypeV2: + description: NetworkTypeV2 is the type of this network. type: string prefixes: description: Prefixes are the network prefixes of this network. items: type: string type: array + project: + description: Project of this network + type: string vrf: description: Vrf is vrf id of this network. format: int64 @@ -389,6 +401,20 @@ spec: - liveliness - machineID type: object + nics: + description: Nics connected to the switches + items: + description: Nic contains details of a network interface of this + firewall. + properties: + mac: + description: Mac the macaddress of this interface. + type: string + name: + description: Name of this interface. + type: string + type: object + type: array phase: description: Phase describes the firewall phase at the current time. type: string @@ -417,6 +443,13 @@ spec: - namespace - tokenSecretName type: object + vpn: + description: VPN configuration + properties: + control_plane_address: + description: Address of VPN control plane. + type: string + type: object required: - conditions - phase diff --git a/config/crds/firewall.metal-stack.io_firewallsets.yaml b/config/crds/firewall.metal-stack.io_firewallsets.yaml index 1f2b813..0a595cd 100644 --- a/config/crds/firewall.metal-stack.io_firewallsets.yaml +++ b/config/crds/firewall.metal-stack.io_firewallsets.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.20.0 + controller-gen.kubebuilder.io/version: v0.22.0 name: firewallsets.firewall.metal-stack.io spec: group: firewall.metal-stack.io diff --git a/controllers/firewall/status.go b/controllers/firewall/status.go index 38a1e09..79d4b43 100644 --- a/controllers/firewall/status.go +++ b/controllers/firewall/status.go @@ -89,7 +89,29 @@ func (c *controller) setFirewallNetworks(r *controllers.Ctx[*v2.Firewall], f *mo return fmt.Errorf("firewall entity is missing essential fields") } - var result []v2.FirewallNetwork + var ( + result []v2.FirewallNetwork + nics []v2.Nic + ) + + if f.Hardware != nil { + for _, nic := range f.Hardware.Nics { + if len(nic.Neighbors) == 0 { + continue + } + nics = append(nics, v2.Nic{ + Name: pointer.SafeDeref(nic.Name), + Mac: pointer.SafeDeref(nic.Mac), + }) + } + r.Target.Status.Nics = nics + } + + if f.Allocation.Vpn != nil { + r.Target.Status.VPN = &v2.VPN{ + ControlPlaneAddress: pointer.SafeDeref(f.Allocation.Vpn.Address), + } + } for _, n := range f.Allocation.Networks { if n.Networkid == nil { @@ -106,10 +128,13 @@ func (c *controller) setFirewallNetworks(r *controllers.Ctx[*v2.Firewall], f *mo DestinationPrefixes: n.Destinationprefixes, IPs: n.Ips, Nat: n.Nat, + NATTypeV2: n.Nattypev2, NetworkID: n.Networkid, NetworkType: n.Networktype, + NetworkTypeV2: n.Networktypev2, Prefixes: nw.Prefixes, Vrf: n.Vrf, + Project: n.Projectid, }) }