Implement Openconfig NTP provider - #517
Conversation
Signed-off-by: Adam Trizuljak <adam.trizuljak@sap.com>
Add optional field NTPSpec.SourceAddress Make SourceInterfaceName also optional Don't support SourceInterfaceName in Openconfig provider In NXOS provider ensure that at least one of these fields is defined Signed-off-by: Adam Trizuljak <adam.trizuljak@sap.com>
Signed-off-by: Adam Trizuljak <adam.trizuljak@sap.com>
Signed-off-by: Adam Trizuljak <adam.trizuljak@sap.com>
Signed-off-by: Adam Trizuljak <adam.trizuljak@sap.com>
a355b07 to
e1c927a
Compare
Merging this branch will decrease overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
Signed-off-by: Adam Trizuljak <adam.trizuljak@sap.com>
| @@ -0,0 +1,43 @@ | |||
| # Banner PreLogin | |||
There was a problem hiding this comment.
| # Banner PreLogin | |
| # NTP |
There was a problem hiding this comment.
Why do we need all these files in examples/openconfig-containerlab?
If you just use the following containerlab topology:
name: srlinux
topology:
nodes:
srl:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux:26.3.1
startup-config: |-
system grpc-server mgmt yang-models native
system aaa authentication admin-user password admin
ports:
- 8022:22
- 9339:57400The default device sample in https://github.com/ironcore-dev/network-operator/blob/main/config/samples/v1alpha1_device.yaml connecting to host.docker.internal on port 9339 with admin:admin will work out of the box. This is already setup and integrated with the Tiltfile, so everything is already there.
| Prefer bool `json:"prefer,omitempty"` | ||
|
|
||
| // The name of the vrf used to communicate with the NTP server. | ||
| // Maps to NetworkInstance in Openconfig. If empty, will be set to `mgmt`. |
There was a problem hiding this comment.
We try to avoid such vendor specifics in our core apis, as these are meant to be vendor-agnostic and work across all vendors.
Also note that the management vrf is called differently on different platforms, so it might not always be called "mgmt".
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=63 | ||
| SourceInterfaceName string `json:"sourceInterfaceName"` | ||
| SourceAddress string `json:"sourceAddress,omitempty"` |
There was a problem hiding this comment.
Could we just look up the source address by using the source interface name inside of the provider implementation and then use it as source address without the need to alter the API?
|
|
||
| // DNS represents the OpenConfig /system/ntp container. | ||
| type NTP struct { | ||
| Config *NTPConfig `json:"config,omitempty"` |
There was a problem hiding this comment.
| Config *NTPConfig `json:"config,omitempty"` | |
| Config *NTPConfig `json:"config"` |
If a field is always set/present, we shouldn't have a "omitempty" tag on it. Applies also to the other types in this file. See
Lines 148 to 164 in 7603471
|
|
||
| // NTPConfig holds the config container for NTP. | ||
| type NTPConfig struct { | ||
| Enabled bool `json:"enabled"` // Maps to AdminState |
There was a problem hiding this comment.
| Enabled bool `json:"enabled"` // Maps to AdminState | |
| Enabled bool `json:"enabled"` |
nit: I think the mapping is already clear from the implementation itself, so these comments don't add to much additional value. Would just leave them out.
Work in progress
internal/provider/openconfig/ntp.go) and a gnmi testdata file (test/gnmi/testdata/openconfig/ntp.txt).NTPSpec.SourceAddressand validation logic (see below)DeviceandNTPresourcesSrcIpItems, SrcIptoSrcIPItems,SrcIPininternal/provider/cisco/nxos/ntp.goCisco vs Openconfig compatibility issue (solved)
NTPSpecdefines theSourceInterfaceNamefield https://github.com/ironcore-dev/network-operator/blob/main/api/core/v1alpha1/ntp_types.go#L36. Openconfig has something similarsource-addresshttps://openconfig.net/projects/models/schemadocs/yangdoc/openconfig-system.html#system-ntp-servers-server-config-source-addressA way to handle it would be to look up the interface given by SourceInterfaceName , get its IPv4 address and put it into
source-address. Does it make sense? Do you usually do such operations, or do you keep the provider code clean from reading any additional k8s resources?Other way would be to just ignore
SourceInterfaceNameand not pass it into the Openconfig struct, or even throw aapistatus.FieldViolationsaying that it's unsupportedSolution
Discussed with @nikatza and @rgildein
NTPSpec.SourceInterfaceNameas optionalNTPSpec.SourceAddressSourceInterfaceNameis definedSince both fields are optional, the change will be backwards-compatible with the previous NTPSpec and the generated custom resources.