diff --git a/helm/core/templates/controller-deployment.yaml b/helm/core/templates/controller-deployment.yaml index 6e1aa08af..c429772f8 100644 --- a/helm/core/templates/controller-deployment.yaml +++ b/helm/core/templates/controller-deployment.yaml @@ -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 }} diff --git a/helm/core/templates/deployment.yaml b/helm/core/templates/deployment.yaml index a418700ef..7fbaf41d2 100644 --- a/helm/core/templates/deployment.yaml +++ b/helm/core/templates/deployment.yaml @@ -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 }} diff --git a/helm/core/values.yaml b/helm/core/values.yaml index be3e21dd8..9fa71269c 100644 --- a/helm/core/values.yaml +++ b/helm/core/values.yaml @@ -417,7 +417,8 @@ gateway: # Pod environment variables env: {} - + httpPort: 80 + httpsPort: 443 hostNetwork: false # Labels to apply to all resources diff --git a/pkg/bootstrap/server.go b/pkg/bootstrap/server.go index e5d7228ec..9ac3851df 100644 --- a/pkg/bootstrap/server.go +++ b/pkg/bootstrap/server.go @@ -110,6 +110,8 @@ type ServerArgs struct { KeepStaleWhenEmpty bool GatewaySelectorKey string GatewaySelectorValue string + GatewayHttpPort uint32 + GatewayHttpsPort uint32 } type readinessProbe func() (bool, error) @@ -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 = "" diff --git a/pkg/cmd/server.go b/pkg/cmd/server.go index b848c70f4..391910ba7 100644 --- a/pkg/cmd/server.go +++ b/pkg/cmd/server.go @@ -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) diff --git a/pkg/ingress/config/ingress_config_test.go b/pkg/ingress/config/ingress_config_test.go index d11c8c893..8f45688ac 100644 --- a/pkg/ingress/config/ingress_config_test.go +++ b/pkg/ingress/config/ingress_config_test.go @@ -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) diff --git a/pkg/ingress/kube/common/model.go b/pkg/ingress/kube/common/model.go index e1e1479b6..7e2112be9 100644 --- a/pkg/ingress/kube/common/model.go +++ b/pkg/ingress/kube/common/model.go @@ -105,6 +105,8 @@ type Options struct { SystemNamespace string GatewaySelectorKey string GatewaySelectorValue string + GatewayHttpPort uint32 + GatewayHttpsPort uint32 } type BasicAuthRules struct { diff --git a/pkg/ingress/kube/ingressv1/controller.go b/pkg/ingress/kube/ingressv1/controller.go index e07202375..f6afb80f5 100644 --- a/pkg/ingress/kube/ingressv1/controller.go +++ b/pkg/ingress/kube/ingressv1/controller.go @@ -20,6 +20,7 @@ import ( "path" "reflect" "sort" + "strconv" "strings" "sync" "time" @@ -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{ @@ -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}, }) @@ -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{