Skip to content

Commit

Permalink
only pass K8S_POD_NAME if hostname is set
Browse files Browse the repository at this point in the history
note: the default hostname is not set in meta.Hostname; meta.Hostname is
used to override the default, so we don't have to check for it here and
this should only apply if the user explicitly sets llb.Hostname.
  • Loading branch information
vito committed Aug 20, 2022
1 parent 646b6f3 commit 9cc0bb0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions util/network/cniprovider/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *cniProvider) initNetwork() error {
}
defer l.Unlock()
}
ns, err := c.New("test")
ns, err := c.New("")
if err != nil {
return err
}
Expand All @@ -76,13 +76,16 @@ func (c *cniProvider) New(hostname string) (network.Namespace, error) {
return nil, err
}

nsOpts := []cni.NamespaceOpts{
// NB: K8S_POD_NAME is a semi-well-known arg set by k8s and podman and
// leveraged by the dnsname CNI plugin. a more generic name would be nice.
cni.WithArgs("K8S_POD_NAME", hostname),
nsOpts := []cni.NamespaceOpts{}

// must be set for plugins that don't understand K8S_POD_NAME
cni.WithArgs("IgnoreUnknown", "1"),
if hostname != "" {
nsOpts = append(nsOpts,
// NB: K8S_POD_NAME is a semi-well-known arg set by k8s and podman and
// leveraged by the dnsname CNI plugin. a more generic name would be nice.
cni.WithArgs("K8S_POD_NAME", hostname),

// must be set for plugins that don't understand K8S_POD_NAME
cni.WithArgs("IgnoreUnknown", "1"))
}

if _, err := c.CNI.Setup(context.TODO(), id, nativeID, nsOpts...); err != nil {
Expand Down

0 comments on commit 9cc0bb0

Please sign in to comment.