Skip to content

Commit

Permalink
Merge pull request #102 from alibaba/tengine-ingress-3.1.0
Browse files Browse the repository at this point in the history
Static Config: HTTP routes with static configuration and tengine reload
  • Loading branch information
lianglli authored Oct 25, 2023
2 parents 6e5b6ea + ab759e6 commit 0e4a40e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
16 changes: 8 additions & 8 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]

Expand Down
10 changes: 4 additions & 6 deletions internal/ingress/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions rootfs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 \
Expand All @@ -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; \
Expand Down
6 changes: 5 additions & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 0e4a40e

Please sign in to comment.