Skip to content

Commit 11af6ea

Browse files
jrussettreneighbor
authored andcommitted
removing consul from fileserver
Signed-off-by: Renee Chu <[email protected]>
1 parent 45d4926 commit 11af6ea

File tree

5 files changed

+4
-106
lines changed

5 files changed

+4
-106
lines changed

cmd/file-server/config/config.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import (
1010
)
1111

1212
type FileServerConfig struct {
13-
ServerAddress string `json:"server_address,omitempty"`
14-
StaticDirectory string `json:"static_directory,omitempty"`
15-
ConsulCluster string `json:"consul_cluster,omitempty"`
16-
EnableConsulServiceRegistration bool `json:"enable_consul_service_registration,omitempty"`
13+
ServerAddress string `json:"server_address,omitempty"`
14+
StaticDirectory string `json:"static_directory,omitempty"`
1715

1816
HTTPSServerEnabled bool `json:"https_server_enabled"`
1917
HTTPSListenAddr string `json:"https_listen_addr"`

cmd/file-server/config/config_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var _ = Describe("Config", func() {
1919
configData = `{
2020
"server_address": "192.168.1.1:8080",
2121
"static_directory": "/tmp/static",
22-
"consul_cluster": "consul.example.com",
23-
"enable_consul_service_registration": true,
2422
2523
"https_server_enabled": true,
2624
"https_listen_addr": "192.168.1.1:8443",
@@ -53,10 +51,8 @@ var _ = Describe("Config", func() {
5351
Expect(err).NotTo(HaveOccurred())
5452

5553
expectedConfig := config.FileServerConfig{
56-
ServerAddress: "192.168.1.1:8080",
57-
StaticDirectory: "/tmp/static",
58-
ConsulCluster: "consul.example.com",
59-
EnableConsulServiceRegistration: true,
54+
ServerAddress: "192.168.1.1:8080",
55+
StaticDirectory: "/tmp/static",
6056

6157
HTTPSServerEnabled: true,
6258
HTTPSListenAddr: "192.168.1.1:8443",

cmd/file-server/main.go

-36
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@ package main
33
import (
44
"crypto/tls"
55
"flag"
6-
"net"
76
"net/http"
87
"os"
98
"runtime"
109
"strings"
1110

12-
"code.cloudfoundry.org/clock"
13-
"code.cloudfoundry.org/consuladapter"
1411
"code.cloudfoundry.org/debugserver"
1512
loggingclient "code.cloudfoundry.org/diego-logging-client"
1613
"code.cloudfoundry.org/fileserver/cmd/file-server/config"
1714
"code.cloudfoundry.org/fileserver/handlers"
1815
"code.cloudfoundry.org/go-loggregator/v8/runtimeemitter"
1916
"code.cloudfoundry.org/lager"
2017
"code.cloudfoundry.org/lager/lagerflags"
21-
"code.cloudfoundry.org/locket"
2218
"code.cloudfoundry.org/tlsconfig"
23-
"github.com/hashicorp/consul/api"
2419
"github.com/tedsuo/ifrit"
2520
"github.com/tedsuo/ifrit/grouper"
2621
"github.com/tedsuo/ifrit/http_server"
@@ -50,11 +45,6 @@ func main() {
5045
os.Exit(1)
5146
}
5247

53-
consulClient, err := consuladapter.NewClientFromUrl(cfg.ConsulCluster)
54-
if err != nil {
55-
logger.Fatal("new-client-failed", err)
56-
}
57-
5848
var tlsConfig *tls.Config
5949
if cfg.HTTPSServerEnabled {
6050
if len(cfg.HTTPSListenAddr) == 0 {
@@ -73,11 +63,6 @@ func main() {
7363
{"file server", initializeServer(logger, cfg.StaticDirectory, cfg.ServerAddress, cfg.HTTPSListenAddr, tlsConfig)},
7464
}
7565

76-
if cfg.EnableConsulServiceRegistration {
77-
registrationRunner := initializeRegistrationRunner(logger, consulClient, cfg.ServerAddress, clock.NewClock())
78-
members = append(members, grouper.Member{"registration-runner", registrationRunner})
79-
}
80-
8166
if dbgAddr := debugserver.DebugAddress(flag.CommandLine); dbgAddr != "" {
8267
members = append(grouper.Members{
8368
{"debug-server", debugserver.Runner(dbgAddr, reconfigurableSink)},
@@ -140,24 +125,3 @@ func initializeServer(logger lager.Logger, staticDirectory, serverAddress, serve
140125

141126
return http_server.New(serverAddress, fileServerHandler)
142127
}
143-
144-
func initializeRegistrationRunner(logger lager.Logger, consulClient consuladapter.Client, listenAddress string, clock clock.Clock) ifrit.Runner {
145-
_, portString, err := net.SplitHostPort(listenAddress)
146-
if err != nil {
147-
logger.Fatal("failed-invalid-listen-address", err)
148-
}
149-
portNum, err := net.LookupPort("tcp", portString)
150-
if err != nil {
151-
logger.Fatal("failed-invalid-listen-port", err)
152-
}
153-
154-
registration := &api.AgentServiceRegistration{
155-
Name: "file-server",
156-
Port: portNum,
157-
Check: &api.AgentServiceCheck{
158-
TTL: "20s",
159-
},
160-
}
161-
162-
return locket.NewRegistrationRunner(logger, registration, consulClient, locket.RetryInterval, clock)
163-
}

cmd/file-server/main_suite_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package main_test
22

33
import (
4-
"code.cloudfoundry.org/consuladapter/consulrunner"
54
. "github.com/onsi/ginkgo"
6-
"github.com/onsi/ginkgo/config"
75
. "github.com/onsi/gomega"
86
"github.com/onsi/gomega/gexec"
97

108
"testing"
119
)
1210

1311
var fileServerBinary string
14-
var consulRunner *consulrunner.ClusterRunner
1512

1613
func TestFileServer(t *testing.T) {
1714
RegisterFailHandler(Fail)
@@ -25,24 +22,9 @@ var _ = SynchronizedBeforeSuite(func() []byte {
2522
}, func(fileServerPath []byte) {
2623
fileServerBinary = string(fileServerPath)
2724

28-
consulRunner = consulrunner.NewClusterRunner(
29-
consulrunner.ClusterRunnerConfig{
30-
StartingPort: 9001 + config.GinkgoConfig.ParallelNode*consulrunner.PortOffsetLength,
31-
NumNodes: 1,
32-
Scheme: "http",
33-
},
34-
)
35-
36-
consulRunner.Start()
37-
consulRunner.WaitUntilReady()
3825
})
3926

4027
var _ = SynchronizedAfterSuite(func() {
41-
consulRunner.Stop()
4228
}, func() {
4329
gexec.CleanupBuildArtifacts()
4430
})
45-
46-
var _ = BeforeEach(func() {
47-
consulRunner.Reset()
48-
})

cmd/file-server/main_test.go

-42
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"code.cloudfoundry.org/lager/lagerflags"
1717
"code.cloudfoundry.org/tlsconfig"
1818
"code.cloudfoundry.org/tlsconfig/certtest"
19-
"github.com/hashicorp/consul/api"
2019
. "github.com/onsi/ginkgo"
2120
. "github.com/onsi/gomega"
2221
"github.com/onsi/gomega/gbytes"
@@ -70,7 +69,6 @@ var _ = Describe("File server", func() {
7069
TimeFormat: lagerflags.FormatUnixEpoch,
7170
},
7271
StaticDirectory: servedDirectory,
73-
ConsulCluster: consulRunner.URL(),
7472
ServerAddress: fmt.Sprintf("localhost:%d", port),
7573
}
7674
})
@@ -101,45 +99,6 @@ var _ = Describe("File server", func() {
10199
Expect(err).NotTo(HaveOccurred())
102100
Expect(string(body)).To(Equal("hello"))
103101
})
104-
105-
Context("when consul service registration is enabled", func() {
106-
BeforeEach(func() {
107-
cfg.EnableConsulServiceRegistration = true
108-
})
109-
110-
It("registers itself with consul", func() {
111-
services, err := consulRunner.NewClient().Agent().Services()
112-
Expect(err).NotTo(HaveOccurred())
113-
Expect(services).To(HaveKeyWithValue("file-server",
114-
&api.AgentService{
115-
Service: "file-server",
116-
ID: "file-server",
117-
Port: port,
118-
}))
119-
})
120-
121-
It("registers a TTL healthcheck", func() {
122-
checks, err := consulRunner.NewClient().Agent().Checks()
123-
Expect(err).NotTo(HaveOccurred())
124-
Expect(checks).To(HaveKeyWithValue("service:file-server",
125-
&api.AgentCheck{
126-
Node: "0",
127-
CheckID: "service:file-server",
128-
Name: "Service 'file-server' check",
129-
Status: "passing",
130-
ServiceID: "file-server",
131-
ServiceName: "file-server",
132-
}))
133-
})
134-
})
135-
136-
Context("when consul service registration is disabled", func() {
137-
It("does not register itself with consul", func() {
138-
services, err := consulRunner.NewClient().Agent().Services()
139-
Expect(err).NotTo(HaveOccurred())
140-
Expect(services).NotTo(HaveKey("file-server"))
141-
})
142-
})
143102
})
144103

145104
Context("when HTTPS server is enabled", func() {
@@ -157,7 +116,6 @@ var _ = Describe("File server", func() {
157116
},
158117
HTTPSServerEnabled: true,
159118
StaticDirectory: servedDirectory,
160-
ConsulCluster: consulRunner.URL(),
161119
ServerAddress: fmt.Sprintf("localhost:%d", port),
162120
}
163121
})

0 commit comments

Comments
 (0)