Skip to content

Commit c763904

Browse files
committed
Add service name and group labels to environment variable mapping
1 parent 503427e commit c763904

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const (
2424
ClusterIdEnvName = "JOYLIVE_CLUSTER_ID"
2525
DefaultNamespace = "joylive"
2626
AgentVersionLabel = "x-live-version"
27+
ServiceNameLabel = "jmsf.jd.com/name"
28+
ServiceGroupLabel = "jmsf.jd.com/group"
2729
ServiceSpaceLabel = "jmsf.jd.com/space"
2830
JdapServiceSpaceLabel = "jmsf.jd.com/service-space"
2931
ApplicationLabel = "jmsf.jd.com/application"

pkg/mutation/mutation_deploy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ func injectionDeploy(request *admissionv1.AdmissionRequest) (*admissionv1.Admiss
8787
added := false
8888
// Check if the x-live-enabled label exists in deploy's spec.template.metadata.labels; if not, add it.
8989
if _, ok := deploy.Spec.Template.Labels[config.WebHookMatchKey]; !ok {
90+
log.Infof("[mutation] /injection-deploy: add label %s to deployment %s/%s", config.WebHookMatchKey, deploy.Name, deploy.Namespace)
9091
target.Spec.Template.Labels[config.WebHookMatchKey] = config.WebHookMatchValue
9192
added = true
9293
}
9394

94-
if len(config.ControlPlaneUrl) != 0 {
95+
if len(config.ControlPlaneUrl) == 0 {
9596
return &admissionv1.AdmissionResponse{
9697
UID: request.UID,
9798
Allowed: true,

pkg/resource/control.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ func GetApplicationEnvironments(labels map[string]string) (map[string]string, er
5858
envMaps["APPLICATION_NAME"] = application
5959
envMaps["APPLICATION_SERVICE_NAMESPACE"] = serviceSpace
6060
}
61+
62+
if group, ok := labels[config.ServiceGroupLabel]; ok {
63+
envMaps["APPLICATION_SERVICE_GROUP"] = group
64+
} else {
65+
envMaps["APPLICATION_SERVICE_GROUP"] = "default"
66+
}
67+
68+
if service, ok := labels[config.ServiceNameLabel]; ok {
69+
envMaps["APPLICATION_SERVICE_NAME"] = service
70+
}
71+
6172
envMaps["APPLICATION_LOCATION_CLUSTER"] = config.ClusterId
6273

6374
return envMaps, nil

0 commit comments

Comments
 (0)