Add Swarm cluster to mcp11-k8s-calico model

The change also fixes the network configuration of the infra node and
adds scripts to deploy Kubnernetes environments.

Change-Id: Ib8b3f01210be9180d9c8eaf8dfe885a4475fd82b
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/infra/config.yml b/classes/cluster/virtual-mcp11-k8s-calico/infra/config.yml
index 91332ff..2b295d1 100644
--- a/classes/cluster/virtual-mcp11-k8s-calico/infra/config.yml
+++ b/classes/cluster/virtual-mcp11-k8s-calico/infra/config.yml
@@ -16,10 +16,9 @@
     reclass_data_revision: master
     reclass_config_master: ${_param:infra_config_deploy_address}
     single_address: ${_param:infra_config_address}
-    deploy_address: ${_param:infra_config_deploy_address}
     linux_system_codename: xenial
     salt_api_password_hash: "$6$WV0P1shnoDh2gI/Z$22/Bcd7ffMv0jDlFpT63cAU4PiXHz9pjXwngToKwqAsgoeK4HNR3PiKaushjxp3JsQ8hNoJmAC6TxzVqfV8WH/"
-    salt_master_host: ${_param:infra_config_address}
+    salt_master_host: ${_param:infra_config_deploy_address}
     apt_mk_version: nightly
   reclass:
     storage:
@@ -30,7 +29,7 @@
           classes:
           - cluster.${_param:cluster_name}.kubernetes.compute
           params:
-            salt_master_host: ${_param:infra_config_address}
+            salt_master_host: ${_param:infra_config_deploy_address}
             linux_system_codename: xenial
             single_address: ${_param:kubernetes_compute_node01_address}
         kubernetes_compute_node02:
@@ -39,7 +38,7 @@
           classes:
           - cluster.${_param:cluster_name}.kubernetes.compute
           params:
-            salt_master_host: ${_param:infra_config_address}
+            salt_master_host: ${_param:infra_config_deploy_address}
             linux_system_codename: xenial
             single_address: ${_param:kubernetes_compute_node02_address}
         prx_node:
@@ -48,15 +47,33 @@
           classes:
           - cluster.${_param:cluster_name}.infra
           params:
-            salt_master_host: ${_param:infra_config_address}
+            salt_master_host: ${_param:infra_config_deploy_address}
             linux_system_codename: xenial
             single_address: ${_param:kubernetes_proxy_node01_address}
-        mon_node:
-          name: ${_param:kubernetes_monitor_node01_hostname}
+        docker_swarm_node01:
+          name: ${_param:docker_swarm_node01_hostname}
           domain: ${_param:cluster_domain}
           classes:
-          - cluster.${_param:cluster_name}.infra
+          - cluster.${_param:cluster_name}.swarm.master
           params:
-            salt_master_host: ${_param:infra_config_address}
+            salt_master_host: ${_param:infra_config_deploy_address}
             linux_system_codename: xenial
-            single_address: ${_param:kubernetes_monitor_node01_address}
+            single_address: ${_param:docker_swarm_node01_address}
+        docker_swarm_node02:
+          name: ${_param:docker_swarm_node02_hostname}
+          domain: ${_param:cluster_domain}
+          classes:
+          - cluster.${_param:cluster_name}.swarm.slave
+          params:
+            salt_master_host: ${_param:infra_config_deploy_address}
+            linux_system_codename: xenial
+            single_address: ${_param:docker_swarm_node02_address}
+        docker_swarm_node03:
+          name: ${_param:docker_swarm_node03_hostname}
+          domain: ${_param:cluster_domain}
+          classes:
+          - cluster.${_param:cluster_name}.swarm.slave
+          params:
+            salt_master_host: ${_param:infra_config_deploy_address}
+            linux_system_codename: xenial
+            single_address: ${_param:docker_swarm_node03_address}
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/infra/init.yml b/classes/cluster/virtual-mcp11-k8s-calico/infra/init.yml
index 97511e8..39404c0 100644
--- a/classes/cluster/virtual-mcp11-k8s-calico/infra/init.yml
+++ b/classes/cluster/virtual-mcp11-k8s-calico/infra/init.yml
@@ -1,10 +1,12 @@
-
 classes:
 - system.linux.system.single
 - system.openssh.server.team.lab
+- system.openssh.server.team.stacklight
 - system.openssh.server.team.tcpcloud
 - system.openssh.server.team.mcp_qa
+- system.rsyslog.client.single
 - cluster.virtual-mcp11-k8s-calico.kubernetes
+- cluster.virtual-mcp11-k8s-calico.swarm
 - cluster.overwrite
 parameters:
   _param:
@@ -15,7 +17,6 @@
 
     cluster_domain: virtual-mcp11-k8s-calico.local
     cluster_name: virtual-mcp11-k8s-calico
-    #cluster_public_host: ""
   linux:
     network:
       host:
@@ -24,11 +25,6 @@
           names:
           - ${_param:infra_config_hostname}
           - ${_param:infra_config_hostname}.${_param:cluster_domain}
-        cfg:
-          address: ${_param:infra_config_address}
-          names:
-          - cfg
-          - cfg.${_param:cluster_domain}
       interface:
         ens4:
           enabled: true
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/kubernetes/init.yml b/classes/cluster/virtual-mcp11-k8s-calico/kubernetes/init.yml
index b45cbd5..d1d437d 100644
--- a/classes/cluster/virtual-mcp11-k8s-calico/kubernetes/init.yml
+++ b/classes/cluster/virtual-mcp11-k8s-calico/kubernetes/init.yml
@@ -1,4 +1,3 @@
-
 parameters:
   _param:
     salt_minion_ca_host: ${_param:infra_config_hostname}.${_param:cluster_domain}
@@ -31,9 +30,6 @@
     kubernetes_compute_node02_address: 172.16.10.106
     kubernetes_proxy_node01_hostname: prx01
     kubernetes_proxy_node01_address: 172.16.10.121
-    kubernetes_monitor_node01_hostname: mon01
-    kubernetes_monitor_node01_address: 172.16.10.107
-
 
     cluster_vip_address: ${_param:kubernetes_control_address}
     cluster_local_address: ${_param:single_address}
@@ -97,11 +93,6 @@
           names:
           - ${_param:kubernetes_proxy_node01_hostname}
           - ${_param:kubernetes_proxy_node01_hostname}.${_param:cluster_domain}
-        mon01:
-          address: ${_param:kubernetes_monitor_node01_address}
-          names:
-          - ${_param:kubernetes_monitor_node01_hostname}
-          - ${_param:kubernetes_monitor_node01_hostname}.${_param:cluster_domain}
     system:
       rc:
         local: |
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/swarm/control.yml b/classes/cluster/virtual-mcp11-k8s-calico/swarm/control.yml
new file mode 100644
index 0000000..5f91f9e
--- /dev/null
+++ b/classes/cluster/virtual-mcp11-k8s-calico/swarm/control.yml
@@ -0,0 +1,7 @@
+classes:
+- system.docker.host
+- cluster.virtual-mcp11-k8s-calico.infra
+parameters:
+  _param:
+    cluster_vip_address: ${_param:docker_swarm_address}
+    cluster_public_host: ${_param:docker_swarm_hostname}
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/swarm/init.yml b/classes/cluster/virtual-mcp11-k8s-calico/swarm/init.yml
new file mode 100644
index 0000000..91590b8
--- /dev/null
+++ b/classes/cluster/virtual-mcp11-k8s-calico/swarm/init.yml
@@ -0,0 +1,43 @@
+parameters:
+  _param:
+    docker_swarm_hostname: mon
+    docker_swarm_address: 172.16.10.252
+    docker_swarm_node01_hostname: mon01
+    docker_swarm_node02_hostname: mon02
+    docker_swarm_node03_hostname: mon03
+    docker_swarm_node01_address: 172.16.10.107
+    docker_swarm_node02_address: 172.16.10.108
+    docker_swarm_node03_address: 172.16.10.109
+  linux:
+    network:
+      host:
+        mon:
+          address: ${_param:docker_swarm_address}
+          names:
+          - ${_param:docker_swarm_hostname}
+          - ${_param:docker_swarm_hostname}.${_param:cluster_domain}
+        mon01:
+          address: ${_param:docker_swarm_node01_address}
+          names:
+          - ${_param:docker_swarm_node01_hostname}
+          - ${_param:docker_swarm_node01_hostname}.${_param:cluster_domain}
+        mon02:
+          address: ${_param:docker_swarm_node02_address}
+          names:
+          - ${_param:docker_swarm_node02_hostname}
+          - ${_param:docker_swarm_node02_hostname}.${_param:cluster_domain}
+        mon03:
+          address: ${_param:docker_swarm_node03_address}
+          names:
+          - ${_param:docker_swarm_node03_hostname}
+          - ${_param:docker_swarm_node03_hostname}.${_param:cluster_domain}
+      interface:
+        ens4:
+          enabled: true
+          type: eth
+          proto: static
+          address: ${_param:single_address}
+          netmask: 255.255.255.0
+    system:
+      name: ${_param:infra_config_hostname}
+      domain: ${_param:cluster_domain}
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/swarm/master.yml b/classes/cluster/virtual-mcp11-k8s-calico/swarm/master.yml
new file mode 100644
index 0000000..8d53081
--- /dev/null
+++ b/classes/cluster/virtual-mcp11-k8s-calico/swarm/master.yml
@@ -0,0 +1,15 @@
+classes:
+- system.docker.client
+- system.docker.swarm.master
+- cluster.virtual-mcp11-k8s-calico.swarm.control
+parameters:
+  docker:
+    client:
+      enabled: true
+      compose:
+        source:
+          engine: docker
+          image: "docker/compose:1.8.0"
+    swarm:
+      role: master
+      advertise_addr: ${_param:single_address}
diff --git a/classes/cluster/virtual-mcp11-k8s-calico/swarm/slave.yml b/classes/cluster/virtual-mcp11-k8s-calico/swarm/slave.yml
new file mode 100644
index 0000000..1b1a8d2
--- /dev/null
+++ b/classes/cluster/virtual-mcp11-k8s-calico/swarm/slave.yml
@@ -0,0 +1,8 @@
+classes:
+- system.docker.swarm.manager
+- cluster.virtual-mcp11-k8s-calico.swarm.control
+parameters:
+  docker:
+    swarm:
+      master:
+        host: ${_param:docker_swarm_node01_address}
diff --git a/scripts/bootstrap_k8s.sh b/scripts/bootstrap_k8s.sh
new file mode 100755
index 0000000..b9c4aac
--- /dev/null
+++ b/scripts/bootstrap_k8s.sh
@@ -0,0 +1,8 @@
+#!/bin/bash -x
+
+CWD="$(dirname "$(readlink -f "$0")")"
+
+"$CWD"/fuel_config_verify.sh
+"$CWD"/fuel_infra_install.sh
+"$CWD"/docker_swarm.sh
+"$CWD"/k8s.sh
diff --git a/scripts/docker_swarm.sh b/scripts/docker_swarm.sh
new file mode 100755
index 0000000..8037590
--- /dev/null
+++ b/scripts/docker_swarm.sh
@@ -0,0 +1,9 @@
+#!/bin/bash -x
+exec > >(tee -i /tmp/"$(basename "$0" .sh)"_"$(date '+%Y-%m-%d_%H-%M-%S')".log) 2>&1
+
+salt -C 'I@docker:swarm' state.sls docker.host
+salt -C 'I@docker:swarm:role:master' state.sls docker.swarm
+salt -C 'I@docker:swarm' state.sls salt.minion.grains
+salt -C 'I@docker:swarm' mine.update
+salt -C 'I@docker:swarm:role:manager' state.sls docker.swarm -b 1
+salt -C 'I@docker:swarm:role:master' cmd.run 'docker node ls'
diff --git a/scripts/k8s.sh b/scripts/k8s.sh
new file mode 100755
index 0000000..bcf57d9
--- /dev/null
+++ b/scripts/k8s.sh
@@ -0,0 +1,38 @@
+#!/bin/bash -x
+exec > >(tee -i /tmp/"$(basename "$0" .sh)"_"$(date '+%Y-%m-%d_%H-%M-%S')".log) 2>&1
+
+# Create and distribute SSL certificates for services using salt state
+salt "*" state.sls salt
+
+# Install keepalived
+salt -C 'I@keepalived:cluster' state.sls keepalived -b 1
+
+# Install haproxy
+salt -C 'I@haproxy:proxy' state.sls haproxy
+salt -C 'I@haproxy:proxy' service.status haproxy
+
+# Install docker
+salt -C 'I@docker:host' state.sls docker.host
+salt -C 'I@docker:host' cmd.run "docker ps"
+
+# Install etcd
+salt -C 'I@etcd:server' state.sls etcd.server.service
+salt -C 'I@etcd:server' cmd.run "etcdctl cluster-health"
+
+# Install Kubernetes and Calico
+salt -C 'I@kubernetes:master' state.sls kubernetes.master.kube-addons
+salt -C 'I@kubernetes:pool' state.sls kubernetes.pool
+salt -C 'I@kubernetes:pool' cmd.run "calicoctl node status"
+salt -C 'I@kubernetes:pool' cmd.run "calicoctl get ippool"
+
+# Setup NAT for Calico
+salt -C 'I@kubernetes:master' state.sls etcd.server.setup
+
+# Run whole master to check consistency
+salt -C 'I@kubernetes:master' state.sls kubernetes exclude=kubernetes.master.setup
+
+# Register addons
+salt -C 'I@kubernetes:master' --subset 1 state.sls kubernetes.master.setup
+
+# Nginx needs to be configured
+salt -C 'I@nginx:server' state.sls nginx