Skip to content

Commit

Permalink
Update error message to Consul Enterprise namespaces
Browse files Browse the repository at this point in the history
This would make it easier for a user to understand that they need Consul
Enterprise in order to enable namespaces.
  • Loading branch information
ndhanushkodi committed Nov 4, 2020
1 parent 769ddeb commit 1474369
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/serviceintentions_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ func (in *ServiceIntentions) validateNamespaces(namespacesEnabled bool) field.Er
path := field.NewPath("spec")
if !namespacesEnabled {
if in.Spec.Destination.Namespace != "" {
errs = append(errs, field.Invalid(path.Child("destination").Child("namespace"), in.Spec.Destination.Namespace, `consul namespaces must be enabled to set destination.namespace`))
errs = append(errs, field.Invalid(path.Child("destination").Child("namespace"), in.Spec.Destination.Namespace, `Consul Enterprise namespaces must be enabled to set destination.namespace`))
}
for i, source := range in.Spec.Sources {
if source.Namespace != "" {
errs = append(errs, field.Invalid(path.Child("sources").Index(i).Child("namespace"), source.Namespace, `consul namespaces must be enabled to set source.namespace`))
errs = append(errs, field.Invalid(path.Child("sources").Index(i).Child("namespace"), source.Namespace, `Consul Enterprise namespaces must be enabled to set source.namespace`))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/serviceintentions_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func TestHandle_ServiceIntentions_Patches(t *testing.T) {
},
},
expPatches: []jsonpatch.Operation{},
errMsg: `serviceintentions.consul.hashicorp.com "foo-intention" is invalid: [spec.destination.namespace: Invalid value: "bar": consul namespaces must be enabled to set destination.namespace, spec.sources[0].namespace: Invalid value: "baz": consul namespaces must be enabled to set source.namespace]`,
errMsg: `serviceintentions.consul.hashicorp.com "foo-intention" is invalid: [spec.destination.namespace: Invalid value: "bar": Consul Enterprise namespaces must be enabled to set destination.namespace, spec.sources[0].namespace: Invalid value: "baz": Consul Enterprise namespaces must be enabled to set source.namespace]`,
},
"destination.namespace empty": {
newResource: &ServiceIntentions{
Expand Down Expand Up @@ -577,7 +577,7 @@ func TestHandle_ServiceIntentions_Patches(t *testing.T) {
},
},
expPatches: []jsonpatch.Operation{},
errMsg: `serviceintentions.consul.hashicorp.com "foo-intention" is invalid: spec.destination.namespace: Invalid value: "bar": consul namespaces must be enabled to set destination.namespace`,
errMsg: `serviceintentions.consul.hashicorp.com "foo-intention" is invalid: spec.destination.namespace: Invalid value: "bar": Consul Enterprise namespaces must be enabled to set destination.namespace`,
},
}
for name, c := range cases {
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/serviceresolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ func (in *ServiceResolver) validateNamespaces(namespacesEnabled bool) field.Erro
if !namespacesEnabled {
if in.Spec.Redirect != nil {
if in.Spec.Redirect.Namespace != "" {
errs = append(errs, field.Invalid(path.Child("redirect").Child("namespace"), in.Spec.Redirect.Namespace, `consul namespaces must be enabled to set redirect.namespace`))
errs = append(errs, field.Invalid(path.Child("redirect").Child("namespace"), in.Spec.Redirect.Namespace, `Consul Enterprise namespaces must be enabled to set redirect.namespace`))
}
}
for k, v := range in.Spec.Failover {
if v.Namespace != "" {
errs = append(errs, field.Invalid(path.Child("failover").Key(k).Child("namespace"), v.Namespace, `consul namespaces must be enabled to set failover.namespace`))
errs = append(errs, field.Invalid(path.Child("failover").Key(k).Child("namespace"), v.Namespace, `Consul Enterprise namespaces must be enabled to set failover.namespace`))
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/servicerouter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (in *ServiceRouter) validateNamespaces(namespacesEnabled bool) field.ErrorL
for i, r := range in.Spec.Routes {
if r.Destination != nil {
if r.Destination.Namespace != "" {
errs = append(errs, field.Invalid(path.Child("routes").Index(i).Child("destination").Child("namespace"), r.Destination.Namespace, `consul namespaces must be enabled to set destination.namespace`))
errs = append(errs, field.Invalid(path.Child("routes").Index(i).Child("destination").Child("namespace"), r.Destination.Namespace, `Consul Enterprise namespaces must be enabled to set destination.namespace`))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/servicesplitter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (in *ServiceSplitter) validateNamespaces(namespacesEnabled bool) field.Erro
if !namespacesEnabled {
for i, s := range in.Spec.Splits {
if s.Namespace != "" {
errs = append(errs, field.Invalid(path.Child("splits").Index(i).Child("namespace"), s.Namespace, `consul namespaces must be enabled to set split.namespace`))
errs = append(errs, field.Invalid(path.Child("splits").Index(i).Child("namespace"), s.Namespace, `Consul Enterprise namespaces must be enabled to set split.namespace`))
}

}
Expand Down

0 comments on commit 1474369

Please sign in to comment.