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
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"
113 changes: 113 additions & 0 deletions api/v1/iprange_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
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 {
// the startAddress is the first ip address included in the ip range
//+kubebuilder:validation:Format=cidr
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'startAddress' is immutable"
//+kubebuilder:validation:Required
StartAddress string `json:"startAddress"`

// the endAddress is the last ip address included in the ip range
//+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=ipr

// 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: "IPRangeReservedInNetbox",
Message: "IP Range was reserved/updated in NetBox",
}

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

var ConditionIpRangeReadyFalseDeletionFailed = metav1.Condition{
Type: "Ready",
Status: "False",
Reason: "FailedToDeleteIPRangeInNetbox",
Message: "Failed to delete IP Range in NetBox",
}
146 changes: 146 additions & 0 deletions api/v1/iprangeclaim_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
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"`

// Size is the amount of consecutive IP Addresses you wish to reserve. Currently only sizes up to 50 are supported due to pagination of the NetBox API. In practice, this might be even lower depending on the fragmentation of the parent prefix.
//+kubebuilder:validation:Required
//+kubebuilder:validation:Minimum=2
//+kubebuilder:validation:Maximum=50
//+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"`

IpRangeDotDecimal string `json:"ipRangeDotDecimal,omitempty"`

IpAddresses []string `json:"ipAddresses,omitempty"`

IpAddressesDotDecimal []string `json:"ipAddressesDotDecimal,omitempty"`

StartAddress string `json:"startAddress,omitempty"`

StartAddressDotDecimal string `json:"startAddressDotDecimal,omitempty"`

EndAddress string `json:"endAddress,omitempty"`

EndAddressDotDecimal string `json:"endAddressDotDecimal,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=="IPRangeAssigned")].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=iprc

// 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: "IPRangeResourceReady",
Message: "IP Range Resource is ready",
}

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

var ConditionIpRangeClaimReadyFalseStatusGen = metav1.Condition{
Type: "Ready",
Status: "False",
Reason: "IPRangeClaimStatusGenerationFailed",
Message: "Failed to generate IP Range Status",
}

var ConditionIpRangeAssignedTrue = metav1.Condition{
Type: "IPRangeAssigned",
Status: "True",
Reason: "IPRangeCRCreated",
Message: "New IP Range fetched from NetBox and IpRange CR was created",
}

var ConditionIpRangeAssignedFalse = metav1.Condition{
Type: "IPRangeAssigned",
Status: "False",
Reason: "IPRangeCRNotCreated",
Message: "Failed to fetch new IP Range from NetBox",
}

var ConditionIpRangeAssignedFalseSizeMissmatch = metav1.Condition{
Type: "IPRangeAssigned",
Status: "False",
Reason: "IPRangeCRNotCreated",
Message: "Assigned/Restored IP range has less available IP addresses than requested",
}
Loading
Loading