github.com/verrazzano/verrazzano@v1.7.1/ci/scripts/chaos_test_ephemeral_storage.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright (c) 2022, Oracle and/or its affiliates.
     4  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     5  #
     6  
     7  # Save resource version of the Keycloak pod
     8  RV=$(kubectl get pod -l app.kubernetes.io/name=keycloak -n keycloak -o jsonpath="{.items[0].metadata.resourceVersion}")
     9  
    10  # Kill the MySQL pod, this will cause the Keycloak configuration to be lost
    11  POD=$(kubectl get pod -l app=mysql -n keycloak -o jsonpath="{.items[0].metadata.name}" 2>/dev/null)
    12  if [ $? -ne 0 ] ; then
    13    POD=$(kubectl get pod -l tier=mysql -n keycloak -o jsonpath="{.items[0].metadata.name}")
    14  fi
    15  echo "Killing pod $POD"
    16  kubectl delete pod -n keycloak "$POD"
    17  
    18  # Wait for MySQL to restart
    19  POD=$(kubectl get pod -l app=mysql -n keycloak -o jsonpath="{.items[0].metadata.name}" 2>/dev/null)
    20  if [ $? -ne 0 ] ; then
    21    POD=$(kubectl get pod -l tier=mysql -n keycloak -o jsonpath="{.items[0].metadata.name}")
    22  fi
    23  echo "Waiting for $POD to be ready"
    24  kubectl -n keycloak wait --for=condition=ready --timeout=600s pod/"$POD"
    25  
    26  # Wait for Keycloak configuration to be healthy.  The VPO will rebuild the Keycloak configuration.
    27  secret=$(kubectl get secret --namespace keycloak keycloak-http -o jsonpath="{.data.password}" | base64 --decode; echo)
    28  ingress=$(kubectl get ingress -n keycloak keycloak -o jsonpath="{.spec.rules[0].host}")
    29  
    30  response=0
    31  echo "Waiting for the keycloak configuration to be healthy ..."
    32  until [ $response -eq 200 ]
    33  do
    34      sleep 10
    35      token=$(curl -k --data "username=keycloakadmin&password=$secret&grant_type=password&client_id=admin-cli" https://"$ingress"/auth/realms/master/protocol/openid-connect/token | jq -r '.access_token')
    36      response=$(curl -o /dev/null -s -w "%{http_code}\n" -k -H  "Authorization: bearer $token" -X GET https://"$ingress"/auth/admin/realms/verrazzano-system/groups)
    37  done
    38  echo "Keycloak configuration is healthy"