From 8d8af75bb6cb86dadd7ece60681fa98b49e2fba4 Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Tue, 18 Jun 2019 17:02:23 -0600 Subject: [PATCH 1/2] fix(brigade-worker): ensure backwards compatibility for project name and repo name values Signed-off-by: Vaughn Dice --- brigade-worker/src/k8s.ts | 6 +++++- brigade-worker/test/k8s.ts | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/brigade-worker/src/k8s.ts b/brigade-worker/src/k8s.ts index 87c5c2b9f..c02556b8b 100644 --- a/brigade-worker/src/k8s.ts +++ b/brigade-worker/src/k8s.ts @@ -1023,8 +1023,12 @@ export function secretToProject( allowHostMounts: false }; if (secret.data.repository != null) { + // For legacy/backwards-compatibility reasons, + // we set project name and repo name to the following values, + // despite the fact that they should logically be swapped. + p.name = b64dec(secret.data.repository) p.repo = { - name: b64dec(secret.data.repository), + name: secret.metadata.annotations["projectName"], cloneURL: null, initGitSubmodules: false } diff --git a/brigade-worker/test/k8s.ts b/brigade-worker/test/k8s.ts index 94613bea3..62ffd03d3 100644 --- a/brigade-worker/test/k8s.ts +++ b/brigade-worker/test/k8s.ts @@ -29,8 +29,8 @@ describe("k8s", function() { p.id, "brigade-7e3d1157331f6726338395e320cffa41d2bc9e20157fd7a4df355d" ); - assert.equal(p.name, "brigadecore/test-private-testbed"); - assert.equal(p.repo.name, "github.com/brigadecore/test-private-testbed"); + assert.equal(p.name, "github.com/brigadecore/test-private-testbed"); + assert.equal(p.repo.name, "brigadecore/test-private-testbed"); assert.equal( p.repo.cloneURL, "https://github.com/brigadecore/empty-testbed.git" @@ -53,8 +53,8 @@ describe("k8s", function() { p.id, "brigade-7e3d1157331f6726338395e320cffa41d2bc9e20157fd7a4df355d" ); - assert.equal(p.name, "brigadecore/test-private-testbed"); - assert.equal(p.repo.name, "github.com/brigadecore/test-private-testbed"); + assert.equal(p.name, "github.com/brigadecore/test-private-testbed"); + assert.equal(p.repo.name, "brigadecore/test-private-testbed"); assert.equal(p.repo.token, "pretend password\n"); assert.equal(p.kubernetes.namespace, "default"); assert.equal(p.kubernetes.vcsSidecar, "vcs-image:latest"); From 697a29adb9acc0014f1052cf2216f70448df64de Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Wed, 19 Jun 2019 10:02:36 -0600 Subject: [PATCH 2/2] fix(brig): remove setting p.Repo fields for non-VCS project Signed-off-by: Vaughn Dice --- brig/cmd/brig/commands/project_create_no_vcs.go | 3 --- brig/cmd/brig/commands/project_create_test.go | 11 +++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/brig/cmd/brig/commands/project_create_no_vcs.go b/brig/cmd/brig/commands/project_create_no_vcs.go index 1efa062db..68a50f835 100644 --- a/brig/cmd/brig/commands/project_create_no_vcs.go +++ b/brig/cmd/brig/commands/project_create_no_vcs.go @@ -87,7 +87,4 @@ func setDefaultValuesNoVCS(p *brigade.Project) { p.Name = "myproject" // setting the sidecar to NONE p.Kubernetes.VCSSidecar = "NONE" - // empty values for the repo - p.Repo.CloneURL = "" - p.Repo.Name = "" } diff --git a/brig/cmd/brig/commands/project_create_test.go b/brig/cmd/brig/commands/project_create_test.go index c4643a39e..e364ae9fe 100644 --- a/brig/cmd/brig/commands/project_create_test.go +++ b/brig/cmd/brig/commands/project_create_test.go @@ -2,7 +2,10 @@ package commands import ( "os" + "reflect" "testing" + + "github.com/brigadecore/brigade/pkg/brigade" ) const testProjectSecret = "./testdata/project_secret.json" @@ -27,12 +30,8 @@ func TestInitProjectNoVCS(t *testing.T) { t.Fatal("VCSSidecar should be NONE") } - if p.Repo.CloneURL != "" { - t.Fatal("CloneURL should be an empty string") - } - - if p.Repo.Name != "" { - t.Fatal("Repo.Name should be an empty string") + if reflect.DeepEqual(p.Repo, brigade.Repo{}) { + t.Fatal("Project Repo should be empty/unset") } }