Connector

目录

概述

Connector 是一个命名空间级别的资源,用于定义工具与平台之间的连接配置。它包括:

  • 工具的访问地址
  • 工具的认证信息
  • 工具的状态信息

例如,下面的定义展示了一个 Git 类型的连接器:

apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-github
  namespace: default
spec:
  connectorClassName: git  ##  指定连接器类型为 git,该 ConnectorClass 必须存在
  address: "https://github.com"  ##  工具的访问地址
  auth:
    secretRef:  ##  认证信息的引用
      name: github-secret

认证信息

认证信息定义了访问工具所需的凭据。根据工具类型,可以配置不同的认证方式。该认证方式在 ConnectorClass 中定义。更多详情请参考 ConnectorClass 中认证信息的说明

配置认证信息

认证信息的配置方式如下:

  1. 根据 ConnectorClass 定义,指定所使用的认证类型名称。
  2. 创建包含凭据的 Secret。
  3. 在 Connector 中通过 spec.auth.secretRef 引用该 Secret。
  4. 指定认证校验时所需的参数信息。

例如,配置基本认证:

##  创建包含用户名和密码的 Secret
apiVersion: v1
kind: Secret
metadata:
  name: github-secret
  namespace: default
type: kubernetes.io/basic-auth
data:
  username: dXNlcm5hbWU=  ##  Base64 编码的用户名
  password: cGFzc3dvcmQ=  ##  Base64 编码的密码
---
##  在 Connector 中引用该 Secret
apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-github
spec:
  connectorClassName: git
  address: "https://github.com"
  auth:
    name: basic-auth
    secretRef:
      name: github-secret
      namespace: default

可选认证

部分工具支持无认证访问,此时可以省略 spec.auth.secretRef

例如,访问公共 Git 仓库:

apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-public
spec:
  connectorClassName: git
  address: "https://github.com"
  auth:
    name: basic-auth ##  git connectorclass 的 basic-auth 认证是可选的

认证校验

Connector 支持校验认证信息的有效性。校验的配置通过 spec.auth.params 设置,包含认证校验所需的参数。

例如,校验对 Git 仓库的访问权限:

apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-github
spec:
  connectorClassName: git
  address: "https://github.com"
  auth:
    name: basic-auth
    secretRef:
      name: github-secret
      namespace: default
    params:
    - name: repository  ##  指定要校验的仓库
      value: "org/repo.git"

代理地址

如果 Connector 指向的 ConnectorClass 配置了代理能力,系统会为每个 Connector 分配一个代理地址。

客户端可以使用该代理地址实现无密访问工具。

代理地址的默认格式为 http://c-{connector-name}.{namespace}.svc.cluster.local,可通过 status.proxy 获取。

例如,下面示例描述了一个带代理地址的连接器:

apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: harbor
  namespace: default
spec:
  address: https://example.com
status:
 proxy:
    httpAddress:
      url: http://c-harbor.default.svc.cluster.local

状态信息

Connector 的状态信息记录在 status 字段,包含以下内容:

  • ConnectorClassReady:表示连接器类型是否正确。
  • SecretReady:表示认证信息是否配置正确。
  • LivenessReady:表示工具是否可访问。
  • AuthReady:表示认证信息是否有效。
  • ProxyServiceReady:表示当前 Connector 的代理地址是否成功分配。
  • Ready:表示整体状态。

例如:

status:
  conditions:
  - type: ConnectorClassReady
    status: "True"
    message: ""
  - type: SecretReady
    status: "True"
    message: ""
  - type: LivenessReady
    status: "True"
    lastProbeTime: "2024-10-16T02:27:44Z"
    message: ""
  - type: AuthReady
    status: "True"
    lastProbeTime: "2024-10-16T02:27:44Z"
    message: ""
  - type: ProxyServiceReady
    status: "True"
    lastProbeTime: "2024-10-16T02:27:44Z"
    message: ""
  - type: Ready
    status: "True"
    message: ""

关于 conditions 的更多信息,请参考 Connector Conditions

示例

带基本认证的 Git 连接器

##  创建认证信息
apiVersion: v1
kind: Secret
metadata:
  name: git-auth
  namespace: default
type: kubernetes.io/basic-auth
data:
  username: dXNlcm5hbWU=
  password: cGFzc3dvcmQ=
---
##  创建 Connector
apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-github
  namespace: default
spec:
  connectorClassName: git
  address: "https://github.com"
  auth:
    name: basic-auth
    secretRef:
      name: git-auth
      namespace: default
    params:
    - name: repository
      value: "org/repo.git"

带 SSH 认证的 Git 连接器

##  创建 SSH Key
apiVersion: v1
kind: Secret
metadata:
  name: git-ssh
  namespace: default
type: kubernetes.io/ssh-auth
data:
  ssh-privatekey: LS0tLS1CRUdJTi...  ##  Base64 编码的私钥
---
##  创建 Connector
apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-github-ssh
  namespace: default
spec:
  connectorClassName: git
  address: "git@github.com"
  auth:
    name: ssh-auth
    secretRef:
      name: git-ssh
      namespace: default
    params:
    - name: repository
      value: "org/repo.git"

无认证的 Git 连接器

apiVersion: connectors.alauda.io/v1alpha1
kind: Connector
metadata:
  name: git-public
  namespace: default
spec:
  connectorClassName: git
  address: "https://github.com"
  auth:
    name: basic-auth
  params:
    - name: repository
      value: "org/repo.git"