|  | 
|  | 1 | +/* | 
|  | 2 | +Copyright 2024 Swisscom (Schweiz) AG. | 
|  | 3 | +
 | 
|  | 4 | +Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | +you may not use this file except in compliance with the License. | 
|  | 6 | +You may obtain a copy of the License at | 
|  | 7 | +
 | 
|  | 8 | +    http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | +
 | 
|  | 10 | +Unless required by applicable law or agreed to in writing, software | 
|  | 11 | +distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | +See the License for the specific language governing permissions and | 
|  | 14 | +limitations under the License. | 
|  | 15 | +*/ | 
|  | 16 | + | 
|  | 17 | +package v1 | 
|  | 18 | + | 
|  | 19 | +import ( | 
|  | 20 | +	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | 
|  | 21 | +) | 
|  | 22 | + | 
|  | 23 | +// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN! | 
|  | 24 | +// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized. | 
|  | 25 | + | 
|  | 26 | +// IpRangeClaimSpec defines the desired state of IpRangeClaim | 
|  | 27 | +type IpRangeClaimSpec struct { | 
|  | 28 | +	//+kubebuilder:validation:Required | 
|  | 29 | +	//+kubebuilder:validation:Format=cidr | 
|  | 30 | +	//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'parentPrefix' is immutable" | 
|  | 31 | +	ParentPrefix string `json:"parentPrefix"` | 
|  | 32 | + | 
|  | 33 | +	// 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. | 
|  | 34 | +	//+kubebuilder:validation:Required | 
|  | 35 | +	//+kubebuilder:validation:Minimum=2 | 
|  | 36 | +	//+kubebuilder:validation:Maximum=50 | 
|  | 37 | +	//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'size' is immutable" | 
|  | 38 | +	Size int `json:"size,omitempty"` | 
|  | 39 | + | 
|  | 40 | +	//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'tenant' is immutable" | 
|  | 41 | +	Tenant string `json:"tenant,omitempty"` | 
|  | 42 | + | 
|  | 43 | +	CustomFields map[string]string `json:"customFields,omitempty"` | 
|  | 44 | + | 
|  | 45 | +	Comments string `json:"comments,omitempty"` | 
|  | 46 | + | 
|  | 47 | +	Description string `json:"description,omitempty"` | 
|  | 48 | + | 
|  | 49 | +	PreserveInNetbox bool `json:"preserveInNetbox,omitempty"` | 
|  | 50 | +} | 
|  | 51 | + | 
|  | 52 | +// IpRangeClaimStatus defines the observed state of IpRangeClaim | 
|  | 53 | +type IpRangeClaimStatus struct { | 
|  | 54 | +	IpRange string `json:"ipRange,omitempty"` | 
|  | 55 | + | 
|  | 56 | +	IpRangeDotDecimal string `json:"ipRangeDotDecimal,omitempty"` | 
|  | 57 | + | 
|  | 58 | +	IpAddresses []string `json:"ipAddresses,omitempty"` | 
|  | 59 | + | 
|  | 60 | +	IpAddressesDotDecimal []string `json:"ipAddressesDotDecimal,omitempty"` | 
|  | 61 | + | 
|  | 62 | +	StartAddress string `json:"startAddress,omitempty"` | 
|  | 63 | + | 
|  | 64 | +	StartAddressDotDecimal string `json:"startAddressDotDecimal,omitempty"` | 
|  | 65 | + | 
|  | 66 | +	EndAddress string `json:"endAddress,omitempty"` | 
|  | 67 | + | 
|  | 68 | +	EndAddressDotDecimal string `json:"endAddressDotDecimal,omitempty"` | 
|  | 69 | + | 
|  | 70 | +	IpRangeName string `json:"ipAddressName,omitempty"` | 
|  | 71 | + | 
|  | 72 | +	Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` | 
|  | 73 | +} | 
|  | 74 | + | 
|  | 75 | +//+kubebuilder:object:root=true | 
|  | 76 | +//+kubebuilder:subresource:status | 
|  | 77 | +//+kubebuilder:storageversion | 
|  | 78 | +//+kubebuilder:printcolumn:name="IpRange",type=string,JSONPath=`.status.ipRange` | 
|  | 79 | +//+kubebuilder:printcolumn:name="IpRangeAssigned",type=string,JSONPath=`.status.conditions[?(@.type=="IPRangeAssigned")].status` | 
|  | 80 | +//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` | 
|  | 81 | +//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` | 
|  | 82 | +// +kubebuilder:resource:shortName=iprc | 
|  | 83 | + | 
|  | 84 | +// IpRangeClaim is the Schema for the iprangeclaims API | 
|  | 85 | +type IpRangeClaim struct { | 
|  | 86 | +	metav1.TypeMeta   `json:",inline"` | 
|  | 87 | +	metav1.ObjectMeta `json:"metadata,omitempty"` | 
|  | 88 | + | 
|  | 89 | +	Spec   IpRangeClaimSpec   `json:"spec,omitempty"` | 
|  | 90 | +	Status IpRangeClaimStatus `json:"status,omitempty"` | 
|  | 91 | +} | 
|  | 92 | + | 
|  | 93 | +//+kubebuilder:object:root=true | 
|  | 94 | + | 
|  | 95 | +// IpRangeClaimList contains a list of IpRangeClaim | 
|  | 96 | +type IpRangeClaimList struct { | 
|  | 97 | +	metav1.TypeMeta `json:",inline"` | 
|  | 98 | +	metav1.ListMeta `json:"metadata,omitempty"` | 
|  | 99 | +	Items           []IpRangeClaim `json:"items"` | 
|  | 100 | +} | 
|  | 101 | + | 
|  | 102 | +func init() { | 
|  | 103 | +	SchemeBuilder.Register(&IpRangeClaim{}, &IpRangeClaimList{}) | 
|  | 104 | +} | 
|  | 105 | + | 
|  | 106 | +var ConditionIpRangeClaimReadyTrue = metav1.Condition{ | 
|  | 107 | +	Type:    "Ready", | 
|  | 108 | +	Status:  "True", | 
|  | 109 | +	Reason:  "IPRangeResourceReady", | 
|  | 110 | +	Message: "IP Range Resource is ready", | 
|  | 111 | +} | 
|  | 112 | + | 
|  | 113 | +var ConditionIpRangeClaimReadyFalse = metav1.Condition{ | 
|  | 114 | +	Type:    "Ready", | 
|  | 115 | +	Status:  "False", | 
|  | 116 | +	Reason:  "IPRangeResourceNotReady", | 
|  | 117 | +	Message: "IP Range Resource is not ready", | 
|  | 118 | +} | 
|  | 119 | + | 
|  | 120 | +var ConditionIpRangeClaimReadyFalseStatusGen = metav1.Condition{ | 
|  | 121 | +	Type:    "Ready", | 
|  | 122 | +	Status:  "False", | 
|  | 123 | +	Reason:  "IPRangeClaimStatusGenerationFailed", | 
|  | 124 | +	Message: "Failed to generate IP Range Status", | 
|  | 125 | +} | 
|  | 126 | + | 
|  | 127 | +var ConditionIpRangeAssignedTrue = metav1.Condition{ | 
|  | 128 | +	Type:    "IPRangeAssigned", | 
|  | 129 | +	Status:  "True", | 
|  | 130 | +	Reason:  "IPRangeCRCreated", | 
|  | 131 | +	Message: "New IP Range fetched from NetBox and IpRange CR was created", | 
|  | 132 | +} | 
|  | 133 | + | 
|  | 134 | +var ConditionIpRangeAssignedFalse = metav1.Condition{ | 
|  | 135 | +	Type:    "IPRangeAssigned", | 
|  | 136 | +	Status:  "False", | 
|  | 137 | +	Reason:  "IPRangeCRNotCreated", | 
|  | 138 | +	Message: "Failed to fetch new IP Range from NetBox", | 
|  | 139 | +} | 
|  | 140 | + | 
|  | 141 | +var ConditionIpRangeAssignedFalseSizeMissmatch = metav1.Condition{ | 
|  | 142 | +	Type:    "IPRangeAssigned", | 
|  | 143 | +	Status:  "False", | 
|  | 144 | +	Reason:  "IPRangeCRNotCreated", | 
|  | 145 | +	Message: "Assigned/Restored IP range has less available IP addresses than requested", | 
|  | 146 | +} | 
0 commit comments