Skip to content

Commit

Permalink
Merge pull request #936 from vdice/fix/project-repo-name-back-compat
Browse files Browse the repository at this point in the history
fix(brigade-worker): ensure backwards compatibility for project name and repo name values
  • Loading branch information
vdice authored Jun 19, 2019
2 parents 9ec9d13 + 697a29a commit b2f892b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
3 changes: 0 additions & 3 deletions brig/cmd/brig/commands/project_create_no_vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
11 changes: 5 additions & 6 deletions brig/cmd/brig/commands/project_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package commands

import (
"os"
"reflect"
"testing"

"github.com/brigadecore/brigade/pkg/brigade"
)

const testProjectSecret = "./testdata/project_secret.json"
Expand All @@ -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")
}
}

Expand Down
6 changes: 5 additions & 1 deletion brigade-worker/src/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions brigade-worker/test/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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");
Expand Down

0 comments on commit b2f892b

Please sign in to comment.