diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index 177468f..b83c5b6 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -608,7 +608,7 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in continue } - upsName, _ := upstreamName(ing.Namespace, ing.Name, path.Backend.Service) + upsName := upstreamName(ing.Namespace, path.Backend.Service) ups := upstreams[upsName] // Backend is not referenced to by a server @@ -819,7 +819,7 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B var defBackend string if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil { - defBackend, _ = upstreamName(ing.Namespace, ing.Name, ing.Spec.DefaultBackend.Service) + defBackend = upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service) klog.V(3).Infof("Creating upstream %q", defBackend) upstreams[defBackend] = newUpstream(defBackend) @@ -878,7 +878,7 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B continue } - name, _ := upstreamName(ing.Namespace, ing.Name, path.Backend.Service) + name := upstreamName(ing.Namespace, path.Backend.Service) svcName, svcPort := upstreamServiceNameAndPort(path.Backend.Service) if _, ok := upstreams[name]; ok { continue @@ -910,8 +910,8 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B // configure traffic shaping for canary if anns.Canary.Enabled && n.verifyCanaryReferrer(ingKey, anns) { - upstreams[svcName].NoServer = true - setTrafficShapingPolicy(anns, &upstreams[svcName].TrafficShapingPolicy) + upstreams[name].NoServer = true + setTrafficShapingPolicy(anns, &upstreams[name].TrafficShapingPolicy) } if len(upstreams[name].Endpoints) == 0 { @@ -1098,7 +1098,7 @@ func (n *NGINXController) createServers(data []*ingress.Ingress, } if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil { - defUpstream, _ := upstreamName(ing.Namespace, ing.Name, ing.Spec.DefaultBackend.Service) + defUpstream := upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service) if backendUpstream, ok := upstreams[defUpstream]; ok { // use backend specified in Ingress as the default backend for all its rules @@ -1366,7 +1366,7 @@ func (n *NGINXController) mergeAlternativeBackends(ing *ingress.Ingress, upstrea // merge catch-all alternative backends if ing.Spec.DefaultBackend != nil { - upsName, _ := upstreamName(ing.Namespace, ing.Name, ing.Spec.DefaultBackend.Service) + upsName := upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service) altUps := upstreams[upsName] if altUps == nil { @@ -1413,7 +1413,7 @@ func (n *NGINXController) mergeAlternativeBackends(ing *ingress.Ingress, upstrea continue } - upsName, _ := upstreamName(ing.Namespace, ing.Name, path.Backend.Service) + upsName := upstreamName(ing.Namespace, path.Backend.Service) altUps := upstreams[upsName] diff --git a/internal/ingress/controller/util.go b/internal/ingress/controller/util.go index 1349f22..227a939 100644 --- a/internal/ingress/controller/util.go +++ b/internal/ingress/controller/util.go @@ -48,18 +48,16 @@ func newUpstream(name string) *ingress.Backend { } // upstreamName returns a formatted upstream name based on namespace, service, and port -func upstreamName(namespace string, name string, service *networking.IngressServiceBackend) (string, intstr.IntOrString) { - port := intstr.IntOrString{} +func upstreamName(namespace string, service *networking.IngressServiceBackend) string { if service != nil { if service.Port.Number > 0 { - port = intstr.FromInt(int(service.Port.Number)) + return fmt.Sprintf("%s-%s-%d", namespace, service.Name, service.Port.Number) } if service.Port.Name != "" { - port = intstr.FromString(service.Port.Name) + return fmt.Sprintf("%s-%s-%s", namespace, service.Name, service.Port.Name) } } - - return fmt.Sprintf("%v-%v-%v-%v", namespace, name, service.Name, port), port + return fmt.Sprintf("%s-INVALID", namespace) } // upstreamServiceNameAndPort verifies if service is not nil, and then return the diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile index 8df9ff4..513f516 100644 --- a/rootfs/Dockerfile +++ b/rootfs/Dockerfile @@ -22,7 +22,7 @@ ARG GOLANG_VERSION ARG GOLANG_SHA LABEL org.opencontainers.image.title="Tengine Ingress Controller for Kubernetes" -LABEL org.opencontainers.image.documentation="https://tengine.taobao.org/ingress/" +LABEL org.opencontainers.image.documentation="https://tengine.taobao.org/ingress.html" LABEL org.opencontainers.image.source="https://github.com/alibaba/tengine-ingress" LABEL org.opencontainers.image.vendor="The Alibaba Authors" LABEL org.opencontainers.image.licenses="Apache-2.0" @@ -36,7 +36,12 @@ WORKDIR /etc/nginx COPY --chown=admin:admin . / -RUN rpm --rebuilddb && yum install -y golang-bin +#RUN rpm --rebuilddb && yum install -y -b current golang-bin +RUN ["chmod", "+x", "/build.sh"] +RUN /build.sh -v "1.17.13" -s "/" + +ENV GOROOT "/.goroot" +ENV PATH "$PATH:$GOROOT/bin" RUN set -eux; \ export \ @@ -59,7 +64,8 @@ RUN set -eux; \ # esac; \ # \ #wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz"; \ - mv /source/go1.13.8.src.tar.gz go.tgz; \ + #wget -O go.tgz "http:// tengine-console.oss-cn-beijing.aliyuncs.com/go1.20.6.src.tar.gz"; \ + mv /source/go1.20.6.src.tar.gz go.tgz; \ echo "$GOLANG_SHA *go.tgz" | sha256sum -c -; \ tar -C /usr/local -xzf go.tgz; \ rm go.tgz; \ diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index ea38a7c..4cf441d 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1195,7 +1195,11 @@ stream { port_in_redirect {{ if $location.UsePortInRedirects }}on{{ else }}off{{ end }}; set $balancer_ewma_score -1; - #set $proxy_upstream_name {{ buildUpstreamName $location | quote }}; + + {{ if $all.Cfg.TengineReload }} + set $proxy_upstream_name {{ buildUpstreamName $location | quote }}; + {{ end }} + set $proxy_host $proxy_upstream_name; set $pass_access_scheme $scheme;