Skip to content

Commit 0c9f190

Browse files
authored
Consul sunset (#294)
* Consul sunset * Consul sunset * Consul sunset * Consul sunset * Disabled integration tests until Docker for AWS is fixed
1 parent 6d185e1 commit 0c9f190

27 files changed

+162
-2103
lines changed

Dockerfile

-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ RUN go build -v -o docker-flow-proxy
1010
FROM haproxy:1.7-alpine
1111
MAINTAINER Viktor Farcic <[email protected]>
1212

13-
RUN apk add --no-cache --virtual .build-deps curl unzip && \
14-
curl -SL https://releases.hashicorp.com/consul-template/0.13.0/consul-template_0.13.0_linux_amd64.zip -o /usr/local/bin/consul-template.zip && \
15-
unzip /usr/local/bin/consul-template.zip -d /usr/local/bin/ && \
16-
rm -f /usr/local/bin/consul-template.zip && \
17-
chmod +x /usr/local/bin/consul-template && \
18-
apk del .build-deps
19-
2013
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
2114
RUN mkdir -p /cfg/tmpl /consul_templates /templates /certs /logs
2215

@@ -25,7 +18,6 @@ ENV CERTS="" \
2518
CFG_TEMPLATE_PATH="/cfg/tmpl/haproxy.tmpl" \
2619
CHECK_RESOLVERS=false \
2720
CONNECTION_MODE="http-keep-alive" \
28-
CONSUL_ADDRESS="" \
2921
DEBUG="false" \
3022
DEFAULT_PORTS="80,443:ssl" \
3123
EXTRA_FRONTEND="" \

Jenkinsfile

+12-12
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ pipeline {
3131
sh "docker image build -t vfarcic/docker-flow-proxy-docs -f Dockerfile.docs ."
3232
}
3333
}
34-
stage("test") {
35-
environment {
36-
HOST_IP = "build.dockerflow.com"
37-
DOCKER_HUB_USER = "vfarcic"
38-
}
39-
steps {
40-
sh "docker-compose -f docker-compose-test.yml run --rm staging-swarm"
41-
}
42-
}
34+
// stage("test") {
35+
// environment {
36+
// HOST_IP = "build.dockerflow.com"
37+
// DOCKER_HUB_USER = "vfarcic"
38+
// }
39+
// steps {
40+
// sh "docker-compose -f docker-compose-test.yml run --rm staging-swarm"
41+
// }
42+
// }
4343
stage("release") {
4444
when {
4545
branch "master"
@@ -67,9 +67,9 @@ pipeline {
6767
}
6868
}
6969
post {
70-
always {
71-
sh "docker system prune -f"
72-
}
70+
// always {
71+
// sh "docker system prune -f"
72+
// }
7373
failure {
7474
slackSend(
7575
color: "danger",

Vagrantfile

-66
This file was deleted.

actions/fetch.go

+5-98
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,33 @@ package actions
22

33
import (
44
"../proxy"
5-
"../registry"
65
"encoding/json"
76
"fmt"
8-
"io/ioutil"
97
"net/http"
10-
"strings"
118
)
129

1310
// Fetchable defines interface that fetches information from other sources
1411
type Fetchable interface {
15-
// TODO: It's deprecated (Consul). Remove it.
16-
ReloadServicesFromRegistry(addresses []string, instanceName, mode string) error
1712
// Sends request to swarm-listener to request reconfiguration of all proxy instances in Swarm.
1813
ReloadClusterConfig(listenerAddr string) error
1914
// Reconfigures this instance of proxy based on configuration taken from swarm-listener.
2015
// This is synchronous.
2116
// If listenerAddr is nil, unreachable or any other problem error is returned.
22-
ReloadConfig(baseData BaseReconfigure, mode string, listenerAddr string) error
17+
ReloadConfig(baseData BaseReconfigure, listenerAddr string) error
2318
}
2419
type fetch struct {
2520
BaseReconfigure
26-
Mode string `short:"m" long:"mode" env:"MODE" description:"If set to 'swarm', proxy will operate assuming that Docker service from v1.12+ is used."`
2721
}
2822

2923
// NewFetch returns instance of the Fetchable object
30-
var NewFetch = func(baseData BaseReconfigure, mode string) Fetchable {
24+
var NewFetch = func(baseData BaseReconfigure) Fetchable {
3125
return &fetch{
3226
BaseReconfigure: baseData,
33-
Mode: mode,
3427
}
3528
}
3629

37-
// TODO: It's deprecated (Consul). Remove it.
38-
func (m *fetch) ReloadServicesFromRegistry(addresses []string, instanceName, mode string) error {
39-
if len(addresses) > 0 {
40-
return m.reloadFromRegistry(addresses, instanceName, mode)
41-
}
42-
return nil
43-
}
44-
4530
// ReloadConfig recreates proxy configuration with data fetches from Swarm Listener
46-
func (m *fetch) ReloadConfig(baseData BaseReconfigure, mode string, listenerAddr string) error {
31+
func (m *fetch) ReloadConfig(baseData BaseReconfigure, listenerAddr string) error {
4732
if len(listenerAddr) == 0 {
4833
return fmt.Errorf("Swarm Listener address is missing %s", listenerAddr)
4934
}
@@ -64,7 +49,7 @@ func (m *fetch) ReloadConfig(baseData BaseReconfigure, mode string, listenerAddr
6449
for _, s := range services {
6550
proxyService := proxy.GetServiceFromMap(&s)
6651
if statusCode, _ := proxy.IsValidReconf(proxyService); statusCode == http.StatusOK {
67-
reconfigure := NewReconfigure(baseData, *proxyService, mode)
52+
reconfigure := NewReconfigure(baseData, *proxyService)
6853
reconfigure.Execute(false)
6954
needsReload = true
7055
}
@@ -91,88 +76,10 @@ func (m *fetch) ReloadClusterConfig(listenerAddr string) error {
9176
}
9277

9378
func (m *fetch) getReconfigure(service *proxy.Service) Reconfigurable {
94-
return NewReconfigure(m.BaseReconfigure, *service, m.Mode)
79+
return NewReconfigure(m.BaseReconfigure, *service)
9580
}
9681

9782
func (m *fetch) getReload() Reloader {
9883
return NewReload()
9984
}
10085

101-
// TODO: It's deprecated (Consul). Remove it.
102-
func (m *fetch) reloadFromRegistry(addresses []string, instanceName, mode string) error {
103-
var resp *http.Response
104-
var err error
105-
logPrintf("Configuring existing services")
106-
found := false
107-
for _, address := range addresses {
108-
address = strings.ToLower(address)
109-
if !strings.HasPrefix(address, "http") {
110-
address = fmt.Sprintf("http://%s", address)
111-
}
112-
servicesUrl := fmt.Sprintf("%s/v1/catalog/services", address)
113-
resp, err = http.Get(servicesUrl)
114-
if err == nil {
115-
found = true
116-
break
117-
}
118-
}
119-
if !found {
120-
return fmt.Errorf("Could not retrieve the list of services from Consul")
121-
}
122-
defer resp.Body.Close()
123-
body, _ := ioutil.ReadAll(resp.Body)
124-
c := make(chan proxy.Service)
125-
count := 0
126-
var data map[string]interface{}
127-
json.Unmarshal(body, &data)
128-
count = len(data)
129-
for key := range data {
130-
go m.getService(addresses, key, instanceName, c)
131-
}
132-
logPrintf("\tFound %d services", count)
133-
for i := 0; i < count; i++ {
134-
s := <-c
135-
if len(s.ServiceDest) > 0 && len(s.ServiceDest[0].ServicePath) > 0 {
136-
reconfigure := m.getReconfigure(&s)
137-
reconfigure.Execute(false)
138-
}
139-
}
140-
reload := m.getReload()
141-
return reload.Execute(true)
142-
}
143-
144-
// TODO: It's deprecated (Consul). Remove it.
145-
func (m *fetch) getService(addresses []string, serviceName, instanceName string, c chan proxy.Service) {
146-
sr := proxy.Service{ServiceName: serviceName}
147-
148-
path, err := registryInstance.GetServiceAttribute(addresses, serviceName, registry.PATH_KEY, instanceName)
149-
port, _ := m.getServiceAttribute(addresses, serviceName, registry.PORT, instanceName)
150-
sd := proxy.ServiceDest{
151-
ServicePath: strings.Split(path, ","),
152-
Port: port,
153-
}
154-
if err == nil {
155-
sr.ServiceDest = []proxy.ServiceDest{sd}
156-
sr.ServiceColor, _ = m.getServiceAttribute(addresses, serviceName, registry.COLOR_KEY, instanceName)
157-
sr.ServiceCert, _ = m.getServiceAttribute(addresses, serviceName, registry.CERT_KEY, instanceName)
158-
sr.OutboundHostname, _ = m.getServiceAttribute(addresses, serviceName, registry.HOSTNAME_KEY, instanceName)
159-
sr.PathType, _ = m.getServiceAttribute(addresses, serviceName, registry.PATH_TYPE_KEY, instanceName)
160-
sr.ConsulTemplateFePath, _ = m.getServiceAttribute(addresses, serviceName, registry.CONSUL_TEMPLATE_FE_PATH_KEY, instanceName)
161-
sr.ConsulTemplateBePath, _ = m.getServiceAttribute(addresses, serviceName, registry.CONSUL_TEMPLATE_BE_PATH_KEY, instanceName)
162-
}
163-
c <- sr
164-
}
165-
166-
// TODO: It's deprecated (Consul). Remove it.
167-
func (m *fetch) getServiceAttribute(addresses []string, serviceName, key, instanceName string) (string, bool) {
168-
for _, address := range addresses {
169-
url := fmt.Sprintf("%s/v1/kv/%s/%s/%s?raw", address, instanceName, serviceName, key)
170-
resp, err := http.Get(url)
171-
if err == nil && resp.StatusCode == http.StatusOK {
172-
defer resp.Body.Close()
173-
body, _ := ioutil.ReadAll(resp.Body)
174-
return string(body), true
175-
}
176-
}
177-
return "", false
178-
}

0 commit comments

Comments
 (0)