@@ -24,24 +24,36 @@ import (
24
24
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25
25
26
26
// 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
27
28
// +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))"
28
30
type PrefixClaimSpec struct {
31
+
29
32
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
30
33
// Important: Run "make" to regenerate code after modifying this file
31
34
32
- //+kubebuilder:validation:Required
33
35
//+kubebuilder:validation:Format=cidr
34
36
//+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"`
36
46
37
47
//+kubebuilder:validation:Required
38
48
//+kubebuilder:validation:Pattern=`^\/[0-9]|[1-9][0-9]|1[01][0-9]|12[0-8]$`
39
49
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'prefixLength' is immutable"
40
50
PrefixLength string `json:"prefixLength"`
41
51
52
+ // Use the `name` value instead of the `slug` value
42
53
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'site' is immutable"
43
54
Site string `json:"site,omitempty"`
44
55
56
+ // Use the `name` value instead of the `slug` value
45
57
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="Field 'tenant' is immutable"
46
58
Tenant string `json:"tenant,omitempty"`
47
59
@@ -58,10 +70,15 @@ type PrefixClaimSpec struct {
58
70
type PrefixClaimStatus struct {
59
71
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
60
72
// 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"`
65
82
}
66
83
67
84
// +kubebuilder:object:root=true
@@ -120,3 +137,17 @@ var ConditionPrefixAssignedFalse = metav1.Condition{
120
137
Reason : "PrefixCRNotCreated" ,
121
138
Message : "Failed to fetch new Prefix from NetBox" ,
122
139
}
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