Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reservation of IpRanges #130

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ resources:
kind: PrefixClaim
path: github.com/netbox-community/netbox-operator/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: netbox.dev
kind: IpRangeClaim
path: github.com/netbox-community/netbox-operator/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: netbox.dev
kind: IpRange
path: github.com/netbox-community/netbox-operator/api/v1
version: v1
version: "3"
7 changes: 7 additions & 0 deletions api/v1/ipaddressclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,10 @@ var ConditionIpAssignedFalse = metav1.Condition{
Reason: "IPAddressCRNotCreated",
Message: "Failed to fetch new IP from NetBox",
}

var ConditionIpAssignedFalseSizeMissmatch = metav1.Condition{
Type: "IPAssigned",
Status: "False",
Reason: "IPAddressCRNotCreated",
Message: "Size of restored IpRange does not match the requested size",
}
111 changes: 111 additions & 0 deletions api/v1/iprange_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
Copyright 2024 Swisscom (Schweiz) AG.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// IpRangeSpec defines the desired state of IpRange
type IpRangeSpec struct {
//+kubebuilder:validation:Format=cidr
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'startAddress' is immutable"
//+kubebuilder:validation:Required
StartAddress string `json:"startAddress"`

//+kubebuilder:validation:Format=cidr
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'endAddress' is immutable"
//+kubebuilder:validation:Required
EndAddress string `json:"endAddress"`

//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'tenant' is immutable"
Tenant string `json:"tenant,omitempty"`

CustomFields map[string]string `json:"customFields,omitempty"`

Comments string `json:"comments,omitempty"`

Description string `json:"description,omitempty"`

PreserveInNetbox bool `json:"preserveInNetbox,omitempty"`
}

// IpRangeStatus defines the observed state of IpRange
type IpRangeStatus struct {
IpRangeId int64 `json:"id,omitempty"`

IpRangeUrl string `json:"url,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion
//+kubebuilder:printcolumn:name="StartAddress",type=string,JSONPath=`.spec.startAddress`
//+kubebuilder:printcolumn:name="EndAddress",type=string,JSONPath=`.spec.endAddress`
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
//+kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:resource:shortName=ir

// IpRange is the Schema for the ipranges API
type IpRange struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IpRangeSpec `json:"spec,omitempty"`
Status IpRangeStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&IpRange{}, &IpRangeList{})
}

var ConditionIpRangeReadyTrue = metav1.Condition{
Type: "Ready",
Status: "True",
Reason: "IpReservedInNetbox",
Message: "IP was reserved/updated in NetBox",
}

var ConditionIpRangeReadyFalse = metav1.Condition{
Type: "Ready",
Status: "False",
Reason: "FailedToReserveIpInNetbox",
Message: "Failed to reserve IP Range in NetBox",
}

var ConditionIpRangeReadyFalseDeletionFailed = metav1.Condition{
Type: "Ready",
Status: "False",
Reason: "FailedToDeleteIpInNetbox",
Message: "Failed to delete IP Range in NetBox",
}
116 changes: 116 additions & 0 deletions api/v1/iprangeclaim_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright 2024 Swisscom (Schweiz) AG.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// IpRangeClaimSpec defines the desired state of IpRangeClaim
type IpRangeClaimSpec struct {
//+kubebuilder:validation:Required
//+kubebuilder:validation:Format=cidr
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'parentPrefix' is immutable"
ParentPrefix string `json:"parentPrefix"`

//+kubebuilder:validation:Required
//+kubebuilder:validation:XValisation:Minimum=1
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'size' is immutable"
Size int `json:"size,omitempty"`

//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'tenant' is immutable"
Tenant string `json:"tenant,omitempty"`

CustomFields map[string]string `json:"customFields,omitempty"`

Comments string `json:"comments,omitempty"`

Description string `json:"description,omitempty"`

PreserveInNetbox bool `json:"preserveInNetbox,omitempty"`
}

// IpRangeClaimStatus defines the observed state of IpRangeClaim
type IpRangeClaimStatus struct {
IpRange string `json:"ipRange,omitempty"`

IpRangeName string `json:"ipAddressName,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion
//+kubebuilder:printcolumn:name="IpRange",type=string,JSONPath=`.status.ipRange`
//+kubebuilder:printcolumn:name="IpRangeAssigned",type=string,JSONPath=`.status.conditions[?(@.type=="IPAssigned")].status`
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:resource:shortName=irc

// IpRangeClaim is the Schema for the iprangeclaims API
type IpRangeClaim struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IpRangeClaimSpec `json:"spec,omitempty"`
Status IpRangeClaimStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&IpRangeClaim{}, &IpRangeClaimList{})
}

var ConditionIpRangeClaimReadyTrue = metav1.Condition{
Type: "Ready",
Status: "True",
Reason: "IPAddressResourceReady",
Message: "IPAddress Resource is ready",
}

var ConditionIpRangeClaimReadyFalse = metav1.Condition{
Type: "Ready",
Status: "False",
Reason: "IPAddressResourceNotReady",
Message: "IPAddress Resource is not ready",
}

var ConditionIpRangeAssignedTrue = metav1.Condition{
Type: "IPAssigned",
Status: "True",
Reason: "IPAddressCRCreated",
Message: "New IP fetched from NetBox and IPAddress CR was created",
}

var ConditionIpRangeAssignedFalse = metav1.Condition{
Type: "IPAssigned",
Status: "False",
Reason: "IPAddressCRNotCreated",
Message: "Failed to fetch new IP from NetBox",
}
Loading
Loading