Skip to content

Commit f346efd

Browse files
authored
Merge pull request kubernetes#5240 from nebril/etcd-tls
Add etcd TLS support for Cilium
2 parents 5313176 + a72b9e4 commit f346efd

File tree

6 files changed

+24
-44
lines changed

6 files changed

+24
-44
lines changed

nodeup/pkg/model/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ go_library(
44
name = "go_default_library",
55
srcs = [
66
"architecture.go",
7-
"calico.go",
87
"cloudconfig.go",
98
"context.go",
109
"convenience.go",
1110
"directories.go",
1211
"docker.go",
1312
"etcd.go",
13+
"etcd_tls.go",
1414
"file_assets.go",
1515
"firewall.go",
1616
"hooks.go",

nodeup/pkg/model/calico.go nodeup/pkg/model/etcd_tls.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import (
2222
"k8s.io/kops/upup/pkg/fi"
2323
)
2424

25-
// CalicoBuilder configures the calico CNI provider
26-
type CalicoBuilder struct {
25+
// EtcdTLSBuilder configures the etcd TLS support
26+
type EtcdTLSBuilder struct {
2727
*NodeupModelContext
2828
}
2929

30-
var _ fi.ModelBuilder = &CalicoBuilder{}
30+
var _ fi.ModelBuilder = &EtcdTLSBuilder{}
3131

32-
// Build is responsible for performing any setup to the calico CNI provider
33-
func (b *CalicoBuilder) Build(c *fi.ModelBuilderContext) error {
32+
// Build is responsible for performing setup for CNIs that need etcd TLS support
33+
func (b *EtcdTLSBuilder) Build(c *fi.ModelBuilderContext) error {
3434
// @check if tls is enabled and if so, we need to download the client certificates
3535
if b.UseEtcdTLS() {
3636
name := "calico-client"

pkg/model/iam/iam_builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (b *PolicyBuilder) AddS3Permissions(p *Policy) (*Policy, error) {
377377
}
378378

379379
// @check if calico is enabled as the CNI provider and permit access to the client TLS certificate by default
380-
if b.Cluster.Spec.Networking.Calico != nil {
380+
if b.Cluster.Spec.Networking.Calico != nil || b.Cluster.Spec.Networking.Cilium != nil {
381381
p.Statement = append(p.Statement, &Statement{
382382
Effect: StatementEffectAllow,
383383
Action: stringorslice.Slice([]string{"s3:Get*"}),

pkg/model/pki.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ func (b *PKIModelBuilder) Build(c *fi.ModelBuilderContext) error {
142142
Format: format,
143143
})
144144

145-
// @check if calico is enabled as the CNI provider
146-
if b.KopsModelContext.Cluster.Spec.Networking.Calico != nil {
145+
// @check if calico or Cilium is enabled as the CNI provider
146+
if b.KopsModelContext.Cluster.Spec.Networking.Calico != nil || b.KopsModelContext.Cluster.Spec.Networking.Cilium != nil {
147147
c.AddTask(&fitasks.Keypair{
148148
Name: fi.String("calico-client"),
149149
Lifecycle: b.Lifecycle,

upup/models/cloudup/resources/addons/networking.cilium.io/k8s-1.7.yaml.template

+13-33
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1+
{{- $etcd_scheme := EtcdScheme }}
12
kind: ConfigMap
23
apiVersion: v1
34
metadata:
45
name: cilium-config
56
namespace: kube-system
67
data:
7-
# This etcd-config contains the etcd endpoints of your cluster. If you use
8-
# TLS please make sure you uncomment the ca-file line and add the respective
9-
# certificate has a k8s secret, see explanation bellow in the comment labeled
10-
# "ETCD-CERT"
118
etcd-config: |-
129
---
1310
endpoints: [{{ $cluster := index .EtcdClusters 0 -}}
1411
{{- range $j, $member := $cluster.Members -}}
1512
{{- if $j }},{{ end -}}
16-
"http://etcd-{{ $member.Name }}.internal.{{ ClusterName }}:4001"
13+
"{{ $etcd_scheme }}://etcd-{{ $member.Name }}.internal.{{ ClusterName }}:4001"
1714
{{- end }}]
18-
#
19-
# In case you want to use TLS in etcd, uncomment the following line
20-
# and add the certificate as explained in the comment labeled "ETCD-CERT"
21-
#ca-file: '/var/lib/etcd-secrets/etcd-ca'
22-
#
23-
# In case you want client to server authentication, uncomment the following
24-
# lines and add the certificate and key in cilium-etcd-secrets bellow
25-
#key-file: '/var/lib/etcd-secrets/etcd-client-key'
26-
#cert-file: '/var/lib/etcd-secrets/etcd-client-crt'
15+
{{- if eq $etcd_scheme "https" }}
16+
ca-file: '/var/lib/etcd-secrets/ca.pem'
17+
key-file: '/var/lib/etcd-secrets/calico-client-key.pem'
18+
cert-file: '/var/lib/etcd-secrets/calico-client.pem'
19+
{{- end }}
2720

2821
# If you want to run cilium in debug mode change this value to true
2922
debug: "false"
@@ -32,22 +25,6 @@ data:
3225
# If you want to clean cilium state; change this value to true
3326
clean-cilium-state: "false"
3427
---
35-
# The etcd secrets can be populated in kubernetes.
36-
# For more information see: https://kubernetes.io/docs/concepts/configuration/secret
37-
apiVersion: v1
38-
kind: Secret
39-
type: Opaque
40-
metadata:
41-
name: cilium-etcd-secrets
42-
namespace: kube-system
43-
data:
44-
# ETCD-CERT: Each value should contain the whole certificate in base64, on a
45-
# single line. You can generate the base64 with: $ base64 -w 0 ./ca.pem
46-
# (the "-w 0" generates the output on a single line)
47-
etcd-ca: ""
48-
etcd-client-key: ""
49-
etcd-client-crt: ""
50-
---
5128
apiVersion: v1
5229
kind: ServiceAccount
5330
metadata:
@@ -365,9 +342,11 @@ spec:
365342
- name: etcd-config-path
366343
mountPath: /var/lib/etcd-config
367344
readOnly: true
345+
{{- if eq $etcd_scheme "https" }}
368346
- name: etcd-secrets
369347
mountPath: /var/lib/etcd-secrets
370348
readOnly: true
349+
{{- end }}
371350
securityContext:
372351
capabilities:
373352
add:
@@ -402,10 +381,11 @@ spec:
402381
items:
403382
- key: etcd-config
404383
path: etcd.config
405-
# To read the k8s etcd secrets in case the user might want to use TLS
384+
{{- if eq $etcd_scheme "https" }}
406385
- name: etcd-secrets
407-
secret:
408-
secretName: cilium-etcd-secrets
386+
hostPath:
387+
path: /srv/kubernetes/calico
388+
{{- end }}
409389
tolerations:
410390
- effect: NoSchedule
411391
key: node-role.kubernetes.io/master

upup/pkg/fi/nodeup/command.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
241241
} else {
242242
loader.Builders = append(loader.Builders, &model.KubeRouterBuilder{NodeupModelContext: modelContext})
243243
}
244-
if c.cluster.Spec.Networking.Calico != nil {
245-
loader.Builders = append(loader.Builders, &model.CalicoBuilder{NodeupModelContext: modelContext})
244+
if c.cluster.Spec.Networking.Calico != nil || c.cluster.Spec.Networking.Cilium != nil {
245+
loader.Builders = append(loader.Builders, &model.EtcdTLSBuilder{NodeupModelContext: modelContext})
246246
}
247247

248248
taskMap, err := loader.Build(c.ModelDir)

0 commit comments

Comments
 (0)