orange-policeman-59119
02/26/2019, 7:22 PMComponentResource
? I would like the component to take a namespace to install into as an argument, but I can't figure out how to extract the name
of the namespace out of a k8s.core.v1.Namespace
object.gorgeous-egg-16927
02/26/2019, 7:24 PMorange-policeman-59119
02/26/2019, 7:29 PMPortSet
and a constructor for it that allowed me to declare the ports I cared about, and then use them in a deployment/daemonset/replicaset context and a service context:
export interface PortSet {
containerPort: pulumi.Input<core.v1.ContainerPort>;
servicePort: pulumi.Input<core.v1.ServicePort>;
scrapeTarget: pulumi.Input<string>;
}
export interface PortSetInput {
containerPort: pulumi.Input<number>;
servicePort: pulumi.Input<number>;
nodePort?: pulumi.Input<number>;
}
export function portSet(
name: pulumi.Input<string>,
protocol: pulumi.Input<ServiceProtocol>,
{ containerPort, servicePort, nodePort }: PortSetInput
): PortSet {
const toServicePort = (
protocol: pulumi.Input<ServiceProtocol>
): pulumi.Input<core.v1.ServicePort> => ({
name,
protocol,
targetPort: containerPort,
nodePort,
port: servicePort
});
return {
containerPort: {
name,
containerPort
},
servicePort: pulumi.output(protocol).apply(toServicePort),
scrapeTarget: pulumi.output(servicePort).apply(x => x.toString()),
};
}
const service = new k8s.core.v1.Service(resourceName, {
metadata: { ... },
spec: {
clusterIP: "None",
ports: [metricsPortSet.servicePort, metricsSelfPortSet.servicePort],
selector: kubeStateMetricsLabels
}
});
const deployment = new k8s.apps.v1.Deployment(resourceName, {
metadata: { ... },
spec: {
...
template: {
spec: {
containers: [
{
ports: [
metricsPortSet.containerPort,
metricsSelfPortSet.containerPort
],
gorgeous-egg-16927
02/27/2019, 4:32 PM