mirror of https://github.com/knative/pkg.git
make namespace optional so existing objects keep working (#1034)
This commit is contained in:
parent
99abcc2ff5
commit
d5698e90e2
|
@ -61,16 +61,6 @@ func TestValidateDestination(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: "",
|
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": {
|
"invalid ref, missing name": {
|
||||||
dest: &Destination{
|
dest: &Destination{
|
||||||
Ref: &KnativeReference{
|
Ref: &KnativeReference{
|
||||||
|
|
|
@ -31,7 +31,9 @@ type KnativeReference struct {
|
||||||
|
|
||||||
// Namespace of the referent.
|
// Namespace of the referent.
|
||||||
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
|
// 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.
|
// Name of the referent.
|
||||||
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
|
// 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 {
|
func (kr *KnativeReference) Validate(ctx context.Context) *apis.FieldError {
|
||||||
var errs *apis.FieldError
|
var errs *apis.FieldError
|
||||||
if kr == nil {
|
if kr == nil {
|
||||||
errs = errs.Also(apis.ErrMissingField("namespace"))
|
|
||||||
errs = errs.Also(apis.ErrMissingField("name"))
|
errs = errs.Also(apis.ErrMissingField("name"))
|
||||||
errs = errs.Also(apis.ErrMissingField("apiVersion"))
|
errs = errs.Also(apis.ErrMissingField("apiVersion"))
|
||||||
errs = errs.Also(apis.ErrMissingField("kind"))
|
errs = errs.Also(apis.ErrMissingField("kind"))
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
if kr.Namespace == "" {
|
|
||||||
errs = errs.Also(apis.ErrMissingField("namespace"))
|
|
||||||
}
|
|
||||||
if kr.Name == "" {
|
if kr.Name == "" {
|
||||||
errs = errs.Also(apis.ErrMissingField("name"))
|
errs = errs.Also(apis.ErrMissingField("name"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func TestValidate(t *testing.T) {
|
||||||
"nil valid": {
|
"nil valid": {
|
||||||
ref: nil,
|
ref: nil,
|
||||||
want: func() *apis.FieldError {
|
want: func() *apis.FieldError {
|
||||||
fe := apis.ErrMissingField("name", "namespace", "kind", "apiVersion")
|
fe := apis.ErrMissingField("name", "kind", "apiVersion")
|
||||||
return fe
|
return fe
|
||||||
}(),
|
}(),
|
||||||
},
|
},
|
||||||
|
@ -52,18 +52,7 @@ func TestValidate(t *testing.T) {
|
||||||
},
|
},
|
||||||
"invalid ref, empty": {
|
"invalid ref, empty": {
|
||||||
ref: &KnativeReference{},
|
ref: &KnativeReference{},
|
||||||
want: apis.ErrMissingField("name", "namespace", "kind", "apiVersion"),
|
want: apis.ErrMissingField("name", "kind", "apiVersion"),
|
||||||
},
|
|
||||||
"invalid ref, missing namespace": {
|
|
||||||
ref: &KnativeReference{
|
|
||||||
Name: name,
|
|
||||||
Kind: kind,
|
|
||||||
APIVersion: apiVersion,
|
|
||||||
},
|
|
||||||
want: func() *apis.FieldError {
|
|
||||||
fe := apis.ErrMissingField("namespace")
|
|
||||||
return fe
|
|
||||||
}(),
|
|
||||||
},
|
},
|
||||||
"invalid ref, missing kind": {
|
"invalid ref, missing kind": {
|
||||||
ref: &KnativeReference{
|
ref: &KnativeReference{
|
||||||
|
|
Loading…
Reference in New Issue