Skip to content

Commit

Permalink
Implement env_from reverse mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Oct 26, 2017
1 parent f4a1eb1 commit 4d5f5d9
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions kubernetes/structures_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ func flattenProbe(in *v1.Probe) []interface{} {
return []interface{}{att}
}

func flattenConfigMapRef(in *v1.ConfigMapEnvSource) []interface{} {
att := make(map[string]interface{})

if in.Name != "" {
att["name"] = in.Name
}
if in.Optional != nil {
att["optional"] = in.Optional
}
return []interface{}{att}
}

func flattenConfigMapKeyRef(in *v1.ConfigMapKeySelector) []interface{} {
att := make(map[string]interface{})

Expand Down Expand Up @@ -205,6 +217,18 @@ func flattenResourceFieldSelector(in *v1.ResourceFieldSelector) []interface{} {
return []interface{}{att}
}

func flattenSecretRef(in *v1.SecretEnvSource) []interface{} {
att := make(map[string]interface{})

if in.Name != "" {
att["name"] = in.Name
}
if in.Optional != nil {
att["optional"] = in.Optional
}
return []interface{}{att}
}

func flattenSecretKeyRef(in *v1.SecretKeySelector) []interface{} {
att := make(map[string]interface{})

Expand Down Expand Up @@ -276,6 +300,25 @@ func flattenContainerEnvs(in []v1.EnvVar) []interface{} {
return att
}

func flattenContainerEnvFroms(in []v1.EnvFromSource) []interface{} {
att := make([]interface{}, len(in))
for i, v := range in {
m := map[string]interface{}{}
if v.ConfigMapRef != nil {
m["config_map_ref"] = flattenConfigMapRef(v.ConfigMapRef)
}
if v.Prefix != "" {
m["prefix"] = v.Prefix
}
if v.SecretRef != nil {
m["secret_ref"] = flattenSecretRef(v.SecretRef)
}

att[i] = m
}
return att
}

func flattenContainerPorts(in []v1.ContainerPort) []interface{} {
att := make([]interface{}, len(in))
for i, v := range in {
Expand Down Expand Up @@ -351,6 +394,9 @@ func flattenContainers(in []v1.Container) ([]interface{}, error) {
if len(v.Env) > 0 {
c["env"] = flattenContainerEnvs(v.Env)
}
if len(v.EnvFrom) > 0 {
c["env_from"] = flattenContainerEnvFroms(v.EnvFrom)
}

if len(v.VolumeMounts) > 0 {
volumeMounts, err := flattenContainerVolumeMounts(v.VolumeMounts)
Expand Down

0 comments on commit 4d5f5d9

Please sign in to comment.