-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathcompute.go
123 lines (111 loc) · 3.18 KB
/
compute.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"strings"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func (ri *ResourceInfo) createImage(ctx *pulumi.Context) error {
imgName := strings.Replace("talos-"+TalosVersion, ".", "-", -1)
obj, err := storage.NewBucketObject(
ctx,
imgName+".tar.gz",
&storage.BucketObjectArgs{
Bucket: ri.Bucket.Name,
Name: pulumi.String(imgName + ".tar.gz"),
Source: pulumi.NewRemoteAsset("https://github.com/siderolabs/talos/releases/download/" + TalosVersion + "/gcp-amd64.tar.gz"),
},
)
if err != nil {
return err
}
img, err := compute.NewImage(
ctx,
imgName,
&compute.ImageArgs{
Name: pulumi.String(imgName),
RawDisk: &compute.ImageRawDiskArgs{
Source: obj.MediaLink.ToStringOutput(),
},
},
)
if err != nil {
return err
}
ri.Image = img
return nil
}
func (ri *ResourceInfo) createCPVMs(ctx *pulumi.Context) error {
for i := 0; i < ControlPlaneNodesCount; i++ {
instance, err := compute.NewInstance(
ctx,
fmt.Sprintf("%s-cp-%d", ClusterName, i),
&compute.InstanceArgs{
MachineType: pulumi.String("e2-medium"),
BootDisk: &compute.InstanceBootDiskArgs{
InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
Image: ri.Image.SelfLink.ToStringOutput(),
Size: pulumi.IntPtr(10),
},
},
Metadata: pulumi.StringMap{"user-data": ri.TalosClusterConfig.ControlplaneConfig},
NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
&compute.InstanceNetworkInterfaceArgs{
Network: ri.Network.Name,
AccessConfigs: compute.InstanceNetworkInterfaceAccessConfigArray{
&compute.InstanceNetworkInterfaceAccessConfigArgs{
NatIp: ri.CPAddresses[fmt.Sprintf("%s-cp-%d", ClusterName, i)].Address,
},
},
},
},
Tags: pulumi.StringArray{
pulumi.String(ClusterName + "-cp"),
},
Zone: pulumi.String(ri.Zone),
},
)
if err != nil {
return err
}
ri.CPInstances = append(ri.CPInstances, instance)
}
return nil
}
func (ri *ResourceInfo) createWorkerVMs(ctx *pulumi.Context) error {
for i := 0; i < WorkerNodesCount; i++ {
_, err := compute.NewInstance(
ctx,
fmt.Sprintf("%s-worker-%d", ClusterName, i),
&compute.InstanceArgs{
MachineType: pulumi.String("e2-medium"),
BootDisk: &compute.InstanceBootDiskArgs{
InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
Image: ri.Image.SelfLink.ToStringOutput(),
Size: pulumi.IntPtr(10),
},
},
Metadata: pulumi.StringMap{"user-data": ri.TalosClusterConfig.WorkerConfig},
NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
&compute.InstanceNetworkInterfaceArgs{
Network: ri.Network.Name,
AccessConfigs: compute.InstanceNetworkInterfaceAccessConfigArray{
&compute.InstanceNetworkInterfaceAccessConfigArgs{
NatIp: ri.WorkerAddresses[fmt.Sprintf("%s-worker-%d", ClusterName, i)].Address,
},
},
},
},
Tags: pulumi.StringArray{
pulumi.String(ClusterName + "-worker"),
},
Zone: pulumi.String(ri.Zone),
},
)
if err != nil {
return err
}
}
return nil
}