Skip to content
Permalink
Browse files

fix(cmd): fix pod name parsing for newer k8s

  • Loading branch information...
rwos committed Nov 8, 2018
1 parent 3a7143e commit b83abd86c1cc20abb6ca4d7fcef2ec0bcfc158e7
Showing with 26 additions and 15 deletions.
  1. +2 −2 cmd/ps.go
  2. +24 −13 cmd/ps_test.go
@@ -125,8 +125,8 @@ func parseType(target string, appID string) (string, string) {
parts := strings.Split(replaced, "-")
// the API requires the type, for now
// regex matches against how Deployment pod name is constructed
regex := regexp.MustCompile("[0-9]{8,10}-[a-z0-9]{5}$")
if regex.MatchString(replaced) {
regex := regexp.MustCompile("[a-z0-9]{8,10}-[a-z0-9]{5}$")
if regex.MatchString(replaced) || len(parts) == 2 {
psType = parts[0]
} else {
psType = parts[1]
@@ -15,24 +15,35 @@ import (
func TestParseType(t *testing.T) {
t.Parallel()

// test RC pod name
appID := "earthy-underdog"
rcPod := "earthy-underdog-v2-cmd-8yngj"
psType, psName := parseType(rcPod, appID)
if psType != "cmd" || psName != rcPod {
t.Errorf("type was not cmd (got %s) or psName was not %s (got %s)", psType, rcPod, psName)
var input = map[string]string{
// RC pod name
"earthy-underdog": "earthy-underdog-v2-cmd-8yngj",
// Deployment pod name - they are longer due to hash
"nonfat-yearbook": "nonfat-yearbook-cmd-2180299075-7na91",
// newer style of Deployment pod name
"foo-bar": "foo-bar-cmd-57f6c4bb68-7na91",
// same as above but leaving out the app-name from the pod name
"earthy-underdog2": "cmd-8yngj",
"nonfat-yearbook2": "cmd-2180299075-7na91",
"foo-bar2": "cmd-57f6c4bb68-7na91",
// same as above but with app names without hyphens
"earthy": "earthy-v2-cmd-8yngj",
"nonfat": "nonfat-cmd-2180299075-7na91",
"foo": "foo-cmd-57f6c4bb68-7na91",
"earthy2": "cmd-8yngj",
"nonfat2": "cmd-2180299075-7na91",
"foo2": "cmd-57f6c4bb68-7na91",
}

// test Deployment pod name - they are longer due to hash
appID = "nonfat-yearbook"
deployPod := "nonfat-yearbook-cmd-2180299075-7na91"
psType, psName = parseType(deployPod, appID)
if psType != "cmd" || psName != deployPod {
t.Errorf("type was not cmd (got %s) or psName was not %s (got %s)", psType, deployPod, psName)
for appID, podName := range input {
psType, psName := parseType(podName, appID)
if psType != "cmd" || psName != podName {
t.Errorf("parseType(%#v, %#v): type was not cmd (got %s) or psName was not %s (got %s)", podName, appID, psType, podName, psName)
}
}

// test type by itself
psType, psName = parseType("cmd", "fake")
psType, psName := parseType("cmd", "fake")
if psType != "cmd" || psName != "" {
t.Error("type was not cmd")
}

0 comments on commit b83abd8

Please sign in to comment.
You can’t perform that action at this time.