• Русский
  • Быстрый старт

    Это руководство показывает, как создать GitHub Connector и использовать его для клонирования репозитория, не раскрывая учетные данные GitHub напрямую в вашей workload.

    Предварительные требования

    • Kubernetes cluster с установленными Connectors (Operator, ConnectorsCore, ConnectorsGitHub)
    • kubectl, настроенный для вашего cluster
    • GitHub Personal Access Token (PAT)

    Шаг 1: Создание Namespace

    kubectl create ns github-connector-demo

    Шаг 2: Создание Secret и Connector

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Secret
    metadata:
      name: github-secret
      namespace: github-connector-demo
    type: Opaque
    stringData:
      token: ghp_xxxxxxxxxxxxxxxxxxxx
    ---
    apiVersion: connectors.alauda.io/v1alpha1
    kind: Connector
    metadata:
      name: github-connector
      namespace: github-connector-demo
    spec:
      connectorClassName: github
      address: https://github.com
      auth:
        name: patAuth
        secretRef:
          name: github-secret
      addressExtensions:
        - name: api
          value: https://api.github.com
    EOF

    Проверьте готовность:

    kubectl get connector -n github-connector-demo github-connector

    Шаг 3: Запуск Clone Job

    cat <<EOF | kubectl apply -f -
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: github-git-clone
      namespace: github-connector-demo
    spec:
      template:
        spec:
          restartPolicy: Never
          containers:
          - name: git
            image: bitnami/git
            command: ["sh", "-c"]
            args:
            - |
              set -ex
              cp /opt/git/.gitconfig /root/
              chmod 644 /root/.gitconfig
              git clone --progress https://github.com/octocat/hello-world.git /tmp/repo
            volumeMounts:
            - name: github-auth
              mountPath: /opt/git
          volumes:
          - name: github-auth
            csi:
              readOnly: true
              driver: connectors-csi
              volumeAttributes:
                connector.name: "github-connector"
                configuration.names: "gitconfig"
    EOF

    Шаг 4: Проверка

    kubectl logs -f job/github-git-clone -n github-connector-demo

    Дальнейшие шаги

    • См. GitHub ConnectorClass для поддерживаемых полей и конфигураций.