Skip to content
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

Upgrade whereabouts CNI to v0.5.4 and align secondary network IPAM with additional pluginArgs #3987

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build/charts/antrea/templates/whereabouts/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rules:
- whereabouts.cni.cncf.io
resources:
- ippools
- overlappingrangeipreservations
verbs:
- get
- put
Expand All @@ -19,4 +20,13 @@ rules:
- patch
- create
- delete
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- create
- get
- list
- update
{{- end }}
2 changes: 1 addition & 1 deletion build/images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG OVS_VERSION
FROM ubuntu:20.04 as cni-binaries

ARG CNI_BINARIES_VERSION
ARG WHEREABOUTS_VERSION=v0.5.1
ARG WHEREABOUTS_VERSION=v0.5.4

RUN apt-get update && \
apt-get install -y --no-install-recommends wget ca-certificates
Expand Down
29 changes: 20 additions & 9 deletions pkg/agent/secondarynetwork/podwatch/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,24 @@ func generatePodSecondaryIfaceName(podCNIInfo *cnipodcache.CNIConfigInfo) string
return string("eth") + strconv.Itoa(rand.IntnRange(end_iface_index, max_rand_index))
}

func whereaboutsArgsBuilder(cmd string, interfaceName string, podCNIInfo *cnipodcache.CNIConfigInfo) *invoke.Args {
// PluginArgs added to provide additional arguments required for whereabouts v0.5.1 and above.
return &invoke.Args{Command: cmd, ContainerID: podCNIInfo.ContainerID,
NetNS: podCNIInfo.ContainerNetNS, IfName: interfaceName,
Path: cniPath, PluginArgs: [][2]string{
{"K8S_POD_NAME", podCNIInfo.PodName},
{"K8S_POD_NAMESPACE", podCNIInfo.PodNameSpace},
{"K8S_POD_INFRA_CONTAINER_ID", podCNIInfo.ContainerID},
}}

}

func removePodAllSecondaryNetwork(podCNIInfo *cnipodcache.CNIConfigInfo) error {
var cmdArgs *invoke.Args
// Clean-up IPAM at whereabouts db (etcd or kubernetes API server) for all the secondary networks of the Pod which is getting removed.
// PluginArgs added to provide additional arguments required for whereabouts v0.5.1 and above.
// NOTE: SR-IOV VF interface clean-up, upon Pod delete will be handled by SR-IOV device plugin. Not handled here.
cmdArgs = &invoke.Args{Command: string("DEL"), ContainerID: podCNIInfo.ContainerID,
NetNS: podCNIInfo.ContainerNetNS, Path: cniPath}
cmdArgs = whereaboutsArgsBuilder("DEL", "", podCNIInfo)
// example: podCNIInfo.NetworkConfig = {"eth1": net1-cniconfig, "eth2": net2-cniconfig}
for secNetInstIface, secNetInstConfig := range podCNIInfo.NetworkConfig {
cmdArgs.IfName = secNetInstIface
Expand Down Expand Up @@ -190,7 +202,7 @@ func (pc *PodController) handleAddUpdatePod(obj interface{}) error {
// Avoid processing Pod annotation, if we already have at least one secondary network successfully configured on this Pod.
// We do not support/handle Annotation updates yet.
if len(podCNIInfo.NetworkConfig) > 0 {
klog.InfoS("Secondary network already configured on this Pod. Annotation update not supported.", klog.KObj(pod))
klog.InfoS("Secondary network already configured on this Pod and annotation update not supported, skipping update", "pod", klog.KObj(pod))
return nil
}
// Parse Pod annotation and proceed with the secondary network configuration.
Expand Down Expand Up @@ -293,9 +305,8 @@ func (pc *PodController) configureSecondaryInterface(pod *corev1.Pod, netinfo *S
netinfo.InterfaceName = generatePodSecondaryIfaceName(podCNIInfo)
}
if netinfo.InterfaceType == sriovInterfaceType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to avoid code duplication by using a helper function to craft the cni plugin args?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Moved the command building into a separate function whereaboutsCmdBuilder().

cmdArgs = &invoke.Args{Command: string("ADD"), ContainerID: podCNIInfo.ContainerID,
NetNS: podCNIInfo.ContainerNetNS, IfName: netinfo.InterfaceName,
Path: cniPath}
// PluginArgs added to provide additional arguments required for whereabouts v0.5.1 and above.
cmdArgs = whereaboutsArgsBuilder("ADD", netinfo.InterfaceName, podCNIInfo)
ipamResult, err = ipam.GetIPAMSubnetAddress(cniconfig, cmdArgs)
if err != nil {
return errors.New("secondary network IPAM failed")
Expand Down Expand Up @@ -329,7 +340,7 @@ func (pc *PodController) configureSecondaryInterface(pod *corev1.Pod, netinfo *S
func (pc *PodController) configureSecondaryNetwork(pod *corev1.Pod, networklist []*SecondaryNetworkObject, podCNIInfo *cnipodcache.CNIConfigInfo) error {

for _, netinfo := range networklist {
klog.InfoS("Secondary Network Information:", netinfo)
klog.InfoS("Secondary Network Information:", "Info", netinfo)
if len(netinfo.NetworkName) > 0 {
netDefCRD, err := pc.netAttachDefClient.NetworkAttachmentDefinitions(pod.Namespace).Get(context.TODO(), netinfo.NetworkName, metav1.GetOptions{})
if err != nil {
Expand All @@ -353,10 +364,10 @@ func (pc *PodController) configureSecondaryNetwork(pod *corev1.Pod, networklist

func (pc *PodController) Run(stopCh <-chan struct{}) {
defer func() {
klog.InfoS("Shutting down", controllerName)
klog.InfoS("Shutting down", "controller", controllerName)
pc.queue.ShutDown()
}()
klog.InfoS("Starting ", controllerName)
klog.InfoS("Starting ", "controller", controllerName)
go pc.podInformer.Run(stopCh)
if !cache.WaitForNamedCacheSync(controllerName, stopCh, pc.podInformer.HasSynced) {
return
Expand Down