Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit f06baee

Browse files
authored
Merge pull request #1779 from ndeloof/labels
define compose labels within the compose API
2 parents ff08642 + 89a63b7 commit f06baee

31 files changed

+160
-145
lines changed

api/compose/labels.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package compose
18+
19+
const (
20+
// ProjectLabel allow to track resource related to a compose project
21+
ProjectLabel = "com.docker.compose.project"
22+
// ServiceLabel allow to track resource related to a compose service
23+
ServiceLabel = "com.docker.compose.service"
24+
// ConfigHashLabel stores configuration hash for a compose service
25+
ConfigHashLabel = "com.docker.compose.config-hash"
26+
// ContainerNumberLabel stores the container index of a replicated service
27+
ContainerNumberLabel = "com.docker.compose.container-number"
28+
// VolumeLabel allow to track resource related to a compose volume
29+
VolumeLabel = "com.docker.compose.volume"
30+
// NetworkLabel allow to track resource related to a compose network
31+
NetworkLabel = "com.docker.compose.network"
32+
// WorkingDirLabel stores absolute path to compose project working directory
33+
WorkingDirLabel = "com.docker.compose.project.working_dir"
34+
// ConfigFilesLabel stores absolute path to compose project configuration files
35+
ConfigFilesLabel = "com.docker.compose.project.config_files"
36+
// EnvironmentFileLabel stores absolute path to compose project env file set by `--env-file`
37+
EnvironmentFileLabel = "com.docker.compose.project.environment_file"
38+
// OneoffLabel stores value 'True' for one-off containers created by `compose run`
39+
OneoffLabel = "com.docker.compose.oneoff"
40+
// SlugLabel stores unique slug used for one-off container identity
41+
SlugLabel = "com.docker.compose.slug"
42+
// VersionLabel stores the compose tool version used to run application
43+
VersionLabel = "com.docker.compose.version"
44+
)

api/compose/tags.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

ecs/awsResources.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ func (b *ecsAPIService) parseExternalVolumes(ctx context.Context, project *types
289289

290290
logrus.Debugf("searching for existing filesystem as volume %q", name)
291291
tags := map[string]string{
292-
compose.ProjectTag: project.Name,
293-
compose.VolumeTag: name,
292+
compose.ProjectLabel: project.Name,
293+
compose.VolumeLabel: name,
294294
}
295295
previous, err := b.aws.ListFileSystems(ctx, tags)
296296
if err != nil {
@@ -397,11 +397,11 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t
397397
FileSystemPolicy: nil,
398398
FileSystemTags: []efs.FileSystem_ElasticFileSystemTag{
399399
{
400-
Key: compose.ProjectTag,
400+
Key: compose.ProjectLabel,
401401
Value: project.Name,
402402
},
403403
{
404-
Key: compose.VolumeTag,
404+
Key: compose.VolumeLabel,
405405
Value: name,
406406
},
407407
{

ecs/cloudformation_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ volumes:
406406
provisioned_throughput: 1024
407407
`, useDefaultVPC, func(m *MockAPIMockRecorder) {
408408
m.ListFileSystems(gomock.Any(), map[string]string{
409-
compose.ProjectTag: t.Name(),
410-
compose.VolumeTag: "db-data",
409+
compose.ProjectLabel: t.Name(),
410+
compose.VolumeLabel: "db-data",
411411
}).Return(nil, nil)
412412
})
413413
n := volumeResourceName("db-data")
@@ -452,8 +452,8 @@ volumes:
452452
db-data: {}
453453
`, useDefaultVPC, func(m *MockAPIMockRecorder) {
454454
m.ListFileSystems(gomock.Any(), map[string]string{
455-
compose.ProjectTag: t.Name(),
456-
compose.VolumeTag: "db-data",
455+
compose.ProjectLabel: t.Name(),
456+
compose.VolumeLabel: "db-data",
457457
}).Return([]awsResource{
458458
existingAWSResource{
459459
id: "fs-123abc",
@@ -521,7 +521,7 @@ services:
521521
for i := 0; i < tags.Len(); i++ {
522522
k := tags.Index(i).FieldByName("Key").String()
523523
v := tags.Index(i).FieldByName("Value").String()
524-
if k == compose.ProjectTag {
524+
if k == compose.ProjectLabel {
525525
assert.Equal(t, v, t.Name())
526526
}
527527
}

ecs/sdk.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (s sdk) CreateStack(ctx context.Context, name string, region string, templa
341341
},
342342
Tags: []*cloudformation.Tag{
343343
{
344-
Key: aws.String(compose.ProjectTag),
344+
Key: aws.String(compose.ProjectLabel),
345345
Value: aws.String(name),
346346
},
347347
},
@@ -455,7 +455,7 @@ func (s sdk) ListStacks(ctx context.Context) ([]compose.Stack, error) {
455455
}
456456
for _, stack := range response.Stacks {
457457
for _, t := range stack.Tags {
458-
if *t.Key == compose.ProjectTag {
458+
if *t.Key == compose.ProjectLabel {
459459
status := compose.RUNNING
460460
switch aws.StringValue(stack.StackStatus) {
461461
case "CREATE_IN_PROGRESS":
@@ -860,12 +860,12 @@ func (s sdk) DescribeService(ctx context.Context, cluster string, arn string) (c
860860
service := services.Services[0]
861861
var name string
862862
for _, t := range service.Tags {
863-
if *t.Key == compose.ServiceTag {
863+
if *t.Key == compose.ServiceLabel {
864864
name = aws.StringValue(t.Value)
865865
}
866866
}
867867
if name == "" {
868-
return compose.ServiceStatus{}, fmt.Errorf("service %s doesn't have a %s tag", *service.ServiceArn, compose.ServiceTag)
868+
return compose.ServiceStatus{}, fmt.Errorf("service %s doesn't have a %s tag", *service.ServiceArn, compose.ServiceLabel)
869869
}
870870
targetGroupArns := []string{}
871871
for _, lb := range service.LoadBalancers {
@@ -919,9 +919,9 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s
919919
var service string
920920
for _, tag := range t.Tags {
921921
switch aws.StringValue(tag.Key) {
922-
case compose.ProjectTag:
922+
case compose.ProjectLabel:
923923
project = aws.StringValue(tag.Value)
924-
case compose.ServiceTag:
924+
case compose.ServiceLabel:
925925
service = aws.StringValue(tag.Value)
926926
}
927927
}

ecs/tags.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
func projectTags(project *types.Project) []tags.Tag {
2727
return []tags.Tag{
2828
{
29-
Key: compose.ProjectTag,
29+
Key: compose.ProjectLabel,
3030
Value: project.Name,
3131
},
3232
}
@@ -35,11 +35,11 @@ func projectTags(project *types.Project) []tags.Tag {
3535
func serviceTags(project *types.Project, service types.ServiceConfig) []tags.Tag {
3636
return []tags.Tag{
3737
{
38-
Key: compose.ProjectTag,
38+
Key: compose.ProjectLabel,
3939
Value: project.Name,
4040
},
4141
{
42-
Key: compose.ServiceTag,
42+
Key: compose.ServiceLabel,
4343
Value: service.Name,
4444
},
4545
}
@@ -48,11 +48,11 @@ func serviceTags(project *types.Project, service types.ServiceConfig) []tags.Tag
4848
func networkTags(project *types.Project, net types.NetworkConfig) []tags.Tag {
4949
return []tags.Tag{
5050
{
51-
Key: compose.ProjectTag,
51+
Key: compose.ProjectLabel,
5252
Value: project.Name,
5353
},
5454
{
55-
Key: compose.NetworkTag,
55+
Key: compose.NetworkLabel,
5656
Value: net.Name,
5757
},
5858
}

ecs/volumes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func (b *ecsAPIService) createAccessPoints(project *types.Project, r awsResource
6363
ap := efs.AccessPoint{
6464
AccessPointTags: []efs.AccessPoint_AccessPointTag{
6565
{
66-
Key: compose.ProjectTag,
66+
Key: compose.ProjectLabel,
6767
Value: project.Name,
6868
},
6969
{
70-
Key: compose.VolumeTag,
70+
Key: compose.VolumeLabel,
7171
Value: name,
7272
},
7373
{

kube/client/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewKubeClient(config genericclioptions.RESTClientGetter) (*KubeClient, erro
7777
// GetPod retrieves a service pod
7878
func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string) (*corev1.Pod, error) {
7979
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
80-
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, projectName),
80+
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName),
8181
})
8282
if err != nil {
8383
return nil, err
@@ -87,7 +87,7 @@ func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string
8787
}
8888
var pod corev1.Pod
8989
for _, p := range pods.Items {
90-
service := p.Labels[compose.ServiceTag]
90+
service := p.Labels[compose.ServiceLabel]
9191
if service == serviceName {
9292
pod = p
9393
break
@@ -155,7 +155,7 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all
155155
}
156156

157157
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
158-
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, projectName),
158+
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName),
159159
FieldSelector: fieldSelector,
160160
})
161161
if err != nil {
@@ -165,7 +165,7 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all
165165
result := []compose.ContainerSummary{}
166166
for _, pod := range pods.Items {
167167
summary := podToContainerSummary(pod)
168-
serviceName := pod.GetObjectMeta().GetLabels()[compose.ServiceTag]
168+
serviceName := pod.GetObjectMeta().GetLabels()[compose.ServiceLabel]
169169
ports, ok := services[serviceName]
170170
if !ok {
171171
s, err := kc.client.CoreV1().Services(kc.namespace).Get(ctx, serviceName, metav1.GetOptions{})
@@ -202,15 +202,15 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all
202202
// GetLogs retrieves pod logs
203203
func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer compose.LogConsumer, follow bool) error {
204204
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
205-
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, projectName),
205+
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName),
206206
})
207207
if err != nil {
208208
return err
209209
}
210210
eg, ctx := errgroup.WithContext(ctx)
211211
for _, pod := range pods.Items {
212212
request := kc.client.CoreV1().Pods(kc.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow})
213-
service := pod.Labels[compose.ServiceTag]
213+
service := pod.Labels[compose.ServiceLabel]
214214
w := utils.GetWriter(func(line string) {
215215
consumer.Log(pod.Name, service, line)
216216
})
@@ -243,7 +243,7 @@ func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOpti
243243
time.Sleep(500 * time.Millisecond)
244244

245245
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
246-
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, opts.ProjectName),
246+
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, opts.ProjectName),
247247
})
248248
if err != nil {
249249
errch <- err

kube/client/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func TestPodToContainerSummary(t *testing.T) {
3434
ObjectMeta: metav1.ObjectMeta{
3535
Name: "c1-123",
3636
Labels: map[string]string{
37-
compose.ProjectTag: "myproject",
38-
compose.ServiceTag: "service1",
37+
compose.ProjectLabel: "myproject",
38+
compose.ServiceLabel: "service1",
3939
},
4040
},
4141
Status: v1.PodStatus{

kube/client/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ func podToContainerSummary(pod corev1.Pod) compose.ContainerSummary {
4747
return compose.ContainerSummary{
4848
ID: pod.GetObjectMeta().GetName(),
4949
Name: pod.GetObjectMeta().GetName(),
50-
Service: pod.GetObjectMeta().GetLabels()[compose.ServiceTag],
50+
Service: pod.GetObjectMeta().GetLabels()[compose.ServiceLabel],
5151
State: state,
52-
Project: pod.GetObjectMeta().GetLabels()[compose.ProjectTag],
52+
Project: pod.GetObjectMeta().GetLabels()[compose.ProjectLabel],
5353
}
5454
}
5555

5656
func checkPodsState(services []string, pods []corev1.Pod, status string) (bool, map[string]string, error) {
5757
servicePods := map[string]string{}
5858
stateReached := true
5959
for _, pod := range pods {
60-
service := pod.Labels[compose.ServiceTag]
60+
service := pod.Labels[compose.ServiceLabel]
6161

6262
if len(services) > 0 && !utils.StringContains(services, service) {
6363
continue

0 commit comments

Comments
 (0)