Skip to content

Commit d21a52b

Browse files
authored
Merge pull request #75 from phillc/master
Fixes HTTPS port failing on initial creation
2 parents 2ddd848 + 14452ae commit d21a52b

File tree

6 files changed

+289
-141
lines changed

6 files changed

+289
-141
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fmt: vet $(GOPATH)/bin/goimports
3030
.PHONY: test
3131
# we say code is not worth testing unless it's formatted
3232
test: $(GOPATH)/bin/ginkgo fmt
33-
ginkgo -r --v --progress --trace --cover --skipPackage=test -- --v=3
33+
ginkgo -r --v --progress --trace --cover --skipPackage=test $(TEST_ARGS) -- --v=3
3434

3535
.PHONY: build-linux
3636
build-linux:

cloud/linode/fake_linode_test.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
353353
f.nb[strconv.Itoa(nb.ID)] = &nb
354354

355355
for _, nbcco := range nbco.Configs {
356+
if nbcco.Protocol == "https" {
357+
if !strings.Contains(nbcco.SSLCert, "BEGIN CERTIFICATE") {
358+
f.t.Fatal("HTTPS port declared without calid ssl cert", nbcco.SSLCert)
359+
}
360+
if !strings.Contains(nbcco.SSLKey, "BEGIN RSA PRIVATE KEY") {
361+
f.t.Fatal("HTTPS port declared without calid ssl key", nbcco.SSLKey)
362+
}
363+
}
356364
nbc := linodego.NodeBalancerConfig{
357365
ID: rand.Intn(9999),
358366
Port: nbcco.Port,
@@ -368,10 +376,10 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
368376
CheckTimeout: nbcco.CheckTimeout,
369377
CipherSuite: nbcco.CipherSuite,
370378
NodeBalancerID: nb.ID,
371-
SSLCommonName: "",
372-
SSLFingerprint: "",
373-
SSLCert: nbcco.SSLCert,
374-
SSLKey: nbcco.SSLKey,
379+
SSLCommonName: "sslcommonname",
380+
SSLFingerprint: "sslfingerprint",
381+
SSLCert: "<REDACTED>",
382+
SSLKey: "<REDACTED>",
375383
}
376384
f.nbc[strconv.Itoa(nbc.ID)] = &nbc
377385

@@ -410,6 +418,14 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
410418
if err != nil {
411419
f.t.Fatal(err)
412420
}
421+
if nbcco.Protocol == "https" {
422+
if !strings.Contains(nbcco.SSLCert, "BEGIN CERTIFICATE") {
423+
f.t.Fatal("HTTPS port declared without calid ssl cert", nbcco.SSLCert)
424+
}
425+
if !strings.Contains(nbcco.SSLKey, "BEGIN RSA PRIVATE KEY") {
426+
f.t.Fatal("HTTPS port declared without calid ssl key", nbcco.SSLKey)
427+
}
428+
}
413429
nbcc := linodego.NodeBalancerConfig{
414430
ID: nbcid,
415431
Port: nbcco.Port,
@@ -425,11 +441,12 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
425441
CheckTimeout: nbcco.CheckTimeout,
426442
CipherSuite: nbcco.CipherSuite,
427443
NodeBalancerID: nbid,
428-
SSLCommonName: "",
429-
SSLFingerprint: "",
430-
SSLCert: nbcco.SSLCert,
431-
SSLKey: nbcco.SSLKey,
444+
SSLCommonName: "sslcommonname",
445+
SSLFingerprint: "sslfingerprint",
446+
SSLCert: "<REDACTED>",
447+
SSLKey: "<REDACTED>",
432448
}
449+
433450
f.nbc[strconv.Itoa(nbcc.ID)] = &nbcc
434451
for k, n := range f.nbn {
435452
if n.ConfigID == nbcc.ID {
@@ -481,10 +498,10 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
481498
CheckTimeout: nbcco.CheckTimeout,
482499
CipherSuite: nbcco.CipherSuite,
483500
NodeBalancerID: nbid,
484-
SSLCommonName: "",
485-
SSLFingerprint: "",
486-
SSLCert: nbcco.SSLCert,
487-
SSLKey: nbcco.SSLKey,
501+
SSLCommonName: "sslcomonname",
502+
SSLFingerprint: "sslfingerprint",
503+
SSLCert: "<REDACTED>",
504+
SSLKey: "<REDACTED>",
488505
}
489506
f.nbc[strconv.Itoa(nbcc.ID)] = &nbcc
490507

@@ -590,10 +607,10 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
590607
CheckTimeout: nbcco.CheckTimeout,
591608
CipherSuite: nbcco.CipherSuite,
592609
NodeBalancerID: nbid,
593-
SSLCommonName: "",
594-
SSLFingerprint: "",
595-
SSLCert: nbcco.SSLCert,
596-
SSLKey: nbcco.SSLKey,
610+
SSLCommonName: "sslcommonname",
611+
SSLFingerprint: "sslfingerprint",
612+
SSLCert: "<REDACTED>",
613+
SSLKey: "<REDACTED>",
597614
}
598615
f.nbc[strconv.Itoa(nbcc.ID)] = &nbcc
599616

cloud/linode/loadbalancers.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ func (l *loadbalancers) UpdateLoadBalancer(ctx context.Context, clusterName stri
232232
return fmt.Errorf("[port %d] error creating NodeBalancer config: %v", int(port.Port), err)
233233
}
234234
rebuildOpts = currentNBCfg.GetRebuildOptions()
235+
236+
// SSLCert and SSLKey return <REDACTED> from the API, so copy the
237+
// value that we sent in create for the rebuild
238+
rebuildOpts.SSLCert = newNBCfg.SSLCert
239+
rebuildOpts.SSLKey = newNBCfg.SSLKey
235240
} else {
236241
rebuildOpts = newNBCfg.GetRebuildOptions()
237242
}
@@ -476,12 +481,11 @@ func (l *loadbalancers) retrieveKubeClient() error {
476481

477482
// Check to see if --kubeconfig was set. If it was, build a kubeconfig from the given file.
478483
// Otherwise, use the in-cluster config.
479-
kubeconfigPath := Options.KubeconfigFlag.Value.String()
480-
481-
if kubeconfigPath == "" {
484+
kubeconfigFlag := Options.KubeconfigFlag
485+
if kubeconfigFlag == nil || kubeconfigFlag.Value.String() == "" {
482486
kubeConfig, err = rest.InClusterConfig()
483487
} else {
484-
kubeConfig, err = clientcmd.BuildConfigFromFlags("", kubeconfigPath)
488+
kubeConfig, err = clientcmd.BuildConfigFromFlags("", kubeconfigFlag.Value.String())
485489
}
486490

487491
if err != nil {

0 commit comments

Comments
 (0)