如何使用 Argocd API 创建应用程序集

问题描述 投票:0回答:1

使用 argocd API 创建
applicationSet

ArgoCD API DOC

我正在尝试使用 argocd API 创建一个

applicationSet
。我遵循 argocd API swagger 文档,在其中提供了 JSON 对象,在其中定义了应用程序集的元数据,并使用 Postman 测试此端点:

https://localhost:8081/api/v1/applicationsets

我在授权中添加了不记名令牌,在标头中添加了上下文类型:application/json,在正文中添加了 JSON。

这是我的完整 JSON 对象:

   { 
  "metadata": {
    "name": "applicationset-v6",
    "namespace": "argocd"
  },
  "spec": {
    "goTemplate": true,
    "goTemplateOptions": [
      "missingkey=error"
    ],
    "generators": [
      {
        "list": {
          "elements": [
            {
              "name": "feature-ijk",
              "branch": "branch-ijk",
              "expireDate": "2024-12-31",
              "namespace": "test-namespace"
            }
          ]
        }
      }
    ],
    "template": {
      "metadata": {
        "name": "feature-ijk"
      },
      "spec": {
        "project": "default",
        "source": {
          "repoURL": "https://github.com/org/project-test.git",
          "targetRevision": "main",
          "path": "main/helm",
          "helm": {
            "parameters": [
              {
                "name": "global.namespace.endDate",
                "value": "2024-12-31"
              }
            ]
          }
        },
        "destination": {
          "server": "https://kubernetes.default.svc",
          "namespace": "test-namespace"
        },
        "syncPolicy": {
          "automated": {
            "prune": true,
            "selfHeal": true
          }
        }
      }
    }
  }
}

这是我得到的错误(500内部服务器错误):

{ "error": "error creating ApplicationSets: ApplicationSets is nil in request", "code": 2, "message": "error creating ApplicationSets: ApplicationSets is nil in request" }
请问有什么建议吗?

argocd
1个回答
0
投票
The error message ApplicationSets is nil in request suggests that the Argo CD API expects the ApplicationSet object to be nested under a specific field in the request payload. The raw Kubernetes-style manifest on its own isn’t what the Argo CD API endpoint expects. According to the Argo CD ApplicationSet gRPC/REST definitions, when creating an ApplicationSet via the Argo CD API, you must wrap your JSON object inside a applicationSet field. The POST /api/v1/applicationsets endpoint expects a payload in the format defined by the CreateApplicationSetRequest message, which looks like this: { "applicationSet": { "metadata": { "name": "applicationset-v6", "namespace": "argocd" }, "spec": { "goTemplate": true, "goTemplateOptions": [ "missingkey=error" ], "generators": [ { "list": { "elements": [ { "name": "feature-ijk", "branch": "branch-ijk", "expireDate": "2024-12-31", "namespace": "test-namespace" } ] } } ], "template": { "metadata": { "name": "feature-ijk" }, "spec": { "project": "default", "source": { "repoURL": "https://github.com/org/project-test.git", "targetRevision": "main", "path": "main/helm", "helm": { "parameters": [ { "name": "global.namespace.endDate", "value": "2024-12-31" } ] } }, "destination": { "server": "https://kubernetes.default.svc", "namespace": "test-namespace" }, "syncPolicy": { "automated": { "prune": true, "selfHeal": true } } } } } } } Key changes: • Wrap everything inside an "applicationSet": { ... } object. • Ensure that metadata and spec are nested properly under "applicationSet". Once you make this adjustment, and include the required headers (Content-Type: application/json) and the Authorization Bearer token, the request should no longer fail with the ApplicationSets is nil in request error.
    
© www.soinside.com 2019 - 2024. All rights reserved.