Skip to content

Commit

Permalink
feat: get instance info from labels
Browse files Browse the repository at this point in the history
  • Loading branch information
CeerDecy committed Jul 2, 2024
1 parent 2ff6dfd commit 307de3f
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,26 +206,31 @@ func extractEnvs(pod corev1.Pod) (
edgeApplicationName,
edgeSites string) {
envsuffixmap := map[string]*string{
"ADDON_ID": &addonID,
"PIPELINE_ID": &pipelineID,
"DICE_CLUSTER_NAME": &cluster,
"DICE_ORG_NAME": &orgName,
"DICE_ORG_ID": &orgID,
"DICE_PROJECT_NAME": &projectName,
"DICE_PROJECT_ID": &projectID,
"DICE_APPLICATION_NAME": &applicationName,
"DICE_EDGE_APPLICATION_NAME": &edgeApplicationName,
"DICE_EDGE_SITE": &edgeSites,
"DICE_APPLICATION_ID": &applicationID,
"DICE_RUNTIME_NAME": &runtimeName,
"DICE_RUNTIME_ID": &runtimeID,
"DICE_SERVICE_NAME": &serviceName,
"DICE_WORKSPACE": &workspace,
"DICE_ADDON_NAME": &addonName,
"DICE_CPU_ORIGIN": &cpuOriginStr,
"DICE_MEM_ORIGIN": &memOriginStr,
"DICE_COMPONENT": &diceComponent,
}

// TODO use const value in `labels` package for the key (wait new labels merge)
labelSuffixMap := map[string]*string{
"addon.erda.cloud/id": &addonID,
"core.erda.cloud/cluster-name": &cluster,
"core.erda.cloud/org-name": &orgName,
"core.erda.cloud/org-id": &orgID,
"core.erda.cloud/project-name": &projectName,
"core.erda.cloud/project-id": &projectID,
"core.erda.cloud/app-name": &applicationName,
"core.erda.cloud/app-id": &applicationID,
"core.erda.cloud/runtime-id": &runtimeID,
"core.erda.cloud/service-name": &serviceName,
"core.erda.cloud/workspace": &workspace,
"addon.erda.cloud/type": &addonName,

Check warning on line 231 in internal/tools/orchestrator/scheduler/executor/plugins/k8s/instanceinfosync/pod.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/orchestrator/scheduler/executor/plugins/k8s/instanceinfosync/pod.go#L219-L231

Added lines #L219 - L231 were not covered by tests
}

for _, container := range pod.Spec.Containers {
for _, env := range container.Env {
for k, v := range envsuffixmap {
Expand All @@ -235,6 +240,11 @@ func extractEnvs(pod corev1.Pod) (
}
}
}

for k, v := range labelSuffixMap {
*v = pod.Labels[k]

Check warning on line 245 in internal/tools/orchestrator/scheduler/executor/plugins/k8s/instanceinfosync/pod.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/orchestrator/scheduler/executor/plugins/k8s/instanceinfosync/pod.go#L244-L245

Added lines #L244 - L245 were not covered by tests
}

return
}

Expand Down

0 comments on commit 307de3f

Please sign in to comment.