Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support define configscope for k8s service #10598

Merged
merged 4 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pilot/pkg/model/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

authn "istio.io/api/authentication/v1alpha1"
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pkg/features/pilot"
)

// Hostname describes a (possibly wildcarded) hostname
Expand Down Expand Up @@ -360,12 +361,6 @@ type ServiceInstance struct {
ServiceAccount string `json:"serviceaccount,omitempty"`
}

const (
// AZLabel indicates the region/zone of an instance. It is used if the native
// registry doesn't provide one.
AZLabel = "istio-az"
)

// GetLocality returns the availability zone from an instance.
// - k8s: region/zone, extracted from node's failure-domain.beta.kubernetes.io/{region,zone}
// - consul: defaults to 'instance.Datacenter'
Expand All @@ -375,7 +370,7 @@ func (si *ServiceInstance) GetLocality() string {
if si.Endpoint.Locality != "" {
return si.Endpoint.Locality
}
return si.Labels[AZLabel]
return si.Labels[pilot.AZLabel]
}

// IstioEndpoint has the information about a single address+port for a specific
Expand Down
10 changes: 9 additions & 1 deletion pilot/pkg/serviceregistry/kube/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/features/pilot"
)

const (
Expand Down Expand Up @@ -103,6 +104,13 @@ func convertService(svc v1.Service, domainSuffix string) *model.Service {
}
sort.Sort(sort.StringSlice(serviceaccounts))

configScope := networking.ConfigScope_PUBLIC
if svc.Labels != nil {
if svc.Labels[pilot.ServiceScopeLabel] == networking.ConfigScope_name[int32(networking.ConfigScope_PRIVATE)] {
configScope = networking.ConfigScope_PRIVATE
}
}

return &model.Service{
Hostname: serviceHostname(svc.Name, svc.Namespace, domainSuffix),
Ports: ports,
Expand All @@ -115,7 +123,7 @@ func convertService(svc v1.Service, domainSuffix string) *model.Service {
Name: svc.Name,
Namespace: svc.Namespace,
UID: fmt.Sprintf("istio://%s/services/%s", svc.Namespace, svc.Name),
ConfigScope: networking.ConfigScope_PUBLIC,
ConfigScope: configScope,
},
}
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/features/pilot/pilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ const (
// set at injection time. When set, the Endpoints returned to a note and not on same network
// will be replaced with the gateway defined in the settings.
NodeMetadataNetwork = "NETWORK"

// AZLabel indicates the region/zone of an instance. It is used if the native
// registry doesn't provide one.
AZLabel = "istio-az"

// ServiceScopeLabel configs the scope the service visible to.
// "PUBLIC" which is the default, indicates it is reachable within the mesh
// "PRIVATE" indicates it is reachable within its namespace
ServiceScopeLabel = "istio-config-scope"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternate choice is to set this in annotation, any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer annotations. Other parts of istio use annotations. The availability zone thing should also be using annotations (not to mention its incorrect after your recent work on using regions, zones, etc..).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will update

)