Skip to content

Commit

Permalink
Add application ports for gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjohn committed May 13, 2019
1 parent 04850e1 commit 33bc3a6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ spec:
{{- else }}
- istio-pilot:15010
{{- end }}
{{- if $spec.applicationPorts }}
- --applicationPorts
- "{{ $spec.applicationPorts }}"
{{- end }}
{{- end }}
{{- if $.Values.global.trustDomain }}
- --trust-domain={{ $.Values.global.trustDomain }}
Expand Down
9 changes: 9 additions & 0 deletions install/kubernetes/helm/istio/charts/gateways/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ istio-ingressgateway:
secretName: istio-ingressgateway-ca-certs
mountPath: /etc/istio/ingressgateway-ca-certs
### Advanced options ############

# Ports to explicitly check for readiness. If configured, the readiness check will expect a
# listener on these ports. A comma separated list is expected, such as "80,443".
#
# Warning: If you do not have a gateway configured for the ports provided, this check will always
# fail. This is intended for use cases where you always expect to have a listener on the port,
# such as 80 or 443 in typical setups.
applicationPorts: ""

env:
# A gateway with this mode ensures that pilot generates an additional
# set of clusters for internal services but without Istio mTLS, to
Expand Down
1 change: 1 addition & 0 deletions pilot/cmd/pilot-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ var (
StatusPort: statusPort,
ApplicationPorts: parsedPorts,
KubeAppHTTPProbers: prober,
NodeType: role.Type,
})
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion pilot/cmd/pilot-agent/status/ready/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import (

multierror "github.com/hashicorp/go-multierror"

"istio.io/istio/pilot/pkg/model"

"istio.io/istio/pilot/cmd/pilot-agent/status/util"
)

// Probe for readiness.
type Probe struct {
AdminPort uint16
ApplicationPorts []uint16
NodeType model.NodeType
}

// Check executes the probe and returns an error is the probe fails.
Expand All @@ -43,7 +46,7 @@ func (p *Probe) Check() error {
// checkApplicationPorts verifies that Envoy has received configuration for all ports exposed by the application container.
func (p *Probe) checkInboundConfigured() error {
if len(p.ApplicationPorts) > 0 {
listeningPorts, listeners, err := util.GetInboundListeningPorts(p.AdminPort)
listeningPorts, listeners, err := util.GetInboundListeningPorts(p.AdminPort, p.NodeType)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pilot/cmd/pilot-agent/status/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"syscall"
"time"

"istio.io/istio/pilot/pkg/model"

"istio.io/istio/pilot/cmd/pilot-agent/status/ready"
"istio.io/istio/pkg/log"

Expand Down Expand Up @@ -63,6 +65,7 @@ type Config struct {
ApplicationPorts []uint16
// KubeAppHTTPProbers is a json with Kubernetes application HTTP prober config encoded.
KubeAppHTTPProbers string
NodeType model.NodeType
}

// Server provides an endpoint for handling status probes.
Expand All @@ -81,6 +84,7 @@ func NewServer(config Config) (*Server, error) {
ready: &ready.Probe{
AdminPort: config.AdminPort,
ApplicationPorts: config.ApplicationPorts,
NodeType: config.NodeType,
},
}
if config.KubeAppHTTPProbers == "" {
Expand Down
17 changes: 14 additions & 3 deletions pilot/cmd/pilot-agent/status/util/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import (
"strings"

multierror "github.com/hashicorp/go-multierror"

"istio.io/istio/pilot/pkg/model"
)

var (
ipPrefixes = getLocalIPPrefixes()
)

// GetInboundListeningPorts returns a map of inbound ports for which Envoy has active listeners.
func GetInboundListeningPorts(adminPort uint16) (map[uint16]bool, string, error) {
func GetInboundListeningPorts(adminPort uint16, nodeType model.NodeType) (map[uint16]bool, string, error) {
buf, err := doHTTPGet(fmt.Sprintf("http://127.0.0.1:%d/listeners", adminPort))
if err != nil {
return nil, "", multierror.Prefix(err, "failed retrieving Envoy listeners:")
Expand All @@ -50,8 +52,17 @@ func GetInboundListeningPorts(adminPort uint16) (map[uint16]bool, string, error)
}
// Before checking if listener is local, removing port portion of the address
ipAddr := strings.TrimSuffix(l, ":"+ipAddrParts[len(ipAddrParts)-1])
if !isLocalListener(ipAddr) {
continue

switch nodeType {
// For gateways, we will not listen on a local host, instead on 0.0.0.0
case model.Router:
if ipAddr != "0.0.0.0" {
continue
}
default:
if !isLocalListener(ipAddr) {
continue
}
}

portStr := ipAddrParts[len(ipAddrParts)-1]
Expand Down

0 comments on commit 33bc3a6

Please sign in to comment.