Skip to content
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

Static Config: HTTP routes with static configuration and tengine reload #102

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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