github.com/ironcore-dev/gardener-extension-provider-ironcore@v0.3.2-0.20240314231816-8336447fb9a0/hack/dev-setup-admission-ironcore.sh (about)

     1  #!/bin/bash
     2  
     3  set -o errexit
     4  set -o nounset
     5  set -o pipefail
     6  
     7  is_nodeless() {
     8      nodes_len=$(kubectl get node -o json | jq '.items | length')
     9      if [[ "$nodes_len" == "0" ]]; then
    10        return 0
    11      fi
    12  
    13      return 1
    14  }
    15  
    16  IP_ROUTE=$(ip route get 1)
    17  IP_ADDRESS=$(echo ${IP_ROUTE#*src} | awk '{print $1}')
    18  
    19  ADMISSION_SERVICE_NAME="gardener-extension-admission-ironcore"
    20  ADMISSION_ENDPOINT_NAME="gardener-extension-admission-ironcore"
    21  
    22  ADMISSION_EXTERNAL_NAME=gardener.localhost
    23  if [[ "$(uname -s)" == *"Darwin"* ]] || [[ "$(uname -s)" == "Linux" && "$(uname -r)" =~ "microsoft-standard" ]] ; then
    24    ADMISSION_EXTERNAL_NAME=host.docker.internal
    25  fi
    26  
    27  if kubectl -n garden get service "$ADMISSION_SERVICE_NAME" &> /dev/null; then
    28    kubectl -n garden delete service $ADMISSION_SERVICE_NAME
    29  fi
    30  if kubectl -n garden get endpoints "$ADMISSION_ENDPOINT_NAME" &> /dev/null; then
    31    kubectl -n garden delete endpoints $ADMISSION_ENDPOINT_NAME
    32  fi
    33  
    34  if is_nodeless; then
    35    cat <<EOF | kubectl apply -f -
    36  kind: Service
    37  apiVersion: v1
    38  metadata:
    39    name: $ADMISSION_SERVICE_NAME
    40    namespace: garden
    41  spec:
    42    type: ExternalName
    43    externalName: $ADMISSION_EXTERNAL_NAME
    44  EOF
    45  else
    46    cat <<EOF | kubectl apply -f -
    47  kind: Service
    48  apiVersion: v1
    49  metadata:
    50    name: $ADMISSION_SERVICE_NAME
    51    namespace: garden
    52  spec:
    53    ports:
    54    - protocol: TCP
    55      port: 9443
    56      targetPort: 9443
    57  ---
    58  kind: Endpoints
    59  apiVersion: v1
    60  metadata:
    61    name: $ADMISSION_ENDPOINT_NAME
    62    namespace: garden
    63  subsets:
    64  - addresses:
    65    - ip: ${IP_ADDRESS}
    66    ports:
    67    - port: 9443
    68  EOF
    69  fi
    70  
    71  kubectl apply -f $(dirname $0)/../example/40-validatingwebhookconfiguration.yaml