-
Notifications
You must be signed in to change notification settings - Fork 12
Support reservation of IpRanges #130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
170ef55
add IpRange and IpRangeClaim apis
bruelea 1651e48
implement controllers
bruelea dac210a
refactor controller
bruelea 7c2f981
add unit tests
bruelea 5310f7b
use availabe ips in range to create list for status
bruelea 6be9738
refactor iprange recondile funcitons
bruelea 4aee3b8
fix error handling
bruelea c0d7e9e
fix linting
bruelea bc05634
set minimum size of irc to 2
bruelea ca1044e
Apply suggestions from code review
bruelea e3917fe
Apply suggestions from code review
bruelea c78fc7f
Apply suggestions from code review
bruelea a749839
improvements based on review
bruelea e88e232
improvements for review
bruelea b62004a
rename generateManagedCustomFieldsAnnotation funciton
bruelea fd94329
limit size of iprangeclaim CR to 50
bruelea 745cfd2
improve description of iprangeclaim.spec.size field
bruelea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"` | ||
alexandernorth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| //+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", | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"` | ||
jstudler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| //+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", | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.