2

我已经声明了一个 Kubernetes 部署,例如:

const ledgerDeployment = new k8s.extensions.v1beta1.Deployment("ledger", {
  spec: {
    template: {
      metadata: {
        labels: {name: "ledger"},
        name: "ledger",
        // namespace: namespace,
      },
      spec: {
        containers: [
          ...
        ],

        volumes: [

          {
            emptyDir: {},
            name: "gunicorn-socket-dir"
          }
        ]
      }
    }
  }
});

稍后index.ts我想有条件地修改volumes部署。我认为这是 pulumi 的一个怪癖,我还没有完全理解,但这是我目前的尝试:

if(myCondition) {
  ledgerDeployment.spec.template.spec.volumes.apply(volumes =>
    volumes.push(
    {
      name: "certificates",
      secret: {
        items: [
          {key: "tls.key", path: "proxykey"},
          {key: "tls.crt", path: "proxycert"}],
        secretName: "star.builds.qwil.co"
      }
    })
  )
)

当我这样做时,我收到以下错误:Property 'mode' is missing in type '{ key: string; path: string; }' but required in type 'KeyToPath'

我怀疑我使用apply不正确。当我尝试直接修改时ledgerDeployment.spec.template.spec.volumes.push()出现错误Property 'push' does not exist on type 'Output<Volume[]>'

Pulumi 中修改资源的模式是什么?如何将新卷添加到我的部署中?

4

1 回答 1

3

创建资源后无法修改资源输入。相反,您应该在调用构造函数之前放置所有定义输入形状的逻辑。

在您的示例中,这可能是:

let volumes = [
  {
    emptyDir: {},
    name: "gunicorn-socket-dir"
  }
]
if (myCondition) {
  volumes.push({...});
}
const ledgerDeployment = new k8s.extensions.v1beta1.Deployment("ledger", {
  // <-- use `volumes` here
});
于 2020-01-23T15:35:16.630 回答