make namespace optional so existing objects keep working (#1034)

This commit is contained in:
Ville Aikas 2020-02-02 22:17:30 -08:00 committed by GitHub
parent 99abcc2ff5
commit d5698e90e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 28 deletions

View File

@ -61,16 +61,6 @@ func TestValidateDestination(t *testing.T) {
},
want: "",
},
"invalid ref, missing namespace": {
dest: &Destination{
Ref: &KnativeReference{
Name: name,
Kind: kind,
APIVersion: apiVersion,
},
},
want: "missing field(s): ref.namespace",
},
"invalid ref, missing name": {
dest: &Destination{
Ref: &KnativeReference{

View File

@ -31,7 +31,9 @@ type KnativeReference struct {
// Namespace of the referent.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
Namespace string `json:"namespace"`
// This is optional field, it gets defaulted to the object holding it if left out.
// +optional
Namespace string `json:"namespace,omitempty"`
// Name of the referent.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
@ -44,15 +46,11 @@ type KnativeReference struct {
func (kr *KnativeReference) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError
if kr == nil {
errs = errs.Also(apis.ErrMissingField("namespace"))
errs = errs.Also(apis.ErrMissingField("name"))
errs = errs.Also(apis.ErrMissingField("apiVersion"))
errs = errs.Also(apis.ErrMissingField("kind"))
return errs
}
if kr.Namespace == "" {
errs = errs.Also(apis.ErrMissingField("namespace"))
}
if kr.Name == "" {
errs = errs.Also(apis.ErrMissingField("name"))
}

View File

@ -42,7 +42,7 @@ func TestValidate(t *testing.T) {
"nil valid": {
ref: nil,
want: func() *apis.FieldError {
fe := apis.ErrMissingField("name", "namespace", "kind", "apiVersion")
fe := apis.ErrMissingField("name", "kind", "apiVersion")
return fe
}(),
},
@ -52,18 +52,7 @@ func TestValidate(t *testing.T) {
},
"invalid ref, empty": {
ref: &KnativeReference{},
want: apis.ErrMissingField("name", "namespace", "kind", "apiVersion"),
},
"invalid ref, missing namespace": {
ref: &KnativeReference{
Name: name,
Kind: kind,
APIVersion: apiVersion,
},
want: func() *apis.FieldError {
fe := apis.ErrMissingField("namespace")
return fe
}(),
want: apis.ErrMissingField("name", "kind", "apiVersion"),
},
"invalid ref, missing kind": {
ref: &KnativeReference{