github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/ansible/roles/validate-pod/tasks/validate-pod.yaml (about)

     1  ---
     2      # kubeconfig is required because this task can be triggered from any k8s node
     3    - name: wait up to 5 min until pod '{{ name }}' has the desired version
     4      command: kubectl --kubeconfig {{ kubernetes_kubeconfig.kubectl }} get pods --selector {{ selector }} --namespace kube-system -o jsonpath='{.items[0].metadata.annotations.kismatic/version}'
     5      register: podVersion
     6      until: podVersion.stdout == kismatic_short_version
     7      retries: 60
     8      delay: 5
     9      failed_when: false # We don't want this task to actually fail (We catch the failure with a custom msg in the next task)
    10  
    11    - name: fail if pod '{{ name }}' does not have the desired version
    12      fail:
    13        msg: |
    14          An error occurred getting the pod's version using kubectl.
    15          
    16          {{ podVersion.stderr }}
    17      when: podVersion.stderr != ""
    18  
    19    - name: fail if pod '{{ name }}' does not have the desired version
    20      fail:
    21        msg: The pod '{{ name }}' is expected to have version '{{ kismatic_short_version }}', but it has version '{{ podVersion.stdout }}'.
    22      when: podVersion.stdout != kismatic_short_version
    23  
    24    - name: wait up to 5 min until pod '{{ name }}' is running
    25      command: kubectl --kubeconfig {{ kubernetes_kubeconfig.kubectl }} get pods --selector {{ selector }} --namespace kube-system
    26      register: phase
    27      until: phase|success and "Running" in phase.stdout
    28      retries: 60
    29      delay: 5
    30      failed_when: false # We don't want this task to actually fail (We catch the failure with a custom msg in the next task)
    31  
    32    - name: get docker container ID for pod '{{ name }}'
    33      command: docker ps -a -f name={{ name }} --format {%raw%}"{{.ID}}"{%endraw%} -l
    34      register: containerID
    35      when: phase|failure or "Running" not in phase.stdout
    36  
    37    - name: get docker logs for pod '{{ name }}'
    38      command: docker logs {{ containerID.stdout }} --tail 15
    39      register: docker_logs
    40      when: containerID is defined and containerID|success and containerID.stdout is defined and containerID.stdout != ""
    41  
    42    - name: fail if pod '{{ name }}' is not running
    43      fail:
    44        msg: |
    45          Waited for pod '{{ name }}' to be running, but it did not start up in time.
    46  
    47          The pod's latest logs may indicate why it failed to start up:
    48  
    49          {{ docker_logs.stderr }}
    50  
    51      when: phase|failure or "Running" not in phase.stdout