-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dynamic selection of parent prefix from a set of custom fie…
…lds (#90) Implement dynamic selection of parent prefix from a set of custom fields 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]>
- Loading branch information
1 parent
5502c04
commit f002bf8
Showing
21 changed files
with
696 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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,56 @@ | ||
# A guide of `ParentPrefixSelector` in `PrefixClaim` | ||
|
||
There are 2 ways to make a Prefix claim: | ||
- provide a `parentPrefix` | ||
- provide a `parentPrefixSelector` | ||
|
||
In this documentation, we will focus on the `parentPrefixSelector` only. | ||
|
||
# CRD format | ||
|
||
The following is a sample of utilizing the `parentPrefixSelector`: | ||
|
||
```bash | ||
apiVersion: netbox.dev/v1 | ||
kind: PrefixClaim | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: netbox-operator | ||
app.kubernetes.io/managed-by: kustomize | ||
name: prefixclaim-customfields-sample | ||
spec: | ||
tenant: "MY_TENANT" | ||
site: "DM-Akron" | ||
description: "some description" | ||
comments: "your comments" | ||
preserveInNetbox: true | ||
prefixLength: "/31" | ||
parentPrefixSelector: | ||
tenant: "MY_TENANT" | ||
site: "DM-Buffalo" | ||
environment: "Production" | ||
poolName: "Pool 1" | ||
``` | ||
|
||
The usage will be explained in the following sections. | ||
|
||
## Notes on `Spec.tenant` and `Spec.site` | ||
|
||
Please provide the *name*, not the *slug* value | ||
|
||
## `parentPrefixSelector` | ||
|
||
The `parentPrefixSelector` is a key-value map, where all the entries are of data type `<string-string>`. | ||
|
||
The map contains a set of query conditions for selecting a set of prefixes that can be used as the parent prefix. | ||
|
||
The query conditions will be chained by the AND operator, and exact match of the keys and values will be performed. | ||
|
||
The fields that can be used as query conditions in the `parentPrefixSelector` are: | ||
- `tenant` and `site` (in lowercase characters) | ||
- these 2 fields are built-in fields from NetBox, so you do *not* need to create custom fields for them | ||
- please provide the *name*, not the *slug* value | ||
- if the entry for tenant or site is missing, it will *not* inherit from the tenant and site from the Spec | ||
- custom fields | ||
- the data types tested and supported so far are `string`, `integer`, and `boolean` | ||
- for `boolean` type, please use `true` and `false` as the value |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
24 changes: 24 additions & 0 deletions
24
config/samples/netbox_v1_prefixclaim_parentprefixselector.yaml
This file contains 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,24 @@ | ||
apiVersion: netbox.dev/v1 | ||
kind: PrefixClaim | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: netbox-operator | ||
app.kubernetes.io/managed-by: kustomize | ||
name: prefixclaim-parentprefixselector-sample | ||
spec: | ||
tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value | ||
site: "DM-Akron" # Use the `name` value instead of the `slug` value | ||
description: "some description" | ||
comments: "your comments" | ||
preserveInNetbox: true | ||
prefixLength: "/31" | ||
parentPrefixSelector: # The keys and values are case-sensitive | ||
# if the entry for tenant or site is missing, it will *not* inherit from the tenant and site from the Spec | ||
tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value | ||
site: "DM-Buffalo" # Use the `name` value instead of the `slug` value | ||
|
||
# custom fields of your interest | ||
environment: "Production" | ||
poolName: "Pool 1" | ||
# environment: "production" | ||
# poolName: "pool 3" |
28 changes: 28 additions & 0 deletions
28
config/samples/netbox_v1_prefixclaim_parentprefixselector_bool_int.yaml
This file contains 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,28 @@ | ||
apiVersion: netbox.dev/v1 | ||
kind: PrefixClaim | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: netbox-operator | ||
app.kubernetes.io/managed-by: kustomize | ||
name: prefixclaim-parentprefixselector-bool-int-sample | ||
spec: | ||
tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value | ||
site: "DM-Akron" # Use the `name` value instead of the `slug` value | ||
description: "some description" | ||
comments: "your comments" | ||
preserveInNetbox: true | ||
prefixLength: "/31" | ||
parentPrefixSelector: # The keys and values are case-sensitive | ||
# should return a prefix in 3.0.0.0/24 | ||
environment: "Production" | ||
poolName: "Pool 1" | ||
# same condition as above, should return a prefix in 3.0.0.0/24 | ||
# cfDataTypeBool: "true" | ||
# cfDataTypeInteger: "1" | ||
|
||
# should return a prefix in 3.0.2.0/24 | ||
# environment: "Development" | ||
# poolName: "Pool 1" | ||
# same condition as above, should return a prefix in 3.0.0.0/24 | ||
# cfDataTypeBool: "false" | ||
# cfDataTypeInteger: "2" |
This file contains 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 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
Oops, something went wrong.