-
Notifications
You must be signed in to change notification settings - Fork 365
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
allow exposing gateway on nodeport service - status updates #1392
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ rules: | |
- apiGroups: | ||
- "" | ||
resources: | ||
- nodes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- namespaces | ||
- secrets | ||
- services | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package kubernetes | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type nodeDetails struct { | ||
name string | ||
address string | ||
} | ||
|
||
// kubernetesProviderStore holds cached information for the kubernetes provider. | ||
type kubernetesProviderStore struct { | ||
// nodes holds information required for updating Gateway status with the Node | ||
// addresses, in case the Gateway is exposed on every Node of the cluster, using | ||
// Service of type NodePort. | ||
nodes map[string]nodeDetails | ||
} | ||
|
||
func newProviderStore() *kubernetesProviderStore { | ||
return &kubernetesProviderStore{ | ||
nodes: make(map[string]nodeDetails), | ||
} | ||
} | ||
|
||
func (p *kubernetesProviderStore) addNode(n *corev1.Node) { | ||
details := nodeDetails{name: n.Name} | ||
|
||
var internalIP, externalIP string | ||
for _, addr := range n.Status.Addresses { | ||
if addr.Type == corev1.NodeExternalIP { | ||
externalIP = addr.Address | ||
} | ||
if addr.Type == corev1.NodeInternalIP { | ||
internalIP = addr.Address | ||
} | ||
} | ||
|
||
// In certain scenarios (like in local KinD clusters), the Node | ||
// externalIP is not provided, in that case we default back | ||
// to the internalIP of the Node. | ||
if externalIP != "" { | ||
details.address = externalIP | ||
return | ||
} | ||
details.address = internalIP | ||
p.nodes[n.Name] = details | ||
} | ||
|
||
func (p *kubernetesProviderStore) removeNode(n *corev1.Node) { | ||
delete(p.nodes, n.Name) | ||
} | ||
|
||
func (p *kubernetesProviderStore) listNodeAddresses() []string { | ||
addrs := []string{} | ||
for _, n := range p.nodes { | ||
addrs = append(addrs, n.address) | ||
} | ||
return addrs | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ func UpdateGatewayStatusAcceptedCondition(gw *gwapiv1b1.Gateway, accepted bool) | |
// UpdateGatewayStatusProgrammedCondition updates the status addresses for the provided gateway | ||
// based on the status IP/Hostname of svc and updates the Programmed condition based on the | ||
// service and deployment state. | ||
func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1b1.Gateway, svc *corev1.Service, deployment *appsv1.Deployment) { | ||
func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1b1.Gateway, svc *corev1.Service, deployment *appsv1.Deployment, nodeAddresses ...string) { | ||
var addresses, hostnames []string | ||
// Update the status addresses field. | ||
if svc != nil { | ||
|
@@ -50,6 +50,10 @@ func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1b1.Gateway, svc *corev1.S | |
} | ||
} | ||
|
||
if svc.Spec.Type == corev1.ServiceTypeNodePort { | ||
addresses = nodeAddresses | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also append the NodePort to this address, and expose it in the status ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we cannot expose the port in a clean way, because there will be a unique node port per listener port |
||
} | ||
|
||
addresses = append(addresses, svc.Spec.ExternalIPs...) | ||
|
||
var gwAddresses []gwapiv1b1.GatewayAddress | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you simply this lines with a function in a followup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure