Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add container env prefix COM_ALIYUN_META_ENVS_ as custom metas. #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion pilot/extension.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package pilot

import (
"github.com/docker/docker/api/types"
"strings"

"github.com/docker/docker/api/types"
)

func extension(container map[string]string, containerJSON *types.ContainerJSON) {
Expand All @@ -14,4 +15,23 @@ func extension(container map[string]string, containerJSON *types.ContainerJSON)
putIfNotEmpty(container, name, value)
}
}
env := containerJSON.Config.Env
containerEnvMap := make(map[string]string) // all container envs map
containerMetaEnvMap := make(map[string]string) // container meta env which will be injected into log-pilot
for _, e := range env {
envKV := strings.SplitN(e, "=", 2)
containerEnvMap[envKV[0]] = envKV[1]
if strings.HasPrefix(e, "COM_ALIYUN_META_ENVS_") {
// e.g. COM_ALIYUN_META_ENVS_MY_POD_IP = k8s_pod_ip
// MY_POD_IP is the original env key,
// k8s_pod_ip is the target field name which put into the tplt.
metaEnvName := strings.TrimPrefix(envKV[0], "COM_ALIYUN_META_ENVS_")
containerMetaEnvMap[metaEnvName] = envKV[1]
}
}
for metaEnvKey, metaEnvValueAsFieldName := range containerMetaEnvMap {
if envValue, exists := containerEnvMap[metaEnvKey]; exists {
putIfNotEmpty(container, metaEnvValueAsFieldName, envValue)
}
}
}