Skip to content

Commit 1e53e22

Browse files
sdudoladovJan-M
authored andcommitted
Improve error reporting for short cluster names (zalando#377)
* Improve error reporting for short cluster names * Revert to clusterName
1 parent 75a1d78 commit 1e53e22

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pkg/apis/acid.zalan.do/v1/util.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package v1
22

33
import (
44
"fmt"
5-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
65
"regexp"
76
"strings"
87
"time"
8+
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
)
1011

1112
var (
@@ -47,7 +48,7 @@ func parseWeekday(s string) (time.Weekday, error) {
4748
func extractClusterName(clusterName string, teamName string) (string, error) {
4849
teamNameLen := len(teamName)
4950
if len(clusterName) < teamNameLen+2 {
50-
return "", fmt.Errorf("name is too short")
51+
return "", fmt.Errorf("cluster name must match {TEAM}-{NAME} format. Got cluster name '%v', team name '%v'", clusterName, teamName)
5152
}
5253

5354
if teamNameLen == 0 {

pkg/apis/acid.zalan.do/v1/util_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
87
"reflect"
98
"testing"
109
"time"
10+
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
)
1213

1314
var parseTimeTests = []struct {
@@ -49,8 +50,11 @@ var clusterNames = []struct {
4950
{"acid-test", "test", "", errors.New("name must match {TEAM}-{NAME} format")},
5051
{"-test", "", "", errors.New("team name is empty")},
5152
{"-test", "-", "", errors.New("name must match {TEAM}-{NAME} format")},
52-
{"", "-", "", errors.New("name is too short")},
53-
{"-", "-", "", errors.New("name is too short")},
53+
{"", "-", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name '', team name '-'")},
54+
{"-", "-", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name '-', team name '-'")},
55+
// user may specify the team part of the full cluster name differently from the team name returned by the Teams API
56+
// in the case the actual Teams API name is long enough, this will fail the check
57+
{"foo-bar", "qwerty", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name 'foo-bar', team name 'qwerty'")},
5458
}
5559

5660
var cloneClusterDescriptions = []struct {

0 commit comments

Comments
 (0)