Browse code

Align project with upstream resources that exist outside of namespace

derekwaynecarr authored on 2015/01/27 06:26:51
Showing 4 changed files
... ...
@@ -68,6 +68,8 @@ func validateObject(obj runtime.Object) (errors []error) {
68 68
 	case *deployapi.Deployment:
69 69
 		errors = deployv.ValidateDeployment(t)
70 70
 	case *projectapi.Project:
71
+		// this is a global resource that should not have a namespace
72
+		t.Namespace = ""
71 73
 		errors = projectv.ValidateProject(t)
72 74
 	case *routeapi.Route:
73 75
 		errors = routev.ValidateRoute(t)
... ...
@@ -16,8 +16,8 @@ func ValidateProject(project *api.Project) errors.ValidationErrorList {
16 16
 	} else if !util.IsDNS952Label(project.Name) {
17 17
 		result = append(result, errors.NewFieldInvalid("Name", project.Name, "does not conform to lower-cased dns952"))
18 18
 	}
19
-	if !util.IsDNSSubdomain(project.Namespace) {
20
-		result = append(result, errors.NewFieldInvalid("Namespace", project.Namespace, "does not conform to lower-cased dns952"))
19
+	if len(project.Namespace) > 0 {
20
+		result = append(result, errors.NewFieldInvalid("Namespace", project.Namespace, "must be the empty-string"))
21 21
 	}
22 22
 	if !validateNoNewLineOrTab(project.DisplayName) {
23 23
 		result = append(result, errors.NewFieldInvalid("DisplayName", project.DisplayName, "may not contain a new line or tab"))
... ...
@@ -17,7 +17,6 @@ func TestValidateProject(t *testing.T) {
17 17
 			name: "missing id",
18 18
 			project: api.Project{
19 19
 				ObjectMeta: kapi.ObjectMeta{
20
-					Namespace: kapi.NamespaceDefault,
21 20
 					Annotations: map[string]string{
22 21
 						"description": "This is a description",
23 22
 					},
... ...
@@ -31,8 +30,7 @@ func TestValidateProject(t *testing.T) {
31 31
 			name: "invalid id",
32 32
 			project: api.Project{
33 33
 				ObjectMeta: kapi.ObjectMeta{
34
-					Name:      "141-.124.$",
35
-					Namespace: kapi.NamespaceDefault,
34
+					Name: "141-.124.$",
36 35
 					Annotations: map[string]string{
37 36
 						"description": "This is a description",
38 37
 					},
... ...
@@ -43,27 +41,18 @@ func TestValidateProject(t *testing.T) {
43 43
 			numErrs: 1,
44 44
 		},
45 45
 		{
46
-			name: "missing namespace",
46
+			name: "has namespace",
47 47
 			project: api.Project{
48
-				ObjectMeta:  kapi.ObjectMeta{Name: "foo", Namespace: ""},
49
-				DisplayName: "hi",
50
-			},
51
-			// Should fail because the namespace is missing.
52
-			numErrs: 1,
53
-		},
54
-		{
55
-			name: "invalid namespace",
56
-			project: api.Project{
57
-				ObjectMeta:  kapi.ObjectMeta{Name: "foo", Namespace: "141-.124.$"},
48
+				ObjectMeta:  kapi.ObjectMeta{Name: "foo", Namespace: "foo"},
58 49
 				DisplayName: "hi",
59 50
 			},
60
-			// Should fail because the namespace is missing.
51
+			// Should fail because the namespace is supplied.
61 52
 			numErrs: 1,
62 53
 		},
63 54
 		{
64 55
 			name: "invalid display name",
65 56
 			project: api.Project{
66
-				ObjectMeta:  kapi.ObjectMeta{Name: "foo", Namespace: "foo"},
57
+				ObjectMeta:  kapi.ObjectMeta{Name: "foo", Namespace: ""},
67 58
 				DisplayName: "h\t\ni",
68 59
 			},
69 60
 			// Should fail because the display name has \t \n
... ...
@@ -80,8 +69,7 @@ func TestValidateProject(t *testing.T) {
80 80
 
81 81
 	project := api.Project{
82 82
 		ObjectMeta: kapi.ObjectMeta{
83
-			Name:      "foo",
84
-			Namespace: kapi.NamespaceDefault,
83
+			Name: "foo",
85 84
 			Annotations: map[string]string{
86 85
 				"description": "This is a description",
87 86
 			},
... ...
@@ -58,16 +58,10 @@ func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (<-chan apiserver.RE
58 58
 		return nil, fmt.Errorf("not a project: %#v", obj)
59 59
 	}
60 60
 
61
-	// TODO decide if we should set namespace == name, think longer term we need some type of reservation here
62
-	// but i want to be able to let existing kubernetes ns grow into a project as well
63
-	if len(project.Namespace) == 0 {
64
-		project.Namespace = project.Name
65
-	}
66
-
67 61
 	kapi.FillObjectMetaSystemFields(ctx, &project.ObjectMeta)
68 62
 
69
-	// TODO set an id if not provided?, set a Namespace attribute if not provided?
70
-
63
+	// kubectl auto-inserts a value, we need to ignore this value until we have cluster-scoped actions in kubectl
64
+	project.Namespace = ""
71 65
 	if errs := validation.ValidateProject(project); len(errs) > 0 {
72 66
 		return nil, errors.NewInvalid("project", project.Name, errs)
73 67
 	}