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

Reduce antrea cni binary size #6038

Merged
merged 1 commit into from
Feb 29, 2024
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
3 changes: 1 addition & 2 deletions pkg/agent/secondarynetwork/podwatch/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
podresourcesv1alpha1 "k8s.io/kubelet/pkg/apis/podresources/v1alpha1"

cnipodcache "antrea.io/antrea/pkg/agent/secondarynetwork/cnipodcache"
"antrea.io/antrea/pkg/agent/util"
)

const (
Expand Down Expand Up @@ -68,7 +67,7 @@ func getPodContainerDeviceIDs(podName string, podNamespace string) ([]string, er
path.Join(kubeletPodResourcesPath, kubeletSocket),
grpc.WithTransportCredentials(grpcinsecure.NewCredentials()),
grpc.WithContextDialer(func(ctx context.Context, addr string) (conn net.Conn, e error) {
return util.DialLocalSocket(addr)
return net.Dial("unix", addr)
}),
)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ func listenUnix(address string) (net.Listener, error) {
return net.Listen("unix", address)
}

func dialUnix(address string) (net.Conn, error) {
return net.Dial("unix", address)
}

// GetIPNetDeviceFromIP returns local IPs/masks and associated device from IP, and ignores the interfaces which have
// names in the ignoredInterfaces.
func GetIPNetDeviceFromIP(localIPs *ip.DualStackIPs, ignoredInterfaces sets.Set[string]) (v4IPNet *net.IPNet, v6IPNet *net.IPNet, iface *net.Interface, err error) {
Expand Down
5 changes: 0 additions & 5 deletions pkg/agent/util/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ func ListenLocalSocket(address string) (net.Listener, error) {
return listener, nil
}

// DialLocalSocket connects to a Unix domain socket.
func DialLocalSocket(address string) (net.Conn, error) {
return dialUnix(address)
}

// SetAdapterMACAddress set specified MAC address on interface.
func SetAdapterMACAddress(adapterName string, macConfig *net.HardwareAddr) error {
link, err := netlinkUtil.LinkByName(adapterName)
Expand Down
10 changes: 0 additions & 10 deletions pkg/agent/util/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,6 @@ func ListenLocalSocket(address string) (net.Listener, error) {
return listenUnix(address)
}

// DialLocalSocket connects to a Unix domain socket or a Windows named pipe.
// - If the specified address starts with "\\.\pipe\", connect to a Windows named pipe path.
// - Else connect to a Unix domain socket.
func DialLocalSocket(address string) (net.Conn, error) {
if strings.HasPrefix(address, namedPipePrefix) {
return winio.DialPipe(address, nil)
}
return dialUnix(address)
}

func HostInterfaceExists(ifaceName string) bool {
_, err := getAdapterInAllCompartmentsByName(ifaceName)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/cni/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cni
import (
"context"
"fmt"
"net"
"os"

"github.com/containernetworking/cni/pkg/skel"
Expand All @@ -27,7 +26,6 @@ import (
grpcinsecure "google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"

"antrea.io/antrea/pkg/agent/util"
cnipb "antrea.io/antrea/pkg/apis/cni/v1beta1"
)

Expand Down Expand Up @@ -91,9 +89,7 @@ func rpcClient(f func(client cnipb.CniClient) error) error {
conn, err := grpc.Dial(
AntreaCNISocketAddr,
grpc.WithTransportCredentials(grpcinsecure.NewCredentials()),
grpc.WithContextDialer(func(ctx context.Context, addr string) (conn net.Conn, e error) {
return util.DialLocalSocket(addr)
}),
grpc.WithContextDialer(dial),
)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions pkg/cni/dial_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cni

import (
"context"
"net"
)

func dial(_ context.Context, address string) (net.Conn, error) {
return net.Dial("unix", address)
}
32 changes: 32 additions & 0 deletions pkg/cni/dial_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cni

import (
"context"
"net"
"strings"

"github.com/Microsoft/go-winio"
)

const namedPipePrefix = `\\.\pipe\`

func dial(_ context.Context, address string) (net.Conn, error) {
if strings.HasPrefix(address, namedPipePrefix) {
return winio.DialPipe(address, nil)
}
return net.Dial("unix", address)
}
Loading