github.com/skyscape-cloud-services/terraform@v0.9.2-0.20170609144644-7ece028a1747/builtin/providers/kubernetes/structures_container.go (about) 1 package kubernetes 2 3 import ( 4 "strconv" 5 6 "k8s.io/apimachinery/pkg/util/intstr" 7 "k8s.io/kubernetes/pkg/api/v1" 8 ) 9 10 func flattenCapability(in []v1.Capability) []string { 11 att := make([]string, 0, len(in)) 12 for i, v := range in { 13 att[i] = string(v) 14 } 15 return att 16 } 17 18 func flattenContainerSecurityContext(in *v1.SecurityContext) []interface{} { 19 att := make(map[string]interface{}) 20 21 if in.Privileged != nil { 22 att["privileged"] = *in.Privileged 23 } 24 if in.ReadOnlyRootFilesystem != nil { 25 att["read_only_root_filesystem"] = *in.ReadOnlyRootFilesystem 26 } 27 28 if in.RunAsNonRoot != nil { 29 att["run_as_non_root"] = *in.RunAsNonRoot 30 } 31 if in.RunAsUser != nil { 32 att["run_as_user"] = *in.RunAsUser 33 } 34 35 if in.SELinuxOptions != nil { 36 att["se_linux_options"] = flattenSeLinuxOptions(in.SELinuxOptions) 37 } 38 if in.Capabilities != nil { 39 att["capabilities"] = flattenSecurityCapabilities(in.Capabilities) 40 } 41 return []interface{}{att} 42 43 } 44 45 func flattenSecurityCapabilities(in *v1.Capabilities) []interface{} { 46 att := make(map[string]interface{}) 47 48 if in.Add != nil { 49 att["add"] = flattenCapability(in.Add) 50 } 51 if in.Drop != nil { 52 att["drop"] = flattenCapability(in.Drop) 53 } 54 55 return []interface{}{att} 56 } 57 58 func flattenHandler(in *v1.Handler) []interface{} { 59 att := make(map[string]interface{}) 60 61 if in.Exec != nil { 62 att["exec"] = flattenExec(in.Exec) 63 } 64 if in.HTTPGet != nil { 65 att["http_get"] = flattenHTTPGet(in.HTTPGet) 66 } 67 if in.TCPSocket != nil { 68 att["tcp_socket"] = flattenTCPSocket(in.TCPSocket) 69 } 70 71 return []interface{}{att} 72 } 73 74 func flattenHTTPHeader(in []v1.HTTPHeader) []interface{} { 75 att := make([]interface{}, len(in)) 76 for i, v := range in { 77 m := map[string]interface{}{} 78 79 if v.Name != "" { 80 m["name"] = v.Name 81 } 82 83 if v.Value != "" { 84 m["value"] = v.Value 85 } 86 att[i] = m 87 } 88 return att 89 } 90 91 func expandPort(v string) intstr.IntOrString { 92 i, err := strconv.Atoi(v) 93 if err != nil { 94 return intstr.IntOrString{ 95 Type: intstr.String, 96 StrVal: v, 97 } 98 } 99 return intstr.IntOrString{ 100 Type: intstr.Int, 101 IntVal: int32(i), 102 } 103 } 104 105 func flattenHTTPGet(in *v1.HTTPGetAction) []interface{} { 106 att := make(map[string]interface{}) 107 108 if in.Host != "" { 109 att["host"] = in.Host 110 } 111 if in.Path != "" { 112 att["path"] = in.Path 113 } 114 att["port"] = in.Port.String() 115 att["scheme"] = in.Scheme 116 if len(in.HTTPHeaders) > 0 { 117 att["http_header"] = flattenHTTPHeader(in.HTTPHeaders) 118 } 119 120 return []interface{}{att} 121 } 122 123 func flattenTCPSocket(in *v1.TCPSocketAction) []interface{} { 124 att := make(map[string]interface{}) 125 att["port"] = in.Port.String() 126 return []interface{}{att} 127 } 128 129 func flattenExec(in *v1.ExecAction) []interface{} { 130 att := make(map[string]interface{}) 131 if len(in.Command) > 0 { 132 att["command"] = in.Command 133 } 134 return []interface{}{att} 135 } 136 137 func flattenLifeCycle(in *v1.Lifecycle) []interface{} { 138 att := make(map[string]interface{}) 139 140 if in.PostStart != nil { 141 att["post_start"] = flattenHandler(in.PostStart) 142 } 143 if in.PreStop != nil { 144 att["pre_stop"] = flattenHandler(in.PreStop) 145 } 146 147 return []interface{}{att} 148 } 149 150 func flattenProbe(in *v1.Probe) []interface{} { 151 att := make(map[string]interface{}) 152 153 att["failure_threshold"] = in.FailureThreshold 154 att["initial_delay_seconds"] = in.InitialDelaySeconds 155 att["period_seconds"] = in.PeriodSeconds 156 att["success_threshold"] = in.SuccessThreshold 157 att["timeout_seconds"] = in.TimeoutSeconds 158 159 if in.Exec != nil { 160 att["exec"] = flattenExec(in.Exec) 161 } 162 if in.HTTPGet != nil { 163 att["http_get"] = flattenHTTPGet(in.HTTPGet) 164 } 165 if in.TCPSocket != nil { 166 att["tcp_socket"] = flattenTCPSocket(in.TCPSocket) 167 } 168 169 return []interface{}{att} 170 } 171 172 func flattenConfigMapKeyRef(in *v1.ConfigMapKeySelector) []interface{} { 173 att := make(map[string]interface{}) 174 175 if in.Key != "" { 176 att["key"] = in.Key 177 } 178 if in.Name != "" { 179 att["name"] = in.Name 180 } 181 return []interface{}{att} 182 } 183 184 func flattenObjectFieldSelector(in *v1.ObjectFieldSelector) []interface{} { 185 att := make(map[string]interface{}) 186 187 if in.APIVersion != "" { 188 att["api_version"] = in.APIVersion 189 } 190 if in.FieldPath != "" { 191 att["field_path"] = in.FieldPath 192 } 193 return []interface{}{att} 194 } 195 196 func flattenResourceFieldSelector(in *v1.ResourceFieldSelector) []interface{} { 197 att := make(map[string]interface{}) 198 199 if in.ContainerName != "" { 200 att["container_name"] = in.ContainerName 201 } 202 if in.Resource != "" { 203 att["resource"] = in.Resource 204 } 205 return []interface{}{att} 206 } 207 208 func flattenSecretKeyRef(in *v1.SecretKeySelector) []interface{} { 209 att := make(map[string]interface{}) 210 211 if in.Key != "" { 212 att["key"] = in.Key 213 } 214 if in.Name != "" { 215 att["name"] = in.Name 216 } 217 return []interface{}{att} 218 } 219 220 func flattenValueFrom(in *v1.EnvVarSource) []interface{} { 221 att := make(map[string]interface{}) 222 223 if in.ConfigMapKeyRef != nil { 224 att["config_map_key_ref"] = flattenConfigMapKeyRef(in.ConfigMapKeyRef) 225 } 226 if in.ResourceFieldRef != nil { 227 att["resource_field_ref"] = flattenResourceFieldSelector(in.ResourceFieldRef) 228 } 229 if in.SecretKeyRef != nil { 230 att["secret_key_ref"] = flattenSecretKeyRef(in.SecretKeyRef) 231 } 232 if in.FieldRef != nil { 233 att["field_ref"] = flattenObjectFieldSelector(in.FieldRef) 234 } 235 return []interface{}{att} 236 } 237 238 func flattenContainerVolumeMounts(in []v1.VolumeMount) ([]interface{}, error) { 239 att := make([]interface{}, len(in)) 240 for i, v := range in { 241 m := map[string]interface{}{} 242 m["read_only"] = v.ReadOnly 243 244 if v.MountPath != "" { 245 m["mount_path"] = v.MountPath 246 247 } 248 if v.Name != "" { 249 m["name"] = v.Name 250 251 } 252 if v.SubPath != "" { 253 m["sub_path"] = v.SubPath 254 } 255 att[i] = m 256 } 257 return att, nil 258 } 259 260 func flattenContainerEnvs(in []v1.EnvVar) []interface{} { 261 att := make([]interface{}, len(in)) 262 for i, v := range in { 263 m := map[string]interface{}{} 264 if v.Name != "" { 265 m["name"] = v.Name 266 } 267 if v.Value != "" { 268 m["value"] = v.Value 269 } 270 if v.ValueFrom != nil { 271 m["value_from"] = flattenValueFrom(v.ValueFrom) 272 } 273 274 att[i] = m 275 } 276 return att 277 } 278 279 func flattenContainerPorts(in []v1.ContainerPort) []interface{} { 280 att := make([]interface{}, len(in)) 281 for i, v := range in { 282 m := map[string]interface{}{} 283 m["container_port"] = v.ContainerPort 284 if v.HostIP != "" { 285 m["host_ip"] = v.HostIP 286 } 287 m["host_port"] = v.HostPort 288 if v.Name != "" { 289 m["name"] = v.Name 290 } 291 if v.Protocol != "" { 292 m["protocol"] = v.Protocol 293 } 294 att[i] = m 295 } 296 return att 297 } 298 299 func flattenContainerResourceRequirements(in v1.ResourceRequirements) ([]interface{}, error) { 300 att := make(map[string]interface{}) 301 if len(in.Limits) > 0 { 302 att["limits"] = []interface{}{flattenResourceList(in.Limits)} 303 } 304 if len(in.Requests) > 0 { 305 att["requests"] = []interface{}{flattenResourceList(in.Requests)} 306 } 307 return []interface{}{att}, nil 308 } 309 310 func flattenContainers(in []v1.Container) ([]interface{}, error) { 311 att := make([]interface{}, len(in)) 312 for i, v := range in { 313 c := make(map[string]interface{}) 314 c["image"] = v.Image 315 c["name"] = v.Name 316 if len(v.Command) > 0 { 317 c["command"] = v.Command 318 } 319 if len(v.Args) > 0 { 320 c["args"] = v.Args 321 } 322 323 c["image_pull_policy"] = v.ImagePullPolicy 324 c["termination_message_path"] = v.TerminationMessagePath 325 c["stdin"] = v.Stdin 326 c["stdin_once"] = v.StdinOnce 327 c["tty"] = v.TTY 328 c["working_dir"] = v.WorkingDir 329 res, err := flattenContainerResourceRequirements(v.Resources) 330 if err != nil { 331 return nil, err 332 } 333 334 c["resources"] = res 335 if v.LivenessProbe != nil { 336 c["liveness_probe"] = flattenProbe(v.LivenessProbe) 337 } 338 if v.ReadinessProbe != nil { 339 c["readiness_probe"] = flattenProbe(v.ReadinessProbe) 340 } 341 if v.Lifecycle != nil { 342 c["lifecycle"] = flattenLifeCycle(v.Lifecycle) 343 } 344 345 if v.SecurityContext != nil { 346 c["security_context"] = flattenContainerSecurityContext(v.SecurityContext) 347 } 348 if len(v.Ports) > 0 { 349 c["port"] = flattenContainerPorts(v.Ports) 350 } 351 if len(v.Env) > 0 { 352 c["env"] = flattenContainerEnvs(v.Env) 353 } 354 355 if len(v.VolumeMounts) > 0 { 356 volumeMounts, err := flattenContainerVolumeMounts(v.VolumeMounts) 357 if err != nil { 358 return nil, err 359 } 360 c["volume_mount"] = volumeMounts 361 } 362 att[i] = c 363 } 364 return att, nil 365 } 366 367 func expandContainers(ctrs []interface{}) ([]v1.Container, error) { 368 if len(ctrs) == 0 { 369 return []v1.Container{}, nil 370 } 371 cs := make([]v1.Container, len(ctrs)) 372 for i, c := range ctrs { 373 ctr := c.(map[string]interface{}) 374 375 if image, ok := ctr["image"]; ok { 376 cs[i].Image = image.(string) 377 } 378 if name, ok := ctr["name"]; ok { 379 cs[i].Name = name.(string) 380 } 381 if command, ok := ctr["command"].([]interface{}); ok { 382 cs[i].Command = expandStringSlice(command) 383 } 384 if args, ok := ctr["args"].([]interface{}); ok { 385 cs[i].Args = expandStringSlice(args) 386 } 387 388 if v, ok := ctr["resources"].([]interface{}); ok && len(v) > 0 { 389 390 var err error 391 cs[i].Resources, err = expandContainerResourceRequirements(v) 392 if err != nil { 393 return cs, err 394 } 395 } 396 397 if v, ok := ctr["port"].([]interface{}); ok && len(v) > 0 { 398 var err error 399 cs[i].Ports, err = expandContainerPort(v) 400 if err != nil { 401 return cs, err 402 } 403 } 404 if v, ok := ctr["env"].([]interface{}); ok && len(v) > 0 { 405 var err error 406 cs[i].Env, err = expandContainerEnv(v) 407 if err != nil { 408 return cs, err 409 } 410 } 411 412 if policy, ok := ctr["image_pull_policy"]; ok { 413 cs[i].ImagePullPolicy = v1.PullPolicy(policy.(string)) 414 } 415 416 if v, ok := ctr["lifecycle"].([]interface{}); ok && len(v) > 0 { 417 cs[i].Lifecycle = expandLifeCycle(v) 418 } 419 420 if v, ok := ctr["liveness_probe"].([]interface{}); ok && len(v) > 0 { 421 cs[i].LivenessProbe = expandProbe(v) 422 } 423 424 if v, ok := ctr["readiness_probe"].([]interface{}); ok && len(v) > 0 { 425 cs[i].ReadinessProbe = expandProbe(v) 426 } 427 if v, ok := ctr["stdin"]; ok { 428 cs[i].Stdin = v.(bool) 429 } 430 if v, ok := ctr["stdin_once"]; ok { 431 cs[i].StdinOnce = v.(bool) 432 } 433 if v, ok := ctr["termination_message_path"]; ok { 434 cs[i].TerminationMessagePath = v.(string) 435 } 436 if v, ok := ctr["tty"]; ok { 437 cs[i].TTY = v.(bool) 438 } 439 if v, ok := ctr["security_context"].([]interface{}); ok && len(v) > 0 { 440 cs[i].SecurityContext = expandContainerSecurityContext(v) 441 } 442 443 if v, ok := ctr["volume_mount"].([]interface{}); ok && len(v) > 0 { 444 var err error 445 cs[i].VolumeMounts, err = expandContainerVolumeMounts(v) 446 if err != nil { 447 return cs, err 448 } 449 } 450 } 451 return cs, nil 452 } 453 454 func expandExec(l []interface{}) *v1.ExecAction { 455 if len(l) == 0 || l[0] == nil { 456 return &v1.ExecAction{} 457 } 458 in := l[0].(map[string]interface{}) 459 obj := v1.ExecAction{} 460 if v, ok := in["command"].([]interface{}); ok && len(v) > 0 { 461 obj.Command = expandStringSlice(v) 462 } 463 return &obj 464 } 465 466 func expandHTTPHeaders(l []interface{}) []v1.HTTPHeader { 467 if len(l) == 0 { 468 return []v1.HTTPHeader{} 469 } 470 headers := make([]v1.HTTPHeader, len(l)) 471 for i, c := range l { 472 m := c.(map[string]interface{}) 473 if v, ok := m["name"]; ok { 474 headers[i].Name = v.(string) 475 } 476 if v, ok := m["value"]; ok { 477 headers[i].Value = v.(string) 478 } 479 } 480 return headers 481 } 482 func expandContainerSecurityContext(l []interface{}) *v1.SecurityContext { 483 if len(l) == 0 || l[0] == nil { 484 return &v1.SecurityContext{} 485 } 486 in := l[0].(map[string]interface{}) 487 obj := v1.SecurityContext{} 488 if v, ok := in["privileged"]; ok { 489 obj.Privileged = ptrToBool(v.(bool)) 490 } 491 if v, ok := in["read_only_root_filesystem"]; ok { 492 obj.ReadOnlyRootFilesystem = ptrToBool(v.(bool)) 493 } 494 if v, ok := in["run_as_non_root"]; ok { 495 obj.RunAsNonRoot = ptrToBool(v.(bool)) 496 } 497 if v, ok := in["run_as_user"]; ok { 498 obj.RunAsUser = ptrToInt64(int64(v.(int))) 499 } 500 if v, ok := in["se_linux_options"].([]interface{}); ok && len(v) > 0 { 501 obj.SELinuxOptions = expandSeLinuxOptions(v) 502 } 503 if v, ok := in["capabilities"].([]interface{}); ok && len(v) > 0 { 504 obj.Capabilities = expandSecurityCapabilities(v) 505 } 506 507 return &obj 508 } 509 510 func expandCapabilitySlice(s []interface{}) []v1.Capability { 511 result := make([]v1.Capability, len(s), len(s)) 512 for k, v := range s { 513 result[k] = v.(v1.Capability) 514 } 515 return result 516 } 517 518 func expandSecurityCapabilities(l []interface{}) *v1.Capabilities { 519 if len(l) == 0 || l[0] == nil { 520 return &v1.Capabilities{} 521 } 522 in := l[0].(map[string]interface{}) 523 obj := v1.Capabilities{} 524 if v, ok := in["add"].([]interface{}); ok { 525 obj.Add = expandCapabilitySlice(v) 526 } 527 if v, ok := in["drop"].([]interface{}); ok { 528 obj.Drop = expandCapabilitySlice(v) 529 } 530 return &obj 531 } 532 533 func expandTCPSocket(l []interface{}) *v1.TCPSocketAction { 534 if len(l) == 0 || l[0] == nil { 535 return &v1.TCPSocketAction{} 536 } 537 in := l[0].(map[string]interface{}) 538 obj := v1.TCPSocketAction{} 539 if v, ok := in["port"].(string); ok && len(v) > 0 { 540 obj.Port = expandPort(v) 541 } 542 return &obj 543 } 544 545 func expandHTTPGet(l []interface{}) *v1.HTTPGetAction { 546 if len(l) == 0 || l[0] == nil { 547 return &v1.HTTPGetAction{} 548 } 549 in := l[0].(map[string]interface{}) 550 obj := v1.HTTPGetAction{} 551 if v, ok := in["host"].(string); ok && len(v) > 0 { 552 obj.Host = v 553 } 554 if v, ok := in["path"].(string); ok && len(v) > 0 { 555 obj.Path = v 556 } 557 if v, ok := in["scheme"].(string); ok && len(v) > 0 { 558 obj.Scheme = v1.URIScheme(v) 559 } 560 561 if v, ok := in["port"].(string); ok && len(v) > 0 { 562 obj.Port = expandPort(v) 563 } 564 565 if v, ok := in["http_header"].([]interface{}); ok && len(v) > 0 { 566 obj.HTTPHeaders = expandHTTPHeaders(v) 567 } 568 return &obj 569 } 570 571 func expandProbe(l []interface{}) *v1.Probe { 572 if len(l) == 0 || l[0] == nil { 573 return &v1.Probe{} 574 } 575 in := l[0].(map[string]interface{}) 576 obj := v1.Probe{} 577 if v, ok := in["exec"].([]interface{}); ok && len(v) > 0 { 578 obj.Exec = expandExec(v) 579 } 580 if v, ok := in["http_get"].([]interface{}); ok && len(v) > 0 { 581 obj.HTTPGet = expandHTTPGet(v) 582 } 583 if v, ok := in["tcp_socket"].([]interface{}); ok && len(v) > 0 { 584 obj.TCPSocket = expandTCPSocket(v) 585 } 586 if v, ok := in["failure_threshold"].(int); ok { 587 obj.FailureThreshold = int32(v) 588 } 589 if v, ok := in["initial_delay_seconds"].(int); ok { 590 obj.InitialDelaySeconds = int32(v) 591 } 592 if v, ok := in["period_seconds"].(int); ok { 593 obj.PeriodSeconds = int32(v) 594 } 595 if v, ok := in["success_threshold"].(int); ok { 596 obj.SuccessThreshold = int32(v) 597 } 598 if v, ok := in["timeout_seconds"].(int); ok { 599 obj.TimeoutSeconds = int32(v) 600 } 601 602 return &obj 603 } 604 605 func expandHandlers(l []interface{}) *v1.Handler { 606 if len(l) == 0 || l[0] == nil { 607 return &v1.Handler{} 608 } 609 in := l[0].(map[string]interface{}) 610 obj := v1.Handler{} 611 if v, ok := in["exec"].([]interface{}); ok && len(v) > 0 { 612 obj.Exec = expandExec(v) 613 } 614 if v, ok := in["http_get"].([]interface{}); ok && len(v) > 0 { 615 obj.HTTPGet = expandHTTPGet(v) 616 } 617 if v, ok := in["tcp_socket"].([]interface{}); ok && len(v) > 0 { 618 obj.TCPSocket = expandTCPSocket(v) 619 } 620 return &obj 621 622 } 623 func expandLifeCycle(l []interface{}) *v1.Lifecycle { 624 if len(l) == 0 || l[0] == nil { 625 return &v1.Lifecycle{} 626 } 627 in := l[0].(map[string]interface{}) 628 obj := &v1.Lifecycle{} 629 if v, ok := in["post_start"].([]interface{}); ok && len(v) > 0 { 630 obj.PostStart = expandHandlers(v) 631 } 632 if v, ok := in["pre_stop"].([]interface{}); ok && len(v) > 0 { 633 obj.PreStop = expandHandlers(v) 634 } 635 return obj 636 } 637 638 func expandContainerVolumeMounts(in []interface{}) ([]v1.VolumeMount, error) { 639 if len(in) == 0 { 640 return []v1.VolumeMount{}, nil 641 } 642 vmp := make([]v1.VolumeMount, len(in)) 643 for i, c := range in { 644 p := c.(map[string]interface{}) 645 if mountPath, ok := p["mount_path"]; ok { 646 vmp[i].MountPath = mountPath.(string) 647 } 648 if name, ok := p["name"]; ok { 649 vmp[i].Name = name.(string) 650 } 651 if readOnly, ok := p["read_only"]; ok { 652 vmp[i].ReadOnly = readOnly.(bool) 653 } 654 if subPath, ok := p["sub_path"]; ok { 655 vmp[i].SubPath = subPath.(string) 656 } 657 } 658 return vmp, nil 659 } 660 661 func expandContainerEnv(in []interface{}) ([]v1.EnvVar, error) { 662 if len(in) == 0 { 663 return []v1.EnvVar{}, nil 664 } 665 envs := make([]v1.EnvVar, len(in)) 666 for i, c := range in { 667 p := c.(map[string]interface{}) 668 if name, ok := p["name"]; ok { 669 envs[i].Name = name.(string) 670 } 671 if value, ok := p["value"]; ok { 672 envs[i].Value = value.(string) 673 } 674 if v, ok := p["value_from"].([]interface{}); ok && len(v) > 0 { 675 var err error 676 envs[i].ValueFrom, err = expandEnvValueFrom(v) 677 if err != nil { 678 return envs, err 679 } 680 } 681 } 682 return envs, nil 683 } 684 685 func expandContainerPort(in []interface{}) ([]v1.ContainerPort, error) { 686 if len(in) == 0 { 687 return []v1.ContainerPort{}, nil 688 } 689 ports := make([]v1.ContainerPort, len(in)) 690 for i, c := range in { 691 p := c.(map[string]interface{}) 692 if containerPort, ok := p["container_port"]; ok { 693 ports[i].ContainerPort = int32(containerPort.(int)) 694 } 695 if hostIP, ok := p["host_ip"]; ok { 696 ports[i].HostIP = hostIP.(string) 697 } 698 if hostPort, ok := p["host_port"]; ok { 699 ports[i].HostPort = int32(hostPort.(int)) 700 } 701 if name, ok := p["name"]; ok { 702 ports[i].Name = name.(string) 703 } 704 if protocol, ok := p["protocol"]; ok { 705 ports[i].Protocol = v1.Protocol(protocol.(string)) 706 } 707 } 708 return ports, nil 709 } 710 711 func expandConfigMapKeyRef(r []interface{}) (*v1.ConfigMapKeySelector, error) { 712 if len(r) == 0 || r[0] == nil { 713 return &v1.ConfigMapKeySelector{}, nil 714 } 715 in := r[0].(map[string]interface{}) 716 obj := &v1.ConfigMapKeySelector{} 717 718 if v, ok := in["key"].(string); ok { 719 obj.Key = v 720 } 721 if v, ok := in["name"].(string); ok { 722 obj.Name = v 723 } 724 return obj, nil 725 726 } 727 func expandFieldRef(r []interface{}) (*v1.ObjectFieldSelector, error) { 728 if len(r) == 0 || r[0] == nil { 729 return &v1.ObjectFieldSelector{}, nil 730 } 731 in := r[0].(map[string]interface{}) 732 obj := &v1.ObjectFieldSelector{} 733 734 if v, ok := in["api_version"].(string); ok { 735 obj.APIVersion = v 736 } 737 if v, ok := in["field_path"].(string); ok { 738 obj.FieldPath = v 739 } 740 return obj, nil 741 } 742 func expandResourceFieldRef(r []interface{}) (*v1.ResourceFieldSelector, error) { 743 if len(r) == 0 || r[0] == nil { 744 return &v1.ResourceFieldSelector{}, nil 745 } 746 in := r[0].(map[string]interface{}) 747 obj := &v1.ResourceFieldSelector{} 748 749 if v, ok := in["container_name"].(string); ok { 750 obj.ContainerName = v 751 } 752 if v, ok := in["resource"].(string); ok { 753 obj.Resource = v 754 } 755 return obj, nil 756 } 757 func expandSecretKeyRef(r []interface{}) (*v1.SecretKeySelector, error) { 758 if len(r) == 0 || r[0] == nil { 759 return &v1.SecretKeySelector{}, nil 760 } 761 in := r[0].(map[string]interface{}) 762 obj := &v1.SecretKeySelector{} 763 764 if v, ok := in["key"].(string); ok { 765 obj.Key = v 766 } 767 if v, ok := in["name"].(string); ok { 768 obj.Name = v 769 } 770 return obj, nil 771 } 772 773 func expandEnvValueFrom(r []interface{}) (*v1.EnvVarSource, error) { 774 if len(r) == 0 || r[0] == nil { 775 return &v1.EnvVarSource{}, nil 776 } 777 in := r[0].(map[string]interface{}) 778 obj := &v1.EnvVarSource{} 779 780 var err error 781 if v, ok := in["config_map_key_ref"].([]interface{}); ok && len(v) > 0 { 782 obj.ConfigMapKeyRef, err = expandConfigMapKeyRef(v) 783 if err != nil { 784 return obj, err 785 } 786 } 787 if v, ok := in["field_ref"].([]interface{}); ok && len(v) > 0 { 788 obj.FieldRef, err = expandFieldRef(v) 789 if err != nil { 790 return obj, err 791 } 792 } 793 if v, ok := in["secret_key_ref"].([]interface{}); ok && len(v) > 0 { 794 obj.SecretKeyRef, err = expandSecretKeyRef(v) 795 if err != nil { 796 return obj, err 797 } 798 } 799 if v, ok := in["resource_field_ref"].([]interface{}); ok && len(v) > 0 { 800 obj.ResourceFieldRef, err = expandResourceFieldRef(v) 801 if err != nil { 802 return obj, err 803 } 804 } 805 return obj, nil 806 807 } 808 809 func expandContainerResourceRequirements(l []interface{}) (v1.ResourceRequirements, error) { 810 if len(l) == 0 || l[0] == nil { 811 return v1.ResourceRequirements{}, nil 812 } 813 in := l[0].(map[string]interface{}) 814 obj := v1.ResourceRequirements{} 815 816 fn := func(in []interface{}) (v1.ResourceList, error) { 817 for _, c := range in { 818 p := c.(map[string]interface{}) 819 if p["cpu"] == "" { 820 delete(p, "cpu") 821 } 822 if p["memory"] == "" { 823 delete(p, "memory") 824 } 825 return expandMapToResourceList(p) 826 } 827 return nil, nil 828 } 829 830 var err error 831 if v, ok := in["limits"].([]interface{}); ok && len(v) > 0 { 832 obj.Limits, err = fn(v) 833 if err != nil { 834 return obj, err 835 } 836 } 837 838 if v, ok := in["requests"].([]interface{}); ok && len(v) > 0 { 839 obj.Requests, err = fn(v) 840 if err != nil { 841 return obj, err 842 } 843 } 844 845 return obj, nil 846 }