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

[release-v3.0] Allow configuration of veth prefix in KDD mode #864

Merged
Merged
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
13 changes: 12 additions & 1 deletion lib/backend/k8s/conversion/conversion.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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