Skip to content

Commit

Permalink
Merge pull request #864 from caseydavenport/cherry-pick-863-v3.0
Browse files Browse the repository at this point in the history
[release-v3.0] Allow configuration of veth prefix in KDD mode
  • Loading branch information
caseydavenport committed May 16, 2018
2 parents 9126d58 + 7467e58 commit ee5c674
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/backend/k8s/conversion/conversion.go
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/sha1"
"encoding/hex"
"fmt"
"os"
"sort"
"strings"

Expand Down Expand Up @@ -58,7 +59,17 @@ func VethNameForWorkload(namespace, podname string) string {
// veth name and mac addr.
h := sha1.New()
h.Write([]byte(fmt.Sprintf("%s.%s", namespace, podname)))
return fmt.Sprintf("cali%s", hex.EncodeToString(h.Sum(nil))[:11])
prefix := os.Getenv("FELIX_INTERFACEPREFIX")
if prefix == "" {
// Prefix is not set. Default to "cali"
prefix = "cali"
} else {
// Prefix is set - use the first value in the list.
splits := strings.Split(prefix, ",")
prefix = splits[0]
}
log.WithField("prefix", prefix).Debugf("Using prefix to create a WorkloadEndpoint veth name")
return fmt.Sprintf("%s%s", prefix, hex.EncodeToString(h.Sum(nil))[:11])
}

// ParseWorkloadName extracts the Node name, Orchestrator, Pod name and endpoint from the
Expand Down
10 changes: 10 additions & 0 deletions lib/backend/k8s/conversion/conversion_test.go
Expand Up @@ -15,6 +15,8 @@
package conversion

import (
"os"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -44,6 +46,14 @@ var _ = Describe("Test parsing strings", func() {
Expect(weid.Pod).To(Equal("pod-name"))
})

It("generate a veth name with the right prefix", func() {
os.Setenv("FELIX_INTERFACEPREFIX", "eni,veth,foo")
defer os.Setenv("FELIX_INTERFACEPREFIX", "")

name := VethNameForWorkload("namespace", "podname")
Expect(name).To(Equal("eni82111e10a96"))
})

It("should parse valid profile names", func() {
name := "kns.default"
ns, err := c.ProfileNameToNamespace(name)
Expand Down

0 comments on commit ee5c674

Please sign in to comment.