Skip to content

Commit

Permalink
Merge pull request #1 from PlayEveryWare/mendsley/nerdctl_mac_address
Browse files Browse the repository at this point in the history
feat: Use MAC address provided by nerdctl
  • Loading branch information
mendsley authored Nov 22, 2024
2 parents a0463d8 + 1c75a46 commit a90205b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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
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)
return err
}

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

// Check for missing namespace
Expand Down

0 comments on commit a90205b

Please sign in to comment.