pulumi / pulumi-kubernetesx

Kubernetes for Everyone
Apache License 2.0
135 stars 16 forks source link

[feature] configure pod labels/metadata from PodBuilder #50

Open bigkraig opened 4 years ago

bigkraig commented 4 years ago

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!

abatilo commented 4 years ago

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

dotansimha commented 3 years ago

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,
          }
        ),