声明后如何编辑pulumi资源

时间:2020-01-23 15:18:01

标签: pulumi

我已经宣布了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。我认为这是一种怪癖,我还没缠好头,但这是我目前的尝试:

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中修改资源的模式是什么?如何为部署添加新卷?

1 个答案:

答案 0 :(得分:2)

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

在您的示例中,可能是:

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