Skip to content

Commit 2ba9578

Browse files
committed
fix: undefined: TkeInstanceAdvancedSetting, tkeGetInstanceAdvancedPara and TKEGpuArgsSetting
1 parent 10c90aa commit 2ba9578

File tree

1 file changed

+268
-0
lines changed

1 file changed

+268
-0
lines changed

tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment_extension.go

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"strings"
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1011
tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
1112

1213
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
1314
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
15+
svcas "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/as"
1416
svccvm "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cvm"
1517
)
1618

@@ -285,3 +287,269 @@ func completeInstanceAdvancedSettings(dMap map[string]interface{}, setting *tke.
285287
}
286288
}
287289
}
290+
291+
func TKEGpuArgsSetting() map[string]*schema.Schema {
292+
return map[string]*schema.Schema{
293+
"mig_enable": {
294+
Type: schema.TypeBool,
295+
Optional: true,
296+
Default: false,
297+
Description: "Whether to enable MIG.",
298+
},
299+
"driver": {
300+
Type: schema.TypeMap,
301+
Optional: true,
302+
ValidateFunc: tccommon.ValidateTkeGpuDriverVersion,
303+
Description: "GPU driver version. Format like: `{ version: String, name: String }`. `version`: Version of GPU driver or CUDA; `name`: Name of GPU driver or CUDA.",
304+
},
305+
"cuda": {
306+
Type: schema.TypeMap,
307+
Optional: true,
308+
ValidateFunc: tccommon.ValidateTkeGpuDriverVersion,
309+
Description: "CUDA version. Format like: `{ version: String, name: String }`. `version`: Version of GPU driver or CUDA; `name`: Name of GPU driver or CUDA.",
310+
},
311+
"cudnn": {
312+
Type: schema.TypeMap,
313+
Optional: true,
314+
ValidateFunc: tccommon.ValidateTkeGpuDriverVersion,
315+
Description: "cuDNN version. Format like: `{ version: String, name: String, doc_name: String, dev_name: String }`." +
316+
" `version`: cuDNN version; `name`: cuDNN name; `doc_name`: Doc name of cuDNN; `dev_name`: Dev name of cuDNN.",
317+
},
318+
"custom_driver": {
319+
Type: schema.TypeMap,
320+
Optional: true,
321+
Description: "Custom GPU driver. Format like: `{address: String}`. `address`: URL of custom GPU driver address.",
322+
},
323+
}
324+
}
325+
326+
func TkeInstanceAdvancedSetting() map[string]*schema.Schema {
327+
return map[string]*schema.Schema{
328+
"mount_target": {
329+
Type: schema.TypeString,
330+
Optional: true,
331+
ForceNew: true,
332+
Description: "Mount target. Default is not mounting.",
333+
},
334+
"docker_graph_path": {
335+
Type: schema.TypeString,
336+
Optional: true,
337+
ForceNew: true,
338+
Default: "/var/lib/docker",
339+
Description: "Docker graph path. Default is `/var/lib/docker`.",
340+
},
341+
"data_disk": {
342+
Type: schema.TypeList,
343+
ForceNew: true,
344+
Optional: true,
345+
MaxItems: 11,
346+
Description: "Configurations of data disk.",
347+
Elem: &schema.Resource{
348+
Schema: map[string]*schema.Schema{
349+
"disk_type": {
350+
Type: schema.TypeString,
351+
ForceNew: true,
352+
Optional: true,
353+
Default: svcas.SYSTEM_DISK_TYPE_CLOUD_PREMIUM,
354+
ValidateFunc: tccommon.ValidateAllowedStringValue(svcas.SYSTEM_DISK_ALLOW_TYPE),
355+
Description: "Types of disk. Valid value: `LOCAL_BASIC`, `LOCAL_SSD`, `CLOUD_BASIC`, `CLOUD_PREMIUM`, `CLOUD_SSD`, `CLOUD_HSSD`, `CLOUD_TSSD` and `CLOUD_BSSD`.",
356+
},
357+
"disk_size": {
358+
Type: schema.TypeInt,
359+
ForceNew: true,
360+
Optional: true,
361+
Default: 0,
362+
Description: "Volume of disk in GB. Default is `0`.",
363+
},
364+
"file_system": {
365+
Type: schema.TypeString,
366+
ForceNew: true,
367+
Optional: true,
368+
Default: "",
369+
Description: "File system, e.g. `ext3/ext4/xfs`.",
370+
},
371+
"auto_format_and_mount": {
372+
Type: schema.TypeBool,
373+
Optional: true,
374+
ForceNew: true,
375+
Default: false,
376+
Description: "Indicate whether to auto format and mount or not. Default is `false`.",
377+
},
378+
"mount_target": {
379+
Type: schema.TypeString,
380+
Optional: true,
381+
ForceNew: true,
382+
Default: "",
383+
Description: "Mount target.",
384+
},
385+
"disk_partition": {
386+
Type: schema.TypeString,
387+
ForceNew: true,
388+
Optional: true,
389+
Description: "The name of the device or partition to mount. NOTE: this argument doesn't support setting in node pool, or will leads to mount error.",
390+
},
391+
},
392+
},
393+
},
394+
"extra_args": {
395+
Type: schema.TypeList,
396+
Optional: true,
397+
ForceNew: true,
398+
Elem: &schema.Schema{Type: schema.TypeString},
399+
Description: "Custom parameter information related to the node. This is a white-list parameter.",
400+
},
401+
"user_data": {
402+
Type: schema.TypeString,
403+
ForceNew: true,
404+
Optional: true,
405+
Description: "Base64-encoded User Data text, the length limit is 16KB.",
406+
},
407+
"pre_start_user_script": {
408+
Type: schema.TypeString,
409+
ForceNew: true,
410+
Optional: true,
411+
Description: "Base64-encoded user script, executed before initializing the node, currently only effective for adding existing nodes.",
412+
},
413+
"is_schedule": {
414+
Type: schema.TypeBool,
415+
ForceNew: true,
416+
Optional: true,
417+
Default: true,
418+
Description: "Indicate to schedule the adding node or not. Default is true.",
419+
},
420+
"desired_pod_num": {
421+
Type: schema.TypeInt,
422+
ForceNew: true,
423+
Optional: true,
424+
Description: "Indicate to set desired pod number in node. valid when the cluster is podCIDR.",
425+
},
426+
"gpu_args": {
427+
Type: schema.TypeList,
428+
Optional: true,
429+
ForceNew: true,
430+
MaxItems: 1,
431+
Elem: &schema.Resource{
432+
Schema: TKEGpuArgsSetting(),
433+
},
434+
Description: "GPU driver parameters.",
435+
},
436+
}
437+
}
438+
439+
func tkeGetInstanceAdvancedPara(dMap map[string]interface{}, meta interface{}) (setting tke.InstanceAdvancedSettings) {
440+
setting = tke.InstanceAdvancedSettings{}
441+
if v, ok := dMap["mount_target"]; ok {
442+
setting.MountTarget = helper.String(v.(string))
443+
}
444+
445+
if v, ok := dMap["data_disk"]; ok {
446+
dataDisks := v.([]interface{})
447+
setting.DataDisks = make([]*tke.DataDisk, len(dataDisks))
448+
for i, d := range dataDisks {
449+
value := d.(map[string]interface{})
450+
var diskType, fileSystem, mountTarget, diskPartition string
451+
if v, ok := value["disk_type"].(string); ok {
452+
diskType = v
453+
}
454+
if v, ok := value["file_system"].(string); ok {
455+
fileSystem = v
456+
}
457+
if v, ok := value["mount_target"].(string); ok {
458+
mountTarget = v
459+
}
460+
if v, ok := value["disk_partition"].(string); ok {
461+
diskPartition = v
462+
}
463+
464+
diskSize := int64(value["disk_size"].(int))
465+
autoFormatAndMount := value["auto_format_and_mount"].(bool)
466+
dataDisk := &tke.DataDisk{
467+
DiskType: &diskType,
468+
FileSystem: &fileSystem,
469+
AutoFormatAndMount: &autoFormatAndMount,
470+
MountTarget: &mountTarget,
471+
DiskPartition: &diskPartition,
472+
}
473+
if diskSize > 0 {
474+
dataDisk.DiskSize = &diskSize
475+
}
476+
setting.DataDisks[i] = dataDisk
477+
}
478+
}
479+
if v, ok := dMap["is_schedule"]; ok {
480+
setting.Unschedulable = helper.BoolToInt64Ptr(!v.(bool))
481+
}
482+
483+
if v, ok := dMap["user_data"]; ok {
484+
setting.UserScript = helper.String(v.(string))
485+
}
486+
487+
if v, ok := dMap["pre_start_user_script"]; ok {
488+
setting.PreStartUserScript = helper.String(v.(string))
489+
}
490+
491+
if v, ok := dMap["docker_graph_path"]; ok {
492+
setting.DockerGraphPath = helper.String(v.(string))
493+
}
494+
495+
if v, ok := dMap["desired_pod_num"]; ok {
496+
setting.DesiredPodNumber = helper.Int64(int64(v.(int)))
497+
}
498+
499+
if temp, ok := dMap["extra_args"]; ok {
500+
extraArgs := helper.InterfacesStrings(temp.([]interface{}))
501+
clusterExtraArgs := tke.InstanceExtraArgs{}
502+
clusterExtraArgs.Kubelet = make([]*string, 0)
503+
for i := range extraArgs {
504+
clusterExtraArgs.Kubelet = append(clusterExtraArgs.Kubelet, &extraArgs[i])
505+
}
506+
setting.ExtraArgs = &clusterExtraArgs
507+
}
508+
509+
// get gpu_args
510+
if v, ok := dMap["gpu_args"]; ok && len(v.([]interface{})) > 0 {
511+
gpuArgs := v.([]interface{})[0].(map[string]interface{})
512+
513+
var (
514+
migEnable = gpuArgs["mig_enable"].(bool)
515+
driver = gpuArgs["driver"].(map[string]interface{})
516+
cuda = gpuArgs["cuda"].(map[string]interface{})
517+
cudnn = gpuArgs["cudnn"].(map[string]interface{})
518+
customDriver = gpuArgs["custom_driver"].(map[string]interface{})
519+
)
520+
tkeGpuArgs := tke.GPUArgs{}
521+
tkeGpuArgs.MIGEnable = &migEnable
522+
if len(driver) > 0 {
523+
tkeGpuArgs.Driver = &tke.DriverVersion{
524+
Version: helper.String(driver["version"].(string)),
525+
Name: helper.String(driver["name"].(string)),
526+
}
527+
}
528+
if len(cuda) > 0 {
529+
tkeGpuArgs.CUDA = &tke.DriverVersion{
530+
Version: helper.String(cuda["version"].(string)),
531+
Name: helper.String(cuda["name"].(string)),
532+
}
533+
}
534+
if len(cudnn) > 0 {
535+
tkeGpuArgs.CUDNN = &tke.CUDNN{
536+
Version: helper.String(cudnn["version"].(string)),
537+
Name: helper.String(cudnn["name"].(string)),
538+
}
539+
if cudnn["doc_name"] != nil {
540+
tkeGpuArgs.CUDNN.DocName = helper.String(cudnn["doc_name"].(string))
541+
}
542+
if cudnn["dev_name"] != nil {
543+
tkeGpuArgs.CUDNN.DevName = helper.String(cudnn["dev_name"].(string))
544+
}
545+
}
546+
if len(customDriver) > 0 {
547+
tkeGpuArgs.CustomDriver = &tke.CustomDriver{
548+
Address: helper.String(customDriver["address"].(string)),
549+
}
550+
}
551+
setting.GPUArgs = &tkeGpuArgs
552+
}
553+
554+
return setting
555+
}

0 commit comments

Comments
 (0)