-
Notifications
You must be signed in to change notification settings - Fork 584
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
Add DeviceInfo Data to NetworkStatus Annotation #577
Add DeviceInfo Data to NetworkStatus Annotation #577
Conversation
/hold This PR requires k8snetworkplumbingwg/network-attachment-definition-client#29 to be merged first. Once that is merged, go.mod will be updated to point to those changes, |
2f86cde
to
ae33f06
Compare
@@ -558,9 +585,16 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c | |||
cniArgs := os.Getenv("CNI_ARGS") | |||
for idx, delegate := range n.Delegates { | |||
ifName := getIfname(delegate, args.IfName, idx) | |||
rt, cniDeviceInfoPath := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, n.RuntimeConfig, delegate) | |||
if cniDeviceInfoPath != "" { | |||
err = nadutils.CopyDeviceInfoForCNIFromDP(cniDeviceInfoPath, delegate.ResourceName, delegate.DeviceID) |
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.
@amorenoz There are several places in the PR where I ignore the errors coming back from utility calls for the DP and CNI files. Is there anyway to know for sure if a file should exist and take extra action? Or leave as is and handle file if it exists and move on otherwise.
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.
The thing is, everything is optional for now right?
From Multul's point of view:
- If DP file does not exist, we may want to log, but that 's not an error
- If CNI does not create a file, we may want to log, but is not an error either.
If DP does exist, we do the copy and then it is magically removed after the delegation-chain call (i.e: when we write the NetworkStatus Annotation), then yes, that's an error.
func MergeCNIRuntimeConfig(runtimeConfig *RuntimeConfig, delegate *DelegateNetConf) *RuntimeConfig { | ||
logging.Debugf("MergeCNIRuntimeConfig: %v %v", runtimeConfig, delegate) | ||
// mergeCNIRuntimeConfig creates CNI runtimeconfig from delegate | ||
func mergeCNIRuntimeConfig(runtimeConfig *RuntimeConfig, delegate *DelegateNetConf) *RuntimeConfig { |
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.
Just making sure I understand this, but, you're making this a private function in favor of the types.CreateCNIRuntimeConf
where it's called from multus.go?
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.
Yes making private. All cases in multus.go that mergeCNIRuntimeConfig
was called, it was followed by a call to CreateCNIRuntimeConf
. So mergeCNIRuntimeConfig
is now called from CreateCNIRuntimeConf
and no longer called from multus.go.
c58f060
to
c86a4fc
Compare
Pull Request Test Coverage Report for Build 373163174
💛 - Coveralls |
types/conf.go
Outdated
@@ -164,18 +168,26 @@ func mergeCNIRuntimeConfig(runtimeConfig *RuntimeConfig, delegate *DelegateNetCo | |||
if delegate.DeviceID != "" { | |||
runtimeConfig.DeviceID = delegate.DeviceID | |||
} | |||
logging.Debugf("mergeCNIRuntimeConfig: add runtimeConfig for net-attach-def: %v", runtimeConfig) | |||
} | |||
|
|||
return runtimeConfig | |||
} | |||
|
|||
// CreateCNIRuntimeConf create CNI RuntimeConf for a delegate |
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.
This function has changed, maybe update the comment?
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.
Tweaked the comment. Let me know if you think there should be more.
@@ -111,6 +112,8 @@ type DelegateNetConf struct { | |||
ConfListPlugin bool `json:"-"` | |||
// DeviceID is only used internal housekeeping | |||
DeviceID string `json:"deviceID,omitempty"` | |||
// ResourceName is only used internal housekeeping | |||
ResourceName string `json:"resourceName,omitempty"` | |||
|
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.
Why do we need this for?
It may be there from my old poc code in which I used the ResourceName to derive the CNIDeviceInfoFile.
But now we're using the RuntimeConfig to store the entire CNIDeviceInfoFile so this might not be needed
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.
It looks like Billy needs to pass this between two places and he's stashed it here in the DelegateNetConf.
I'm personally OK with this. However, if you have a recommendation for a way to extract it otherwise, I'm definitely all ears.
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.
ResourceName is used in multus.go in cmdAdd()
to call nadutils.CopyDeviceInfoForCNIFromDP()
, used to determine the DP file name. There may be a better way to get the data from k8sclient.go in getKubernetesDelegate()
where it is pulled from the annotation from NetworkAttachmentDefinition, but I haven't found it.
/hold cancel |
Move Multus to use latest network-attachment-definition-client repo which contains the device-info-spec changes. Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
c86a4fc
to
1127411
Compare
RuntimeConfig depends on the delegate configuration. The Netconf runtime information should be merged with the delegate config and the result added to each command that is sent to the delegates. That was being done for all commands except for delPlugins. Do not export MergeCNIRuntimeConfig and call it from CreateCNIRuntimeConf that now accepts a delegate ptr. Call it from delPlugins for each delegate Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
DPDeviceFile is used by Device Plugins to pass device data to CNIs, as defined in the device-info-spec. The name of the DPDeviceFile is defined by the device-info-spec as: <ResourceName>-<DeviceID>-device.json If the DPDeviceFile exists, the NPWG implementation makes a copy of the file and passes the name of the file to the delegate CNI via capabilityArgs as CNIDeviceFile. If the DPDeviceFile does not exist, the filename is still passed to the CNI. The CNI can create the file and popluate it if a device is created within the CNI. The name of the CNIDeviceFile is not defined by device-info-spec, but to ensure the name does not clash it is formed by the following unique triplet: [networkName, PodUUID, ifName] k8snetworkplumbingwg/network-attachment-definition-client repo has utility functions to abstract some of this functionality so it can be reused across Device Plugins, NPWG implementations and CNIs. Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
NetworkStatus was moved to network-attachment-definition-client in previous merges and the Multus version of the structure was left behind, and not being used. Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
1127411
to
ae79780
Compare
@@ -202,6 +212,9 @@ func CreateCNIRuntimeConf(args *skel.CmdArgs, k8sArgs *K8sArgs, ifName string, r | |||
if len(delegateRc.InfinibandGUID) != 0 { | |||
capabilityArgs["infinibandGUID"] = delegateRc.InfinibandGUID | |||
} | |||
if delegateRc.DeviceID != "" { |
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.
Does this mean we need to add DeviceID
capability explicitly when creating net-attach-def?
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.
It's not required. You would only need it if the CNI supports deviceIDs not coming from DevicePlugin, e.g: host-device
@@ -122,6 +122,13 @@ func LoadDelegateNetConf(bytes []byte, net *NetworkSelectionElement, deviceID st | |||
if net.InfinibandGUIDRequest != "" { | |||
delegateConf.InfinibandGUIDRequest = net.InfinibandGUIDRequest | |||
} | |||
if net.DeviceID != "" { | |||
if deviceID != "" { | |||
logging.Debugf("Warning: Both RuntimeConfig and ResourceMap provide deviceID. Ignoring RuntimeConfig") |
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.
Do you see RuntimeConfig.DeviceID is to replace ResourceMap.DeviceID as default in the future?
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.
@zshi-redhat AFAIK, I don't think so. RuntimeConfig.DeviceID is useful for cases in which you don't have Device Plugin (hence, no ResourceMap.DeviceID)
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 Billy -- I realize this was a long road. Thanks for all the attention between both the spec, as well as this PR, and all the due dilligence.
@@ -55,7 +56,7 @@ func LoadDelegateNetConfList(bytes []byte, delegateConf *DelegateNetConf) error | |||
} | |||
|
|||
// LoadDelegateNetConf converts raw CNI JSON into a DelegateNetConf structure | |||
func LoadDelegateNetConf(bytes []byte, net *NetworkSelectionElement, deviceID string) (*DelegateNetConf, error) { | |||
func LoadDelegateNetConf(bytes []byte, net *NetworkSelectionElement, deviceID string, resourceName string) (*DelegateNetConf, error) { |
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.
Is there any testcase that contains LoadDelegateNetConf() with resourceName? As far as I looked your code, all test cases uses LoadDelegateNetConf() with empty resource name.
Update the NetworkStatus with DeviceInfo per the approved device-info-spec, which can be found:
https://github.com/k8snetworkplumbingwg/device-info-spec
This allows DevicePlugins and CNIs to add additional data to the NetworkStatus annotation, which can be used by a container to add in deployment of the container workload.
This PR is based on npwg_poc2 by Adrian Moreno