diff --git a/agent/04_agent_configure.sh b/agent/04_agent_configure.sh index 15ea0c18f..3a3146e6d 100755 --- a/agent/04_agent_configure.sh +++ b/agent/04_agent_configure.sh @@ -17,83 +17,6 @@ early_deploy_validation export CLUSTER_NAMESPACE=${CLUSTER_NAMESPACE:-"cluster0"} -function get_nmstate_interface_block { - -index="$1" - -if [[ "$IP_STACK" = "v4" ]]; then - echo "ipv4: - enabled: true - address: - - ip: ${AGENT_NODES_IPS[index]} - prefix-length: ${CLUSTER_HOST_PREFIX_V4} - dhcp: false" -elif [[ "$IP_STACK" = "v6" ]]; then - echo "ipv6: - enabled: true - address: - - ip: ${AGENT_NODES_IPSV6[index]} - prefix-length: ${CLUSTER_HOST_PREFIX_V6} - dhcp: false" -else - # v4v6 - echo "ipv4: - enabled: true - address: - - ip: ${AGENT_NODES_IPS[index]} - prefix-length: ${CLUSTER_HOST_PREFIX_V4} - dhcp: false - ipv6: - enabled: true - address: - - ip: ${AGENT_NODES_IPSV6[index]} - prefix-length: ${CLUSTER_HOST_PREFIX_V6} - dhcp: false" -fi - -} - -function get_nmstate_dns_block { - -if [[ "$IP_STACK" != "v4v6" ]]; then - echo "server: - - ${PROVISIONING_HOST_EXTERNAL_IP}" - -else - provisioning_host_external_ipv6=$(nth_ip $EXTERNAL_SUBNET_V6 1) - echo "server: - - ${PROVISIONING_HOST_EXTERNAL_IP} - - ${provisioning_host_external_ipv6}" -fi - -} - -function get_nmstate_route_block { - -if [[ "$IP_STACK" = "v4" ]]; then - echo "- destination: 0.0.0.0/0 - next-hop-address: ${PROVISIONING_HOST_EXTERNAL_IP} - next-hop-interface: eth0 - table-id: 254" -elif [[ "$IP_STACK" = "v6" ]]; then - echo "- destination: ::/0 - next-hop-address: ${PROVISIONING_HOST_EXTERNAL_IP} - next-hop-interface: eth0 - table-id: 254" -else - provisioning_host_external_ipv6=$(nth_ip $EXTERNAL_SUBNET_V6 1) - echo "- destination: 0.0.0.0/0 - next-hop-address: ${PROVISIONING_HOST_EXTERNAL_IP} - next-hop-interface: eth0 - table-id: 254 - - destination: ::/0 - next-hop-address: ${provisioning_host_external_ipv6} - next-hop-interface: eth0 - table-id: 254" -fi - -} - function add_dns_entry { ip=${1} hostname=${2} @@ -155,211 +78,6 @@ function get_static_ips_and_macs() { done } -function setNetworkingVars() { - if [[ "$IP_STACK" = "v4" ]]; then - cluster_network=${CLUSTER_SUBNET_V4} - service_network=${SERVICE_SUBNET_V4} - machine_network=${EXTERNAL_SUBNET_V4} - cluster_host_prefix=${CLUSTER_HOST_PREFIX_V4} - elif [[ "$IP_STACK" = "v6" ]]; then - cluster_network=${CLUSTER_SUBNET_V6} - service_network=${SERVICE_SUBNET_V6} - machine_network=${EXTERNAL_SUBNET_V6} - cluster_host_prefix=${CLUSTER_HOST_PREFIX_V6} - fi -} - -function generate_cluster_manifests() { - - MANIFESTS_PATH="${OCP_DIR}/cluster-manifests" - MIRROR_PATH="${OCP_DIR}/mirror" - - # Fetch current OpenShift version from the release payload - VERSION="$(openshift_version ${OCP_DIR})" - - mkdir -p ${MANIFESTS_PATH} - if [ ! -z "${MIRROR_IMAGES}" ]; then - mkdir -p ${MIRROR_PATH} - fi - - setNetworkingVars - - cat > "${MANIFESTS_PATH}/agent-cluster-install.yaml" << EOF -apiVersion: extensions.hive.openshift.io/v1beta1 -kind: AgentClusterInstall -metadata: - name: test-agent-cluster-install - namespace: ${CLUSTER_NAMESPACE} -spec: -EOF -if [[ "${NUM_MASTERS}" > "1" ]]; then -cat >> "${MANIFESTS_PATH}/agent-cluster-install.yaml" << EOF - apiVIP: ${API_VIPS%${VIPS_SEPARATOR}*} - ingressVIP: ${INGRESS_VIPS%${VIPS_SEPARATOR}*} -EOF -fi - -if [[ "$IP_STACK" != "v4v6" ]]; then -cat >> "${MANIFESTS_PATH}/agent-cluster-install.yaml" << EOF - clusterDeploymentRef: - name: ${CLUSTER_NAME} - imageSetRef: - name: openshift-${VERSION} - networking: - clusterNetwork: - - cidr: ${cluster_network} - hostPrefix: ${cluster_host_prefix} - serviceNetwork: - - ${service_network} - machineNetwork: - - cidr: ${machine_network} - networkType: ${NETWORK_TYPE} - provisionRequirements: - controlPlaneAgents: ${NUM_MASTERS} - workerAgents: ${NUM_WORKERS} - sshPublicKey: ${SSH_PUB_KEY} -EOF -else -cat >> "${MANIFESTS_PATH}/agent-cluster-install.yaml" << EOF - clusterDeploymentRef: - name: ${CLUSTER_NAME} - imageSetRef: - name: openshift-${VERSION} - networking: - clusterNetwork: - - cidr: ${CLUSTER_SUBNET_V4} - hostPrefix: ${CLUSTER_HOST_PREFIX_V4} - - cidr: ${CLUSTER_SUBNET_V6} - hostPrefix: ${CLUSTER_HOST_PREFIX_V6} - serviceNetwork: - - ${SERVICE_SUBNET_V4} - - ${SERVICE_SUBNET_V6} - machineNetwork: - - cidr: ${EXTERNAL_SUBNET_V4} - - cidr: ${EXTERNAL_SUBNET_V6} - networkType: ${NETWORK_TYPE} - provisionRequirements: - controlPlaneAgents: ${NUM_MASTERS} - workerAgents: ${NUM_WORKERS} - sshPublicKey: ${SSH_PUB_KEY} -EOF -fi - - cat > "${MANIFESTS_PATH}/cluster-deployment.yaml" << EOF -apiVersion: hive.openshift.io/v1 -kind: ClusterDeployment -metadata: - name: ${CLUSTER_NAME} - namespace: ${CLUSTER_NAMESPACE} -spec: - baseDomain: ${BASE_DOMAIN} - clusterInstallRef: - group: extensions.hive.openshift.io - kind: AgentClusterInstall - name: test-agent-cluster-install - version: v1beta1 - clusterName: ${CLUSTER_NAME} - pullSecretRef: - name: pull-secret -EOF - - cat > "${MANIFESTS_PATH}/cluster-image-set.yaml" << EOF -apiVersion: hive.openshift.io/v1 -kind: ClusterImageSet -metadata: - name: openshift-${VERSION} -spec: - releaseImage: $(getReleaseImage) -EOF - -if [[ ! -z "${MIRROR_IMAGES}" ]]; then - - # Set up registries.conf and ca-bundle.crt for mirroring - get_mirror_info - - ansible-playbook "${SCRIPTDIR}/agent/assets/ztp/registries-conf-playbook.yaml" -e "mirror_path=${SCRIPTDIR}/${MIRROR_PATH}" - - # Store the certs for registry - if [[ "${REGISTRY_BACKEND}" = "podman" ]]; then - cp $REGISTRY_DIR/certs/$REGISTRY_CRT ${MIRROR_PATH}/ca-bundle.crt - else - cp ${WORKING_DIR}/quay-install/quay-rootCA/rootCA.pem ${MIRROR_PATH}/ca-bundle.crt - fi -fi - - cat > "${MANIFESTS_PATH}/infraenv.yaml" << EOF -apiVersion: agent-install.openshift.io/v1beta1 -kind: InfraEnv -metadata: - name: myinfraenv - namespace: ${CLUSTER_NAMESPACE} -spec: - clusterRef: - name: ${CLUSTER_NAME} - namespace: ${CLUSTER_NAMESPACE} - pullSecretRef: - name: pull-secret - sshAuthorizedKey: ${SSH_PUB_KEY} - nmStateConfigLabelSelector: - matchLabels: - ${CLUSTER_NAMESPACE}-nmstate-label-name: ${CLUSTER_NAMESPACE}-nmstate-label-value -EOF - - set +x - pull_secret=$(cat $PULL_SECRET_FILE) - cat > "${MANIFESTS_PATH}/pull-secret.yaml" << EOF -apiVersion: v1 -kind: Secret -type: kubernetes.io/dockerconfigjson -metadata: - name: pull-secret - namespace: ${CLUSTER_NAMESPACE} -stringData: - .dockerconfigjson: '${pull_secret}' - -EOF - - if [[ "$IP_STACK" = "v4" ]]; then - num_ips=${#AGENT_NODES_IPS[@]} - else - num_ips=${#AGENT_NODES_IPSV6[@]} - fi - - # Create a yaml for each host in nmstateconfig.yaml - for (( i=0; i<$num_ips; i++ )) - do - cat >> "${MANIFESTS_PATH}/nmstateconfig.yaml" << EOF -apiVersion: agent-install.openshift.io/v1beta1 -kind: NMStateConfig -metadata: - name: ${AGENT_NODES_HOSTNAMES[i]} - namespace: openshift-machine-api - labels: - ${CLUSTER_NAMESPACE}-nmstate-label-name: ${CLUSTER_NAMESPACE}-nmstate-label-value -spec: - config: - interfaces: - - name: eth0 - type: ethernet - state: up - mac-address: ${AGENT_NODES_MACS[i]} - $(get_nmstate_interface_block i) - dns-resolver: - config: - $(get_nmstate_dns_block) - routes: - config: - $(get_nmstate_route_block) - interfaces: - - name: "eth0" - macAddress: ${AGENT_NODES_MACS[i]} ---- -EOF - done - - set -x -} - function generate_extra_cluster_manifests() { EXTRA_MANIFESTS_PATH="${OCP_DIR}/openshift" @@ -376,7 +94,7 @@ data: EOF if [ ! -z "${AGENT_DEPLOY_MCE}" ]; then - cp ${SCRIPTDIR}/agent/assets/mce/agent_mce_0_*.yaml ${EXTRA_MANIFESTS_PATH} + cp ${SCRIPTDIR}/agent/mce/agent_mce_0_*.yaml ${EXTRA_MANIFESTS_PATH} fi } @@ -462,11 +180,23 @@ function get_mirror_info { export MIRROR_INFO_FILE=${tmpmirrorinfo} } -function generate_install_agent_config() { +function generate_cluster_manifests() { INSTALL_CONFIG_PATH="${OCP_DIR}" mkdir -p ${INSTALL_CONFIG_PATH} + export MANIFESTS_PATH="${SCRIPTDIR}/${OCP_DIR}/cluster-manifests" + mkdir -p ${MANIFESTS_PATH} + + export MIRROR_PATH="${SCRIPTDIR}/${OCP_DIR}/mirror" + if [ ! -z "${MIRROR_IMAGES}" ]; then + mkdir -p ${MIRROR_PATH} + fi + + # Fetch current OpenShift version from the release payload + export VERSION="$(openshift_version ${OCP_DIR})" + export IMAGE=$(getReleaseImage) + # set arrays as strings to pass in env nodes_ips=$(printf '%s,' "${AGENT_NODES_IPS[@]}") export AGENT_NODES_IPS_STR=${nodes_ips::-1} @@ -480,6 +210,8 @@ function generate_install_agent_config() { if [[ "${NUM_MASTERS}" > "1" ]]; then export API_VIPS=${API_VIPS} export INGRESS_VIPS=${INGRESS_VIPS} + export API_VIP=${API_VIPS%${VIPS_SEPARATOR}*} + export INGRESS_VIP=${INGRESS_VIPS%${VIPS_SEPARATOR}*} fi if [[ "$IP_STACK" = "v4v6" ]]; then @@ -497,9 +229,10 @@ function generate_install_agent_config() { get_mirror_info fi + # Create manifests ansible-playbook -vvv \ -e install_path=${SCRIPTDIR}/${INSTALL_CONFIG_PATH} \ - "${SCRIPTDIR}/agent/assets/installconfig/install-agent-config-playbook.yaml" + "${SCRIPTDIR}/agent/create-manifests-playbook.yaml" } @@ -537,22 +270,6 @@ else configure_dnsmasq ${ip} "" fi -MANIFESTS_PATH="${OCP_DIR}/cluster-manifests" - -mkdir -p ${MANIFESTS_PATH} -if [ ! -z "${MIRROR_IMAGES}" ]; then - export MIRROR_PATH="${SCRIPTDIR}/${OCP_DIR}/mirror" - mkdir -p ${MIRROR_PATH} -fi - -if [[ ${AGENT_USE_ZTP_MANIFESTS} == true ]]; then - - generate_cluster_manifests - - else - - generate_install_agent_config - -fi +generate_cluster_manifests generate_extra_cluster_manifests diff --git a/agent/05_agent_create_cluster.sh b/agent/05_agent_create_cluster.sh index 10ffb54eb..088154172 100755 --- a/agent/05_agent_create_cluster.sh +++ b/agent/05_agent_create_cluster.sh @@ -106,7 +106,7 @@ function mce_prepare_postinstallation_manifests() { local mceManifests=$1 # Copy all the manifests required after the installation completed - cp ${SCRIPTDIR}/agent/assets/mce/agent_mce_1*.yaml ${mceManifests} + cp ${SCRIPTDIR}/agent/mce/agent_mce_1*.yaml ${mceManifests} # Render the cluster image set template local clusterImageSetTemplate=${mceManifests}/agent_mce_1_04_clusterimageset.yaml diff --git a/agent/assets/installconfig/agent-config_yaml.j2 b/agent/assets/installconfig/agent-config_yaml.j2 deleted file mode 100644 index f225b8821..000000000 --- a/agent/assets/installconfig/agent-config_yaml.j2 +++ /dev/null @@ -1,87 +0,0 @@ -{% set ips = agent_nodes_ips.split(',') %} -{% set ipsv6 = agent_nodes_ipsv6.split(',') %} -{% set macs = agent_nodes_macs.split(',') %} -{% set hostnames = agent_nodes_hostnames.split(',') %} -apiVersion: v1alpha1 -metadata: - name: {{ cluster_name }} - namespace: {{ cluster_namespace }} -rendezvousIP: {{ ips[0] }} -{% if networking_mode != "dhcp" %} -hosts: -{% for hostname in hostnames %} - - hostname: {{ hostname }} - interfaces: - - name: eth0 - macAddress: {{ macs[loop.index0] }} - networkConfig: - interfaces: - - name: eth0 - type: ethernet - state: up - mac-address: {{ macs[loop.index0] }} -{% if ip_stack == "v4" %} - ipv4: - enabled: true - address: - - ip: {{ ips[loop.index0] }} - prefix-length: {{ cluster_host_prefix_v4 }} - dhcp: false - dns-resolver: - config: - server: - - {{ provisioning_host_external_ip }} - routes: - config: - - destination: 0.0.0.0/0 - next-hop-address: {{ provisioning_host_external_ip }} - next-hop-interface: eth0 - table-id: 254 -{% elif ip_stack == "v6" %} - ipv6: - enabled: true - address: - - ip: {{ ipsv6[loop.index0] }} - prefix-length: {{ cluster_host_prefix_v6 }} - dhcp: false - dns-resolver: - config: - server: - - {{ provisioning_host_external_ip }} - routes: - config: - - destination: ::/0 - next-hop-address: {{ provisioning_host_external_ip }} - next-hop-interface: eth0 - table-id: 254 -{% else %} - ipv4: - enabled: true - address: - - ip: {{ ips[loop.index0] }} - prefix-length: {{ cluster_host_prefix_v4 }} - dhcp: false - ipv6: - enabled: true - address: - - ip: {{ ipsv6[loop.index0] }} - prefix-length: {{ cluster_host_prefix_v6 }} - dhcp: false - dns-resolver: - config: - server: - - {{ provisioning_host_external_ip }} - - {{ provisioning_host_external_ip_dualstack }} - routes: - config: - - destination: 0.0.0.0/0 - next-hop-address: {{ provisioning_host_external_ip }} - next-hop-interface: eth0 - table-id: 254 - - destination: ::/0 - next-hop-address: {{ provisioning_host_external_ip_dualstack }} - next-hop-interface: eth0 - table-id: 254 -{% endif %} -{% endfor %} -{% endif %} diff --git a/agent/assets/installconfig/install-agent-config-playbook.yaml b/agent/assets/installconfig/install-agent-config-playbook.yaml deleted file mode 100644 index 94424f184..000000000 --- a/agent/assets/installconfig/install-agent-config-playbook.yaml +++ /dev/null @@ -1,61 +0,0 @@ -- name: Create install-config and agent-config for Agent Installer - hosts: localhost - collections: - - community.general - gather_facts: no - vars: - - agent_deploy_mce: "{{ lookup('env', 'AGENT_DEPLOY_MCE') }}" - - cluster_name: "{{ lookup('env', 'CLUSTER_NAME') }}" - - cluster_namespace: "{{ lookup('env', 'CLUSTER_NAMESPACE') }}" - - base_domain: "{{ lookup('env', 'BASE_DOMAIN') }}" - - num_workers: "{{ lookup('env', 'NUM_WORKERS') }}" - - num_masters: "{{ lookup('env', 'NUM_MASTERS') }}" - - network_type: "{{ lookup('env', 'NETWORK_TYPE') }}" - - ip_stack: "{{ lookup('env', 'IP_STACK') }}" - - agent_nodes_macs: "{{ lookup('env', 'AGENT_NODES_MACS_STR') }}" - - agent_nodes_ips: "{{ lookup('env', 'AGENT_NODES_IPS_STR') }}" - - agent_nodes_ipsv6: "{{ lookup('env', 'AGENT_NODES_IPSV6_STR') }}" - - agent_nodes_hostnames: "{{ lookup('env', 'AGENT_NODES_HOSTNAMES_STR') }}" - - cluster_host_prefix_v4: "{{ lookup('env', 'CLUSTER_HOST_PREFIX_V4') }}" - - cluster_host_prefix_v6: "{{ lookup('env', 'CLUSTER_HOST_PREFIX_V6') }}" - - cluster_subnet_v4: "{{ lookup('env', 'CLUSTER_SUBNET_V4') }}" - - cluster_subnet_v6: "{{ lookup('env', 'CLUSTER_SUBNET_V6') }}" - - service_subnet_v4: "{{ lookup('env', 'SERVICE_SUBNET_V4') }}" - - service_subnet_v6: "{{ lookup('env', 'SERVICE_SUBNET_V6') }}" - - external_subnet_v4: "{{ lookup('env', 'EXTERNAL_SUBNET_V4') }}" - - external_subnet_v6: "{{ lookup('env', 'EXTERNAL_SUBNET_V6') }}" - - provisioning_host_external_ip: "{{ lookup('env', 'PROVISIONING_HOST_EXTERNAL_IP') }}" - - networking_mode: "{{ lookup('env', 'NETWORKING_MODE') }}" - - ssh_pub_key: "{{ lookup('env', 'SSH_PUB_KEY') }}" - - pull_secret: "{{ lookup('env', 'PULL_SECRET_FILE') }}" - - pull_secret_contents: "{{ lookup('file', pull_secret) | to_json }}" - - mirror_images: "{{ lookup('env', 'MIRROR_IMAGES') }}" - - mirror_path: "{{ lookup('env', 'MIRROR_PATH') }}" - - mirror_info_file: "{{ lookup('env', 'MIRROR_INFO_FILE', default='') }}" - - mirror_command: "{{ lookup('env', 'MIRROR_COMMAND') }}" - - local_registry_dns_name: "{{ lookup('env', 'LOCAL_REGISTRY_DNS_NAME') }}" - - local_registry_port: "{{ lookup('env', 'LOCAL_REGISTRY_PORT') }}" - - tasks: - - name: Get files for mirror configuration - set_fact: - ca_bundle_crt: "{{ lookup('file', mirror_path + '/ca-bundle.crt') | to_json }}" - image_content_sources: "{{ lookup('file', mirror_info_file) }}" - when: mirror_images == 'true' - - name: Get VIPs when not using SNO - set_fact: - ingress_vips: "{{ lookup('env', 'INGRESS_VIPS') }}" - api_vips: "{{ lookup('env', 'API_VIPS') }}" - when: num_masters != 1 - - name: Get external IPV6 address when set for dualstack - set_fact: - provisioning_host_external_ip_dualstack: "{{ lookup('env', 'PROVISIONING_HOST_EXTERNAL_IP_DUALSTACK') }}" - when: ip_stack == 'v4v6' - - name: write the install-config.yaml - template: - src: "install-config_yaml.j2" - dest: "{{ install_path }}/install-config.yaml" - - name: write the agent-config.yaml - template: - src: "agent-config_yaml.j2" - dest: "{{ install_path }}/agent-config.yaml" diff --git a/agent/assets/ztp/registries-conf-playbook.yaml b/agent/assets/ztp/registries-conf-playbook.yaml deleted file mode 100644 index 6d33472c9..000000000 --- a/agent/assets/ztp/registries-conf-playbook.yaml +++ /dev/null @@ -1,23 +0,0 @@ -- name: Create registries.conf for Agent Installer - hosts: localhost - collections: - - community.general - gather_facts: no - vars: - - agent_deploy_mce: "{{ lookup('env', 'AGENT_DEPLOY_MCE') }}" - - local_registry_dns_name: "{{ lookup('env', 'LOCAL_REGISTRY_DNS_NAME') }}" - - local_registry_port: "{{ lookup('env', 'LOCAL_REGISTRY_PORT') }}" - - mirror_images: "{{ lookup('env', 'MIRROR_IMAGES') }}" - - mirror_path: "{{ lookup('env', 'MIRROR_PATH') }}" - - mirror_command: "{{ lookup('env', 'MIRROR_COMMAND') }}" - - mirror_info_file: "{{ lookup('env', 'MIRROR_INFO_FILE', default='') }}" - - tasks: - - name: Get mirror settings - set_fact: - registries: "{{ lookup('file', mirror_info_file) }}" - when: mirror_images == 'true' - - name: write the registries.conf - template: - src: "registries_conf.j2" - dest: "{{ mirror_path }}/registries.conf" diff --git a/agent/common.sh b/agent/common.sh index 75f714015..70887bed0 100644 --- a/agent/common.sh +++ b/agent/common.sh @@ -3,7 +3,7 @@ set -euxo pipefail export AGENT_STATIC_IP_NODE0_ONLY=${AGENT_STATIC_IP_NODE0_ONLY:-"false"} -export AGENT_USE_ZTP_MANIFESTS=${AGENT_USE_ZTP_MANIFESTS=:-"false"} +export AGENT_USE_ZTP_MANIFESTS=${AGENT_USE_ZTP_MANIFESTS:-"false"} # Override command name in case of extraction export OPENSHIFT_INSTALLER_CMD="openshift-install" diff --git a/agent/create-manifests-playbook.yaml b/agent/create-manifests-playbook.yaml new file mode 100644 index 000000000..e3b30ee0f --- /dev/null +++ b/agent/create-manifests-playbook.yaml @@ -0,0 +1,7 @@ +- name: Create manifests to use for the Agent Installer + hosts: localhost + collections: + - community.general + gather_facts: true + roles: + - role: manifests diff --git a/agent/assets/mce/agent_mce_0_01_lso_namespace.yaml b/agent/mce/agent_mce_0_01_lso_namespace.yaml similarity index 100% rename from agent/assets/mce/agent_mce_0_01_lso_namespace.yaml rename to agent/mce/agent_mce_0_01_lso_namespace.yaml diff --git a/agent/assets/mce/agent_mce_0_02_lso_operatorgroup.yaml b/agent/mce/agent_mce_0_02_lso_operatorgroup.yaml similarity index 100% rename from agent/assets/mce/agent_mce_0_02_lso_operatorgroup.yaml rename to agent/mce/agent_mce_0_02_lso_operatorgroup.yaml diff --git a/agent/assets/mce/agent_mce_0_03_lso_subscription.yaml b/agent/mce/agent_mce_0_03_lso_subscription.yaml similarity index 100% rename from agent/assets/mce/agent_mce_0_03_lso_subscription.yaml rename to agent/mce/agent_mce_0_03_lso_subscription.yaml diff --git a/agent/assets/mce/agent_mce_0_03_mce_namespace.yaml b/agent/mce/agent_mce_0_03_mce_namespace.yaml similarity index 100% rename from agent/assets/mce/agent_mce_0_03_mce_namespace.yaml rename to agent/mce/agent_mce_0_03_mce_namespace.yaml diff --git a/agent/assets/mce/agent_mce_0_04_mce_operatorgroup.yaml b/agent/mce/agent_mce_0_04_mce_operatorgroup.yaml similarity index 100% rename from agent/assets/mce/agent_mce_0_04_mce_operatorgroup.yaml rename to agent/mce/agent_mce_0_04_mce_operatorgroup.yaml diff --git a/agent/assets/mce/agent_mce_0_05_mce_subscription.yaml b/agent/mce/agent_mce_0_05_mce_subscription.yaml similarity index 100% rename from agent/assets/mce/agent_mce_0_05_mce_subscription.yaml rename to agent/mce/agent_mce_0_05_mce_subscription.yaml diff --git a/agent/assets/mce/agent_mce_1_01_localvolumes.yaml b/agent/mce/agent_mce_1_01_localvolumes.yaml similarity index 100% rename from agent/assets/mce/agent_mce_1_01_localvolumes.yaml rename to agent/mce/agent_mce_1_01_localvolumes.yaml diff --git a/agent/assets/mce/agent_mce_1_02_mce.yaml b/agent/mce/agent_mce_1_02_mce.yaml similarity index 100% rename from agent/assets/mce/agent_mce_1_02_mce.yaml rename to agent/mce/agent_mce_1_02_mce.yaml diff --git a/agent/assets/mce/agent_mce_1_03_agentserviceconfig.yaml b/agent/mce/agent_mce_1_03_agentserviceconfig.yaml similarity index 100% rename from agent/assets/mce/agent_mce_1_03_agentserviceconfig.yaml rename to agent/mce/agent_mce_1_03_agentserviceconfig.yaml diff --git a/agent/assets/mce/agent_mce_1_04_clusterimageset.yaml b/agent/mce/agent_mce_1_04_clusterimageset.yaml similarity index 100% rename from agent/assets/mce/agent_mce_1_04_clusterimageset.yaml rename to agent/mce/agent_mce_1_04_clusterimageset.yaml diff --git a/agent/assets/mce/agent_mce_1_05_autoimport.yaml b/agent/mce/agent_mce_1_05_autoimport.yaml similarity index 100% rename from agent/assets/mce/agent_mce_1_05_autoimport.yaml rename to agent/mce/agent_mce_1_05_autoimport.yaml diff --git a/agent/roles/manifests/tasks/install-config.yml b/agent/roles/manifests/tasks/install-config.yml new file mode 100644 index 000000000..9e9e195c6 --- /dev/null +++ b/agent/roles/manifests/tasks/install-config.yml @@ -0,0 +1,14 @@ +- name: Get mirror settings + set_fact: + image_content_sources: "{{ lookup('file', mirror_info_file) }}" + when: mirror_images == 'true' + +- name: write the install-config.yaml + template: + src: "templates/install-config_yaml.j2" + dest: "{{ install_path }}/install-config.yaml" + +- name: write the agent-config.yaml + template: + src: "agent-config_yaml.j2" + dest: "{{ install_path }}/agent-config.yaml" diff --git a/agent/roles/manifests/tasks/main.yml b/agent/roles/manifests/tasks/main.yml new file mode 100644 index 000000000..96c864efa --- /dev/null +++ b/agent/roles/manifests/tasks/main.yml @@ -0,0 +1,23 @@ +- name: Get additional trust bundle + set_fact: + ca_bundle_crt: "{{ lookup('file', mirror_path + '/ca-bundle.crt') | to_json }}" + when: mirror_images == 'true' + +- name: Get VIPs when not using SNO + set_fact: + ingress_vips: "{{ lookup('env', 'INGRESS_VIPS') }}" + api_vips: "{{ lookup('env', 'API_VIPS') }}" + when: num_masters != 1 + +- name: Get external IPV6 address when set for dualstack + set_fact: + provisioning_host_external_ip_dualstack: "{{ lookup('env', 'PROVISIONING_HOST_EXTERNAL_IP_DUALSTACK') }}" + when: ip_stack == 'v4v6' + +- name: Create install-config and agent-config manifests + import_tasks: install-config.yml + when: agent_use_ztp_manifests == 'false' + +- name: Create ZTP based manifests + import_tasks: ztp.yml + when: agent_use_ztp_manifests == 'true' diff --git a/agent/roles/manifests/tasks/ztp.yml b/agent/roles/manifests/tasks/ztp.yml new file mode 100644 index 000000000..1d882e8f6 --- /dev/null +++ b/agent/roles/manifests/tasks/ztp.yml @@ -0,0 +1,46 @@ +- name: Get VIP, only one is currently supported + set_fact: + api_vip: "{{ lookup('env', 'API_VIP') }}" + ingress_vip: "{{ lookup('env', 'INGRESS_VIP') }}" + when: num_masters != 1 + +- name: Write agent-cluster-install.yaml + template: + src: "agent-cluster-install_yaml.j2" + dest: "{{ manifests_path }}/agent-cluster-install.yaml" + +- name: Write cluster-image-set.yaml + template: + src: "cluster-image-set_yaml.j2" + dest: "{{ manifests_path }}/cluster-image-set.yaml" + +- name: Write cluster-deployment.yaml + template: + src: "cluster-deployment_yaml.j2" + dest: "{{ manifests_path }}/cluster-deployment.yaml" + +- name: Write infraenv.yaml + template: + src: "infraenv_yaml.j2" + dest: "{{ manifests_path }}/infraenv.yaml" + +- name: Write pull-secret.yaml + template: + src: "pull-secret_yaml.j2" + dest: "{{ manifests_path }}/pull-secret.yaml" + +- name: Write nmstateconfig.yaml + template: + src: "nmstateconfig_yaml.j2" + dest: "{{ manifests_path }}/nmstateconfig.yaml" + +- name: Get mirror settings + set_fact: + registries: "{{ lookup('file', mirror_info_file) }}" + when: mirror_images == 'true' + +- name: Write registries.conf + template: + src: "registries_conf.j2" + dest: "{{ mirror_path }}/registries.conf" + when: mirror_images == 'true' diff --git a/agent/roles/manifests/templates/agent-cluster-install_yaml.j2 b/agent/roles/manifests/templates/agent-cluster-install_yaml.j2 new file mode 100644 index 000000000..69209d8e1 --- /dev/null +++ b/agent/roles/manifests/templates/agent-cluster-install_yaml.j2 @@ -0,0 +1,49 @@ +apiVersion: extensions.hive.openshift.io/v1beta1 +kind: AgentClusterInstall +metadata: + name: test-agent-cluster-install + namespace: {{ cluster_namespace }} +spec: +{% if num_masters != "1" %} + apiVIP: {{ api_vip }} + ingressVIP: {{ ingress_vip }} +{% endif %} + clusterDeploymentRef: + name: {{ cluster_name }} + imageSetRef: + name: openshift-{{ version }} + networking: +{% if ip_stack == "v4" %} + clusterNetwork: + - cidr: {{ cluster_subnet_v4 }} + hostPrefix: {{ cluster_host_prefix_v4 }} + serviceNetwork: + - {{ service_subnet_v4 }} + machineNetwork: + - cidr: {{ external_subnet_v4 }} +{% elif ip_stack == "v6" %} + clusterNetwork: + - cidr: {{ cluster_subnet_v6 }} + hostPrefix: {{ cluster_host_prefix_v6 }} + serviceNetwork: + - {{ service_subnet_v6 }} + machineNetwork: + - cidr: {{ external_subnet_v6 }} +{% else %} + clusterNetwork: + - cidr: {{ cluster_subnet_v4 }} + hostPrefix: {{ cluster_host_prefix_v4 }} + - cidr: {{ cluster_subnet_v6 }} + hostPrefix: {{ cluster_host_prefix_v6 }} + serviceNetwork: + - {{ service_subnet_v4 }} + - {{ service_subnet_v6 }} + machineNetwork: + - cidr: {{ external_subnet_v4 }} + - cidr: {{ external_subnet_v6 }} +{% endif %} + networkType: {{ network_type }} + provisionRequirements: + controlPlaneAgents: {{ num_masters }} + workerAgents: {{ num_workers }} + sshPublicKey: {{ ssh_pub_key }} diff --git a/agent/roles/manifests/templates/agent-config_yaml.j2 b/agent/roles/manifests/templates/agent-config_yaml.j2 new file mode 100644 index 000000000..ebadbfd53 --- /dev/null +++ b/agent/roles/manifests/templates/agent-config_yaml.j2 @@ -0,0 +1,40 @@ +{% import 'net_macros.yaml' as net %} + +{% set ips = agent_nodes_ips.split(',') %} +{% set ipsv6 = agent_nodes_ipsv6.split(',') %} +{% set macs = agent_nodes_macs.split(',') %} +{% set hostnames = agent_nodes_hostnames.split(',') %} +apiVersion: v1alpha1 +metadata: + name: {{ cluster_name }} + namespace: {{ cluster_namespace }} +rendezvousIP: {{ ips[0] }} +{% if networking_mode != "dhcp" %} +hosts: +{% for hostname in hostnames %} + - hostname: {{ hostname }} + interfaces: + - name: eth0 + macAddress: {{ macs[loop.index0] }} + networkConfig: + {{ net.interfaces(macs[loop.index0])|indent(4, True) }} +{% if ip_stack == "v4" %} + ipv4: + {{ net.ip(ips[loop.index0], cluster_host_prefix_v4)|indent(4, True) }} + {{ net.dns(provisioning_host_external_ip)|indent(4, True) }} + {{ net.route("0.0.0.0/0", provisioning_host_external_ip)|indent(4, True) }} +{% elif ip_stack == "v6" %} + ipv6: + {{ net.ip(ipsv6[loop.index0], cluster_host_prefix_v6)|indent(4, True) }} + {{ net.dns(provisioning_host_external_ip)|indent(4, True) }} + {{ net.route("::/0", provisioning_host_external_ip)|indent(4, True) }} +{% else %} + ipv4: + {{ net.ip(ips[loop.index0], cluster_host_prefix_v4)|indent(4, True) }} + ipv6: + {{ net.ip(ipsv6[loop.index0], cluster_host_prefix_v6)|indent(4, True) }} + {{ net.dns_dualstack(provisioning_host_external_ip, provisioning_host_external_ip_dualstack)|indent(4, True) }} + {{ net.route_dualstack(provisioning_host_external_ip, provisioning_host_external_ip_dualstack)|indent(4, True) }} +{% endif %} +{% endfor %} +{% endif %} diff --git a/agent/roles/manifests/templates/cluster-deployment_yaml.j2 b/agent/roles/manifests/templates/cluster-deployment_yaml.j2 new file mode 100644 index 000000000..f705d3f1f --- /dev/null +++ b/agent/roles/manifests/templates/cluster-deployment_yaml.j2 @@ -0,0 +1,15 @@ +apiVersion: hive.openshift.io/v1 +kind: ClusterDeployment +metadata: + name: {{ cluster_name }} + namespace: {{ cluster_namespace }} +spec: + baseDomain: {{ base_domain }} + clusterInstallRef: + group: extensions.hive.openshift.io + kind: AgentClusterInstall + name: test-agent-cluster-install + version: v1beta1 + clusterName: {{ cluster_name }} + pullSecretRef: + name: pull-secret diff --git a/agent/roles/manifests/templates/cluster-image-set_yaml.j2 b/agent/roles/manifests/templates/cluster-image-set_yaml.j2 new file mode 100644 index 000000000..6cd4998f1 --- /dev/null +++ b/agent/roles/manifests/templates/cluster-image-set_yaml.j2 @@ -0,0 +1,6 @@ +apiVersion: hive.openshift.io/v1 +kind: ClusterImageSet +metadata: + name: openshift-{{ version }} +spec: + releaseImage: {{ image }} diff --git a/agent/roles/manifests/templates/infraenv_yaml.j2 b/agent/roles/manifests/templates/infraenv_yaml.j2 new file mode 100644 index 000000000..1d87e1f6e --- /dev/null +++ b/agent/roles/manifests/templates/infraenv_yaml.j2 @@ -0,0 +1,15 @@ +apiVersion: agent-install.openshift.io/v1beta1 +kind: InfraEnv +metadata: + name: myinfraenv + namespace: {{ cluster_namespace }} +spec: + clusterRef: + name: {{ cluster_name }} + namespace: {{ cluster_namespace }} + pullSecretRef: + name: pull-secret + sshAuthorizedKey: {{ ssh_pub_key }} + nmStateConfigLabelSelector: + matchLabels: + {{ cluster_namespace }}-nmstate-label-name: {{ cluster_namespace }}-nmstate-label-value diff --git a/agent/assets/installconfig/install-config_yaml.j2 b/agent/roles/manifests/templates/install-config_yaml.j2 similarity index 100% rename from agent/assets/installconfig/install-config_yaml.j2 rename to agent/roles/manifests/templates/install-config_yaml.j2 diff --git a/agent/roles/manifests/templates/net_macros.yaml b/agent/roles/manifests/templates/net_macros.yaml new file mode 100644 index 000000000..524ab8af7 --- /dev/null +++ b/agent/roles/manifests/templates/net_macros.yaml @@ -0,0 +1,52 @@ +{% macro interfaces(mac) -%} + interfaces: + - name: eth0 + type: ethernet + state: up + mac-address: {{ mac }} +{%- endmacro %} + +{% macro ip(ip, prefix) -%} + enabled: true + address: + - ip: {{ ip }} + prefix-length: {{ prefix }} + dhcp: false +{%- endmacro %} + +{% macro dns(ext_ip) -%} + dns-resolver: + config: + server: + - {{ ext_ip }} +{%- endmacro %} + +{% macro route(dest, ext_ip) -%} + routes: + config: + - destination: {{ dest }} + next-hop-address: {{ ext_ip }} + next-hop-interface: eth0 + table-id: 254 +{%- endmacro %} + +{% macro dns_dualstack(ext_ip, dualstack_ext_ip) -%} + dns-resolver: + config: + server: + - {{ ext_ip }} + - {{ dualstack_ext_ip }} +{%- endmacro %} + +{% macro route_dualstack(ext_ip, dualstack_ext_ip) -%} + routes: + config: + - destination: 0.0.0.0/0 + next-hop-address: {{ ext_ip }} + next-hop-interface: eth0 + table-id: 254 + - destination: ::/0 + next-hop-address: {{ dualstack_ext_ip }} + next-hop-interface: eth0 + table-id: 254 +{%- endmacro %} diff --git a/agent/roles/manifests/templates/nmstateconfig_yaml.j2 b/agent/roles/manifests/templates/nmstateconfig_yaml.j2 new file mode 100644 index 000000000..1c5ca45de --- /dev/null +++ b/agent/roles/manifests/templates/nmstateconfig_yaml.j2 @@ -0,0 +1,40 @@ +{% import 'net_macros.yaml' as net %} + +{% set ips = agent_nodes_ips.split(',') %} +{% set ipsv6 = agent_nodes_ipsv6.split(',') %} +{% set macs = agent_nodes_macs.split(',') %} +{% set hostnames = agent_nodes_hostnames.split(',') %} +{% for hostname in hostnames %} +apiVersion: agent-install.openshift.io/v1beta1 +kind: NMStateConfig +metadata: + name: {{ hostname }} + namespace: openshift-machine-api + labels: + {{ cluster_namespace }}-nmstate-label-name: {{ cluster_namespace }}-nmstate-label-value +spec: + config: + {{ net.interfaces(macs[loop.index0]) }} +{% if ip_stack == "v4" %} + ipv4: + {{ net.ip(ips[loop.index0], cluster_host_prefix_v4) }} + {{ net.dns(provisioning_host_external_ip) }} + {{ net.route("0.0.0.0/0", provisioning_host_external_ip) }} +{% elif ip_stack == "v6" %} + ipv6: + {{ net.ip(ipsv6[loop.index0], cluster_host_prefix_v6) }} + {{ net.dns(provisioning_host_external_ip) }} + {{ net.route("::/0", provisioning_host_external_ip) }} +{% else %} + ipv4: + {{ net.ip(ips[loop.index0], cluster_host_prefix_v4) }} + ipv6: + {{ net.ip(ipsv6[loop.index0], cluster_host_prefix_v6) }} + {{ net.dns_dualstack(provisioning_host_external_ip, provisioning_host_external_ip_dualstack) }} + {{ net.route_dualstack(provisioning_host_external_ip, provisioning_host_external_ip_dualstack) }} +{% endif %} + interfaces: + - name: "eth0" + macAddress: {{ macs[loop.index0] }} +--- +{% endfor %} diff --git a/agent/roles/manifests/templates/pull-secret_yaml.j2 b/agent/roles/manifests/templates/pull-secret_yaml.j2 new file mode 100644 index 000000000..0f86b7df2 --- /dev/null +++ b/agent/roles/manifests/templates/pull-secret_yaml.j2 @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +type: kubernetes.io/dockerconfigjson +metadata: + name: pull-secret + namespace: {{ cluster_namespace }} +stringData: + .dockerconfigjson: {{ pull_secret_contents }} diff --git a/agent/assets/ztp/registries_conf.j2 b/agent/roles/manifests/templates/registries_conf.j2 similarity index 100% rename from agent/assets/ztp/registries_conf.j2 rename to agent/roles/manifests/templates/registries_conf.j2 diff --git a/agent/roles/manifests/vars/main.yml b/agent/roles/manifests/vars/main.yml new file mode 100644 index 000000000..5f0ef336f --- /dev/null +++ b/agent/roles/manifests/vars/main.yml @@ -0,0 +1,36 @@ +agent_deploy_mce: "{{ lookup('env', 'AGENT_DEPLOY_MCE') }}" +agent_nodes_macs: "{{ lookup('env', 'AGENT_NODES_MACS_STR') }}" +agent_nodes_ips: "{{ lookup('env', 'AGENT_NODES_IPS_STR') }}" +agent_nodes_ipsv6: "{{ lookup('env', 'AGENT_NODES_IPSV6_STR') }}" +agent_nodes_hostnames: "{{ lookup('env', 'AGENT_NODES_HOSTNAMES_STR') }}" +agent_use_ztp_manifests: "{{ lookup('env', 'AGENT_USE_ZTP_MANIFESTS') }}" +base_domain: "{{ lookup('env', 'BASE_DOMAIN') }}" +cluster_host_prefix_v4: "{{ lookup('env', 'CLUSTER_HOST_PREFIX_V4') }}" +cluster_host_prefix_v6: "{{ lookup('env', 'CLUSTER_HOST_PREFIX_V6') }}" +cluster_name: "{{ lookup('env', 'CLUSTER_NAME') }}" +cluster_namespace: "{{ lookup('env', 'CLUSTER_NAMESPACE') }}" +cluster_subnet_v4: "{{ lookup('env', 'CLUSTER_SUBNET_V4') }}" +cluster_subnet_v6: "{{ lookup('env', 'CLUSTER_SUBNET_V6') }}" +external_subnet_v4: "{{ lookup('env', 'EXTERNAL_SUBNET_V4') }}" +external_subnet_v6: "{{ lookup('env', 'EXTERNAL_SUBNET_V6') }}" +image: "{{ lookup('env', 'IMAGE') }}" +ip_stack: "{{ lookup('env', 'IP_STACK') }}" +local_image_url_suffix: "{{ lookup('env', 'LOCAL_IMAGE_URL_SUFFIX') }}" +local_registry_dns_name: "{{ lookup('env', 'LOCAL_REGISTRY_DNS_NAME') }}" +local_registry_port: "{{ lookup('env', 'LOCAL_REGISTRY_PORT') }}" +manifests_path: "{{ lookup('env', 'MANIFESTS_PATH') }}" +mirror_images: "{{ lookup('env', 'MIRROR_IMAGES') }}" +mirror_path: "{{ lookup('env', 'MIRROR_PATH') }}" +mirror_info_file: "{{ lookup('env', 'MIRROR_INFO_FILE', default='') }}" +mirror_command: "{{ lookup('env', 'MIRROR_COMMAND') }}" +networking_mode: "{{ lookup('env', 'NETWORKING_MODE') }}" +network_type: "{{ lookup('env', 'NETWORK_TYPE') }}" +num_masters: "{{ lookup('env', 'NUM_MASTERS') }}" +num_workers: "{{ lookup('env', 'NUM_WORKERS') }}" +provisioning_host_external_ip: "{{ lookup('env', 'PROVISIONING_HOST_EXTERNAL_IP') }}" +pull_secret: "{{ lookup('env', 'PULL_SECRET_FILE') }}" +pull_secret_contents: "{{ lookup('file', pull_secret) | to_json }}" +ssh_pub_key: "{{ lookup('env', 'SSH_PUB_KEY') }}" +service_subnet_v4: "{{ lookup('env', 'SERVICE_SUBNET_V4') }}" +service_subnet_v6: "{{ lookup('env', 'SERVICE_SUBNET_V6') }}" +version: "{{ lookup('env', 'VERSION') }}"