|
27 | 27 | $exec_onlyif = 'kubectl get nodes' |
28 | 28 |
|
29 | 29 | if $cni_rbac_binding { |
30 | | - $binding_command = ['kubectl', 'apply', '-f', $cni_rbac_binding] |
31 | | - $binding_unless = 'kubectl get clusterrole | grep calico' |
32 | | - |
33 | 30 | exec { 'Install calico rbac bindings': |
34 | 31 | environment => $env, |
35 | | - command => $binding_command, |
| 32 | + command => ['kubectl', 'apply', '-f', $cni_rbac_binding], |
36 | 33 | onlyif => $exec_onlyif, |
37 | | - unless => $binding_unless, |
| 34 | + unless => 'kubectl get clusterrole | grep calico', |
38 | 35 | } |
39 | 36 | } |
40 | 37 |
|
41 | 38 | if $cni_network_provider { |
42 | 39 | if $cni_provider == 'calico-tigera' { |
43 | 40 | if $cni_network_preinstall { |
44 | | - $preinstall_command = ['kubectl', 'apply', '-f', $cni_network_preinstall] |
45 | | - $preinstall_unless = 'kubectl -n tigera-operator get deployments | egrep "^tigera-operator"' |
46 | | - |
47 | 41 | exec { 'Install cni network (preinstall)': |
48 | | - command => $preinstall_command, |
| 42 | + command => ['kubectl', 'apply', '-f', $cni_network_preinstall], |
49 | 43 | onlyif => $exec_onlyif, |
50 | | - unless => $preinstall_unless, |
| 44 | + unless => 'kubectl -n tigera-operator get deployments | egrep "^tigera-operator"', |
51 | 45 | environment => $env, |
52 | 46 | before => Exec['Install cni network provider'], |
53 | 47 | } |
54 | 48 | } |
55 | | - # Removing Calico_installation_path variable as it doesnt seem to apport any extra value here. |
56 | | - $calico_installation_path = '/etc/kubernetes/calico-installation.yaml' |
57 | | - $path_command = 'kubectl apply -f /etc/kubernetes/calico-installation.yaml' |
58 | | - $path_unless = 'kubectl -n calico-system get daemonset | egrep "^calico-node"' |
59 | | - |
60 | | - file { $calico_installation_path: |
| 49 | + file { '/etc/kubernetes/calico-installation.yaml': |
61 | 50 | ensure => 'present', |
62 | 51 | group => 'root', |
63 | 52 | mode => '0400', |
|
66 | 55 | source => $cni_network_provider, |
67 | 56 | } -> file_line { 'Configure calico ipPools.cidr': |
68 | 57 | ensure => present, |
69 | | - path => $calico_installation_path, |
| 58 | + path => '/etc/kubernetes/calico-installation.yaml', |
70 | 59 | match => ' cidr:', |
71 | 60 | line => " cidr: ${cni_pod_cidr}", |
72 | 61 | multiple => false, |
73 | 62 | replace => true, |
74 | 63 | } -> exec { 'Install cni network provider': |
75 | | - command => $path_command, |
| 64 | + command => 'kubectl apply -f /etc/kubernetes/calico-installation.yaml', |
76 | 65 | onlyif => $exec_onlyif, |
77 | | - unless => $path_unless, |
| 66 | + unless => 'kubectl -n calico-system get daemonset | egrep "^calico-node"', |
78 | 67 | environment => $env, |
79 | 68 | } |
80 | 69 | } else { |
81 | | - $provider_command = ['kubectl', 'apply', '-f', $cni_network_provider] |
82 | | - $provider_unless = 'kubectl -n kube-system get daemonset | egrep "(flannel|weave|calico-node|cilium)"' |
83 | | - |
84 | 70 | exec { 'Install cni network provider': |
85 | | - command => $provider_command, |
| 71 | + command => ['kubectl', 'apply', '-f', $cni_network_provider], |
86 | 72 | onlyif => $exec_onlyif, |
87 | | - unless => $provider_unless, |
| 73 | + unless => 'kubectl -n kube-system get daemonset | egrep "(flannel|weave|calico-node|cilium)"', |
88 | 74 | environment => $env, |
89 | 75 | } |
90 | 76 | } |
91 | 77 | } |
92 | 78 |
|
93 | 79 | if $schedule_on_controller { |
94 | | - $schedule_command = ['kubectl', 'taint', 'nodes', $node_name, 'node-role.kubernetes.io/master-'] |
95 | | - $schedule_onlyif = "kubectl describe nodes ${node_name} | tr -s ' ' | grep 'Taints: node-role.kubernetes.io/master:NoSchedule'" |
96 | | - |
97 | 80 | exec { 'schedule on controller': |
98 | | - command => $schedule_command, |
99 | | - onlyif => $schedule_onlyif, |
| 81 | + command => "kubectl taint nodes ${node_name} node-role.kubernetes.io/master-", |
| 82 | + onlyif => "kubectl describe nodes ${node_name} | tr -s ' ' | grep 'Taints: node-role.kubernetes.io/master:NoSchedule'", |
100 | 83 | } |
101 | 84 | } |
102 | 85 |
|
103 | 86 | if $install_dashboard { |
104 | | - $dashboard_command = ['kubectl', 'apply', '-f', $dashboard_url] |
105 | | - $dashboard_unless = [ |
106 | | - 'kubectl get pods --field-selector="status.phase=Running" -n kubernetes-dashboard | grep kubernetes-dashboard-', |
107 | | - 'kubectl get pods --field-selector="status.phase=Running" -n kube-system | grep kubernetes-dashboard-' |
108 | | - ] |
109 | | - |
110 | 87 | exec { 'Install Kubernetes dashboard': |
111 | | - command => $dashboard_command, |
| 88 | + command => ['kubectl', 'apply', '-f', $dashboard_url], |
112 | 89 | onlyif => $exec_onlyif, |
113 | | - unless => $dashboard_unless, |
| 90 | + unless => [ |
| 91 | + 'kubectl get pods --field-selector="status.phase=Running" -n kubernetes-dashboard | grep kubernetes-dashboard-', |
| 92 | + 'kubectl get pods --field-selector="status.phase=Running" -n kube-system | grep kubernetes-dashboard-', |
| 93 | + ], |
114 | 94 | environment => $env, |
115 | 95 | } |
116 | 96 | } |
|
0 commit comments