Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

remove envFrom expansion support #345

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ Go in the following order:
5. [Defining ConfigMap](configmap)
6. [Ingress](ingress)
7. [Secrets](secrets)
8. [envFrom Field](envFrom)
9. [Defining resources not supported by kedge](includeResources)
10. [Define multiple apps in single file](single_file)
11. [All constructs](all)
12. [All constructs no magic](allnomagic)
8. [Defining resources not supported by kedge](includeResources)
9. [Define multiple apps in single file](single_file)
10. [All constructs](all)
11. [All constructs no magic](allnomagic)

Specific controllers:

Expand Down
67 changes: 0 additions & 67 deletions docs/examples/envFrom/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions docs/examples/envFrom/db.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions docs/examples/envFrom/web.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions docs/file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,6 @@ define only `health`. And then it gets copied in both in the resultant spec.
But if `health` and `livenessProbe` or `readinessProbe` are defined
simultaneously then the tool will error out.

#### envFrom

```yaml
envFrom:
- configMapRef:
name: <string>
- secretRef:
name: <string>
```

This is similar to the envFrom field in container which is added since Kubernetes
1.6. All the data from the ConfigMaps and Secrets referred here will be populated
as `env` inside the container.

The restriction is that the ConfigMaps and Secrets also have to be defined in the
file since there is no way to get the data to be populated.

To read more about this field from the Kubernetes upstream docs see this:
https://kubernetes.io/docs/api-reference/v1.6/#envfromsource-v1-core


## volumeClaims

```yaml
Expand Down
116 changes: 0 additions & 116 deletions pkg/spec/populators.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package spec
import (
"encoding/json"
"fmt"
"sort"
"strconv"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -54,116 +53,6 @@ func populateProbes(c Container) (Container, error) {
return c, nil
}

func searchConfigMap(cms []ConfigMapMod, name string) (ConfigMapMod, error) {
for _, cm := range cms {
if cm.ObjectMeta.Name == name {
return cm, nil
}
}
return ConfigMapMod{}, fmt.Errorf("configMap %q not found", name)
}

func getSecretDataKeys(secrets []SecretMod, name string) ([]string, error) {
var dataKeys []string
for _, secret := range secrets {
if secret.ObjectMeta.Name == name {
for dk := range secret.Data {
dataKeys = append(dataKeys, dk)
}
for sdk := range secret.StringData {
dataKeys = append(dataKeys, sdk)
}
return dataKeys, nil
}
}
return nil, fmt.Errorf("secret %q not found", name)
}

func getMapKeys(m map[string]string) []string {
var d []string
for k := range m {
d = append(d, k)
}
return d
}

func convertEnvFromToEnvs(envFrom []api_v1.EnvFromSource, cms []ConfigMapMod, secrets []SecretMod) ([]api_v1.EnvVar, error) {
var envs []api_v1.EnvVar

// we will iterate on all envFroms
for ei, e := range envFrom {
if e.ConfigMapRef != nil {

cmName := e.ConfigMapRef.Name

// see if the configMap name which is given actually exists
cm, err := searchConfigMap(cms, cmName)
if err != nil {
return nil, errors.Wrapf(err, "envFrom[%d].configMapRef.name", ei)
}
// once that configMap is found extract all data from it and create a env out of it
configMapKeys := getMapKeys(cm.Data)
sort.Strings(configMapKeys)
for _, key := range configMapKeys {
envs = append(envs, api_v1.EnvVar{
Name: key,
ValueFrom: &api_v1.EnvVarSource{
ConfigMapKeyRef: &api_v1.ConfigMapKeySelector{
LocalObjectReference: api_v1.LocalObjectReference{
Name: cmName,
},
Key: key,
},
},
})
}
}

if e.SecretRef != nil {
rootSecretDataKeys, err := getSecretDataKeys(secrets, e.SecretRef.Name)
if err != nil {
return nil, errors.Wrapf(err, "envFrom[%d].secretRef.name", ei)
}

sort.Strings(rootSecretDataKeys)
for _, secretDataKey := range rootSecretDataKeys {
envs = append(envs, api_v1.EnvVar{
Name: secretDataKey,
ValueFrom: &api_v1.EnvVarSource{
SecretKeyRef: &api_v1.SecretKeySelector{
LocalObjectReference: api_v1.LocalObjectReference{
Name: e.SecretRef.Name,
},
Key: secretDataKey,
},
},
})
}
}
}
return envs, nil
}

func populateEnvFrom(c Container, cms []ConfigMapMod, secrets []SecretMod) (Container, error) {
// now do the env from
envs, err := convertEnvFromToEnvs(c.EnvFrom, cms, secrets)
if err != nil {
return c, err
}
// Since we are not supporting envFrom in our generated Kubernetes
// artifacts right now, we need to set it as nil for every container.
// This makes sure that Kubernetes artifacts do not contain an
// envFrom field.
// This is safe to set since all of the data from envFrom has been
// extracted till this point.
c.EnvFrom = nil
// we collect all the envs from configMap before
// envs provided inside the container
envs = append(envs, c.Env...)
c.Env = envs
return c, nil
}

func populateContainers(containers []Container, cms []ConfigMapMod, secrets []SecretMod) ([]api_v1.Container, error) {
var cnts []api_v1.Container

Expand All @@ -173,11 +62,6 @@ func populateContainers(containers []Container, cms []ConfigMapMod, secrets []Se
if err != nil {
return cnts, errors.Wrapf(err, "error converting 'health' to 'probes', app.containers[%d]", cn)
}
// process envFrom field
c, err = populateEnvFrom(c, cms, secrets)
if err != nil {
return cnts, fmt.Errorf("error converting 'envFrom' to 'envs', app.containers[%d].%s", cn, err.Error())
}

// this is where we are only taking apart upstream container
// and not our own remix of containers
Expand Down
Loading