Skip to content

Commit

Permalink
Moving config hostname to subpackage (istio#16026)
Browse files Browse the repository at this point in the history
This is part of the cleanup of pkg/config. Planning on moving everything here to subpackages.
  • Loading branch information
nmittler authored and istio-testing committed Aug 2, 2019
1 parent 34739c1 commit 9c9a726
Show file tree
Hide file tree
Showing 58 changed files with 668 additions and 643 deletions.
4 changes: 2 additions & 2 deletions istioctl/cmd/proxyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"istio.io/istio/istioctl/pkg/writer/envoy/clusters"
"istio.io/istio/istioctl/pkg/writer/envoy/configdump"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/host"
)

const (
Expand Down Expand Up @@ -115,7 +115,7 @@ func proxyConfig() *cobra.Command {
return err
}
filter := configdump.ClusterFilter{
FQDN: config.Hostname(fqdn),
FQDN: host.Name(fqdn),
Port: port,
Subset: subset,
Direction: model.TrafficDirection(direction),
Expand Down
10 changes: 5 additions & 5 deletions istioctl/pkg/writer/envoy/configdump/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (

protio "istio.io/istio/istioctl/pkg/util/proto"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/host"
)

// ClusterFilter is used to pass filter information into cluster based config writer print functions
type ClusterFilter struct {
FQDN config.Hostname
FQDN host.Name
Port int
Subset string
Direction model.TrafficDirection
Expand Down Expand Up @@ -151,10 +151,10 @@ func (c *ConfigWriter) retrieveSortedClusterSlice() ([]*xdsapi.Cluster, error) {
return clusters, nil
}

func safelyParseSubsetKey(key string) (model.TrafficDirection, string, config.Hostname, int) {
func safelyParseSubsetKey(key string) (model.TrafficDirection, string, host.Name, int) {
if len(strings.Split(key, "|")) > 3 {
return model.ParseSubsetKey(key)
}
name := config.Hostname(key)
return model.TrafficDirection(""), "", name, 0
name := host.Name(key)
return "", "", name, 0
}
8 changes: 4 additions & 4 deletions mixer/test/client/gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"istio.io/istio/pilot/pkg/networking/plugin"
"istio.io/istio/pilot/pkg/networking/plugin/mixer"
pilotutil "istio.io/istio/pilot/pkg/networking/util"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/config/labels"
)

Expand Down Expand Up @@ -238,7 +238,7 @@ func (mock) GetProxyServiceInstances(_ *model.Proxy) ([]*model.ServiceInstance,
func (mock) GetProxyWorkloadLabels(proxy *model.Proxy) (labels.Collection, error) {
return nil, nil
}
func (mock) GetService(_ config.Hostname) (*model.Service, error) { return nil, nil }
func (mock) GetService(_ host.Name) (*model.Service, error) { return nil, nil }
func (mock) InstancesByPort(_ *model.Service, _ int, _ labels.Collection) ([]*model.ServiceInstance, error) {
return nil, nil
}
Expand Down Expand Up @@ -268,8 +268,8 @@ var (
ServiceDiscovery: mock{},
}
pushContext = model.PushContext{
ServiceByHostnameAndNamespace: map[config.Hostname]map[string]*model.Service{
config.Hostname("svc.ns3"): {
ServiceByHostnameAndNamespace: map[host.Name]map[string]*model.Service{
host.Name("svc.ns3"): {
"ns3": &svc,
},
},
Expand Down
8 changes: 4 additions & 4 deletions mixer/test/client/pilotplugin/pilotplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"istio.io/istio/pilot/pkg/networking/plugin"
"istio.io/istio/pilot/pkg/networking/plugin/mixer"
pilotutil "istio.io/istio/pilot/pkg/networking/util"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/config/labels"
)

Expand Down Expand Up @@ -304,7 +304,7 @@ func (mock) GetProxyServiceInstances(_ *model.Proxy) ([]*model.ServiceInstance,
func (mock) GetProxyWorkloadLabels(proxy *model.Proxy) (labels.Collection, error) {
return nil, nil
}
func (mock) GetService(_ config.Hostname) (*model.Service, error) { return nil, nil }
func (mock) GetService(_ host.Name) (*model.Service, error) { return nil, nil }
func (mock) InstancesByPort(_ *model.Service, _ int, _ labels.Collection) ([]*model.ServiceInstance, error) {
return nil, nil
}
Expand Down Expand Up @@ -335,8 +335,8 @@ var (
ServiceDiscovery: mock{},
}
pushContext = model.PushContext{
ServiceByHostnameAndNamespace: map[config.Hostname]map[string]*model.Service{
config.Hostname("svc.ns3"): {
ServiceByHostnameAndNamespace: map[host.Name]map[string]*model.Service{
host.Name("svc.ns3"): {
"ns3": &svc,
},
},
Expand Down
8 changes: 4 additions & 4 deletions mixer/test/client/pilotplugin_mtls/pilotplugin_mtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"istio.io/istio/pilot/pkg/networking/plugin"
"istio.io/istio/pilot/pkg/networking/plugin/mixer"
pilotutil "istio.io/istio/pilot/pkg/networking/util"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/config/labels"
"istio.io/istio/pkg/proto"
)
Expand Down Expand Up @@ -319,7 +319,7 @@ func (mock) GetProxyServiceInstances(_ *model.Proxy) ([]*model.ServiceInstance,
func (mock) GetProxyWorkloadLabels(proxy *model.Proxy) (labels.Collection, error) {
return nil, nil
}
func (mock) GetService(_ config.Hostname) (*model.Service, error) { return nil, nil }
func (mock) GetService(_ host.Name) (*model.Service, error) { return nil, nil }
func (mock) InstancesByPort(_ *model.Service, _ int, _ labels.Collection) ([]*model.ServiceInstance, error) {
return nil, nil
}
Expand Down Expand Up @@ -350,8 +350,8 @@ var (
ServiceDiscovery: mock{},
}
pushContext = model.PushContext{
ServiceByHostnameAndNamespace: map[config.Hostname]map[string]*model.Service{
config.Hostname("svc.ns3"): {
ServiceByHostnameAndNamespace: map[host.Name]map[string]*model.Service{
host.Name("svc.ns3"): {
"ns3": &svc,
},
},
Expand Down
8 changes: 4 additions & 4 deletions mixer/test/client/pilotplugin_tcp/pilotplugin_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"istio.io/istio/pilot/pkg/networking/plugin"
"istio.io/istio/pilot/pkg/networking/plugin/mixer"
pilotutil "istio.io/istio/pilot/pkg/networking/util"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/config/labels"
)

Expand Down Expand Up @@ -187,7 +187,7 @@ func (mock) GetProxyServiceInstances(_ *model.Proxy) ([]*model.ServiceInstance,
func (mock) GetProxyWorkloadLabels(proxy *model.Proxy) (labels.Collection, error) {
return nil, nil
}
func (mock) GetService(_ config.Hostname) (*model.Service, error) { return nil, nil }
func (mock) GetService(_ host.Name) (*model.Service, error) { return nil, nil }
func (mock) InstancesByPort(_ *model.Service, _ int, _ labels.Collection) ([]*model.ServiceInstance, error) {
return nil, nil
}
Expand Down Expand Up @@ -217,8 +217,8 @@ var (
ServiceDiscovery: mock{},
}
pushContext = model.PushContext{
ServiceByHostnameAndNamespace: map[config.Hostname]map[string]*model.Service{
config.Hostname("svc.ns3"): {
ServiceByHostnameAndNamespace: map[host.Name]map[string]*model.Service{
host.Name("svc.ns3"): {
"ns3": &svc,
},
},
Expand Down
38 changes: 19 additions & 19 deletions pilot/pkg/bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ import (
"istio.io/istio/pilot/pkg/serviceregistry/external"
controller2 "istio.io/istio/pilot/pkg/serviceregistry/kube/controller"
srmemory "istio.io/istio/pilot/pkg/serviceregistry/memory"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/config/mesh"
istiokeepalive "istio.io/istio/pkg/keepalive"
kubelib "istio.io/istio/pkg/kube"
Expand Down Expand Up @@ -365,11 +365,11 @@ func GetMeshConfig(kube kubernetes.Interface, namespace, name string) (*v1.Confi
return nil, nil, fmt.Errorf("missing configuration map key %q", ConfigMapKey)
}

mesh, err := mesh.ApplyMeshConfigDefaults(cfgYaml)
meshConfig, err := mesh.ApplyMeshConfigDefaults(cfgYaml)
if err != nil {
return nil, nil, err
}
return cfg, mesh, nil
return cfg, meshConfig, nil
}

// initMesh creates the mesh in the pilotConfig from the input arguments.
Expand All @@ -379,58 +379,58 @@ func (s *Server) initMesh(args *PilotArgs) error {
s.mesh = args.MeshConfig
return nil
}
var mesh *meshconfig.MeshConfig
var meshConfig *meshconfig.MeshConfig
var err error

if args.Mesh.ConfigFile != "" {
mesh, err = cmd.ReadMeshConfig(args.Mesh.ConfigFile)
meshConfig, err = cmd.ReadMeshConfig(args.Mesh.ConfigFile)
if err != nil {
log.Warnf("failed to read mesh configuration, using default: %v", err)
}

// Watch the config file for changes and reload if it got modified
s.addFileWatcher(args.Mesh.ConfigFile, func() {
// Reload the config file
mesh, err = cmd.ReadMeshConfig(args.Mesh.ConfigFile)
meshConfig, err = cmd.ReadMeshConfig(args.Mesh.ConfigFile)
if err != nil {
log.Warnf("failed to read mesh configuration, using default: %v", err)
return
}
if !reflect.DeepEqual(mesh, s.mesh) {
log.Infof("mesh configuration updated to: %s", spew.Sdump(mesh))
if !reflect.DeepEqual(mesh.ConfigSources, s.mesh.ConfigSources) {
if !reflect.DeepEqual(meshConfig, s.mesh) {
log.Infof("mesh configuration updated to: %s", spew.Sdump(meshConfig))
if !reflect.DeepEqual(meshConfig.ConfigSources, s.mesh.ConfigSources) {
log.Infof("mesh configuration sources have changed")
//TODO Need to re-create or reload initConfigController()
}
s.mesh = mesh
s.mesh = meshConfig
if s.EnvoyXdsServer != nil {
s.EnvoyXdsServer.Env.Mesh = mesh
s.EnvoyXdsServer.Env.Mesh = meshConfig
s.EnvoyXdsServer.ConfigUpdate(true)
}
}
})
}

if mesh == nil {
if meshConfig == nil {
// Config file either wasn't specified or failed to load - use a default mesh.
if _, mesh, err = GetMeshConfig(s.kubeClient, controller2.IstioNamespace, controller2.IstioConfigMap); err != nil {
if _, meshConfig, err = GetMeshConfig(s.kubeClient, controller2.IstioNamespace, controller2.IstioConfigMap); err != nil {
log.Warnf("failed to read the default mesh configuration: %v, from the %s config map in the %s namespace",
err, controller2.IstioConfigMap, controller2.IstioNamespace)
return err
}

// Allow some overrides for testing purposes.
if args.Mesh.MixerAddress != "" {
mesh.MixerCheckServer = args.Mesh.MixerAddress
mesh.MixerReportServer = args.Mesh.MixerAddress
meshConfig.MixerCheckServer = args.Mesh.MixerAddress
meshConfig.MixerReportServer = args.Mesh.MixerAddress
}
}

log.Infof("mesh configuration %s", spew.Sdump(mesh))
log.Infof("mesh configuration %s", spew.Sdump(meshConfig))
log.Infof("version %s", version.Info.String())
log.Infof("flags %s", spew.Sdump(args))

s.mesh = mesh
s.mesh = meshConfig
return nil
}

Expand Down Expand Up @@ -865,11 +865,11 @@ func (s *Server) initServiceControllers(args *PilotArgs) error {
func (s *Server) initMemoryRegistry(serviceControllers *aggregate.Controller) {
// MemServiceDiscovery implementation
discovery1 := srmemory.NewDiscovery(
map[config.Hostname]*model.Service{ // srmemory.HelloService.Hostname: srmemory.HelloService,
map[host.Name]*model.Service{ // srmemory.HelloService.Hostname: srmemory.HelloService,
}, 2)

discovery2 := srmemory.NewDiscovery(
map[config.Hostname]*model.Service{ // srmemory.WorldService.Hostname: srmemory.WorldService,
map[host.Name]*model.Service{ // srmemory.WorldService.Hostname: srmemory.WorldService,
}, 2)

registry1 := aggregate.Registry{
Expand Down
21 changes: 11 additions & 10 deletions pilot/pkg/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"istio.io/istio/pilot/pkg/model/test"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/config/labels"
)

Expand Down Expand Up @@ -550,7 +551,7 @@ var (
// ResolveHostname produces a FQDN based on either the service or
// a concat of the namespace + domain
// Deprecated. Do not use
func ResolveHostname(meta ConfigMeta, svc *mccpb.IstioService) config.Hostname {
func ResolveHostname(meta ConfigMeta, svc *mccpb.IstioService) host.Name {
out := svc.Name
// if FQDN is specified, do not append domain or namespace to hostname
// Service field has precedence over Name
Expand All @@ -570,20 +571,20 @@ func ResolveHostname(meta ConfigMeta, svc *mccpb.IstioService) config.Hostname {
}
}

return config.Hostname(out)
return host.Name(out)
}

// ResolveShortnameToFQDN uses metadata information to resolve a reference
// to shortname of the service to FQDN
func ResolveShortnameToFQDN(host string, meta ConfigMeta) config.Hostname {
out := host
// Treat the wildcard host as fully qualified. Any other variant of a wildcard hostname will contain a `.` too,
func ResolveShortnameToFQDN(hostname string, meta ConfigMeta) host.Name {
out := hostname
// Treat the wildcard hostname as fully qualified. Any other variant of a wildcard hostname will contain a `.` too,
// and skip the next if, so we only need to check for the literal wildcard itself.
if host == "*" {
return config.Hostname(out)
if hostname == "*" {
return host.Name(out)
}
// if FQDN is specified, do not append domain or namespace to hostname
if !strings.Contains(host, ".") {
if !strings.Contains(hostname, ".") {
if meta.Namespace != "" {
out = out + "." + meta.Namespace
}
Expand All @@ -596,7 +597,7 @@ func ResolveShortnameToFQDN(host string, meta ConfigMeta) config.Hostname {
}
}

return config.Hostname(out)
return host.Name(out)
}

// resolveGatewayName uses metadata information to resolve a reference
Expand Down Expand Up @@ -627,7 +628,7 @@ func resolveGatewayName(gwname string, meta ConfigMeta) string {

// MostSpecificHostMatch compares the elements of the stack to the needle, and returns the longest stack element
// matching the needle, or false if no element in the stack matches the needle.
func MostSpecificHostMatch(needle config.Hostname, stack []config.Hostname) (config.Hostname, bool) {
func MostSpecificHostMatch(needle host.Name, stack []host.Name) (host.Name, bool) {
for _, h := range stack {
if needle.Matches(h) {
return h, true
Expand Down
Loading

0 comments on commit 9c9a726

Please sign in to comment.