![Matt McEuen](/assets/img/avatar_default.png)
To facilitate catalogue-driven generation of BareMetalHost resources, airship splits the work into two pieces: 1. <phasename>/hostgenerator/ is responsible for substituting catalogue variables into a host generation template 2. <phasename>/ invokes its hostgenerator/ as a Kustomize generator:, leveraging the results of 1. to generate BMH. However, a weird side-effect of this setup is that the catalogues used in step 1. above are still hanging around in step 2., and Kustomize tries to interpret them as generator: plugin configs, resulting in a rendering error. Previously, we'd worked around this by having a pass-through plugin implementation, which performs a no-op generation for the spent catalogues. However, with the change below, airshipctl migrated to container-based KRM functions for its kustomize plugins, and also adopted a strategic-patch-delete mechanism to clean up the spent catalogues, so that they aren't still hanging around by the time the generation occurs. https://review.opendev.org/#/c/759279/ Change-Id: I50a9bd2fcc37b70f50b8ded88f152775aff928bc Closes: #48
72 lines
2.6 KiB
YAML
72 lines
2.6 KiB
YAML
# 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.
|
|
|
|
# TODO(drewwalters96): Move this logic to an airshipctl role so breaking changes
|
|
# do not impact Treasuremap.
|
|
|
|
- name: get BareMetalHost objects
|
|
shell: |
|
|
set -e
|
|
kustomize build --enable_alpha_plugins \
|
|
{{ airship_config_manifest_directory }}/{{ airship_config_site_path }}/{{ path }} 2>/dev/null |
|
|
kustomize cfg grep "kind=BareMetalHost"
|
|
register: bmh_command
|
|
failed_when: "bmh_command.stdout == ''"
|
|
environment:
|
|
KUSTOMIZE_PLUGIN_HOME: "/tmp"
|
|
KUSTOMIZE_ENABLE_ALPHA_COMMANDS: "true"
|
|
|
|
- set_fact:
|
|
bmh: "{{ bmh_command.stdout | from_yaml_all | list }}"
|
|
|
|
- name: get network configuration for BareMetalHost objects
|
|
shell: |
|
|
set -e
|
|
kustomize build --enable_alpha_plugins \
|
|
{{ airship_config_manifest_directory }}/{{ airship_config_site_path }}/{{ path }} 2>/dev/null |
|
|
kustomize cfg grep "metadata.name={{ item.spec.networkData.name }}"
|
|
register: netdata_command
|
|
failed_when: "netdata_command.stdout == ''"
|
|
environment:
|
|
KUSTOMIZE_PLUGIN_HOME: "/tmp"
|
|
KUSTOMIZE_ENABLE_ALPHA_COMMANDS: "true"
|
|
with_items: "{{ bmh }}"
|
|
|
|
- name: get links from network data per BareMetalHost object
|
|
set_fact:
|
|
links: |
|
|
{{
|
|
netdata_command.results |
|
|
map(attribute='stdout')| map('from_yaml') |
|
|
map(attribute='stringData.networkData') | map('from_yaml') |
|
|
map(attribute='links') | list
|
|
}}
|
|
- name: define list of VM mac addresses and VM boot mode
|
|
set_fact:
|
|
vm_cfg: "{{ dict(['boot_mode', 'nat_mac', 'provision_mac'] | zip([item.spec.bootMode, nat_mac_list[0], item.spec.bootMACAddress])) }}"
|
|
vars:
|
|
nat_mac_list: |
|
|
{{
|
|
links[idx] |
|
|
rejectattr('ethernet_mac_address', 'undefined') |
|
|
selectattr('ethernet_mac_address', '!=', item.spec.bootMACAddress) |
|
|
map(attribute='ethernet_mac_address') | list
|
|
}}
|
|
failed_when: nat_mac_list | length == 0
|
|
loop: "{{ bmh }}"
|
|
loop_control:
|
|
index_var: idx
|
|
register: vm_cfg_fact
|
|
|
|
- set_fact:
|
|
"{{ name }}_vm_cfg": "{{ vm_cfg_fact.results | map(attribute='ansible_facts.vm_cfg') | list }}"
|