Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit eb27ef4

Browse files
authored
Merge pull request #42 from jetstack/disable-dex-on-none-masters
Don't deploy dex on non-masters
2 parents 393d1c0 + d706bef commit eb27ef4

File tree

10 files changed

+64
-78
lines changed

10 files changed

+64
-78
lines changed

demo/Makefile

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ CLOUD ?= google
44

55
KUBECONFIG := $(CURDIR)/.kubeconfig-$(CLOUD)
66

7-
ifeq ($(CLOUD),google)
87
GOOGLE_PROJECT := $(shell gcloud config get-value core/project)
8+
9+
ifeq ($(CLOUD),google)
10+
EXT_VARS ?= "master=true,cloud=$(CLOUD)"
11+
else
12+
EXT_VARS ?= "master=false,cloud=$(CLOUD)"
913
endif
1014

1115
UNAME_S := $(shell uname -s)
@@ -32,38 +36,37 @@ help: ## Display this help
3236
.PHONY: terraform_apply
3337
terraform_apply: ## Applies terraform infrastructure
3438
echo '' > infrastructure/$(CLOUD)/terraform.tfvars
35-
ifeq ($(CLOUD),google)
3639
echo 'google_project = "$(GOOGLE_PROJECT)"' > infrastructure/$(CLOUD)/terraform.tfvars
37-
endif
3840
cd infrastructure/$(CLOUD) && terraform init && terraform apply
39-
cd infrastructure/$(CLOUD) && terraform output config > ../../manifests/config.json
41+
cd infrastructure/$(CLOUD) && terraform output config > ../../manifests/$(CLOUD)-config.json
4042
$(shell cd infrastructure/$(CLOUD) && terraform output kubeconfig_command)
4143

4244
.PHONY: terraform_destroy
4345
terraform_destroy: ## Destroy terraform infrastructure
4446
cd infrastructure/$(CLOUD) && terraform init && terraform destroy
4547

46-
manifests/config.json:
48+
manifests/$(CLOUD)-config.json:
4749
$(MAKE) terraform_apply
4850

4951
.PHONY: manifests_apply
50-
manifests_apply: depend manifests/config.json ## Use kubecfg to apply manifests into cluster
52+
manifests_apply: depend manifests/$(CLOUD)-config.json ## Use kubecfg to apply manifests into cluster
53+
rm -f manifests/config.json && ln -s $(CLOUD)-config.json manifests/config.json
5154
# apply all CRDs
52-
$(BINDIR)/kubecfg show config.jsonnet --format json | sed 's#^---$$##' | jq 'select(.kind == "CustomResourceDefinition")' | kubectl apply -f -
55+
$(BINDIR)/kubecfg -V ${EXT_VARS} show config.jsonnet --format json | sed 's#^---$$##' | jq 'select(.kind == "CustomResourceDefinition")' | kubectl apply -f -
5356
# apply everything
54-
$(BINDIR)/kubecfg show config.jsonnet | kubectl apply -f -
57+
$(BINDIR)/kubecfg -V ${EXT_VARS} show config.jsonnet | kubectl apply -f -
5558

5659
.PHONY: manifests_validate
57-
manifests_validate: depend manifests/config.json ## Use kubecfg to validate manifests
58-
$(BINDIR)/kubecfg validate config.jsonnet
60+
manifests_validate: depend manifests/$(CLOUD)-config.json ## Use kubecfg to validate manifests
61+
$(BINDIR)/kubecfg -V ${EXT_VARS} validate config.jsonnet
5962

6063
.PHONY: manifests_validate
6164
jsonnet_fmt: depend ## validate formatting of jsonnet files
6265
$(BINDIR)/jsonnet fmt --test $(shell find manifests/components/. manifests/main.jsonnet -name "*.jsonnet")
6366

6467
.PHONY: manifests_destroy
65-
manifests_destroy: depend manifests/config.json ## Use kubecfg to delete manifests
66-
$(BINDIR)/kubecfg show config.jsonnet | kubectl delete -f - --ignore-not-found
68+
manifests_destroy: depend manifests/$(CLOUD)-config.json ## Use kubecfg to delete manifests
69+
$(BINDIR)/kubecfg -V ${EXT_VARS} show config.jsonnet | kubectl delete -f - --ignore-not-found
6770

6871
.PHONY: manifests_backup_certificates
6972
manifests_backup_certificates:

demo/config.dist.jsonnet

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(import './manifests/main.jsonnet') {
22
base_domain: 'kubernetes.example.net',
3+
// dex_domain: 'dex.kubernetes.example.net', // to be used on non dex hosting clusters
34
cert_manager+: {
45
letsencrypt_contact_email:: '[email protected]',
56
},
@@ -18,4 +19,12 @@
1819
}),
1920
],
2021
},
22+
23+
// Here we can register more dex clients
24+
//extraClient: $.dex.Client('123') + $.dex.metadata {
25+
// secret: '4567',
26+
// redirectURIs: [
27+
// 'https://gangway.other.kubernetes.example.net/callback',
28+
// ],
29+
//},
2130
}

demo/infrastructure/amazon/dns.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
module "dns" {
2-
source = "../modules/amazon-dns"
3-
suffix = "${random_id.suffix.hex}"
4-
region = "${var.region}"
1+
data "external" "cert_manager" {
2+
program = ["jq", ".cert_manager", "../../manifests/google-config.json"]
3+
query = { }
4+
}
5+
6+
data "external" "externaldns" {
7+
program = ["jq", ".externaldns", "../../manifests/google-config.json"]
8+
query = { }
59
}

demo/infrastructure/amazon/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
22
config = {
3-
cert_manager = "${module.dns.config}"
4-
externaldns = "${module.dns.config}"
3+
cert_manager = "${data.external.cert_manager.result}"
4+
externaldns = "${data.external.externaldns.result}"
55
gangway = "${module.gangway.config}"
66
}
77
}

demo/infrastructure/amazon/providers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
variable "region" {
1+
variable "aws_region" {
22
default = "eu-west-1"
33
}
44

@@ -7,7 +7,7 @@ variable "cluster_version" {
77
}
88

99
provider "aws" {
10-
region = "${var.region}"
10+
region = "${var.aws_region}"
1111
}
1212

1313
module "cluster" {

demo/infrastructure/modules/amazon-dns/dns.tf

Lines changed: 0 additions & 46 deletions
This file was deleted.

demo/manifests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/config.json
2+
/*-config.json

demo/manifests/components/contour.jsonnet

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ local ENVOY_IMAGE = 'docker.io/envoyproxy/envoy-alpine:v1.9.0';
1010
local apiGroup = 'contour.heptio.com';
1111
local apiVersion = 'v1beta1';
1212

13+
local ServiceAnnotations(cloud) =
14+
if cloud == 'amazon' then
15+
{
16+
'service.beta.kubernetes.io/aws-load-balancer-backend-protocol': 'tcp',
17+
'service.beta.kubernetes.io/aws-load-balancer-type': 'nlb',
18+
}
19+
else
20+
{};
21+
1322
{
1423
p:: '',
1524
app:: 'contour',
@@ -128,9 +137,7 @@ local apiVersion = 'v1beta1';
128137

129138
svc: kube._Object('v1', 'Service', $.name) + $.metadata {
130139
metadata+: {
131-
annotations+: {
132-
'service.beta.kubernetes.io/aws-load-balancer-backend-protocol': 'tcp',
133-
},
140+
annotations+: ServiceAnnotations(std.extVar('cloud')),
134141
},
135142
spec+: {
136143
type: 'LoadBalancer',

demo/manifests/components/dex.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ local dexNameHash(s) = std.asciiLower(std.strReplace(base32.base32(fakeHashFNV(s
7474

7575
domain:: $.name + '.' + $.base_domain,
7676

77-
namespace:: 'foo',
77+
namespace:: 'dex',
7878

7979
labels:: {
8080
metadata+: {

demo/manifests/main.jsonnet

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ local IngressRouteTLSPassthrough(namespace, name, domain, serviceName, servicePo
4343
},
4444
};
4545

46+
local only_master(obj) =
47+
if std.extVar('master') == 'true' then
48+
obj
49+
else
50+
{};
51+
4652
{
4753
config:: config,
4854

@@ -56,6 +62,8 @@ local IngressRouteTLSPassthrough(namespace, name, domain, serviceName, servicePo
5662

5763
ns: kube.Namespace($.namespace),
5864

65+
dex_domain:: $.dex.domain,
66+
5967
cert_manager: cert_manager {
6068
google_secret: kube.Secret($.cert_manager.p + 'clouddns-google-credentials') + $.cert_manager.metadata {
6169
data_+: {
@@ -154,14 +162,14 @@ local IngressRouteTLSPassthrough(namespace, name, domain, serviceName, servicePo
154162
// this add a final dot to the domain name and joins the list
155163
'external-dns.alpha.kubernetes.io/hostname': std.join(',', std.map(
156164
(function(o) o + '.'),
157-
[$.dex.domain, $.gangway.domain, $.kube_oidc_proxy.domain],
165+
[$.dex_domain, $.gangway.domain, $.kube_oidc_proxy.domain],
158166
)),
159167
},
160168
},
161169
},
162170
},
163171

164-
dex: dex {
172+
dex: only_master(dex {
165173
local this = self,
166174
base_domain:: $.base_domain,
167175
p:: $.p,
@@ -184,7 +192,7 @@ local IngressRouteTLSPassthrough(namespace, name, domain, serviceName, servicePo
184192
[this.domain]
185193
),
186194
ingressRoute: IngressRouteTLSPassthrough($.namespace, this.name, this.domain, this.name, 5556),
187-
},
195+
}),
188196

189197
gangway: gangway {
190198
local this = self,
@@ -248,20 +256,20 @@ local IngressRouteTLSPassthrough(namespace, name, domain, serviceName, servicePo
248256
sessionSecurityKey: $.config.gangway.session_security_key,
249257

250258
config+: {
251-
authorizeURL: 'https://' + $.dex.domain + '/auth',
252-
tokenURL: 'https://' + $.dex.domain + '/token',
259+
authorizeURL: 'https://' + $.dex_domain + '/auth',
260+
tokenURL: 'https://' + $.dex_domain + '/token',
253261
apiServerURL: 'https://' + $.kube_oidc_proxy.domain,
254262
clientID: $.config.gangway.client_id,
255263
clientSecret: $.config.gangway.client_secret,
256264
clusterCAPath: this.config_path + '/cluster-ca.crt',
257265
},
258266

259-
dexClient: dex.Client(this.config.clientID) + $.dex.metadata {
267+
dexClient: only_master(dex.Client(this.config.clientID) + $.dex.metadata {
260268
secret: this.config.clientSecret,
261269
redirectURIs: [
262270
this.config.redirectURL,
263271
],
264-
},
272+
}),
265273
},
266274

267275
kube_oidc_proxy: kube_oidc_proxy {
@@ -276,7 +284,7 @@ local IngressRouteTLSPassthrough(namespace, name, domain, serviceName, servicePo
276284

277285
config+: {
278286
oidc+: {
279-
issuerURL: 'https://' + $.dex.domain,
287+
issuerURL: 'https://' + $.dex_domain,
280288
clientID: $.config.gangway.client_id,
281289
},
282290
},

0 commit comments

Comments
 (0)