Skip to content

Commit 63c1071

Browse files
committed
chore(builder): simplify the connection controller
1 parent bd9bc6f commit 63c1071

11 files changed

Lines changed: 28 additions & 39 deletions

File tree

charts/builder/templates/_helpers.tpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ env:
2020
valueFrom:
2121
fieldRef:
2222
fieldPath: metadata.namespace
23+
- name: "DRYCC_CONTROLLER_URL"
24+
value: http://drycc-controller-api
2325
{{- if (.Values.storageEndpoint) }}
2426
- name: "DRYCC_STORAGE_LOOKUP"
2527
valueFrom:
@@ -52,7 +54,7 @@ env:
5254
- name: "DRYCC_STORAGE_BUCKET"
5355
value: "builder"
5456
- name: "DRYCC_STORAGE_ENDPOINT"
55-
value: {{ printf "http://drycc-storage.%s.svc.%s:9000" .Release.Namespace .Values.global.clusterDomain }}
57+
value: http://drycc-storage:9000
5658
- name: "DRYCC_STORAGE_ACCESSKEY"
5759
valueFrom:
5860
secretKeyRef:
@@ -89,7 +91,7 @@ env:
8991
key: registry-organization
9092
{{- else if .Values.registry.enabled }}
9193
- name: "DRYCC_REGISTRY_HOST"
92-
value: {{ printf "drycc-registry.%s.svc.%s:5000" .Release.Namespace .Values.global.clusterDomain }}
94+
value: drycc-registry:5000
9395
- name: "DRYCC_REGISTRY_PROXY_HOST"
9496
value: {{ print "127.0.0.1" ":" .Values.registry.proxy.port }}
9597
- name: "DRYCC_REGISTRY_USERNAME"
@@ -103,7 +105,6 @@ env:
103105
name: registry-secret
104106
key: password
105107
{{- end }}
106-
107108
{{- if (.Values.builderPodNodeSelector) }}
108109
- name: BUILDER_POD_NODE_SELECTOR
109110
value: {{.Values.builderPodNodeSelector}}

charts/builder/templates/builder-deployment.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ spec:
3434
- netcat
3535
- -v
3636
- -u
37-
- $(DRYCC_STORAGE_ENDPOINT)
38-
- -a
39-
- $(DRYCC_CONTROLLER_API_SERVICE_HOST):$(DRYCC_CONTROLLER_API_SERVICE_PORT)
37+
- $(DRYCC_STORAGE_ENDPOINT),$(DRYCC_CONTROLLER_URL)
4038
{{- include "builder.envs" . | indent 8 }}
4139
containers:
4240
- name: drycc-builder

pkg/controller/utils.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package controller
22

33
import (
4-
"fmt"
5-
64
"github.com/drycc/builder/pkg/conf"
75
drycc "github.com/drycc/controller-sdk-go"
86
"github.com/drycc/pkg/log"
97
)
108

119
// New creates a new SDK client configured as the builder.
12-
func New(host, port string) (*drycc.Client, error) {
10+
func New(url string) (*drycc.Client, error) {
1311

14-
client, err := drycc.New(true, fmt.Sprintf("http://%s:%s/", host, port), "")
12+
client, err := drycc.New(true, url, "")
1513
if err != nil {
1614
return client, err
1715
}

pkg/controller/utils_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package controller
22

33
import (
44
"errors"
5-
"fmt"
65
"os"
76
"path/filepath"
87
"testing"
@@ -31,24 +30,22 @@ func TestNew(t *testing.T) {
3130
t.Fatalf("error creating %s (%s)", builderconf.ServiceKeyLocation, err)
3231
}
3332

34-
host := "127.0.0.1"
35-
port := "80"
36-
cli, err := New(host, port)
33+
url := "http://127.0.0.1:80"
34+
cli, err := New(url)
3735
assert.Equal(t, err, nil)
38-
assert.Equal(t, cli.ControllerURL.String(), fmt.Sprintf("http://%s:%s/", host, port), "data")
36+
assert.Equal(t, cli.ControllerURL.String(), url, "data")
3937
assert.Equal(t, cli.ServiceKey, string(data), "data")
4038
assert.Equal(t, cli.UserAgent, "drycc-builder", "user-agent")
4139

42-
port = "invalid-port-number"
43-
if _, err = New(host, port); err == nil {
40+
url = "http://127.0.0.1:invalid-port-number"
41+
if _, err = New(url); err == nil {
4442
t.Errorf("expected error with invalid port number, got nil")
4543
}
4644
}
4745

4846
func TestNewWithInvalidBuilderKeyPath(t *testing.T) {
49-
host := "127.0.0.1"
50-
port := "80"
51-
_, err := New(host, port)
47+
url := "http://127.0.0.1:80"
48+
_, err := New(url)
5249
assert.True(t, err != nil, "no error received when there should have been")
5350
}
5451

pkg/gitreceive/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func build(
9090
}
9191
}()
9292

93-
client, err := controller.New(conf.ControllerHost, conf.ControllerPort)
93+
client, err := controller.New(conf.ControllerURL)
9494
if err != nil {
9595
return err
9696
}

pkg/gitreceive/build_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ func TestBuild(t *testing.T) {
7070
t.Error("expected running build() without valid controller client info to fail")
7171
}
7272

73-
config.ControllerHost = "localhost"
74-
config.ControllerPort = "1234"
73+
config.ControllerURL = "http://localhost:1234"
7574

7675
if err := build(config, storageDriver, nil, env, sha); err == nil {
7776
t.Error("expected running build() without a valid builder key to fail")

pkg/gitreceive/config.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ const (
1313
// Config is the envconfig (http://github.com/kelseyhightower/envconfig) compatible struct for the
1414
// builder's git-receive hook.
1515
type Config struct {
16-
// k8s service discovery env vars
17-
ControllerHost string `envconfig:"DRYCC_CONTROLLER_API_SERVICE_HOST" required:"true"`
18-
ControllerPort string `envconfig:"DRYCC_CONTROLLER_API_SERVICE_PORT" required:"true"`
19-
16+
ControllerURL string `envconfig:"DRYCC_CONTROLLER_URL" required:"true"`
2017
GitHome string `envconfig:"GIT_HOME" required:"true"`
2118
SSHConnection string `envconfig:"SSH_CONNECTION" required:"true"`
2219
SSHOriginalCommand string `envconfig:"SSH_ORIGINAL_COMMAND" required:"true"`

pkg/gitreceive/imagebuilder_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func TestGetImagebuilderEnvOffclusterErr(t *testing.T) {
1717
env.Envs = map[string]string{
1818
"DRYCC_STORAGE_LOOKUP": "path",
1919
"DRYCC_STORAGE_BUCKET": "builder",
20-
"DRYCC_STORAGE_ENDPOINT": "drycc-storage.drycc.svc.cluster.local",
20+
"DRYCC_STORAGE_ENDPOINT": "drycc-storage",
2121
"DRYCC_REGISTRY_LOCATION": "off-cluster",
2222
}
2323
_, err := getImagebuilderEnv(&image, config, env)
2424
assert.Error(t, err, errors.New("the environment variable DRYCC_REGISTRY_HOST is required"))
25-
env.Envs["DRYCC_REGISTRY_HOST"] = "drycc-registry.drycc.svc.cluster.local"
25+
env.Envs["DRYCC_REGISTRY_HOST"] = "drycc-registry"
2626
_, err = getImagebuilderEnv(&image, config, env)
2727
assert.Error(t, err, errors.New("the environment variable DRYCC_REGISTRY_ORGANIZATION is required"))
2828
}
@@ -32,15 +32,15 @@ func TestGetImagebuilderEnvOffclusterSuccess(t *testing.T) {
3232
env.Envs = map[string]string{
3333
"DRYCC_STORAGE_LOOKUP": "path",
3434
"DRYCC_STORAGE_BUCKET": "builder",
35-
"DRYCC_STORAGE_ENDPOINT": "drycc-storage.drycc.svc.cluster.local",
35+
"DRYCC_STORAGE_ENDPOINT": "drycc-storage",
3636
"DRYCC_REGISTRY_HOST": "quay.io",
3737
"DRYCC_REGISTRY_ORGANIZATION": "kmala",
3838
"DRYCC_REGISTRY_LOCATION": "off-cluster",
3939
}
4040
expectedData := map[string]string{
4141
"DRYCC_STORAGE_LOOKUP": "path",
4242
"DRYCC_STORAGE_BUCKET": "builder",
43-
"DRYCC_STORAGE_ENDPOINT": "drycc-storage.drycc.svc.cluster.local",
43+
"DRYCC_STORAGE_ENDPOINT": "drycc-storage",
4444
"DRYCC_REGISTRY_LOCATION": "off-cluster",
4545
"DRYCC_REGISTRY_HOST": "quay.io",
4646
"DRYCC_REGISTRY_ORGANIZATION": "kmala",
@@ -63,16 +63,16 @@ func TestGetImagebuilderEnvOnclusterSuccess(t *testing.T) {
6363
env.Envs = map[string]string{
6464
"DRYCC_STORAGE_LOOKUP": "path",
6565
"DRYCC_STORAGE_BUCKET": "builder",
66-
"DRYCC_STORAGE_ENDPOINT": "drycc-storage.drycc.svc.cluster.local",
67-
"DRYCC_REGISTRY_HOST": "drycc-registry.drycc.svc.cluster.local",
66+
"DRYCC_STORAGE_ENDPOINT": "drycc-storage",
67+
"DRYCC_REGISTRY_HOST": "drycc-registry",
6868
"DRYCC_REGISTRY_PROXY_HOST": "127.0.0.1:8000",
6969
"DRYCC_REGISTRY_LOCATION": "on-cluster",
7070
}
7171
expectedData := map[string]string{
7272
"DRYCC_STORAGE_LOOKUP": "path",
7373
"DRYCC_STORAGE_BUCKET": "builder",
74-
"DRYCC_STORAGE_ENDPOINT": "drycc-storage.drycc.svc.cluster.local",
75-
"DRYCC_REGISTRY_HOST": "drycc-registry.drycc.svc.cluster.local",
74+
"DRYCC_STORAGE_ENDPOINT": "drycc-storage",
75+
"DRYCC_REGISTRY_HOST": "drycc-registry",
7676
"DRYCC_REGISTRY_LOCATION": "on-cluster",
7777
"DRYCC_REGISTRY_PROXY_HOST": "127.0.0.1:8000",
7878
"DRYCC_REGISTRY_ORGANIZATION": "python-getting-started",

pkg/healthsrv/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// with the indicative error.
1313
func Start(cnf *sshd.Config, nsLister NamespaceLister, bLister BucketLister, sshServerCircuit *sshd.Circuit) error {
1414
mux := http.NewServeMux()
15-
client, err := controller.New(cnf.ControllerHost, cnf.ControllerPort)
15+
client, err := controller.New(cnf.ControllerURL)
1616
if err != nil {
1717
return err
1818
}

pkg/sshd/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66

77
// Config represents the required SSH server configuration.
88
type Config struct {
9-
ControllerHost string `envconfig:"DRYCC_CONTROLLER_API_SERVICE_HOST" required:"true"`
10-
ControllerPort string `envconfig:"DRYCC_CONTROLLER_API_SERVICE_PORT" required:"true"`
9+
ControllerURL string `envconfig:"DRYCC_CONTROLLER_URL" required:"true"`
1110
SSHHostIP string `envconfig:"SSH_HOST_IP" default:"0.0.0.0" required:"true"`
1211
SSHHostPort int `envconfig:"SSH_HOST_PORT" default:"2223" required:"true"`
1312
HealthSrvPort int `envconfig:"HEALTH_SERVER_PORT" default:"8092"`

0 commit comments

Comments
 (0)