Skip to content

Commit 5d96504

Browse files
authored
Merge pull request #1228 from jiaqiluo/graceful-shutdown
2 parents e28bd24 + 4375f36 commit 5d96504

8 files changed

Lines changed: 102 additions & 71 deletions

docs/resources/machine_config_v2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ The following attributes are exported:
312312
* `datastore_cluster` - (Optional) vSphere datastore cluster for virtual machine (string)
313313
* `disk_size` - (Optional) vSphere size of disk for docker VM (in MB). Default `20480` (string)
314314
* `folder` - (Optional) vSphere folder for the docker VM. This folder must already exist in the datacenter (string)
315+
* `graceful_shutdown_timeout` (Optional) Duration in seconds before the graceful shutdown of the VM times out and the VM is destroyed. A force destroy will be performed when the value is zero (string)
315316
* `hostsystem` - (Optional) vSphere compute resource where the docker VM will be instantiated. This can be omitted if using a cluster with DRS (string)
316317
* `memory_size` - (Optional) vSphere size of memory for docker VM (in MB). Default `2048` (string)
317318
* `network` - (Optional) vSphere network where the docker VM will be attached (list)

rancher2/resource_rancher2_node_template_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ resource "` + testAccRancher2NodeTemplateType + `" "foo-vsphere" {
267267
cpu_count = "8"
268268
disk_size = "20480"
269269
pool = "pool-YYYYYYYY"
270+
graceful_shutdown_timeout = "30"
270271
}
271272
}
272273
`
@@ -742,6 +743,7 @@ func TestAccRancher2NodeTemplate_basic_Vsphere(t *testing.T) {
742743
resource.TestCheckResourceAttr(name, "vsphere_config.0.cpu_count", "8"),
743744
resource.TestCheckResourceAttr(name, "vsphere_config.0.disk_size", "20480"),
744745
resource.TestCheckResourceAttr(name, "vsphere_config.0.pool", "pool-YYYYYYYY"),
746+
resource.TestCheckResourceAttr(name, "vsphere_config.0.graceful_shutdown_timeout", "30"),
745747
),
746748
},
747749
{

rancher2/schema_cloud_credential_vsphere.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
55
)
66

7-
//Types
7+
// Types
88

99
type vmwarevsphereCredentialConfig struct {
1010
Password string `json:"password,omitempty" yaml:"password,omitempty"`
@@ -13,7 +13,7 @@ type vmwarevsphereCredentialConfig struct {
1313
VcenterPort string `json:"vcenterPort,omitempty" yaml:"vcenterPort,omitempty"`
1414
}
1515

16-
//Schemas
16+
// Schemas
1717

1818
func cloudCredentialVsphereFields() map[string]*schema.Schema {
1919
s := map[string]*schema.Schema{

rancher2/schema_cluster_rke_config_cloud_provider_vsphere.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
55
)
66

7-
//Schemas
7+
// Schemas
88

99
func clusterRKEConfigCloudProviderVsphereDiskFields() map[string]*schema.Schema {
1010
s := map[string]*schema.Schema{
@@ -51,6 +51,10 @@ func clusterRKEConfigCloudProviderVsphereGlobalFields() map[string]*schema.Schem
5151
Optional: true,
5252
Computed: true,
5353
},
54+
"graceful_shutdown_timeout": {
55+
Type: schema.TypeString,
56+
Optional: true,
57+
},
5458
}
5559
return s
5660
}

rancher2/schema_machine_config_v2_vsphere.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
machineConfigV2VmwarevsphereVappTransports = []string{"iso", "com.vmware.guestInfo"}
1717
)
1818

19-
//Schemas
19+
// Schemas
2020

2121
func machineConfigV2VmwarevsphereFields() map[string]*schema.Schema {
2222
s := map[string]*schema.Schema{
@@ -206,6 +206,11 @@ func machineConfigV2VmwarevsphereFields() map[string]*schema.Schema {
206206
Default: "443",
207207
Description: "vSphere Port for vCenter",
208208
},
209+
"graceful_shutdown_timeout": {
210+
Type: schema.TypeString,
211+
Optional: true,
212+
Description: "Duration in seconds before the graceful shutdown of the VM times out and the VM is destroyed. A force destroy will be performed when the value is zero",
213+
},
209214
}
210215

211216
return s

rancher2/schema_node_template_vsphere.go

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,44 @@ var (
1717
vmwarevsphereConfigVappTransports = []string{"iso", "com.vmware.guestInfo"}
1818
)
1919

20-
//Types
20+
// Types
2121

2222
type vmwarevsphereConfig struct {
23-
Boot2dockerURL string `json:"boot2dockerUrl,omitempty" yaml:"boot2dockerUrl,omitempty"`
24-
Cfgparam []string `json:"cfgparam,omitempty" yaml:"cfgparam,omitempty"`
25-
CloneFrom string `json:"cloneFrom,omitempty" yaml:"cloneFrom,omitempty"`
26-
CloudConfig string `json:"cloudConfig,omitempty" yaml:"cloudConfig,omitempty"`
27-
Cloudinit string `json:"cloudinit,omitempty" yaml:"cloudinit,omitempty"`
28-
ContentLibrary string `json:"contentLibrary,omitempty" yaml:"contentLibrary,omitempty"`
29-
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
30-
CreationType string `json:"creationType,omitempty" yaml:"creationType,omitempty"`
31-
CustomAttributes []string `json:"customAttribute,omitempty" yaml:"customAttribute,omitempty"`
32-
Datacenter string `json:"datacenter,omitempty" yaml:"datacenter,omitempty"`
33-
Datastore string `json:"datastore,omitempty" yaml:"datastore,omitempty"`
34-
DatastoreCluster string `json:"datastoreCluster,omitempty" yaml:"datastoreCluster,omitempty"`
35-
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
36-
Folder string `json:"folder,omitempty" yaml:"folder,omitempty"`
37-
Hostsystem string `json:"hostsystem,omitempty" yaml:"hostsystem,omitempty"`
38-
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
39-
Network []string `json:"network,omitempty" yaml:"network,omitempty"`
40-
Password string `json:"password,omitempty" yaml:"password,omitempty"`
41-
Pool string `json:"pool,omitempty" yaml:"pool,omitempty"`
42-
SSHPassword string `json:"sshPassword,omitempty" yaml:"sshPassword,omitempty"`
43-
SSHPort string `json:"sshPort,omitempty" yaml:"sshPort,omitempty"`
44-
SSHUser string `json:"sshUser,omitempty" yaml:"sshUser,omitempty"`
45-
SSHUserGroup string `json:"sshUserGroup,omitempty" yaml:"sshUserGroup,omitempty"`
46-
Tags []string `json:"tag,omitempty" yaml:"tag,omitempty"`
47-
Username string `json:"username,omitempty" yaml:"username,omitempty"`
48-
VappIpallocationpolicy string `json:"vappIpallocationpolicy,omitempty" yaml:"vappIpallocationpolicy,omitempty"`
49-
VappIpprotocol string `json:"vappIpprotocol,omitempty" yaml:"vappIpprotocol,omitempty"`
50-
VappProperty []string `json:"vappProperty,omitempty" yaml:"vappProperty,omitempty"`
51-
VappTransport string `json:"vappTransport,omitempty" yaml:"vappTransport,omitempty"`
52-
Vcenter string `json:"vcenter,omitempty" yaml:"vcenter,omitempty"`
53-
VcenterPort string `json:"vcenterPort,omitempty" yaml:"vcenterPort,omitempty"`
23+
Boot2dockerURL string `json:"boot2dockerUrl,omitempty" yaml:"boot2dockerUrl,omitempty"`
24+
Cfgparam []string `json:"cfgparam,omitempty" yaml:"cfgparam,omitempty"`
25+
CloneFrom string `json:"cloneFrom,omitempty" yaml:"cloneFrom,omitempty"`
26+
CloudConfig string `json:"cloudConfig,omitempty" yaml:"cloudConfig,omitempty"`
27+
Cloudinit string `json:"cloudinit,omitempty" yaml:"cloudinit,omitempty"`
28+
ContentLibrary string `json:"contentLibrary,omitempty" yaml:"contentLibrary,omitempty"`
29+
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
30+
CreationType string `json:"creationType,omitempty" yaml:"creationType,omitempty"`
31+
CustomAttributes []string `json:"customAttribute,omitempty" yaml:"customAttribute,omitempty"`
32+
Datacenter string `json:"datacenter,omitempty" yaml:"datacenter,omitempty"`
33+
Datastore string `json:"datastore,omitempty" yaml:"datastore,omitempty"`
34+
DatastoreCluster string `json:"datastoreCluster,omitempty" yaml:"datastoreCluster,omitempty"`
35+
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
36+
Folder string `json:"folder,omitempty" yaml:"folder,omitempty"`
37+
Hostsystem string `json:"hostsystem,omitempty" yaml:"hostsystem,omitempty"`
38+
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
39+
Network []string `json:"network,omitempty" yaml:"network,omitempty"`
40+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
41+
Pool string `json:"pool,omitempty" yaml:"pool,omitempty"`
42+
SSHPassword string `json:"sshPassword,omitempty" yaml:"sshPassword,omitempty"`
43+
SSHPort string `json:"sshPort,omitempty" yaml:"sshPort,omitempty"`
44+
SSHUser string `json:"sshUser,omitempty" yaml:"sshUser,omitempty"`
45+
SSHUserGroup string `json:"sshUserGroup,omitempty" yaml:"sshUserGroup,omitempty"`
46+
Tags []string `json:"tag,omitempty" yaml:"tag,omitempty"`
47+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
48+
VappIpallocationpolicy string `json:"vappIpallocationpolicy,omitempty" yaml:"vappIpallocationpolicy,omitempty"`
49+
VappIpprotocol string `json:"vappIpprotocol,omitempty" yaml:"vappIpprotocol,omitempty"`
50+
VappProperty []string `json:"vappProperty,omitempty" yaml:"vappProperty,omitempty"`
51+
VappTransport string `json:"vappTransport,omitempty" yaml:"vappTransport,omitempty"`
52+
Vcenter string `json:"vcenter,omitempty" yaml:"vcenter,omitempty"`
53+
VcenterPort string `json:"vcenterPort,omitempty" yaml:"vcenterPort,omitempty"`
54+
GracefulShutdownTimeout string `json:"gracefulShutdownTimeout,omitempty" yaml:"gracefulShutdownTimeout, omitempty"`
5455
}
5556

56-
//Schemas
57+
// Schemas
5758

5859
func vsphereConfigFields() map[string]*schema.Schema {
5960
s := map[string]*schema.Schema{
@@ -243,6 +244,11 @@ func vsphereConfigFields() map[string]*schema.Schema {
243244
Default: "443",
244245
Description: "vSphere Port for vCenter",
245246
},
247+
"graceful_shutdown_timeout": {
248+
Type: schema.TypeString,
249+
Optional: true,
250+
Description: "Duration in seconds before the graceful shutdown of the VM times out and the VM is destroyed. A force destroy will be performed when the value is zero",
251+
},
246252
}
247253
return s
248254
}

rancher2/structure_machine_config_v2_vsphere.go

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,43 @@ const (
1212
machineConfigV2VmwarevsphereClusterIDsep = "."
1313
)
1414

15-
//Types
15+
// Types
1616

1717
type machineConfigV2Vmwarevsphere struct {
18-
metav1.TypeMeta `json:",inline"`
19-
metav1.ObjectMeta `json:"metadata,omitempty"`
20-
Boot2dockerURL string `json:"boot2dockerUrl,omitempty" yaml:"boot2dockerUrl,omitempty"`
21-
Cfgparam []string `json:"cfgparam,omitempty" yaml:"cfgparam,omitempty"`
22-
CloneFrom string `json:"cloneFrom,omitempty" yaml:"cloneFrom,omitempty"`
23-
CloudConfig string `json:"cloudConfig,omitempty" yaml:"cloudConfig,omitempty"`
24-
Cloudinit string `json:"cloudinit,omitempty" yaml:"cloudinit,omitempty"`
25-
ContentLibrary string `json:"contentLibrary,omitempty" yaml:"contentLibrary,omitempty"`
26-
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
27-
CreationType string `json:"creationType,omitempty" yaml:"creationType,omitempty"`
28-
CustomAttributes []string `json:"customAttribute,omitempty" yaml:"customAttribute,omitempty"`
29-
Datacenter string `json:"datacenter,omitempty" yaml:"datacenter,omitempty"`
30-
Datastore string `json:"datastore,omitempty" yaml:"datastore,omitempty"`
31-
DatastoreCluster string `json:"datastoreCluster,omitempty" yaml:"datastoreCluster,omitempty"`
32-
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
33-
Folder string `json:"folder,omitempty" yaml:"folder,omitempty"`
34-
Hostsystem string `json:"hostsystem,omitempty" yaml:"hostsystem,omitempty"`
35-
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
36-
Network []string `json:"network,omitempty" yaml:"network,omitempty"`
37-
Password string `json:"password,omitempty" yaml:"password,omitempty"`
38-
Pool string `json:"pool,omitempty" yaml:"pool,omitempty"`
39-
SSHPassword string `json:"sshPassword,omitempty" yaml:"sshPassword,omitempty"`
40-
SSHPort string `json:"sshPort,omitempty" yaml:"sshPort,omitempty"`
41-
SSHUser string `json:"sshUser,omitempty" yaml:"sshUser,omitempty"`
42-
SSHUserGroup string `json:"sshUserGroup,omitempty" yaml:"sshUserGroup,omitempty"`
43-
Tags []string `json:"tag,omitempty" yaml:"tag,omitempty"`
44-
Username string `json:"username,omitempty" yaml:"username,omitempty"`
45-
VappIpallocationpolicy string `json:"vappIpallocationpolicy,omitempty" yaml:"vappIpallocationpolicy,omitempty"`
46-
VappIpprotocol string `json:"vappIpprotocol,omitempty" yaml:"vappIpprotocol,omitempty"`
47-
VappProperty []string `json:"vappProperty,omitempty" yaml:"vappProperty,omitempty"`
48-
VappTransport string `json:"vappTransport,omitempty" yaml:"vappTransport,omitempty"`
49-
Vcenter string `json:"vcenter,omitempty" yaml:"vcenter,omitempty"`
50-
VcenterPort string `json:"vcenterPort,omitempty" yaml:"vcenterPort,omitempty"`
18+
metav1.TypeMeta `json:",inline"`
19+
metav1.ObjectMeta `json:"metadata,omitempty"`
20+
Boot2dockerURL string `json:"boot2dockerUrl,omitempty" yaml:"boot2dockerUrl,omitempty"`
21+
Cfgparam []string `json:"cfgparam,omitempty" yaml:"cfgparam,omitempty"`
22+
CloneFrom string `json:"cloneFrom,omitempty" yaml:"cloneFrom,omitempty"`
23+
CloudConfig string `json:"cloudConfig,omitempty" yaml:"cloudConfig,omitempty"`
24+
Cloudinit string `json:"cloudinit,omitempty" yaml:"cloudinit,omitempty"`
25+
ContentLibrary string `json:"contentLibrary,omitempty" yaml:"contentLibrary,omitempty"`
26+
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
27+
CreationType string `json:"creationType,omitempty" yaml:"creationType,omitempty"`
28+
CustomAttributes []string `json:"customAttribute,omitempty" yaml:"customAttribute,omitempty"`
29+
Datacenter string `json:"datacenter,omitempty" yaml:"datacenter,omitempty"`
30+
Datastore string `json:"datastore,omitempty" yaml:"datastore,omitempty"`
31+
DatastoreCluster string `json:"datastoreCluster,omitempty" yaml:"datastoreCluster,omitempty"`
32+
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
33+
Folder string `json:"folder,omitempty" yaml:"folder,omitempty"`
34+
Hostsystem string `json:"hostsystem,omitempty" yaml:"hostsystem,omitempty"`
35+
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
36+
Network []string `json:"network,omitempty" yaml:"network,omitempty"`
37+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
38+
Pool string `json:"pool,omitempty" yaml:"pool,omitempty"`
39+
SSHPassword string `json:"sshPassword,omitempty" yaml:"sshPassword,omitempty"`
40+
SSHPort string `json:"sshPort,omitempty" yaml:"sshPort,omitempty"`
41+
SSHUser string `json:"sshUser,omitempty" yaml:"sshUser,omitempty"`
42+
SSHUserGroup string `json:"sshUserGroup,omitempty" yaml:"sshUserGroup,omitempty"`
43+
Tags []string `json:"tag,omitempty" yaml:"tag,omitempty"`
44+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
45+
VappIpallocationpolicy string `json:"vappIpallocationpolicy,omitempty" yaml:"vappIpallocationpolicy,omitempty"`
46+
VappIpprotocol string `json:"vappIpprotocol,omitempty" yaml:"vappIpprotocol,omitempty"`
47+
VappProperty []string `json:"vappProperty,omitempty" yaml:"vappProperty,omitempty"`
48+
VappTransport string `json:"vappTransport,omitempty" yaml:"vappTransport,omitempty"`
49+
Vcenter string `json:"vcenter,omitempty" yaml:"vcenter,omitempty"`
50+
VcenterPort string `json:"vcenterPort,omitempty" yaml:"vcenterPort,omitempty"`
51+
GracefulShutdownTimeout string `json:"gracefulShutdownTimeout,omitempty" yaml:"gracefulShutdownTimeout, omitempty"`
5152
}
5253

5354
type MachineConfigV2Vmwarevsphere struct {
@@ -157,6 +158,9 @@ func flattenMachineConfigV2Vmwarevsphere(in *MachineConfigV2Vmwarevsphere) []int
157158
if len(in.VcenterPort) > 0 {
158159
obj["vcenter_port"] = in.VcenterPort
159160
}
161+
if len(in.GracefulShutdownTimeout) > 0 {
162+
obj["graceful_shutdown_timeout"] = in.GracefulShutdownTimeout
163+
}
160164

161165
return []interface{}{obj}
162166
}
@@ -272,6 +276,9 @@ func expandMachineConfigV2Vmwarevsphere(p []interface{}, source *MachineConfigV2
272276
if v, ok := in["vcenter_port"].(string); ok && len(v) > 0 {
273277
obj.VcenterPort = v
274278
}
279+
if v, ok := in["graceful_shutdown_timeout"].(string); ok && len(v) > 0 {
280+
obj.GracefulShutdownTimeout = v
281+
}
275282

276283
return obj
277284
}

rancher2/structure_node_template_vsphere.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func flattenVsphereConfig(in *vmwarevsphereConfig) []interface{} {
101101
if len(in.VcenterPort) > 0 {
102102
obj["vcenter_port"] = in.VcenterPort
103103
}
104+
if len(in.GracefulShutdownTimeout) > 0 {
105+
obj["graceful_shutdown_timeout"] = in.GracefulShutdownTimeout
106+
}
104107

105108
return []interface{}{obj}
106109
}
@@ -207,6 +210,9 @@ func expandVsphereConfig(p []interface{}) *vmwarevsphereConfig {
207210
if v, ok := in["vcenter_port"].(string); ok && len(v) > 0 {
208211
obj.VcenterPort = v
209212
}
213+
if v, ok := in["graceful_shutdown_timeout"].(string); ok && len(v) > 0 {
214+
obj.GracefulShutdownTimeout = v
215+
}
210216

211217
return obj
212218
}

0 commit comments

Comments
 (0)