github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/tests/integration-tests/cluster-setup/setup-cluster-ssh.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -eu
     4  set -o pipefail
     5  
     6  
     7  scratch=$(mktemp -d)
     8  
     9  ssh-keygen -t ed25519 -N "" -C host -f "${scratch}/host" &>/dev/null
    10  ssh-keygen -t ed25519 -N "" -C client -f "${scratch}/client" &>/dev/null
    11  
    12  host_pub="$(cat "${scratch}/host.pub")"
    13  
    14  cp "${scratch}/client" ./client
    15  cat <<EOF > known_hosts
    16  server.${GIT_NAMESPACE}.svc.cluster.local ${host_pub}
    17  localhost ${host_pub}
    18  EOF
    19  
    20  kubectl create namespace "git" || echo "already exists"
    21  kubectl create namespace "argocd" || echo "already exists"
    22  
    23  kubectl apply -f - <<EOF
    24  ---
    25  apiVersion: v1
    26  kind: Secret
    27  metadata:
    28    name: my-private-ssh-repo
    29    namespace: default
    30    labels:
    31      argocd.argoproj.io/secret-type: repository
    32    namespace: ${ARGO_NAMESPACE}
    33  stringData:
    34    url: ssh://git@server.${GIT_NAMESPACE}.svc.cluster.local/git/repos/manifests
    35    sshPrivateKey: |
    36  $(sed -e "s/^/    /" <"$scratch"/client)
    37  ---
    38  apiVersion: v1
    39  kind: ConfigMap
    40  metadata:
    41    name: ssh-host
    42    namespace: ${GIT_NAMESPACE}
    43  data:
    44    ssh_host_ed25519_key: |
    45  $(sed -e "s/^/    /" <"$scratch"/host)
    46    ssh_host_ed25519_key.pub: |
    47  $(sed -e "s/^/    /" <"$scratch"/host.pub)
    48  ---
    49  apiVersion: v1
    50  kind: ConfigMap
    51  metadata:
    52    name: ssh-client
    53    namespace: ${GIT_NAMESPACE}
    54  data:
    55    client.pub: |
    56  $(sed -e "s/^/    /" <"$scratch"/client.pub)
    57  ---
    58  apiVersion: v1
    59  kind: Service
    60  metadata:
    61    name: server
    62    namespace: ${GIT_NAMESPACE}
    63  spec:
    64    ports:
    65    - name: ssh
    66      port: 22
    67      protocol: TCP
    68      targetPort: 22
    69    selector:
    70      app.kubernetes.io/name: server
    71  ---
    72  apiVersion: apps/v1
    73  kind: Deployment
    74  metadata:
    75    name: server
    76    namespace: ${GIT_NAMESPACE}
    77  spec:
    78    replicas: 1
    79    selector:
    80      matchLabels:
    81        app.kubernetes.io/name: server
    82    strategy:
    83      type: RollingUpdate
    84    template:
    85      metadata:
    86        labels:
    87          app.kubernetes.io/name: server
    88          app: git-server
    89      spec:
    90        initContainers:
    91        - image: "europe-west3-docker.pkg.dev/fdc-public-docker-registry/kuberpult/git-ssh:1.1.1"
    92          imagePullPolicy: IfNotPresent
    93          name: "git-init"
    94          command: ["/bin/sh","-c"]
    95          args: ["ls -l /template/; git init --bare /git/repos/manifests"]
    96          volumeMounts:
    97          - mountPath: /git/repos
    98            name: repos
    99          - name: template
   100            mountPath: /template
   101        containers:
   102        - image: "europe-west3-docker.pkg.dev/fdc-public-docker-registry/kuberpult/git-ssh:1.1.1"
   103          imagePullPolicy: IfNotPresent
   104          name: git
   105          ports:
   106          - containerPort: 22
   107            protocol: TCP
   108          env:
   109          - name: PUID
   110            value: "1000"
   111          - name: PGID
   112            value: "1000"
   113          volumeMounts:
   114          - mountPath: /git/keys-host
   115            name: ssh-host
   116            readOnly: true
   117          - mountPath: /git/keys
   118            name: ssh-client
   119            readOnly: true
   120          - mountPath: /git/repos
   121            name: repos
   122        volumes:
   123        - name: template # for initial test data
   124          hostPath:
   125            path: /create-testdata
   126        - name: ssh-host
   127          configMap:
   128            name: ssh-host
   129            defaultMode: 0600
   130        - name: ssh-client
   131          configMap:
   132            name: ssh-client
   133        - name: repos
   134          emptyDir:
   135            sizeLimit: 50Mi
   136        restartPolicy: Always
   137  EOF
   138  echo "done setting up ssh"