-
Notifications
You must be signed in to change notification settings - Fork 878
/
Copy pathk8s.go
46 lines (40 loc) · 1.29 KB
/
k8s.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
package main
import (
"github.com/ovh/pulumi-ovh/sdk/go/ovh/cloudproject"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"os"
"strconv"
)
func initk8s(ctx *pulumi.Context) (*cloudproject.Kube, *cloudproject.KubeNodePool, error) {
// Get ServiceName (ie your account ID in OVH)
serviceName := os.Getenv(OvhServiceName)
// Create a new Kubernetes cluster
myKube, err := cloudproject.NewKube(ctx,
clusterConfig(ctx, NAME),
&cloudproject.KubeArgs{
ServiceName: pulumi.String(serviceName),
Region: pulumi.String(clusterConfig(ctx, REGION)),
})
if err != nil {
return nil, nil, err
}
// Export kubeconfig file to a secret
ctx.Export("kubeconfig", pulumi.ToSecret(myKube.Kubeconfig))
//Create a Node Pool for the cluster
var minNodes, _ = strconv.Atoi(clusterConfig(ctx, MinNodes))
var maxNodes, _ = strconv.Atoi(clusterConfig(ctx, MaxNodes))
nodePool, err := cloudproject.NewKubeNodePool(ctx,
clusterConfig(ctx, NodePool),
&cloudproject.KubeNodePoolArgs{
ServiceName: pulumi.String(serviceName),
KubeId: myKube.ID(),
DesiredNodes: pulumi.Int(minNodes),
MaxNodes: pulumi.Int(maxNodes),
MinNodes: pulumi.Int(minNodes),
FlavorName: pulumi.String(clusterConfig(ctx, FLAVOR)),
})
if err != nil {
return nil, nil, err
}
return myKube, nodePool, nil
}