Skip to content

Commit d2deaad

Browse files
Merge pull request #473 from djschaap/calico-469
Fix calico CNI support
2 parents 20574d0 + 7075af0 commit d2deaad

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The above parameters are:
6767
* `VERSION`: The version of Kubernetes to deploy.
6868
* `CONTAINER_RUNTIME`: The container runtime Kubernetes uses. Set this value to `docker` (officially supported) or `cri_containerd`. Advanced Kubernetes users can use `cri_containerd`, however this requires an increased understanding of Kubernetes, specifically when running applications in a HA cluster. To run a HA cluster and access your applications, an external load balancer is required in front of your cluster. Setting this up is beyond the scope of this module. For more information, see the Kubernetes [documentation](https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/).
6969
* `CNI_PROVIDER`: The CNI network to install. Set this value to `weave`, `flannel`, `calico` or `cilium`.
70-
* `CNI_PROVIDER_VERSION` The CNI version to use `calico` and `cilium` use this variable to reference the correct deployment file. Current version for `calico` is `3.6` and `cilium` is `1.4.3`
70+
* `CNI_PROVIDER_VERSION` The CNI version to use. `cilium` uses this variable to reference the correct deployment file. Current version `cilium` is `1.4.3`
7171
* `ETCD_INITIAL_CLUSTER`: The server hostnames and IPs in the form of `hostname:ip`. When in production, include three, five, or seven nodes for etcd.
7272
* `ETCD_IP`: The IP each etcd member listens on. We recommend passing the fact for the interface to be used by the cluster.
7373
* `KUBE_API_ADVERTISE_ADDRESS`: The IP each etcd/apiserver instance uses on each controller. We recommend passing the fact for the interface to be used by the cluster.

manifests/init.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,20 @@
6767
# The overlay (internal) network range to use.
6868
# Defaults to undef. kube_tool sets this per cni provider.
6969
#
70+
# [*cni_network_preinstall*]
71+
#
72+
# The URL to install the Tigera operator.
73+
# Used only by calico.
74+
#
7075
# [*cni_network_provider*]
7176
#
7277
# The URL to get the cni providers yaml file.
7378
# Defaults to `undef`. `kube_tool` sets this value.
7479
#
80+
# [*cni_provider*]
81+
#
82+
# The NAME of the CNI provider, as provided to kubetool.
83+
#
7584
# [*cni_rbac_binding*]
7685
# The URL get the cni providers rbac rules. This is for use with Calico only.
7786
# Defaults to `undef`.
@@ -542,7 +551,9 @@
542551
Optional[String] $etcdserver_key = undef,
543552
Optional[String] $etcdpeer_crt = undef,
544553
Optional[String] $etcdpeer_key = undef,
554+
Optional[String] $cni_network_preinstall = undef,
545555
Optional[String] $cni_network_provider = undef,
556+
Optional[String] $cni_provider = undef,
546557
Optional[String] $cni_rbac_binding = undef,
547558
Boolean $install_dashboard = false,
548559
String $dashboard_version = 'v1.10.1',

manifests/kube_addons.pp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Class kubernetes kube_addons
22
class kubernetes::kube_addons (
33

4+
Optional[String] $cni_network_preinstall = $kubernetes::cni_network_preinstall,
45
Optional[String] $cni_network_provider = $kubernetes::cni_network_provider,
6+
Optional[String] $cni_pod_cidr = $kubernetes::cni_pod_cidr,
7+
Optional[String] $cni_provider = $kubernetes::cni_provider,
58
Optional[String] $cni_rbac_binding = $kubernetes::cni_rbac_binding,
69
Boolean $install_dashboard = $kubernetes::install_dashboard,
710
String $dashboard_version = $kubernetes::dashboard_version,
@@ -32,12 +35,46 @@
3235
}
3336

3437
if $cni_network_provider {
35-
$shellsafe_provider = shell_escape($cni_network_provider)
36-
exec { 'Install cni network provider':
37-
command => "kubectl apply -f ${shellsafe_provider}",
38-
onlyif => 'kubectl get nodes',
39-
unless => "kubectl -n kube-system get daemonset | egrep '(flannel|weave|calico-node|cilium)'",
40-
environment => $env,
38+
if $cni_provider == 'calico' {
39+
if $cni_network_preinstall {
40+
$shellsafe_preinstall = shell_escape($cni_network_preinstall)
41+
exec { 'Install cni network (preinstall)':
42+
command => "kubectl apply -f ${shellsafe_preinstall}",
43+
onlyif => 'kubectl get nodes',
44+
unless => "kubectl -n tigera-operator get deployments | egrep '^tigera-operator'",
45+
environment => $env,
46+
before => Exec['Install cni network provider'],
47+
}
48+
}
49+
$calico_installation_path='/etc/kubernetes/calico-installation.yaml'
50+
file { $calico_installation_path:
51+
ensure => 'present',
52+
group => 'root',
53+
mode => '0400',
54+
owner => 'root',
55+
replace => false,
56+
source => $cni_network_provider,
57+
} -> file_line { 'Configure calico ipPools.cidr':
58+
ensure => present,
59+
path => $calico_installation_path,
60+
match => ' cidr:',
61+
line => " cidr: ${cni_pod_cidr}",
62+
multiple => false,
63+
replace => true,
64+
} -> exec { 'Install cni network provider':
65+
command => "kubectl apply -f ${calico_installation_path}",
66+
onlyif => 'kubectl get nodes',
67+
unless => "kubectl -n calico-system get daemonset | egrep '^calico-node'",
68+
environment => $env,
69+
}
70+
} else {
71+
$shellsafe_provider = shell_escape($cni_network_provider)
72+
exec { 'Install cni network provider':
73+
command => "kubectl apply -f ${shellsafe_provider}",
74+
onlyif => 'kubectl get nodes',
75+
unless => "kubectl -n kube-system get daemonset | egrep '(flannel|weave|cilium)'",
76+
environment => $env,
77+
}
4178
}
4279
}
4380

spec/classes/kube_addons_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@
3131
it { should contain_exec('Install calico rbac bindings')}
3232
it { should contain_exec('Install cni network provider')}
3333
it { should contain_exec('schedule on controller')}
34+
35+
it { should_not contain_exec('Install cni network (preinstall)')}
36+
it { should_not contain_file('/etc/kubernetes/calico-installation.yaml')}
37+
it { should_not contain_file_line('Configure calico ipPools.cidr')}
38+
end
39+
40+
context 'with cni_provider => calico' do
41+
let(:params) do {
42+
'controller' => true,
43+
'cni_network_preinstall' => 'https://foo.test/tigera-operator',
44+
'cni_network_provider' => 'https://foo.test',
45+
'cni_provider' => 'calico',
46+
'install_dashboard' => false,
47+
'dashboard_version' => 'v1.10.1',
48+
'kubernetes_version' => '1.10.2',
49+
'node_name' => 'foo',
50+
}
51+
end
52+
53+
it { should contain_exec('Install cni network (preinstall)')}
54+
it { should contain_file('/etc/kubernetes/calico-installation.yaml')}
55+
it { should contain_file_line('Configure calico ipPools.cidr')}
56+
it { should contain_exec('Install cni network provider')}
3457
end
3558

3659
context 'with install_dashboard => false' do

tooling/kube_tool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
opts.on('-c', '--cni-provider cni-provider', 'the networking provider to use, flannel, weave, calico or cilium are supported') do |cni_provider|
3434
options[:cni_provider] = cni_provider;
3535
end
36-
opts.on('-p', '--cni-provider-version [cni_provider_version]', 'the networking provider version to use, calico and cilium will use this to reference the correct deployment downloadlink') do |cni_provider_version|
36+
opts.on('-p', '--cni-provider-version [cni_provider_version]', 'the networking provider version to use, cilium will use this to reference the correct deployment download link') do |cni_provider_version|
3737
options[:cni_provider_version] = cni_provider_version;
3838
end
3939

tooling/kube_tool/other_params.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def OtherParams.create(os, version, container_runtime, cni_provider, cni_provide
2828
cni_network_provider = 'https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml'
2929
cni_pod_cidr = '10.244.0.0/16'
3030
elsif cni_provider.match('calico')
31-
cni_network_provider = "https://docs.projectcalico.org/v#{cni_provider_version}/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml"
31+
cni_network_preinstall = "https://docs.projectcalico.org/manifests/tigera-operator.yaml"
32+
cni_network_provider = "https://docs.projectcalico.org/manifests/custom-resources.yaml"
3233
cni_pod_cidr = '192.168.0.0/16'
3334
elsif cni_provider.match('cilium')
3435
cni_pod_cidr = '10.244.0.0/16'
@@ -68,8 +69,12 @@ def OtherParams.create(os, version, container_runtime, cni_provider, cni_provide
6869
data['kubernetes::kubernetes_version'] = version
6970
data['kubernetes::kubernetes_package_version'] = kubernetes_package_version
7071
data['kubernetes::container_runtime'] = container_runtime
72+
if cni_network_preinstall
73+
data['kubernetes::cni_network_preinstall'] = cni_network_preinstall
74+
end
7175
data['kubernetes::cni_network_provider'] = cni_network_provider
7276
data['kubernetes::cni_pod_cidr'] = cni_pod_cidr
77+
data['kubernetes::cni_provider'] = cni_provider
7378
data['kubernetes::etcd_initial_cluster'] = etcd_initial_cluster
7479
data['kubernetes::etcd_peers'] = etcd_peers
7580
data['kubernetes::etcd_ip'] = etcd_ip

0 commit comments

Comments
 (0)