use contrail-ansible-deployer to integrate opencontrail into k8s 83/57083/6
authorzhichaozhu <zhichao.zhu8@gmail.com>
Sat, 5 May 2018 09:23:02 +0000 (17:23 +0800)
committerForrest Zhu <zhichao.zhu8@gmail.com>
Tue, 5 Jun 2018 07:58:25 +0000 (07:58 +0000)
Change-Id: If78430a159e13cf9456b9985d923a8ec107dc7cc
Signed-off-by: Forrest Zhu <zhichao.zhu8@gmail.com>
deploy/adapters/ansible/kubernetes/ansible-kubernetes.yml
deploy/compass_conf/flavor/kubernetes.conf
deploy/compass_conf/role/kubernetes_ansible.conf
deploy/conf/vm_environment/k8-ocl-nofeature-noha.yml [new file with mode: 0644]
plugins/opencontrail/plugin.desc [new file with mode: 0644]
plugins/opencontrail/roles/install-k8s-opencontrail/files/bms-instances.yaml [new file with mode: 0644]
plugins/opencontrail/roles/install-k8s-opencontrail/files/kvm-instances.yaml [new file with mode: 0644]
plugins/opencontrail/roles/install-k8s-opencontrail/files/mirrors.repo [new file with mode: 0644]
plugins/opencontrail/roles/install-k8s-opencontrail/files/mirrors_aarch64.repo [new file with mode: 0644]
plugins/opencontrail/roles/install-k8s-opencontrail/tasks/main.yml [new file with mode: 0644]

index 68dec5c..094c648 100755 (executable)
   remote_user: root
   max_fail_percentage: 0
   roles:
-    - kargo
+    - role: kargo
+      when: opencontrail is not defined
+    - role: install-k8s-opencontrail
+      when: opencontrail is defined and opencontrail == "Enable"
 
 - hosts: kube_master
   remote_user: root
index e7e8ffc..2e808a8 100755 (executable)
@@ -4,8 +4,6 @@ FLAVORS = [{
     'display_name': 'ansible-kubernetes',
     'template': 'ansible-kubernetes.tmpl',
     'roles': [
-        'kube_master', 'etcd', 'kube_node', 'ha', 'storage_master', 'storage_node'
+        'kube_master', 'etcd', 'kube_node', 'ha', 'storage_master', 'storage_node', 'opencontrail'
     ],
 }]
-
-
index 3e79cbb..87bbaf5 100755 (executable)
@@ -12,6 +12,10 @@ ROLES = [{
     'display_name': 'kube node',
     'description': 'kube Node'
 }, {
+    'role': 'opencontrail',
+    'display_name': 'opencontrail node',
+    'description': 'opencontrail node'
+},{
     'role': 'ha',
     'display_name': 'ha',
     'description': 'ha'
diff --git a/deploy/conf/vm_environment/k8-ocl-nofeature-noha.yml b/deploy/conf/vm_environment/k8-ocl-nofeature-noha.yml
new file mode 100644 (file)
index 0000000..fd7bfda
--- /dev/null
@@ -0,0 +1,27 @@
+##############################################################################
+# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+---
+TYPE: virtual
+FLAVOR: cluster
+
+plugins:
+  - opencontrail: "Enable"
+
+hosts:
+  - name: host1
+    roles:
+      - kube_master
+      - etcd
+      - opencontrail
+      - ha
+
+  - name: host2
+    roles:
+      - kube_node
diff --git a/plugins/opencontrail/plugin.desc b/plugins/opencontrail/plugin.desc
new file mode 100644 (file)
index 0000000..82ccd5e
--- /dev/null
@@ -0,0 +1,43 @@
+# Plugin for opencontrail service for Compass4nfv.
+# opencontrail provides a sdn network for k8s.
+#
+# More details can be found in the development document.
+# ##############################################################
+---
+plugin:
+  # plugin name,it is also as the switch to enable/disable plugin in scenario
+  # files
+  name: opencontrail
+
+  description: provide a sdn solution for k8s
+
+  maintainers:
+
+  # host os type: centos
+  os_version: centos
+
+  # true: this plugin is deployed separately on a new node
+  # false: this plugin is deployed on controller or compute node
+  independent_hosts: false
+
+  # artifact: package download url for this plugin
+  artifacts:
+    url:
+
+  # orchestration
+  # A plugin can have mutiple components, each component may need to be
+  # installed on different inventory or have its own configuration.
+  # due to Compass4nfv currently only supports ansible, so each component
+  # of the installation and configuration script need to be use ansible.
+  # cm : congfiguration management tool : only ansible support
+  # role: each component corresponds to ansible script that locates in the same
+  # directory as plugin.desc.
+  # phrase:
+  # inventory:
+  orchestration:
+    cm: ansible
+    roles:
+      - role: opencontrail
+        phrase: post_k8s
+        inventory:
+          - localhost
diff --git a/plugins/opencontrail/roles/install-k8s-opencontrail/files/bms-instances.yaml b/plugins/opencontrail/roles/install-k8s-opencontrail/files/bms-instances.yaml
new file mode 100644 (file)
index 0000000..7fb7037
--- /dev/null
@@ -0,0 +1,32 @@
+---
+provider_config:
+  bms:
+    ssh_pwd: root
+    ssh_user: root
+    ssh_public_key: /root/.ssh/id_rsa.pub
+    ssh_private_key: /root/.ssh/id_rsa
+    domainsuffix: local
+instances:
+  bms1:
+    provider: bms
+    roles:
+      config_database:
+      config:
+      control:
+      analytics_database:
+      analytics:
+      webui:
+      k8s_master:
+      kubemanager:
+    ip: 192.16.1.211
+  bms2:
+    provider: bms
+    roles:
+      k8s_node:
+      vrouter:
+    ip: 192.16.1.212
+
+contrail_configuration:
+  CONTAINER_REGISTRY: opencontrailnightly
+  CONTRAIL_VERSION: latest
+  KUBERNETES_CLUSTER_PROJECT: {}
diff --git a/plugins/opencontrail/roles/install-k8s-opencontrail/files/kvm-instances.yaml b/plugins/opencontrail/roles/install-k8s-opencontrail/files/kvm-instances.yaml
new file mode 100644 (file)
index 0000000..b2f9e6d
--- /dev/null
@@ -0,0 +1,32 @@
+---
+provider_config:
+  kvm:
+    ssh_pwd: root
+    ssh_user: root
+    ssh_public_key: /root/.ssh/id_rsa.pub
+    ssh_private_key: /root/.ssh/id_rsa
+    domainsuffix: local
+instances:
+  kvm1:
+    provider: kvm
+    roles:
+      config_database:
+      config:
+      control:
+      analytics_database:
+      analytics:
+      webui:
+      k8s_master:
+      kubemanager:
+    ip: 10.1.0.50
+  kvm2:
+    provider: kvm
+    roles:
+      k8s_node:
+      vrouter:
+    ip: 10.1.0.51
+
+contrail_configuration:
+  CONTAINER_REGISTRY: opencontrailnightly
+  CONTRAIL_VERSION: latest
+  KUBERNETES_CLUSTER_PROJECT: {}
diff --git a/plugins/opencontrail/roles/install-k8s-opencontrail/files/mirrors.repo b/plugins/opencontrail/roles/install-k8s-opencontrail/files/mirrors.repo
new file mode 100644 (file)
index 0000000..4900db6
--- /dev/null
@@ -0,0 +1,32 @@
+[base]\r
+name=CentOS-$releasever - Base\r
+mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra\r
+#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/\r
+gpgcheck=1\r
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\r
+\r
+#released updates\r
+[updates]\r
+name=CentOS-$releasever - Updates\r
+mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra\r
+#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/\r
+gpgcheck=1\r
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\r
+\r
+#additional packages that may be useful\r
+[extras]\r
+name=CentOS-$releasever - Extras\r
+mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra\r
+#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/\r
+gpgcheck=1\r
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\r
+\r
+#additional packages that extend functionality of existing packages\r
+[centosplus]\r
+name=CentOS-$releasever - Plus\r
+mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra\r
+#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/\r
+gpgcheck=1\r
+enabled=0\r
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\r
+\r
diff --git a/plugins/opencontrail/roles/install-k8s-opencontrail/files/mirrors_aarch64.repo b/plugins/opencontrail/roles/install-k8s-opencontrail/files/mirrors_aarch64.repo
new file mode 100644 (file)
index 0000000..1d622d3
--- /dev/null
@@ -0,0 +1,22 @@
+[base]
+name=CentOS-$releasever - Base
+baseurl=http://mirror.centos.org/altarch/$releasever/os/$basearch/
+gpgcheck=1
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
+       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64
+
+#released updates
+[updates]
+name=CentOS-$releasever - Updates
+baseurl=http://mirror.centos.org/altarch/$releasever/updates/$basearch/
+gpgcheck=1
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
+       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64
+
+#additional packages that may be useful
+[extras]
+name=CentOS-$releasever - Extras
+baseurl=http://mirror.centos.org/altarch/$releasever/extras/$basearch/
+gpgcheck=1
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
+       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64
diff --git a/plugins/opencontrail/roles/install-k8s-opencontrail/tasks/main.yml b/plugins/opencontrail/roles/install-k8s-opencontrail/tasks/main.yml
new file mode 100644 (file)
index 0000000..712ebfa
--- /dev/null
@@ -0,0 +1,92 @@
+##############################################################################
+# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+---
+- name: clean local repo conf
+  file:
+    path: /etc/yum.repos.d
+    state: absent
+  run_once: "True"
+  when: ansible_os_family == 'RedHat'
+
+- name: create local repo conf dir
+  file:
+    path: /etc/yum.repos.d
+    state: directory
+  run_once: "True"
+  when: ansible_os_family == 'RedHat'
+
+- name: configure local mirror repo
+  copy:
+    src: "{{ item }}"
+    dest: /etc/yum.repos.d/mirrors.repo
+  with_first_found:
+    - mirrors_{{ ansible_architecture }}.repo
+    - mirrors.repo
+  run_once: "True"
+  when: ansible_os_family == 'RedHat'
+
+- name: clean local pip conf to use official pip repo
+  file:
+    path: /root/.pip/pip.conf
+    state: absent
+  run_once: "True"
+
+- name: install dependency for ansible update
+  yum:
+    name: "{{ item }}"
+    state: latest
+  with_items:
+    - git
+    - libffi-devel
+    - openssl-devel
+    - python-devel
+  run_once: "True"
+  when: ansible_os_family == 'RedHat'
+
+- name: update python packages
+  pip:
+    name: "{{ item }}"
+    state: latest
+  with_items:
+    - netaddr
+    - jinja2
+
+- name: git clone contrail-ansible-deployer repo
+  shell: |
+    rm -rf /opt/contrail-ansible-deployer
+    git clone https://github.com/Juniper/contrail-ansible-deployer.git \
+    /opt/contrail-ansible-deployer
+
+- name: copy overrided variables
+  copy:
+    src: "{{ item }}"
+    dest: /opt/contrail-ansible-deployer/config/instances.yaml
+  with_first_found:
+    - kvm-instances.yaml
+
+- name: do not restart network
+  shell: |
+    cd /opt/contrail-ansible-deployer
+    sed -i '9, 13d' playbooks/roles/configure_instances/tasks/RedHat.yml
+
+- name: run config playbook
+  shell: |
+    cd /opt/contrail-ansible-deployer
+    ansible-playbook -i inventory/ playbooks/configure_instances.yml \
+                     -b -v 2>&1  | tee config-contrail.log
+  tags:
+    - ansible
+
+- name: run install playbook
+  shell: |
+    cd /opt/contrail-ansible-deployer
+    ansible-playbook -e orchestrator=kubernetes -i inventory/ playbooks/install_contrail.yml \
+                     -b -v 2>&1  | tee install-contrail.log
+  tags:
+    - ansible