From 1e53e22773e7ed2a0acc1dc4c9365c7da84fadf9 Mon Sep 17 00:00:00 2001 From: zerg-junior Date: Wed, 29 Aug 2018 17:08:59 +0200 Subject: [PATCH] Improve error reporting for short cluster names (#377) * Improve error reporting for short cluster names * Revert to clusterName --- pkg/apis/acid.zalan.do/v1/util.go | 5 +++-- pkg/apis/acid.zalan.do/v1/util_test.go | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/apis/acid.zalan.do/v1/util.go b/pkg/apis/acid.zalan.do/v1/util.go index 7d071ce22..2d3c90db8 100644 --- a/pkg/apis/acid.zalan.do/v1/util.go +++ b/pkg/apis/acid.zalan.do/v1/util.go @@ -2,10 +2,11 @@ package v1 import ( "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "regexp" "strings" "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var ( @@ -47,7 +48,7 @@ func parseWeekday(s string) (time.Weekday, error) { func extractClusterName(clusterName string, teamName string) (string, error) { teamNameLen := len(teamName) if len(clusterName) < teamNameLen+2 { - return "", fmt.Errorf("name is too short") + return "", fmt.Errorf("cluster name must match {TEAM}-{NAME} format. Got cluster name '%v', team name '%v'", clusterName, teamName) } if teamNameLen == 0 { diff --git a/pkg/apis/acid.zalan.do/v1/util_test.go b/pkg/apis/acid.zalan.do/v1/util_test.go index d1f06a2cc..ab5a39e9e 100644 --- a/pkg/apis/acid.zalan.do/v1/util_test.go +++ b/pkg/apis/acid.zalan.do/v1/util_test.go @@ -4,10 +4,11 @@ import ( "bytes" "encoding/json" "errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "reflect" "testing" "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var parseTimeTests = []struct { @@ -49,8 +50,11 @@ var clusterNames = []struct { {"acid-test", "test", "", errors.New("name must match {TEAM}-{NAME} format")}, {"-test", "", "", errors.New("team name is empty")}, {"-test", "-", "", errors.New("name must match {TEAM}-{NAME} format")}, - {"", "-", "", errors.New("name is too short")}, - {"-", "-", "", errors.New("name is too short")}, + {"", "-", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name '', team name '-'")}, + {"-", "-", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name '-', team name '-'")}, + // user may specify the team part of the full cluster name differently from the team name returned by the Teams API + // in the case the actual Teams API name is long enough, this will fail the check + {"foo-bar", "qwerty", "", errors.New("cluster name must match {TEAM}-{NAME} format. Got cluster name 'foo-bar', team name 'qwerty'")}, } var cloneClusterDescriptions = []struct {