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

feat: Use MAC address provided by nerdctl #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ type K8SPodEnvArgs struct {
K8S_POD_INFRA_CONTAINER_ID cniTypes.UnmarshallableString `json:"K8S_POD_INFRA_CONTAINER_ID,omitempty"`
}

type EndpointArgs struct {
cniTypes.CommonArgs
MAC cniTypes.UnmarshallableString
}

type OptionalFlags struct {
LocalRoutePortMapping bool `json:"localRoutedPortMapping"`
AllowAclPortMapping bool `json:"allowAclPortMapping"`
Expand Down Expand Up @@ -194,6 +199,17 @@ func ParseCniArgs(args string) (*K8SPodEnvArgs, error) {
return &podConfig, nil
}

// ParseCniEndpointArgs
Copy link

Choose a reason for hiding this comment

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

Comment doesn't seem useful.

Suggested change
// ParseCniEndpointArgs

func ParseCniEndpointArgs(args string) (*EndpointArgs, error) {
epArgs := EndpointArgs{}
err := cniTypes.LoadArgs(args, &epArgs)
if err != nil {
return nil, err
}

return &epArgs, nil
}

// Serialize marshals a network configuration to bytes.
func (config *NetworkConfig) Serialize() []byte {
bytes, _ := json.Marshal(config)
Expand Down
12 changes: 12 additions & 0 deletions common/core/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) (resultError error) {
return err
}

epConfig, err := cni.ParseCniEndpointArgs(args.Args)
if err == nil {
if epConfig.MAC != "" {
hwAddr, err := net.ParseMAC(string(epConfig.MAC))
if err != nil {
logrus.Errorf("[cni-net] Failed to parse MAC addres '%s', err:%v", epConfig.MAC, err)
Copy link

Choose a reason for hiding this comment

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

Typo.

Suggested change
logrus.Errorf("[cni-net] Failed to parse MAC addres '%s', err:%v", epConfig.MAC, err)
logrus.Errorf("[cni-net] Failed to parse MAC address '%s', err:%v", epConfig.MAC, err)

return err
}

epInfo.MacAddress = hwAddr
}
}
epInfo.DualStack = cniConfig.OptionalFlags.EnableDualStack

// Check for missing namespace
Expand Down
Loading