Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Fix dex pod reload on config change #1040

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/charts/components/dex/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ spec:
metadata:
labels:
app: dex
### Lokomotive specific change.
annotations:
checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
spec:
securityContext:
runAsNonRoot: true
Expand Down
4 changes: 2 additions & 2 deletions pkg/assets/generated_assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 86 additions & 23 deletions pkg/components/dex/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,46 @@ import (

const name = "dex"

//nolint:funlen
func TestRenderManifest(t *testing.T) {
tests := []struct {
desc string
hcl string
wantErr bool
}{
{
desc: "Valid config",
hcl: `
var tests = []struct {
desc string
hcl string
wantErr bool
}{
{
desc: "first valid config",
hcl: `
component "dex" {
ingress_host = "foo"
issuer_host = "bar"
connector "github" {
id = "github"
name = "Github"
config {
client_id = "clientid"
client_secret = "clientsecret"
redirect_uri = "redirecturi"
team_name_field = "slug"
org {
name = "kinvolk"
teams = [
"lokomotive-developers-1",
]
}
}
}

static_client {
name = "gangway"
id = "gangway id"
secret = "gangway secret"
redirect_uris = ["redirecturis"]
}
}
`,
},
{
desc: "second valid config",
hcl: `
component "dex" {
ingress_host = "foo"
issuer_host = "bar"
Expand All @@ -47,7 +77,7 @@ component "dex" {
org {
name = "kinvolk"
teams = [
"lokomotive-developers",
"lokomotive-developers-2",
]
}
}
Expand All @@ -61,22 +91,23 @@ component "dex" {
}
}
`,
},
{
desc: "invalid config",
hcl: `
},
{
desc: "invalid config",
hcl: `
component "dex" {
ingress_host = "NodePort"
}
`,
wantErr: true,
},
}
wantErr: true,
},
}

func TestRenderManifest(t *testing.T) {
for _, tc := range tests {
b, d := util.GetComponentBody(tc.hcl, name)
if d != nil {
t.Errorf("%s - Error getting component body: %v", tc.desc, d)
t.Fatalf("%s - Error getting component body: %v", tc.desc, d)
}

c, err := components.Get(name)
Expand All @@ -87,20 +118,52 @@ component "dex" {
d = c.LoadConfig(b, nil)

if !tc.wantErr && d.HasErrors() {
t.Errorf("%s - Valid config should not return error, got: %s", tc.desc, d)
t.Fatalf("%s - Valid config should not return error, got: %s", tc.desc, d)
}

if tc.wantErr && !d.HasErrors() {
t.Errorf("%s - Wrong config should have returned an error", tc.desc)
t.Fatalf("%s - Wrong config should have returned an error", tc.desc)
}

m, err := c.RenderManifests()
if err != nil {
t.Errorf("%s - Rendering manifests with valid config should succeed, got: %s", tc.desc, err)
t.Fatalf("%s - Rendering manifests with valid config should succeed, got: %s", tc.desc, err)
}

if len(m) == 0 {
t.Errorf("%s - Rendered manifests shouldn't be empty", tc.desc)
t.Fatalf("%s - Rendered manifests shouldn't be empty", tc.desc)
}
}
}

func TestDeploymentAnnotationHashChange(t *testing.T) {
deploymentArr := []string{}

for _, tc := range tests {
b, d := util.GetComponentBody(tc.hcl, name)
if d != nil {
t.Fatalf("%s - Error getting component body: %v", tc.desc, d)
}

c, err := components.Get(name)
if err != nil {
t.Fatalf("failed getting component: %v", err)
}

d = c.LoadConfig(b, nil)
if !tc.wantErr && d.HasErrors() {
t.Fatalf("%s - Valid config should not return error, got: %s", tc.desc, d)
}

m, err := c.RenderManifests()
if err != nil {
t.Fatalf("%s - Rendering manifests with valid config should succeed, got: %s", tc.desc, err)
}

deploymentArr = append(deploymentArr, m["dex/templates/deployment.yaml"])
}

if deploymentArr[0] == deploymentArr[1] {
t.Fatalf("expected checksum/configmap hash to be different.")
}
}