Skip to content

Commit 38fee07

Browse files
committed
Fix flannel install condition
1 parent 09ee337 commit 38fee07

File tree

4 files changed

+74
-31
lines changed

4 files changed

+74
-31
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ class {'kubernetes':
128128
}
129129
```
130130

131+
#### Network Plugins
132+
133+
Kubernetes supports multiple [networking plugins](https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/) that implements the [networking model](https://kubernetes.io/docs/concepts/services-networking/#the-kubernetes-network-model).
134+
135+
This module supports following [Container Network Interface](https://github.com/containernetworking/cni) (CNI) plugins:
136+
137+
- `flannel`
138+
```yaml
139+
kubernetes::cni_network_provider: https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
140+
kubernetes::cni_pod_cidr: 10.244.0.0/16
141+
kubernetes::cni_provider: flannel
142+
```
143+
- `weave`
144+
- `calico-node`
145+
- `cilium`
146+
```yaml
147+
kubernetes::cni_network_provider: https://raw.githubusercontent.com/cilium/cilium/1.4.3/examples/kubernetes/1.26/cilium.yaml
148+
kubernetes::cni_pod_cidr: 10.244.0.0/16
149+
kubernetes::cni_provider: cilium
150+
```
151+
131152
#### Installing Kubernetes on different OS
132153

133154
Currently, `puppetlab-kubernetes` is compatible with Ubuntu Xenial. For different OS, below parameters can be assigned.

manifests/kube_addons.pp

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,54 @@
7575
}
7676

7777
if $cni_network_provider {
78-
if $cni_provider == 'calico-tigera' {
79-
if $cni_network_preinstall {
80-
exec { 'Install cni network (preinstall)':
81-
command => ['kubectl', 'apply', '-f', $cni_network_preinstall],
78+
case $cni_provider {
79+
'calico-tigera': {
80+
if $cni_network_preinstall {
81+
exec { 'Install cni network (preinstall)':
82+
command => ['kubectl', 'apply', '-f', $cni_network_preinstall],
83+
onlyif => $exec_onlyif,
84+
unless => 'kubectl -n tigera-operator get deployments | egrep "^tigera-operator"',
85+
environment => $env,
86+
before => Exec['Install cni network provider'],
87+
}
88+
}
89+
file { '/etc/kubernetes/calico-installation.yaml':
90+
ensure => file,
91+
group => 'root',
92+
mode => '0400',
93+
owner => 'root',
94+
replace => false,
95+
source => $cni_network_provider,
96+
} -> file_line { 'Configure calico ipPools.cidr':
97+
ensure => present,
98+
path => '/etc/kubernetes/calico-installation.yaml',
99+
match => ' cidr:',
100+
line => " cidr: ${cni_pod_cidr}",
101+
multiple => false,
102+
replace => true,
103+
} -> exec { 'Install cni network provider':
104+
command => 'kubectl apply -f /etc/kubernetes/calico-installation.yaml',
82105
onlyif => $exec_onlyif,
83-
unless => 'kubectl -n tigera-operator get deployments | egrep "^tigera-operator"',
106+
unless => 'kubectl -n calico-system get daemonset | egrep "^calico-node"',
84107
environment => $env,
85108
before => Exec['Install cni network provider'],
86109
}
87110
}
88-
file { '/etc/kubernetes/calico-installation.yaml':
89-
ensure => file,
90-
group => 'root',
91-
mode => '0400',
92-
owner => 'root',
93-
replace => false,
94-
source => $cni_network_provider,
95-
} -> file_line { 'Configure calico ipPools.cidr':
96-
ensure => present,
97-
path => '/etc/kubernetes/calico-installation.yaml',
98-
match => ' cidr:',
99-
line => " cidr: ${cni_pod_cidr}",
100-
multiple => false,
101-
replace => true,
102-
} -> exec { 'Install cni network provider':
103-
command => 'kubectl apply -f /etc/kubernetes/calico-installation.yaml',
104-
onlyif => $exec_onlyif,
105-
unless => 'kubectl -n calico-system get daemonset | egrep "^calico-node"',
106-
environment => $env,
111+
'flannel': {
112+
exec { 'Install cni network provider':
113+
command => ['kubectl', 'apply', '-f', $cni_network_provider],
114+
onlyif => $exec_onlyif,
115+
unless => 'kubectl -n kube-flannel get daemonset | egrep "^kube-flannel"',
116+
environment => $env,
117+
}
107118
}
108-
} else {
109-
exec { 'Install cni network provider':
110-
command => ['kubectl', 'apply', '-f', $cni_network_provider],
111-
onlyif => $exec_onlyif,
112-
unless => 'kubectl -n kube-system get daemonset | egrep "(flannel|weave|calico-node|cilium)"',
113-
environment => $env,
119+
default: {
120+
exec { 'Install cni network provider':
121+
command => ['kubectl', 'apply', '-f', $cni_network_provider],
122+
onlyif => $exec_onlyif,
123+
unless => 'kubectl -n kube-system get daemonset | egrep "(flannel|weave|calico-node|cilium)"',
124+
environment => $env,
125+
}
114126
}
115127
}
116128
}

spec/classes/kube_addons_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
it { is_expected.to contain_file('/etc/kubernetes/calico-installation.yaml') }
8282
it { is_expected.to contain_file_line('Configure calico ipPools.cidr') }
8383
it { is_expected.to contain_exec('Install cni network provider') }
84+
when 'flannel'
85+
it {
86+
expect(subject).to contain_exec('Install cni network provider').with(
87+
{
88+
onlyif: ['kubectl get nodes'],
89+
command: ['kubectl', 'apply', '-f', "https://#{provider}.test"],
90+
unless: ['kubectl -n kube-flannel get daemonset | egrep "^kube-flannel"']
91+
},
92+
)
93+
}
8494
else
8595
it {
8696
expect(subject).to contain_exec('Install cni network provider').with({

tooling/kube_tool/other_params.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def self.create(opts)
2424
cni_network_provider = 'https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s-1.11.yaml'
2525
cni_pod_cidr = '10.32.0.0/12'
2626
when 'flannel'
27-
cni_network_provider = 'https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml'
27+
cni_network_provider = 'https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml'
2828
cni_pod_cidr = '10.244.0.0/16'
2929
when 'calico'
3030
cni_network_provider = "https://docs.projectcalico.org/archive/v#{opts[:cni_provider_version]}/manifests/calico.yaml"

0 commit comments

Comments
 (0)