Skip to content

Commit

Permalink
Fixing calico-ipam using hostname instead of nodename
Browse files Browse the repository at this point in the history
It looks as though we were still using the deprecated `hostname` from
the CNI payload, and not `nodename` which was causing issues assigning
affine blocks if you need to use a `NODENAME` that is different from the Nodes `os.Hostname()`.

We'll check for the old `hostname` value as well similar to how we do in
the CNI plugin.
  • Loading branch information
heschlie committed Sep 8, 2017
1 parent c57a2a5 commit 12f2233
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ipam/calico-ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,25 @@ type ipamArgs struct {
IP net.IP `json:"ip,omitempty"`
}

func determineNodename(conf utils.NetConf) string {
nodename, _ := os.Hostname()
if conf.Hostname != "" {
nodename = conf.Hostname
log.Warn("Configuration option 'hostname' is deprecated, use 'nodename' instead.")
}
if conf.Nodename != "" {
nodename = conf.Nodename
}
return nodename
}

func cmdAdd(args *skel.CmdArgs) error {
conf := utils.NetConf{}
if err := json.Unmarshal(args.StdinData, &conf); err != nil {
return fmt.Errorf("failed to load netconf: %v", err)
}

nodename := determineNodename(conf)
cniVersion := conf.CNIVersion

utils.ConfigureLogging(conf.LogLevel)
Expand All @@ -99,8 +112,8 @@ func cmdAdd(args *skel.CmdArgs) error {
if ipamArgs.IP != nil {
fmt.Fprintf(os.Stderr, "Calico CNI IPAM request IP: %v\n", ipamArgs.IP)

// The hostname will be defaulted to the actual hostname if conf.Hostname is empty
assignArgs := client.AssignIPArgs{IP: cnet.IP{ipamArgs.IP}, HandleID: &workloadID, Hostname: conf.Hostname}
// The hostname will be defaulted to the actual hostname if conf.Nodename is empty
assignArgs := client.AssignIPArgs{IP: cnet.IP{ipamArgs.IP}, HandleID: &workloadID, Hostname: nodename}
logger.WithField("assignArgs", assignArgs).Info("Assigning provided IP")
err := calicoClient.IPAM().AssignIP(assignArgs)
if err != nil {
Expand Down Expand Up @@ -157,7 +170,7 @@ func cmdAdd(args *skel.CmdArgs) error {
Num4: num4,
Num6: num6,
HandleID: &workloadID,
Hostname: conf.Hostname,
Hostname: nodename,
IPv4Pools: v4pools,
IPv6Pools: v6pools,
}
Expand Down

0 comments on commit 12f2233

Please sign in to comment.