github.com/percona/percona-xtradb-cluster-operator@v1.14.0/e2e-tests/validation-hook/run (about)

     1  #!/bin/bash
     2  
     3  if [ -z "$OPERATOR_NS" ]; then
     4  	exit 0
     5  fi
     6  
     7  test_dir=$(realpath $(dirname $0))
     8  . ${test_dir}/../functions
     9  
    10  create_infra $namespace
    11  
    12  set +e # don't exit on errors, we're expecting them
    13  desc "cr with invalid version"
    14  output=$(kubectl 2>&1 apply -f "$test_dir/conf/cr-with-invalid-version.yaml")
    15  if [[ $output != *"invalid cr version"* ]]; then
    16  	echo 'invalid hook response'
    17  	exit 1
    18  fi
    19  desc "cr with too long name"
    20  output=$(kubectl 2>&1 apply -f "$test_dir/conf/cr-with-too-long-name.yaml")
    21  
    22  if [[ $output != *"too long, must be no more than 22 characters"* ]]; then
    23  	echo 'invalid hook response'
    24  	exit 1
    25  fi
    26  desc "cr with haproxy and proxysql"
    27  output=$(kubectl 2>&1 apply -f "$test_dir/conf/cr-with-haproxy-and-proxysql.yaml")
    28  
    29  if [[ $output != *"can't enable both HAProxy and ProxySQL"* ]]; then
    30  	echo 'invalid hook response'
    31  	exit 1
    32  fi
    33  desc "cr with no storage"
    34  output=$(kubectl 2>&1 apply -f "$test_dir/conf/cr-with-no-storage.yaml")
    35  
    36  if [[ $output != *"PXC: volumeSpec should be specified"* ]]; then
    37  	echo 'invalid hook response'
    38  	exit 1
    39  fi
    40  desc "cr simple"
    41  if ! kubectl apply -f "$test_dir/conf/cr-simple.yaml"; then
    42  	echo "ERROR: unable to apply simple CR"
    43  	exit 1
    44  fi
    45  
    46  if ! output=$(kubectl 2>&1 wait --for=condition=initializing pxc/simple-pxc --timeout=1m); then
    47  	echo "ERROR: ${output}"
    48  	exit 1
    49  fi
    50  
    51  replicas_num=2
    52  scale_cmd_err='admission webhook "validationwebhook.pxc.percona.com" denied the request: json: unknown field "replicas"'
    53  
    54  if ! output=$(kubectl 2>&1 scale pxc/simple-pxc --replicas ${replicas_num}); then
    55  	echo "ERROR: ${output}"
    56  	exit 1
    57  elif [[ ${output} =~ ${scale_cmd_err}$ ]]; then
    58  	echo "ERROR: unsupported scale command: ${output}"
    59  	exit 1
    60  fi
    61  
    62  sleep 1
    63  
    64  if ! output=$(kubectl 2>&1 get pxc/simple-pxc -o yaml | yq eval ".spec.pxc.size" -); then
    65  	echo "ERROR: ${output}"
    66  elif ((output != replicas_num)); then
    67  	echo "ERROR: pxc did  ${output}"
    68  fi
    69  
    70  destroy $namespace
    71  desc "test passed"