/
main.go
55 lines (50 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ns, err := corev1.NewNamespace(ctx, "test", &corev1.NamespaceArgs{})
if err != nil {
return err
}
rel, err := helm.NewRelease(ctx, "test", &helm.ReleaseArgs{
Chart: pulumi.String("nginx"),
Namespace: ns.Metadata.Name(),
Values: pulumi.Map{
"service": pulumi.StringMap{
"type": pulumi.String("ClusterIP"),
},
"readinessProbe": pulumi.Map{
"tcpSocket": pulumi.Map{
// This will cause initial Helm release install to fail.
"port": pulumi.String("httpunknown"),
},
"initialDelaySeconds": pulumi.Int(1),
"timeoutSeconds": pulumi.Int(1),
"periodSeconds": pulumi.Int(3),
},
},
Timeout: pulumi.Int(30),
})
if err != nil {
return err
}
svc := pulumi.All(rel.Status.Namespace(), rel.Status.Name()).
ApplyT(func(r any) (any, error) {
arr := r.([]any)
namespace := arr[0].(*string)
name := arr[1].(*string)
svc, err := corev1.GetService(ctx, "svc", pulumi.ID(fmt.Sprintf("%s/%s-nginx", *namespace, *name)), nil)
if err != nil {
return "", nil
}
return svc.Spec.ClusterIP(), nil
})
ctx.Export("svc_ip", svc)
return nil
})
}