check_k8s_pods.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Wait for calico pod to come to ready state
  16. command: "kubectl wait --for=condition=ready -n kube-system pod -l k8s-app=calico-node --timeout=10m"
  17. changed_when: false
  18. register: calico_pod_status
  19. failed_when: false
  20. when:
  21. - "'manager' in group_names"
  22. - hostvars['127.0.0.1']['k8s_cni'] == "calico"
  23. tags: install
  24. - name: Wait for flannel pod to come to ready state
  25. command: "kubectl wait --for=condition=ready -n kube-system pod -l app=flannel --timeout=10m"
  26. changed_when: false
  27. register: flannel_pod_status
  28. failed_when: false
  29. when:
  30. - "'manager' in group_names"
  31. - hostvars['127.0.0.1']['k8s_cni'] == "flannel"
  32. tags: install
  33. - name: Wait for nfs-client-provisioner pod to come to ready state
  34. command: "kubectl wait --for=condition=ready -n default pod -l app=nfs-client-provisioner --timeout=10m"
  35. changed_when: false
  36. register: nfs_pod_status
  37. failed_when: false
  38. when:
  39. - "'manager' in group_names"
  40. - calico_pod_status is not failed or flannel_pod_status is not failed
  41. tags: install
  42. - name: Wait for volcano-scheduler pod to come to ready state
  43. command: "kubectl wait --for=condition=ready -n volcano-system pod -l app=volcano-scheduler --timeout=5m"
  44. changed_when: false
  45. register: volcano_pod_status
  46. failed_when: false
  47. when:
  48. - "'manager' in group_names"
  49. - nfs_pod_status is not failed
  50. tags: install
  51. - name: Get K8s pods
  52. command: kubectl get pods --all-namespaces
  53. changed_when: false
  54. register: k8s_pods
  55. when: "'manager' in group_names"
  56. tags: install
  57. - name: Add k8s_pods_status to dummy host
  58. add_host:
  59. name: "check_k8s_pods"
  60. k8s_pods_status: "{{ k8s_pods.stdout }}"
  61. tags: install
  62. - name: Fail message
  63. fail:
  64. msg: "{{ docker_pull_limit_msg }}"
  65. when:
  66. - "'ImagePullBackOff' in hostvars['check_k8s_pods']['k8s_pods_status'] or 'ErrImagePull' in hostvars['check_k8s_pods']['k8s_pods_status']"
  67. - not hostvars['127.0.0.1']['docker_username'] and not hostvars['127.0.0.1']['docker_password']
  68. - name: Docker login
  69. command: docker login -u {{ hostvars['127.0.0.1']['docker_username'] }} -p {{ hostvars['127.0.0.1']['docker_password'] }}
  70. changed_when: true
  71. register: docker_login_output
  72. failed_when: false
  73. when:
  74. - "'ImagePullBackOff' in hostvars['check_k8s_pods']['k8s_pods_status'] or 'ErrImagePull' in hostvars['check_k8s_pods']['k8s_pods_status']"
  75. - hostvars['127.0.0.1']['docker_username'] or hostvars['127.0.0.1']['docker_password']
  76. - "'compute' in group_names"
  77. no_log: true
  78. - name: Docker login check
  79. fail:
  80. msg: "{{ docker_login_fail_msg }}"
  81. when:
  82. - docker_login_output is failed
  83. - "'compute' in group_names"
  84. - name: Pull K8s services docker images
  85. command: docker pull {{ item }}
  86. with_items: "{{ k8s_docker_images }}"
  87. when:
  88. - "'ImagePullBackOff' in hostvars['check_k8s_pods']['k8s_pods_status'] or 'ErrImagePull' in hostvars['check_k8s_pods']['k8s_pods_status']"
  89. - hostvars['127.0.0.1']['docker_username'] and hostvars['127.0.0.1']['docker_password']
  90. register: docker_image_pull_result
  91. until: docker_image_pull_result is not failed
  92. retries: 5