Add DANM TenantConfig creation 25/1625/7
authorKrisztian Lengyel <krisztian.lengyel@nokia.com>
Thu, 19 Sep 2019 17:55:58 +0000 (13:55 -0400)
committerKrisztian Lengyel <krisztian.lengyel@nokia.com>
Mon, 30 Sep 2019 15:25:09 +0000 (17:25 +0200)
TenantConfig moved to post infra chart installation.

Change-Id: I40a5d2ca5c3ec8eb6cd82385bde41e6760611aff
Signed-off-by: Krisztian Lengyel <krisztian.lengyel@nokia.com>
SPECS/infra-charts.spec
SPECS/instantiate.spec
ansible/playbooks/install_caas_infra.yaml
ansible/roles/post_install_caas_infra/defaults/main.yaml [new file with mode: 0644]
ansible/roles/post_install_caas_infra/tasks/main.yaml [new file with mode: 0644]
ansible/roles/post_install_caas_infra/templates/danm-tenant-config.yaml.j2 [new file with mode: 0644]

index 30a9300..892cbfd 100644 (file)
@@ -15,7 +15,7 @@
 %define COMPONENT infra-charts
 %define RPM_NAME caas-%{COMPONENT}
 %define RPM_MAJOR_VERSION 1.0.0
-%define RPM_MINOR_VERSION 29
+%define RPM_MINOR_VERSION 30
 
 Name:           %{RPM_NAME}
 Version:        %{RPM_MAJOR_VERSION}
@@ -44,6 +44,7 @@ rsync -av ansible/playbooks/infra_chart_reconfig_fluentd.yaml %{buildroot}/%{_pl
 mkdir -p %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/install_caas_infra %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/pre_install_caas_infra %{buildroot}/%{_roles_path}/
+rsync -av ansible/roles/post_install_caas_infra %{buildroot}/%{_roles_path}/
 rsync -av ansible/roles/infra_chart_reconfig %{buildroot}/%{_roles_path}/
 
 mkdir -p %{buildroot}/%{_caas_chart_path}/
index 0d32658..21ac01f 100644 (file)
@@ -15,7 +15,7 @@
 %define COMPONENT instantiate
 %define RPM_NAME caas-%{COMPONENT}
 %define RPM_MAJOR_VERSION 1.0.0
-%define RPM_MINOR_VERSION 17
+%define RPM_MINOR_VERSION 18
 
 Name:           %{RPM_NAME}
 Version:        %{RPM_MAJOR_VERSION}
index 733c270..6f3e53e 100644 (file)
   become_user: "{{ users.admin_user_name }}"
   roles:
     - install_caas_infra
+
+- hosts: caas_master
+  strategy: free
+  become: true
+  become_user: "{{ users.admin_user_name }}"
+  roles:
+    - post_install_caas_infra
diff --git a/ansible/roles/post_install_caas_infra/defaults/main.yaml b/ansible/roles/post_install_caas_infra/defaults/main.yaml
new file mode 100644 (file)
index 0000000..bc5f321
--- /dev/null
@@ -0,0 +1,20 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+caas_provider_network_profiles: "{{ network_profiles | filter_network_profiles_by_type('provider_network_interfaces', 'caas') }}"
+caas_sriov_network_profiles: "{{ network_profiles | filter_network_profiles_by_type('sriov_provider_networks', 'caas') }}"
+
+attached_caas_provider_network_profiles: "{{ hosts[hostname]['network_profiles'] | intersect(caas_provider_network_profiles.keys()) }}"
+attached_caas_sriov_network_profiles: "{{ hosts[hostname]['network_profiles'] | intersect(caas_sriov_network_profiles.keys()) }}"
+all_attached_caas_provider_network_profiles: "{{ attached_caas_provider_network_profiles | union(attached_caas_sriov_network_profiles) }}"
diff --git a/ansible/roles/post_install_caas_infra/tasks/main.yaml b/ansible/roles/post_install_caas_infra/tasks/main.yaml
new file mode 100644 (file)
index 0000000..d40da94
--- /dev/null
@@ -0,0 +1,23 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+- name: template DANM tenant configs
+  template:
+    src: "danm_tenant_config.yaml.j2"
+    dest: "{{ caas.manifests_directory }}/danm-tenant-config.yaml"
+
+- name: create DANM tenant configs
+  kubectl:
+    manifest: "{{ caas.manifests_directory }}/danm-tenant-config.yaml"
+    state: present
diff --git a/ansible/roles/post_install_caas_infra/templates/danm-tenant-config.yaml.j2 b/ansible/roles/post_install_caas_infra/templates/danm-tenant-config.yaml.j2
new file mode 100644 (file)
index 0000000..fcad90e
--- /dev/null
@@ -0,0 +1,62 @@
+#jinja2: lstrip_blocks: True
+{#
+Copyright 2019 Nokia
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+#}
+{%- macro make_host_devices(devices, provider_network) %}
+  {% for device in devices %}
+- name: {{ device }}
+  {{ make_vni_config(provider_network) | indent(2) }}
+  {% endfor %}
+{% endmacro -%}
+
+{%- macro make_vni_config(provider_network) %}
+  {% set vlan_ranges = provider_network.get('vlan_ranges', '') %}
+  {% set vxlan_ranges = provider_network.get('vxlan_ranges', '') %}
+  {% if vlan_ranges %}
+vniType: vlan
+vniRange: {{ vlan_ranges | replace(':', '-') }}
+  {% elif vxlan_ranges %}
+vniType: vxlan
+vniRange: {{ vxlan_ranges | replace(':', '-') }}
+  {% endif %}
+{% endmacro -%}
+
+---
+apiVersion: danm.k8s.io/v1
+kind: TenantConfig
+metadata:
+  name: danm-tenant-config
+hostDevices:
+{% caas_tenant_networks = caas.get('tenant_networks', []) %}
+{% if all_attached_caas_provider_network_profiles and caas_tenant_networks %}
+  {% for profile_name in all_attached_caas_provider_network_profiles %}
+    {% set profile = network_profiles[profile_name] %}
+    {% set caas_provider_networks = profile.get('provider_network_interfaces', {}) | filter_provider_networks_by_type('caas') %}
+    {% set caas_sriov_provider_networks = profile.get('sriov_provider_networks', {}) | filter_provider_networks_by_type('caas') %}
+    {% for tenant_network in caas_tenant_networks %}
+      {% if tenant_network in caas_provider_networks | get_provider_networks %}
+  {{ make_host_devices(caas_provider_networks.keys(), networking['provider_networks'][tenant_network]) | indent(2) -}}
+      {% elif tenant_network in caas_sriov_provider_networks %}
+        {% set sriov_interaces = caas_sriov_provider_networks | extract_sriov_provider_network_interfaces %}
+        {% set sriov_device_pools = sriov_interaces | map('regex_replace', '(.*)', 'nokia.k8s.io/sriov_\\1') | list %}
+  {{ make_host_devices(sriov_device_pools, networking['provider_networks'][tenant_network]) | indent(2) -}}
+      {% endif %}
+    {% endfor %}
+  {% endfor %}
+{%- else %}
+ []
+{% endif %}
+networkIds:
+  flannel: flannel