@@ -19,26 +19,29 @@ import (
19
19
"sync"
20
20
21
21
"istio.io/istio/pkg/config/host"
22
- "istio.io/istio/pkg/util/sets"
23
22
)
24
23
25
24
var (
26
25
defaultClusterLocalNamespaces = []string {"kube-system" }
27
26
defaultClusterLocalServices = []string {"kubernetes.default.svc" }
28
27
)
29
28
30
- // ClusterLocalHosts is a map of host names or wildcard patterns which should only
31
- // be made accessible from within the same cluster.
29
+ // ClusterLocalHosts is a map of host names or wildcard patterns which indicate
30
+ // whether a host be made accessible from within the same cluster or not .
32
31
type ClusterLocalHosts struct {
33
- specific sets. Set [host.Name ]
34
- wildcard sets. Set [host.Name ]
32
+ specific map [host.Name ]bool
33
+ wildcard map [host.Name ]bool
35
34
}
36
35
37
36
// IsClusterLocal indicates whether the given host should be treated as a
38
37
// cluster-local destination.
39
38
func (c ClusterLocalHosts ) IsClusterLocal (h host.Name ) bool {
40
- _ , _ , ok := MostSpecificHostMatch (h , c .specific , c .wildcard )
41
- return ok
39
+ _ , local , ok := MostSpecificHostMatch (h , c .specific , c .wildcard )
40
+ // Explicitly set clusterLocal to false if host is not found in clusterLocal settings
41
+ if ! ok {
42
+ local = false
43
+ }
44
+ return local
42
45
}
43
46
44
47
// ClusterLocalProvider provides the cluster-local hosts.
@@ -98,22 +101,15 @@ func (c *clusterLocalProvider) onMeshUpdated(e *Environment) {
98
101
99
102
// Collect the cluster-local hosts.
100
103
hosts := ClusterLocalHosts {
101
- specific : make (map [host.Name ]struct {}, 0 ),
102
- wildcard : make (map [host.Name ]struct {}, 0 ),
104
+ specific : make (map [host.Name ]bool ),
105
+ wildcard : make (map [host.Name ]bool ),
103
106
}
107
+
104
108
for _ , serviceSettings := range e .Mesh ().ServiceSettings {
105
- if serviceSettings .GetSettings ().GetClusterLocal () {
106
- for _ , h := range serviceSettings .GetHosts () {
107
- hostname := host .Name (h )
108
- if hostname .IsWildCarded () {
109
- hosts .wildcard .Insert (hostname )
110
- } else {
111
- hosts .specific .Insert (hostname )
112
- }
113
- }
114
- } else {
115
- // Remove defaults if specified to be non-cluster-local.
116
- for _ , h := range serviceSettings .GetHosts () {
109
+ isClusterLocal := serviceSettings .GetSettings ().GetClusterLocal ()
110
+ for _ , h := range serviceSettings .GetHosts () {
111
+ // If clusterLocal false, check to see if we should remove a default clusterLocal host.
112
+ if ! isClusterLocal {
117
113
for i , defaultClusterLocalHost := range defaultClusterLocalHosts {
118
114
if len (defaultClusterLocalHost ) > 0 {
119
115
if h == string (defaultClusterLocalHost ) ||
@@ -126,15 +122,25 @@ func (c *clusterLocalProvider) onMeshUpdated(e *Environment) {
126
122
}
127
123
}
128
124
}
125
+
126
+ // Add hosts with their clusterLocal setting to sets.
127
+ for _ , h := range serviceSettings .GetHosts () {
128
+ hostname := host .Name (h )
129
+ if hostname .IsWildCarded () {
130
+ hosts .wildcard [hostname ] = isClusterLocal
131
+ } else {
132
+ hosts .specific [hostname ] = isClusterLocal
133
+ }
134
+ }
129
135
}
130
136
131
137
// Add any remaining defaults to the end of the list.
132
138
for _ , defaultClusterLocalHost := range defaultClusterLocalHosts {
133
139
if len (defaultClusterLocalHost ) > 0 {
134
140
if defaultClusterLocalHost .IsWildCarded () {
135
- hosts .wildcard . Insert ( defaultClusterLocalHost )
141
+ hosts .wildcard [ defaultClusterLocalHost ] = true
136
142
} else {
137
- hosts .specific . Insert ( defaultClusterLocalHost )
143
+ hosts .specific [ defaultClusterLocalHost ] = true
138
144
}
139
145
}
140
146
}
0 commit comments