-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement dynamic selection of parent prefix from a set of custom fields #90
Implement dynamic selection of parent prefix from a set of custom fields #90
Conversation
335e04b
to
97c512d
Compare
We agree that the The |
Improved CRD validation: According to [2], the Reference: |
787fecd
to
1ad0f81
Compare
For some reason, when we are querying for custom fields, for example using this URL Reproduction step:
The demo SQL files have adhered to this "observation", but I am not able to wrap my head around this, since for the restoration hash, we have no issue with it |
To maintain the backward compatibility of the restoration hash and extend it to support parentPrefixSelection, we have made the following changes to the hash:
With the aforementioned change, the hash can by design distinguish the prefix claimed by ParentPrefix or parentPrefixSelection, thus, making the restoration process relying on the hash achievable. |
1ad0f81
to
f65550b
Compare
Done |
Please add me as reviewer. |
5c97a94
to
592375a
Compare
So as @alexandernorth explained, on browsers, they might modify the URLs. But for the API endpoints what we send is directly being processed. So in the case, this is not an issue for us when querying using API endpoints! But when we are doing debugging using URLs, we might run into issues. |
592375a
to
cac0ce6
Compare
If you use a PrefixClaim using parentPrefixSelector with an invalid Tenant (a Tenant that doesn't exist in NetBox), the Event will show:
Spec example: apiVersion: netbox.dev/v1
kind: PrefixClaim
metadata:
name: prefixclaim-customfields-sample
spec:
tenant: "MY_TENANT that doesn't exist"
site: "DM-Akron"
preserveInNetbox: true
prefixLength: "/31"
parentPrefixSelector: # The keys and values are case-sensitive
environment: "PostProduction"
poolName: "Pool 1" This is quite misleading. Do you think there is an easy way to enhance this? |
Under some circumstances the parent prefix will be computed but it's already exhausted. Even if you add more prefixes, the system will not recover and compute/chose a new parent prefix. Example describe:
Could we fix this by removing |
@jstudler please take another pass when you have time! :) Thanks |
We actually throw an error indicating this situation, please see the code snippet below: func (r *NetboxClient) GetTenantDetails(name string) (*models.Tenant, error) {
request := tenancy.NewTenancyTenantsListParams().WithName(&name)
response, err := r.Tenancy.TenancyTenantsList(request, nil)
if err != nil {
return nil, utils.NetboxError("failed to fetch Tenant details", err)
}
if len(response.Payload.Results) == 0 {
return nil, utils.NetboxNotFoundError("tenant '" + name + "'")
}
return &models.Tenant{
Id: response.Payload.Results[0].ID,
Slug: *response.Payload.Results[0].Slug,
Name: *response.Payload.Results[0].Name,
}, nil
} I think this is related to the discussion this morning - we need to surface the underlying errors properly to the user. As in this case, we did throw an error clearly specifying the problem, but it's not visible to the user. |
Quick question, what's the desired behavior? IMO, prefix exhaustion might be a temporary issue, so we should requeue and keep trying. WDYT? |
The desired behavior is that the Operator can recover from this case. Yes, we should assume that prefix exhaustion is a temporary issue only. The behaviour I've seen above was deadlock: The parent prefix was chosen but it had no space left, but there were other parent prefix candidates that weren't chosen. So I think removing |
But I think the event is wrong. The event indicates "The parent prefix was not able to be computed" when in fact the problem is that the user set an invalid tenant. Could we create an event in |
5ae7b50
to
1b9b95e
Compare
Tracking under bug #132 |
Tracking under bug #131 |
Fixed. Please take a look @jstudler, thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Thanks a lot for the work @henrybear327 !
6b5b695
to
47eebdd
Compare
Notes: According to [2], the `oneOf` validation will only come in the next version Reference: [1] https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/ [2] https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-ratcheting Signed-off-by: Hoanganh.Mai <[email protected]> Signed-off-by: Chun-Hung Tseng <[email protected]> Co-authored-by: Sergio <[email protected]> Co-authored-by: bruelea <[email protected]>
d17ac16
to
ef07396
Compare
Design
We introduce a new
parentPrefixSelector
field in the CR. It's a list of custom field key-value mapping, where both the key and value are of the typestring
. For exampleWe now have 3 cases:
parentPrefix
is set, we continue on as-isparentPrefixSelector
is set, we would take all Prefixes that exactly match all custom field's key-value specified inparentPrefixSelector
. We would then pick the first prefix that is able to satisfy theprefixLength
requirement as the parent prefix.parentPrefix
andparentPrefixSelector
present in the CR, the CRD validation will reject this yaml fileThe parentPrefix will be set in the
status
fieldParentPrefix
, and this will be used as the source of truth for the rest of the reconcile function.Known issue
TODO
status
field to store the computedParentPrefix
value is desiredparentPrefixSelector
would require some documentation, as there might be the case there the picked parent prefix is different for the sameparentPrefixSelector
(e.g. due to prefix space exhaustion), and thus, the restoration might not work as user anticipated.Notes