Skip to content

Commit

Permalink
feat: custom listening port for gateway pod in helm (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle-Justice authored Feb 23, 2024
1 parent e0e4fc3 commit e55a3c0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 15 deletions.
2 changes: 2 additions & 0 deletions helm/core/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ spec:
- "serve"
- --gatewaySelectorKey=higress
- --gatewaySelectorValue={{ .Release.Namespace }}-{{ include "gateway.name" . }}
- --gatewayHttpPort={{ .Values.gateway.httpPort }}
- --gatewayHttpsPort={{ .Values.gateway.httpsPort }}
{{- if not .Values.global.enableStatus }}
- --enableStatus={{ .Values.global.enableStatus }}
{{- end }}
Expand Down
8 changes: 4 additions & 4 deletions helm/core/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ spec:
protocol: TCP
name: http-envoy-prom
{{- if or .Values.global.local .Values.global.kind }}
- containerPort: 80
hostPort: 80
- containerPort: {{ .Values.gateway.httpPort }}
hostPort: {{ .Values.gateway.httpPort }}
name: http
protocol: TCP
- containerPort: 443
hostPort: 443
- containerPort: {{ .Values.gateway.httpsPort }}
hostPort: {{ .Values.gateway.httpsPort }}
name: https
protocol: TCP
{{- end }}
Expand Down
3 changes: 2 additions & 1 deletion helm/core/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ gateway:

# Pod environment variables
env: {}

httpPort: 80
httpsPort: 443
hostNetwork: false

# Labels to apply to all resources
Expand Down
4 changes: 4 additions & 0 deletions pkg/bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ type ServerArgs struct {
KeepStaleWhenEmpty bool
GatewaySelectorKey string
GatewaySelectorValue string
GatewayHttpPort uint32
GatewayHttpsPort uint32
}

type readinessProbe func() (bool, error)
Expand Down Expand Up @@ -220,6 +222,8 @@ func (s *Server) initConfigController() error {
SystemNamespace: ns,
GatewaySelectorKey: s.GatewaySelectorKey,
GatewaySelectorValue: s.GatewaySelectorValue,
GatewayHttpPort: s.GatewayHttpPort,
GatewayHttpsPort: s.GatewayHttpsPort,
}
if options.ClusterId == "Kubernetes" {
options.ClusterId = ""
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func getServerCommand() *cobra.Command {

serveCmd.PersistentFlags().IntVar(&serverArgs.RegistryOptions.KubeOptions.KubernetesAPIBurst, "kubernetesApiBurst", 160,
"Maximum burst for throttle when communicating with the kubernetes API")
serveCmd.PersistentFlags().Uint32Var(&serverArgs.GatewayHttpPort, "gatewayHttpPort", 80,
"Http listening port of gateway pod")
serveCmd.PersistentFlags().Uint32Var(&serverArgs.GatewayHttpsPort, "gatewayHttpsPort", 443,
"Https listening port of gateway pod")

loggingOptions.AttachCobraFlags(serveCmd)
serverArgs.GrpcKeepAliveOptions.AttachCobraFlags(serveCmd)
Expand Down
16 changes: 10 additions & 6 deletions pkg/ingress/config/ingress_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,18 @@ func TestNormalizeWeightedCluster(t *testing.T) {
func TestConvertGatewaysForIngress(t *testing.T) {
fake := kube.NewFakeClient()
v1Beta1Options := common.Options{
Enable: true,
ClusterId: "ingress-v1beta1",
RawClusterId: "ingress-v1beta1__",
Enable: true,
ClusterId: "ingress-v1beta1",
RawClusterId: "ingress-v1beta1__",
GatewayHttpPort: 80,
GatewayHttpsPort: 443,
}
v1Options := common.Options{
Enable: true,
ClusterId: "ingress-v1",
RawClusterId: "ingress-v1__",
Enable: true,
ClusterId: "ingress-v1",
RawClusterId: "ingress-v1__",
GatewayHttpPort: 80,
GatewayHttpsPort: 443,
}
ingressV1Beta1Controller := controllerv1beta1.NewController(fake, fake, v1Beta1Options, nil)
ingressV1Controller := controllerv1.NewController(fake, fake, v1Options, nil)
Expand Down
2 changes: 2 additions & 0 deletions pkg/ingress/kube/common/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ type Options struct {
SystemNamespace string
GatewaySelectorKey string
GatewaySelectorValue string
GatewayHttpPort uint32
GatewayHttpsPort uint32
}

type BasicAuthRules struct {
Expand Down
10 changes: 6 additions & 4 deletions pkg/ingress/kube/ingressv1/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path"
"reflect"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -357,6 +358,7 @@ func (c *controller) ConvertGateway(convertOptions *common.ConvertOptions, wrapp
return fmt.Errorf("invalid ingress rule %s:%s in cluster %s, either `defaultBackend` or `rules` must be specified", cfg.Namespace, cfg.Name, c.options.ClusterId)
}


for _, rule := range ingressV1.Rules {
// Need create builder for every rule.
domainBuilder := &common.IngressDomainBuilder{
Expand All @@ -383,9 +385,9 @@ func (c *controller) ConvertGateway(convertOptions *common.ConvertOptions, wrapp
}
wrapperGateway.Gateway.Servers = append(wrapperGateway.Gateway.Servers, &networking.Server{
Port: &networking.Port{
Number: 80,
Number: c.options.GatewayHttpPort,
Protocol: string(protocol.HTTP),
Name: common.CreateConvertedName("http-80-ingress", c.options.ClusterId),
Name: common.CreateConvertedName("http-"+strconv.FormatUint(uint64(c.options.GatewayHttpPort), 10)+"-ingress", c.options.ClusterId),
},
Hosts: []string{rule.Host},
})
Expand Down Expand Up @@ -428,9 +430,9 @@ func (c *controller) ConvertGateway(convertOptions *common.ConvertOptions, wrapp
// Append https server
wrapperGateway.Gateway.Servers = append(wrapperGateway.Gateway.Servers, &networking.Server{
Port: &networking.Port{
Number: 443,
Number: uint32(c.options.GatewayHttpsPort),
Protocol: string(protocol.HTTPS),
Name: common.CreateConvertedName("https-443-ingress", c.options.ClusterId),
Name: common.CreateConvertedName("https-"+strconv.FormatUint(uint64(c.options.GatewayHttpsPort), 10)+"-ingress", c.options.ClusterId),
},
Hosts: []string{rule.Host},
Tls: &networking.ServerTLSSettings{
Expand Down

0 comments on commit e55a3c0

Please sign in to comment.