diff --git a/galley/pkg/runtime/projections/serviceentry/converter/instance_test.go b/galley/pkg/runtime/projections/serviceentry/converter/instance_test.go index f68f46dffd22..71d99c0dd713 100644 --- a/galley/pkg/runtime/projections/serviceentry/converter/instance_test.go +++ b/galley/pkg/runtime/projections/serviceentry/converter/instance_test.go @@ -30,9 +30,9 @@ import ( "istio.io/istio/galley/pkg/runtime/projections/serviceentry/converter" "istio.io/istio/galley/pkg/runtime/projections/serviceentry/pod" "istio.io/istio/galley/pkg/runtime/resource" - "istio.io/istio/pkg/config" "istio.io/istio/pkg/config/constants" "istio.io/istio/pkg/config/protocol" + "istio.io/istio/pkg/config/validation" coreV1 "k8s.io/api/core/v1" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -281,7 +281,7 @@ func TestServiceResolution(t *testing.T) { case networking.ServiceEntry_DNS: g.Expect(len(actual.Addresses)).To(Equal(0)) for _, host := range actual.Hosts { - g.Expect(config.ValidateFQDN(host)).To(BeNil()) + g.Expect(validation.ValidateFQDN(host)).To(BeNil()) } case networking.ServiceEntry_STATIC: diff --git a/istioctl/cmd/convert_ingress.go b/istioctl/cmd/convert_ingress.go index 56f2ccf3049b..dd3d96753fd8 100644 --- a/istioctl/cmd/convert_ingress.go +++ b/istioctl/cmd/convert_ingress.go @@ -29,7 +29,8 @@ import ( "istio.io/istio/istioctl/pkg/convert" "istio.io/istio/pilot/pkg/config/kube/crd" "istio.io/istio/pilot/pkg/model" - "istio.io/istio/pkg/config" + "istio.io/istio/pkg/config/validation" + "istio.io/pkg/log" ) @@ -157,7 +158,7 @@ func validateConfigs(configs []model.Config) error { var errs error for _, cfg := range configs { if cfg.Type == model.VirtualService.Type { - if err := config.ValidateVirtualService(cfg.Name, cfg.Namespace, cfg.Spec); err != nil { + if err := validation.ValidateVirtualService(cfg.Name, cfg.Namespace, cfg.Spec); err != nil { errs = multierror.Append(err, errs) } } diff --git a/pilot/cmd/pilot-agent/main.go b/pilot/cmd/pilot-agent/main.go index a525a87a3510..ee67ab9e4fd6 100644 --- a/pilot/cmd/pilot-agent/main.go +++ b/pilot/cmd/pilot-agent/main.go @@ -45,9 +45,9 @@ import ( "istio.io/istio/pilot/pkg/proxy/envoy" "istio.io/istio/pilot/pkg/serviceregistry" "istio.io/istio/pkg/cmd" - "istio.io/istio/pkg/config" "istio.io/istio/pkg/config/constants" "istio.io/istio/pkg/config/mesh" + "istio.io/istio/pkg/config/validation" "istio.io/istio/pkg/spiffe" "istio.io/istio/pkg/util/protomarshal" ) @@ -278,7 +278,7 @@ var ( } } - if err := config.ValidateProxyConfig(&proxyConfig); err != nil { + if err := validation.ValidateProxyConfig(&proxyConfig); err != nil { return err } diff --git a/pilot/pkg/model/config.go b/pilot/pkg/model/config.go index a95fbed1158a..ee00248af4d9 100644 --- a/pilot/pkg/model/config.go +++ b/pilot/pkg/model/config.go @@ -30,10 +30,10 @@ import ( networking "istio.io/api/networking/v1alpha3" "istio.io/istio/galley/pkg/metadata" - "istio.io/istio/pkg/config" "istio.io/istio/pkg/config/constants" "istio.io/istio/pkg/config/host" "istio.io/istio/pkg/config/labels" + "istio.io/istio/pkg/config/validation" testConfig "istio.io/istio/pkg/test/config" ) @@ -222,7 +222,7 @@ type ProtoSchema struct { // Validate configuration as a protobuf message assuming the object is an // instance of the expected message type - Validate config.ValidationFunc + Validate validation.ValidateFunc // MCP collection for this configuration resource schema Collection string @@ -335,7 +335,7 @@ var ( Group: "networking", Version: "v1alpha3", MessageName: "istio.networking.v1alpha3.VirtualService", - Validate: config.ValidateVirtualService, + Validate: validation.ValidateVirtualService, Collection: metadata.IstioNetworkingV1alpha3Virtualservices.Collection.String(), } @@ -346,7 +346,7 @@ var ( Group: "networking", Version: "v1alpha3", MessageName: "istio.networking.v1alpha3.Gateway", - Validate: config.ValidateGateway, + Validate: validation.ValidateGateway, Collection: metadata.IstioNetworkingV1alpha3Gateways.Collection.String(), } @@ -357,7 +357,7 @@ var ( Group: "networking", Version: "v1alpha3", MessageName: "istio.networking.v1alpha3.ServiceEntry", - Validate: config.ValidateServiceEntry, + Validate: validation.ValidateServiceEntry, Collection: metadata.IstioNetworkingV1alpha3Serviceentries.Collection.String(), } @@ -368,7 +368,7 @@ var ( Group: "networking", Version: "v1alpha3", MessageName: "istio.networking.v1alpha3.DestinationRule", - Validate: config.ValidateDestinationRule, + Validate: validation.ValidateDestinationRule, Collection: metadata.IstioNetworkingV1alpha3Destinationrules.Collection.String(), } @@ -379,7 +379,7 @@ var ( Group: "networking", Version: "v1alpha3", MessageName: "istio.networking.v1alpha3.EnvoyFilter", - Validate: config.ValidateEnvoyFilter, + Validate: validation.ValidateEnvoyFilter, Collection: metadata.IstioNetworkingV1alpha3Envoyfilters.Collection.String(), } @@ -390,7 +390,7 @@ var ( Group: "networking", Version: "v1alpha3", MessageName: "istio.networking.v1alpha3.Sidecar", - Validate: config.ValidateSidecar, + Validate: validation.ValidateSidecar, Collection: metadata.IstioNetworkingV1alpha3Sidecars.Collection.String(), } @@ -401,7 +401,7 @@ var ( Group: "config", Version: istioAPIVersion, MessageName: "istio.mixer.v1.config.client.HTTPAPISpec", - Validate: config.ValidateHTTPAPISpec, + Validate: validation.ValidateHTTPAPISpec, Collection: metadata.IstioConfigV1alpha2Httpapispecs.Collection.String(), } @@ -412,7 +412,7 @@ var ( Group: "config", Version: istioAPIVersion, MessageName: "istio.mixer.v1.config.client.HTTPAPISpecBinding", - Validate: config.ValidateHTTPAPISpecBinding, + Validate: validation.ValidateHTTPAPISpecBinding, Collection: metadata.IstioConfigV1alpha2Httpapispecbindings.Collection.String(), } @@ -423,7 +423,7 @@ var ( Group: "config", Version: istioAPIVersion, MessageName: "istio.mixer.v1.config.client.QuotaSpec", - Validate: config.ValidateQuotaSpec, + Validate: validation.ValidateQuotaSpec, Collection: metadata.IstioMixerV1ConfigClientQuotaspecs.Collection.String(), } @@ -434,7 +434,7 @@ var ( Group: "config", Version: istioAPIVersion, MessageName: "istio.mixer.v1.config.client.QuotaSpecBinding", - Validate: config.ValidateQuotaSpecBinding, + Validate: validation.ValidateQuotaSpecBinding, Collection: metadata.IstioMixerV1ConfigClientQuotaspecbindings.Collection.String(), } @@ -446,7 +446,7 @@ var ( Group: "authentication", Version: "v1alpha1", MessageName: "istio.authentication.v1alpha1.Policy", - Validate: config.ValidateAuthenticationPolicy, + Validate: validation.ValidateAuthenticationPolicy, Collection: metadata.IstioAuthenticationV1alpha1Policies.Collection.String(), } @@ -459,7 +459,7 @@ var ( Group: "authentication", Version: "v1alpha1", MessageName: "istio.authentication.v1alpha1.Policy", - Validate: config.ValidateAuthenticationPolicy, + Validate: validation.ValidateAuthenticationPolicy, Collection: metadata.IstioAuthenticationV1alpha1Meshpolicies.Collection.String(), } @@ -470,7 +470,7 @@ var ( Group: "rbac", Version: "v1alpha1", MessageName: "istio.rbac.v1alpha1.ServiceRole", - Validate: config.ValidateServiceRole, + Validate: validation.ValidateServiceRole, Collection: metadata.IstioRbacV1alpha1Serviceroles.Collection.String(), } @@ -482,7 +482,7 @@ var ( Group: "rbac", Version: "v1alpha1", MessageName: "istio.rbac.v1alpha1.ServiceRoleBinding", - Validate: config.ValidateServiceRoleBinding, + Validate: validation.ValidateServiceRoleBinding, Collection: metadata.IstioRbacV1alpha1Servicerolebindings.Collection.String(), } @@ -495,7 +495,7 @@ var ( Group: "rbac", Version: "v1alpha1", MessageName: "istio.rbac.v1alpha1.RbacConfig", - Validate: config.ValidateRbacConfig, + Validate: validation.ValidateRbacConfig, Collection: metadata.IstioRbacV1alpha1Rbacconfigs.Collection.String(), } @@ -507,7 +507,7 @@ var ( Group: "rbac", Version: "v1alpha1", MessageName: "istio.rbac.v1alpha1.RbacConfig", - Validate: config.ValidateClusterRbacConfig, + Validate: validation.ValidateClusterRbacConfig, Collection: metadata.IstioRbacV1alpha1Clusterrbacconfigs.Collection.String(), } diff --git a/pilot/pkg/model/validation.go b/pilot/pkg/model/validation.go index d1e681c8375f..f0c6107966b6 100644 --- a/pilot/pkg/model/validation.go +++ b/pilot/pkg/model/validation.go @@ -23,8 +23,8 @@ import ( "github.com/gogo/protobuf/proto" "github.com/hashicorp/go-multierror" - "istio.io/istio/pkg/config" "istio.io/istio/pkg/config/labels" + "istio.io/istio/pkg/config/validation" ) // UnixAddressPrefix is the prefix used to indicate an address is for a Unix Domain socket. It is used in @@ -95,7 +95,7 @@ func (s *Service) Validate() error { } else if !labels.IsDNS1123Label(port.Name) { errs = multierror.Append(errs, fmt.Errorf("invalid name: %q", port.Name)) } - if err := config.ValidatePort(port.Port); err != nil { + if err := validation.ValidatePort(port.Port); err != nil { errs = multierror.Append(errs, fmt.Errorf("invalid service port value %d for %q: %v", port.Port, port.Name, err)) } @@ -116,7 +116,7 @@ func (instance *ServiceInstance) Validate() error { errs = multierror.Append(errs, err) } - if err := config.ValidatePort(instance.Endpoint.Port); err != nil { + if err := validation.ValidatePort(instance.Endpoint.Port); err != nil { errs = multierror.Append(errs, err) } @@ -149,12 +149,12 @@ func ValidateNetworkEndpointAddress(n *NetworkEndpoint) error { case AddressFamilyTCP: ipAddr := net.ParseIP(n.Address) // Typically it is an IP address if ipAddr == nil { - if err := config.ValidateFQDN(n.Address); err != nil { // Otherwise could be an FQDN + if err := validation.ValidateFQDN(n.Address); err != nil { // Otherwise could be an FQDN return errors.New("invalid address " + n.Address) } } case AddressFamilyUnix: - return config.ValidateUnixAddress(n.Address) + return validation.ValidateUnixAddress(n.Address) default: panic(fmt.Sprintf("unhandled Family %v", n.Family)) } diff --git a/pkg/config/mesh/mesh.go b/pkg/config/mesh/mesh.go index fa419d5a4c61..2b7a2aa55b28 100644 --- a/pkg/config/mesh/mesh.go +++ b/pkg/config/mesh/mesh.go @@ -30,8 +30,8 @@ import ( meshconfig "istio.io/api/mesh/v1alpha1" - "istio.io/istio/pkg/config" "istio.io/istio/pkg/config/constants" + "istio.io/istio/pkg/config/validation" "istio.io/istio/pkg/util/protomarshal" ) @@ -111,7 +111,7 @@ func ApplyMeshConfigDefaults(yaml string) (*meshconfig.MeshConfig, error) { } } - if err := config.ValidateMeshConfig(&out); err != nil { + if err := validation.ValidateMeshConfig(&out); err != nil { return nil, err } diff --git a/pkg/config/mesh/mesh_test.go b/pkg/config/mesh/mesh_test.go index 1a98da6cb09d..1bc488252a01 100644 --- a/pkg/config/mesh/mesh_test.go +++ b/pkg/config/mesh/mesh_test.go @@ -21,20 +21,20 @@ import ( meshconfig "istio.io/api/mesh/v1alpha1" - "istio.io/istio/pkg/config" "istio.io/istio/pkg/config/mesh" + "istio.io/istio/pkg/config/validation" ) func TestDefaultProxyConfig(t *testing.T) { proxyConfig := mesh.DefaultProxyConfig() - if err := config.ValidateProxyConfig(&proxyConfig); err != nil { + if err := validation.ValidateProxyConfig(&proxyConfig); err != nil { t.Errorf("validation of default proxy config failed with %v", err) } } func TestDefaultMeshConfig(t *testing.T) { m := mesh.DefaultMeshConfig() - if err := config.ValidateMeshConfig(&m); err != nil { + if err := validation.ValidateMeshConfig(&m); err != nil { t.Errorf("validation of default mesh config failed with %v", err) } } diff --git a/pkg/config/validation.go b/pkg/config/validation/validation.go similarity index 99% rename from pkg/config/validation.go rename to pkg/config/validation/validation.go index d45cff562d43..a8ff62178413 100644 --- a/pkg/config/validation.go +++ b/pkg/config/validation/validation.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config +package validation import ( "errors" @@ -94,8 +94,8 @@ var supportedMethods = map[string]bool{ http.MethodTrace: true, } -// ValidationFunc defines a validation func for an API proto. -type ValidationFunc func(name, namespace string, config proto.Message) error +// ValidateFunc defines a validation func for an API proto. +type ValidateFunc func(name, namespace string, config proto.Message) error // ValidatePort checks that the network port is in range func ValidatePort(port int) error { diff --git a/pkg/config/validation_test.go b/pkg/config/validation/validation_test.go similarity index 99% rename from pkg/config/validation_test.go rename to pkg/config/validation/validation_test.go index c2ea37a6ff50..fe49449c4c8b 100644 --- a/pkg/config/validation_test.go +++ b/pkg/config/validation/validation_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package config +package validation import ( "fmt"