@@ -24,24 +24,36 @@ import (
2424// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525
2626// PrefixClaimSpec defines the desired state of PrefixClaim
27+ // TODO: The reason for using a workaround please see https://github.com/netbox-community/netbox-operator/pull/90#issuecomment-2402112475
2728// +kubebuilder:validation:XValidation:rule="!has(oldSelf.site) || has(self.site)", message="Site is required once set"
29+ // +kubebuilder:validation:XValidation:rule="(!has(self.parentPrefix) && has(self.parentPrefixSelector)) || (has(self.parentPrefix) && !has(self.parentPrefixSelector))"
2830type PrefixClaimSpec struct {
31+
2932 // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3033 // Important: Run "make" to regenerate code after modifying this file
3134
32- //+kubebuilder:validation:Required
3335 //+kubebuilder:validation:Format=cidr
3436 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'parentPrefix' is immutable"
35- ParentPrefix string `json:"parentPrefix"`
37+ ParentPrefix string `json:"parentPrefix,omitempty"`
38+
39+ // The `parentPrefixSelector` is a key-value map, where all the entries are of data type `<string-string>`
40+ // The map contains a set of query conditions for selecting a set of prefixes that can be used as the parent prefix
41+ // The query conditions will be chained by the AND operator, and exact match of the keys and values will be performed
42+ // 2 built-in fields, namely `tenant` and `site`, along with custom fields, can be used
43+ // For more information, please see ParentPrefixSelectorGuide.md
44+ //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'parentPrefixSelector' is immutable"
45+ ParentPrefixSelector map [string ]string `json:"parentPrefixSelector,omitempty"`
3646
3747 //+kubebuilder:validation:Required
3848 //+kubebuilder:validation:Pattern=`^\/[0-9]|[1-9][0-9]|1[01][0-9]|12[0-8]$`
3949 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'prefixLength' is immutable"
4050 PrefixLength string `json:"prefixLength"`
4151
52+ // Use the `name` value instead of the `slug` value
4253 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'site' is immutable"
4354 Site string `json:"site,omitempty"`
4455
56+ // Use the `name` value instead of the `slug` value
4557 //+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'tenant' is immutable"
4658 Tenant string `json:"tenant,omitempty"`
4759
@@ -58,10 +70,15 @@ type PrefixClaimSpec struct {
5870type PrefixClaimStatus struct {
5971 // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
6072 // Important: Run "make" to regenerate code after modifying this file
61- // Prefix status: container, active, reserved , deprecated
62- Prefix string `json:"prefix,omitempty"`
63- PrefixName string `json:"prefixName,omitempty"`
64- Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
73+ // Prefix status: container, active, reserved, deprecated
74+
75+ // Due to the fact that the parent prefix can be specified directly in `ParentPrefix` or selected from `ParentPrefixSelector`,
76+ // we use this field to store exactly which parent prefix we are using for all subsequent reconcile loop calls,
77+ // as Spec.ParentPrefix is an immutable field, we can't overwrite it
78+ SelectedParentPrefix string `json:"parentPrefix,omitempty"`
79+ Prefix string `json:"prefix,omitempty"`
80+ PrefixName string `json:"prefixName,omitempty"`
81+ Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
6582}
6683
6784// +kubebuilder:object:root=true
@@ -120,3 +137,17 @@ var ConditionPrefixAssignedFalse = metav1.Condition{
120137 Reason : "PrefixCRNotCreated" ,
121138 Message : "Failed to fetch new Prefix from NetBox" ,
122139}
140+
141+ var ConditionParentPrefixSelectedTrue = metav1.Condition {
142+ Type : "ParentPrefixSelected" ,
143+ Status : "True" ,
144+ Reason : "ParentPrefixSelected" ,
145+ Message : "The parent prefix was selected successfully" ,
146+ }
147+
148+ var ConditionParentPrefixSelectedFalse = metav1.Condition {
149+ Type : "ParentPrefixSelected" ,
150+ Status : "False" ,
151+ Reason : "ParentPrefixNotSelected" ,
152+ Message : "The parent prefix was not able to be selected" ,
153+ }
0 commit comments