Skip to content

Commit

Permalink
add gateway to subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
defo89 committed Dec 31, 2024
1 parent ced9fe6 commit 4035d19
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/ipam/v1alpha1/ip_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type IPStatus struct {
State IPState `json:"state,omitempty"`
// Reserved is a reserved IP
Reserved *IPAddr `json:"reserved,omitempty"`
// Gateway represents the gateway address for the subnet
Gateway *IPAddr `json:"gateway,omitempty"`
// Message contains error details if the one has occurred
Message string `json:"message,omitempty"`
}
Expand Down
3 changes: 3 additions & 0 deletions api/ipam/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type SubnetSpec struct {
// Regions represents the network service location
// +kubebuilder:validation:Optional
Regions []Region `json:"regions,omitempty"`
// Gateway represents the gateway address for the subnet
// +kubebuilder:validation:Optional
Gateway *IPAddr `json:"gateway,omitempty"`
// Consumer refers to resource Subnet has been booked for
// +kubebuilder:validation:Optional
Consumer *ResourceReference `json:"consumer,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions api/ipam/v1alpha1/zz_generated.deepcopy.go

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

8 changes: 8 additions & 0 deletions controllers/ip_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ func (r *IPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
return ctrl.Result{}, err
}

if subnet.Spec.Gateway != nil {
ip.Status.Gateway = subnet.Spec.Gateway
if err := r.Status().Update(ctx, ip); err != nil {
log.Error(err, "unable to update ip status", "name", req.NamespacedName, "name", subnetNamespacedName)
return ctrl.Result{}, err
}
}

ip.Status.State = v1alpha1.CFinishedIPState
ip.Status.Message = ""
ip.Status.Reserved = ipCidrToReserve.AsIPAddr()
Expand Down
9 changes: 9 additions & 0 deletions controllers/subnet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ func (r *SubnetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, err
}

// Remove gateway IP from the vacant list
var gwToReserve *v1alpha1.CIDR
if subnet.Spec.Gateway != nil {
gwToReserve = subnet.Spec.Gateway.AsCidr()
if err := subnet.Reserve(gwToReserve); err != nil {
return ctrl.Result{}, err
}
}

// If deletion timestamp is present,
// then resource is scheduled for deletion.
if subnet.GetDeletionTimestamp() != nil {
Expand Down

0 comments on commit 4035d19

Please sign in to comment.