pulumi-kubernetesx icon indicating copy to clipboard operation
pulumi-kubernetesx copied to clipboard

[feature] configure pod labels/metadata from PodBuilder

Open bigkraig opened this issue 5 years ago • 2 comments
trafficstars

Please modify the PodBuilder to allow specifying customized metadata in a pod template. I need to be able to specify annotations (for Prometheus discovery) and labels (for compliance) on my pods.

Thanks!

bigkraig avatar Feb 04 '20 17:02 bigkraig

I believe this would also allow us to specify annotations for clusters that are using kube2iam

abatilo avatar Jun 27 '20 16:06 abatilo

This is really needed.

To eliminate the need to deal with output/input types, I'm doing this:

class ExtendedPodBuilder extends kx.PodBuilder {
  public asExtendedDeploymentSpec(
    args?: types.PodBuilderDeploymentSpec,
    metadata?: k8s.types.input.meta.v1.ObjectMeta
  ): pulumi.Output<k8s.types.input.apps.v1.DeploymentSpec> {
    const podName = this.podSpec.containers.apply((containers: any) => {
      return pulumi.output(containers[0].name);
    });
    const appLabels = { app: podName };

    const _args = args || {};
    const deploymentSpec: k8s.types.input.apps.v1.DeploymentSpec = {
      ..._args,
      selector: { matchLabels: appLabels },
      replicas: _args.replicas ?? 1,
      template: {
        metadata: { labels: appLabels, ...(metadata || {}) },
        spec: this.podSpec,
      },
    };
    return pulumi.output(deploymentSpec);
  }
}

And then:

pb.asExtendedDeploymentSpec(
          { replicas: 1 },
          {
            annotations: myAnnotations,
          }
        ),

dotansimha avatar Jun 24 '21 12:06 dotansimha