Repository navigation
add hostnetworkconfig crd and rbac permissions - #456
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new HostNetworkConfig Custom Resource Definition (CRD) to manage node-level network configurations on Harvester hosts, along with the necessary RBAC permissions to access this resource.
Key Changes:
- Introduces the
HostNetworkConfigCRD supporting both static and DHCP IP assignment modes with VLAN configuration capabilities - Updates RBAC permissions for harvester-network-controller and harvester-network-webhook to include access to the new
hostnetworkconfigsresource
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| charts/harvester-network-controller/templates/crds/network.harvesterhci.io_hostnetworkconfigs.yaml | New CRD defining the HostNetworkConfig resource with spec for network configuration and status for tracking per-node application state |
| charts/harvester-network-controller/templates/rbac.yaml | Adds "hostnetworkconfigs" to the resources list in both the main controller ClusterRole and webhook ClusterRole for appropriate access permissions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type: string | ||
| kind: | ||
| type: string |
There was a problem hiding this comment.
The apiVersion and kind fields lack the detailed descriptions that are present in other CRDs in this repository. For consistency with vlanconfigs, vlanstatuses, and linkmonitors, these fields should include standard Kubernetes descriptions explaining their purpose.
| type: string | |
| kind: | |
| type: string | |
| type: string | |
| description: | | |
| APIVersion defines the versioned schema of this representation of an object. | |
| Servers should convert recognized schemas to the latest internal value, and | |
| may reject unrecognized values. More info: | |
| https://kubernetes.io/docs/reference/using-api/api-overview/ | |
| kind: | |
| type: string | |
| description: | | |
| Kind is a string value representing the REST resource this object represents. | |
| Servers may infer this from the endpoint the client submits requests to. | |
| Cannot be updated. In CamelCase. More info: | |
| https://kubernetes.io/docs/reference/using-api/api-overview/ |
| versions: | ||
| - name: v1beta1 | ||
| served: true | ||
| storage: true |
There was a problem hiding this comment.
The CRD is missing additionalPrinterColumns which are present in similar CRDs like vlanconfigs and vlanstatuses. Adding printer columns for key fields such as clusterNetwork, mode, and AGE would improve the user experience when listing resources with kubectl.
| storage: true | |
| storage: true | |
| additionalPrinterColumns: | |
| - name: ClusterNetwork | |
| type: string | |
| jsonPath: .spec.clusterNetwork | |
| - name: Mode | |
| type: string | |
| jsonPath: .spec.mode | |
| - name: Age | |
| type: date | |
| jsonPath: .metadata.creationTimestamp |
| schema: | ||
| openAPIV3Schema: | ||
| type: object | ||
| description: | | ||
| HostNetworkConfig defines node-level network configuration for Harvester. | ||
| properties: | ||
| apiVersion: | ||
| type: string | ||
| kind: | ||
| type: string | ||
| metadata: | ||
| type: object | ||
|
|
||
| spec: | ||
| type: object | ||
| required: | ||
| - clusterNetwork | ||
| - mode | ||
| properties: | ||
| underlay: | ||
| type: boolean | ||
| description: | | ||
| Indicates whether this configuration represents the underlay network. | ||
| Default is false. Only one HostNetworkConfig per node may set this to true. | ||
| default: false | ||
| clusterNetwork: | ||
| type: string | ||
| description: Name of the cluster network | ||
| vlanID: | ||
| type: integer | ||
| format: int32 | ||
| minimum: 2 | ||
| maximum: 4094 | ||
| description: VLAN ID associated with the host network | ||
| mode: | ||
| type: string | ||
| description: IP assignment mode | ||
| enum: | ||
| - static | ||
| - dhcp | ||
| ips: | ||
| type: object | ||
| description: Static IP assignments per node (used when mode is static) | ||
| additionalProperties: | ||
| type: string | ||
| description: CIDR-formatted IP address assigned to the node | ||
|
|
||
| status: | ||
| type: object | ||
| description: Observed state of the HostNetworkConfig | ||
| properties: | ||
| result: | ||
| type: string | ||
| description: Final result of applying the configuration | ||
| enum: | ||
| - Success | ||
| - Failure | ||
| reason: | ||
| type: string | ||
| description: Reason for failure when result is Failure | ||
| nodeStatuses: | ||
| type: object | ||
| description: Per-node application status | ||
| additionalProperties: | ||
| type: object | ||
| properties: | ||
| applied: | ||
| type: boolean | ||
| description: Whether configuration was successfully applied on the node | ||
| ip: | ||
| type: string | ||
| description: IP address applied to the node | ||
| error: | ||
| type: string | ||
| description: Error message if configuration failed on this node | ||
|
|
There was a problem hiding this comment.
The schema is missing a top-level 'required' field for the spec property. Other CRDs in this repository (vlanconfigs, linkmonitors, vlanstatuses) include a 'required' array at the root level of the schema to enforce that spec is present. This should be added for consistency and to ensure proper validation.
| ips: | ||
| type: object | ||
| description: Static IP assignments per node (used when mode is static) | ||
| additionalProperties: | ||
| type: string | ||
| description: CIDR-formatted IP address assigned to the node |
There was a problem hiding this comment.
The validation for the 'ips' field may need additional constraints. When mode is 'static', the ips field should likely be required, but when mode is 'dhcp', it should not be used. Consider adding validation rules or documenting this relationship more clearly to prevent invalid configurations.
| format: int32 | ||
| minimum: 2 | ||
| maximum: 4094 | ||
| description: VLAN ID associated with the host network |
There was a problem hiding this comment.
The vlanID field has validation constraints (minimum: 2, maximum: 4094) but is not marked as required. The documentation should clarify whether vlanID is optional and, if so, what the behavior is when it's not specified. Alternatively, if vlanID is always required for host network configurations, it should be added to the required array.
| description: VLAN ID associated with the host network | |
| description: | | |
| Optional VLAN ID associated with the host network. If omitted, the | |
| host network configuration uses the controller's default VLAN behavior | |
| (for example, it may be treated as an untagged network). |
5d9d85d to
b496234
Compare
|
Did you add this new CRD first to https://github.com/harvester/network-controller-harvester/tree/master/pkg/apis/network.harvesterhci.io/v1beta1 and https://github.com/harvester/network-controller-harvester/tree/master/manifests/crds? I assume this PR should come after updating the component repo first. |
@innobead yes the corresponding network controller changes are here rrajendran17/network-controller-harvester@7824dcd (work in progress), I will post it for review once complete, Thanks |
| additionalProperties: | ||
| description: CIDR-formatted IP address assigned to the node | ||
| type: string |
There was a problem hiding this comment.
One thing you can consider doing is to use the built-in CEL validation to validate the CIDR format. It makes the API more expressive and ensures K8s rejects any invalid format immediately, without the request ever reaching our webhook.
For example,
ips:
additionalProperties:
description: |-
CIDR is an IP address range in CIDR notation (for example, "10.0.0.0/8" or "fd00::/8").
maxLength: 18 # required
type: string
x-kubernetes-validations:
- message: Invalid CIDR format provided
rule: isCIDR(self)b496234 to
699eaf2
Compare
|
@rrajendran17 As the CIDR related parts are modified manually to yaml, it will be a bit diffcult to maintain please (1) Add comment to the source code api definition on harvester/network-controller-harvester#229 (2) Please check below script, if we could use a diff file or some other ways to patch the crd after thanks. |
fc740b4 to
3da1013
Compare
Thanks @w13915984028 I have updated the original PR with the crd generated from api, but did not update this PR with the same crd. I have pushed the changes now. |
Maybe updating the controller-gen to a newer version might help? |
cbae759 to
d1984c8
Compare
I thought its an issue with controller-gen, looks like the kubebuillder does not provide an explicit maxLength for map values as string.It supports validations for slice formats and strings. If value in map has to be validated for maxLength, then it can be made as a string inside a struct but it complicates the api. Let me know in case there are other options, Thanks |
@ihcsim helped me fix this.Its all good now,I could include maxLength from api into the CRD.Thanks |
5615cca to
707c806
Compare
4039646 to
77be978
Compare
| verbs: [ "*" ] | ||
| - apiGroups: [ "network.harvesterhci.io" ] | ||
| resources: [ "clusternetworks", "vlanconfigs", "vlanstatuses", "linkmonitors" ] | ||
| resources: [ "clusternetworks", "vlanconfigs", "vlanstatuses", "linkmonitors", "hostnetworkconfigs","hostnetworkconfigs/status" ] |
There was a problem hiding this comment.
question: could here and below be "*", as all the resources are by nature operated by network-controller
Signed-off-by: Renuka Devi Rajendran <renuka.rajendran@suse.com>
8fd71c5
f55fe54 to
8fd71c5
Compare
Signed-off-by: Renuka Devi Rajendran <renuka.rajendran@suse.com>
Signed-off-by: Renuka Devi Rajendran <renuka.rajendran@suse.com>
Signed-off-by: Renuka Devi Rajendran <renuka.rajendran@suse.com>
Problem:
New CRD required for introducing host network configs on harvester hosts
Solution:
new crd for creating host network configs on harvester host and its related permissions
Related Issue(s):
harvester/harvester#8101
Test plan:
https://github.com/rrajendran17/harvester-harvester/blob/HEP-ipconfig/enhancements/20251015-support-ipconfig-on-clusternetworks.md
Additional documentation or context