| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- - name: Include utils/controlplane tasks
- include_role:
- name: utils/controlplane
- - name: Check node is join
- shell: test -f /etc/kubernetes/kubelet.conf
- register: kubelet_result
- ignore_errors: yes
- changed_when: false
- failed_when: false
- - name: Get join token
- shell: kubeadm token create --description "ocadm-playbook-node-joining-token" --ttl 15m --print-join-command | awk '{print $5}{print $7}'
- register: K8S_JOIN_TOKEN
- delegate_to: "{{ k8s_controlplane_host }}"
- run_once: yes
- environment:
- http_proxy: ''
- https_proxy: ''
- when:
- k8s_join_token is not defined or k8s_join_token|length == 0
- changed_when: false
- - name: Get certificate key
- shell: /opt/yunion/bin/ocadm init phase upload-certs | grep -v upload-certs
- register: K8S_CERT_KEY
- delegate_to: "{{ k8s_controlplane_host }}"
- run_once: yes
- environment:
- http_proxy: ''
- https_proxy: ''
- when:
- k8s_join_certificate_key is not defined or k8s_join_certificate_key|length == 0
- - name: construct k8s_controlplane_host
- set_fact:
- k8s_controlplane_host: "{{groups['primary_master_node'][0]}}"
- when:
- k8s_controlplane_host is not defined or k8s_controlplane_host|length == 0
- - block:
- - name: fetch join token
- set_fact:
- k8s_join_token: "{{ K8S_JOIN_TOKEN.stdout_lines[0] }}"
- when:
- k8s_join_token is not defined or k8s_join_token|length == 0
- - name: fetch certificate key
- set_fact:
- k8s_join_certificate_key: "{{ K8S_CERT_KEY.stdout_lines[0] }}"
- when:
- k8s_join_certificate_key is not defined or k8s_join_certificate_key|length == 0
- - name: construct controlplane endpoint
- set_fact:
- controlplane_endpoint: "{{k8s_controlplane_host}}:{{ k8s_controlplane_port | default(6443) }}"
- - name: construct join args
- set_fact:
- join_args: "join --control-plane {{ controlplane_endpoint }} --token {{ k8s_join_token }} --certificate-key {{ k8s_join_certificate_key }} --discovery-token-unsafe-skip-ca-verification"
- - name: join node for apiserver-advertise-address
- set_fact:
- join_args: "{{ join_args }} --apiserver-advertise-address {{ node_ip }}"
- when:
- k8s_node_as_oc_controller|default(false)|bool == true
- - name: join node for node-ip
- set_fact:
- join_args: "{{ join_args }} --node-ip {{ node_ip }}"
- when:
- node_ip is defined
- # define var host_networks if not set.
- - name: Set node_interface_name
- include_role:
- name: utils/set-hostnetworks
- when: host_networks is undefined or host_networks == ''
- - name: Set host_networks_options
- set_fact:
- host_networks_options: "{{ host_networks | join(' --host-networks ') }}"
- when:
- host_networks is defined
- - name: construct host network args
- set_fact:
- join_args: "{{ join_args }} --host-networks {{ host_networks_options }} "
- when:
- host_networks is defined
- - name: construct hugepage args
- set_fact:
- join_args: "{{ join_args }} --enable-hugepage "
- when:
- - enable_hugepage is defined
- - onecloud_version is defined
- - onecloud_version is version('v3.10', '>=')
- - name: join node as onecloud controller
- set_fact:
- join_args: "{{ join_args }} --as-onecloud-controller"
- when:
- - k8s_node_as_oc_controller|default(false)|bool == true
- - name: join node as onecloud host agent
- set_fact:
- join_args: "{{ join_args }} --enable-host-agent"
- when:
- - join_as_host | default(false)|bool == true
- - name: join with high availibility ip option
- set_fact:
- join_args: "{{ join_args }} --high-availability-vip {{ high_availability_vip }}"
- when:
- - high_availability_vip is defined
- - name: join keepalived version tag
- set_fact:
- join_args: "{{ join_args }} --keepalived-version-tag {{ keepalived_version_tag }}"
- when:
- - high_availability_vip is defined
- - keepalived_version_tag is defined
- - name: disable-resource-management for join
- set_fact:
- init_cluster_args: "{{ join_args }} --disable-resource-management"
- when:
- - is_kylin_based is defined
- - is_kylin_based |default(false)|bool == true
- - name: show ocadm join args
- debug:
- msg: "/opt/yunion/bin/ocadm {{ join_args }}"
- - name: Wait for port {{ k8s_controlplane_host }}:{{ k8s_controlplane_port | default(6443)}} to be ready
- wait_for:
- host: "{{ k8s_controlplane_host }}"
- port: "{{ k8s_controlplane_port | default(6443)}}"
- delay: 5
- timeout: 60
- become: yes
- retries: 3
- run_once: yes
- - name: Use ocadm join master node
- command: "/opt/yunion/bin/ocadm {{ join_args }}"
- environment:
- http_proxy: ''
- https_proxy: ''
- when:
- kubelet_result.rc != 0
|