Skip to content
Merged
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
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,12 @@ resources:
kind: BGPConfig
path: github.com/ironcore-dev/network-operator/api/cisco/nx/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: networking.metal.ironcore.dev
kind: DHCPRelay
path: github.com/ironcore-dev/network-operator/api/core/v1alpha1
version: v1alpha1
version: "3"
3 changes: 3 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ k8s_resource(new_name='lldp', objects=['leaf1-lldp:lldp'], trigger_mode=TRIGGER_
# k8s_yaml('./config/samples/cisco/nx/v1alpha1_lldpconfig.yaml')
# k8s_resource(new_name='lldpconfig', objects=['leaf1-lldpconfig:lldpconfig'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)

k8s_yaml('./config/samples/v1alpha1_dhcprelay.yaml')
k8s_resource(new_name='dhcprelay', objects=['dhcprelay:dhcprelay'], resource_deps=['eth1-1'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)

print('🚀 network-operator development environment')
print('👉 Edit the code inside the api/, cmd/, or internal/ directories')
print('👉 Tilt will automatically rebuild and redeploy when changes are detected')
Expand Down
125 changes: 125 additions & 0 deletions api/core/v1alpha1/dhcprelay_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
"sync"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// DHCPRelaySpec defines the desired state of DHCPRelay.
// Only a single DHCPRelay resource should be created per Device, the controller will reject additional resources of this type with the same DeviceRef.
type DHCPRelaySpec struct {
// DeviceRef is a reference to the Device this object belongs to. The Device object must exist in the same namespace.
// Immutable.
// +required
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="DeviceRef is immutable"
DeviceRef LocalObjectReference `json:"deviceRef"`

// ProviderConfigRef is a reference to a resource holding the provider-specific configuration for this DHCPRelay.
// If not specified the provider applies the target platform's default settings.
// +optional
ProviderConfigRef *TypedLocalObjectReference `json:"providerConfigRef,omitempty"`

// VrfRef is an optional reference to the VRF to use when relaying DHCP messages in all referenced interfaces.
// +optional
VrfRef *LocalObjectReference `json:"vrfRef,omitempty"`

// Servers is a list of DHCP server addresses to which DHCP messages will be relayed.
// Only IPv4 addresses are currently supported.
// +required
// +listType=atomic
// +kubebuilder:validation:items:Format=ipv4
// +kubebuilder:validation:MinItems=1
Servers []string `json:"servers"`

// InterfaceRefs is a list of interfaces
// +required
// +listType=atomic
// +kubebuilder:validation:MinItems=1
InterfaceRefs []LocalObjectReference `json:"interfaceRefs,omitempty"`
}

// DHCPRelayStatus defines the observed state of DHCPRelay.
type DHCPRelayStatus struct {
// For Kubernetes API conventions, see:
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties

// conditions represent the current state of the DHCPRelay resource.
// Each condition has a unique type and reflects the status of a specific aspect of the resource.
//
// Standard condition types include:
// - "Available": the resource is fully functional
// - "Progressing": the resource is being created or updated
// - "Degraded": the resource failed to reach or maintain its desired state
//
// The status of each condition is one of True, False, or Unknown.
// +listType=map
// +listMapKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// ConfiguredInterfaces contains the names of Interface resources that have DHCP relay configured as known by the device.
// +optional
// +listType=atomic
ConfiguredInterfaces []string `json:"configuredInterfaces,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=dhcprelays
// +kubebuilder:resource:singular=dhcprelay
// +kubebuilder:printcolumn:name="Device",type=string,JSONPath=`.spec.deviceRef.name`
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// DHCPRelay is the Schema for the DHCPRelays API
type DHCPRelay struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitzero"`

// +required
Spec DHCPRelaySpec `json:"spec"`

// +optional
Status DHCPRelayStatus `json:"status,omitzero"`
}

// GetConditions implements conditions.Getter.
func (l *DHCPRelay) GetConditions() []metav1.Condition {
return l.Status.Conditions
}

// SetConditions implements conditions.Setter.
func (l *DHCPRelay) SetConditions(conditions []metav1.Condition) {
l.Status.Conditions = conditions
}

// +kubebuilder:object:root=true

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

var (
DHCPRelayDependencies []schema.GroupVersionKind
DHCPRelayDependenciesMu sync.Mutex
)

// RegisterDHCPRelayDependency registers a provider-specific GVK as a dependency of DHCPRelay.
// ProviderConfigs should call this in their init() function to ensure the dependency is registered.
func RegisterDHCPRelayDependency(gvk schema.GroupVersionKind) {
DHCPRelayDependenciesMu.Lock()
defer DHCPRelayDependenciesMu.Unlock()
DHCPRelayDependencies = append(DHCPRelayDependencies, gvk)
}

func init() {
SchemeBuilder.Register(&DHCPRelay{}, &DHCPRelayList{})
}
6 changes: 6 additions & 0 deletions api/core/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ const (
// NVEAlreadyExistsReason indicates that another NetworkVirtualizationEdge already exists on the same device.
NVEAlreadyExistsReason = "NetworkVirtualizationEdgeAlreadyExists"
)

// Reasons that are specific to [DHCPRelay] objects.
const (
// IPAddressingNotFoundReason indicates that a referenced interface has no IPv4 addresses configured.
IPAddressingNotFoundReason = "IPAddressingNotFound"
)
122 changes: 122 additions & 0 deletions api/core/v1alpha1/zz_generated.deepcopy.go

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

Loading
Loading