浏览代码

align coding-style with network labels

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 年之前
父节点
当前提交
3ff6923d2e
共有 1 个文件被更改,包括 6 次插入10 次删除
  1. 6 10
      local/compose.go

+ 6 - 10
local/compose.go

@@ -73,7 +73,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, detach
 			volume.Name = fmt.Sprintf("%s_%s", project.Name, k)
 			volume.Name = fmt.Sprintf("%s_%s", project.Name, k)
 			project.Volumes[k] = volume
 			project.Volumes[k] = volume
 		}
 		}
-		err := s.ensureVolume(ctx, project, volume)
+		volume.Labels = volume.Labels.Add(volumeLabel, k)
+		volume.Labels = volume.Labels.Add(projectLabel, project.Name)
+		volume.Labels = volume.Labels.Add(versionLabel, ComposeVersion)
+		err := s.ensureVolume(ctx, volume)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
@@ -591,17 +594,10 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi
 	return nil
 	return nil
 }
 }
 
 
-func (s *composeService) ensureVolume(ctx context.Context, project *types.Project, volume types.VolumeConfig) error {
+func (s *composeService) ensureVolume(ctx context.Context, volume types.VolumeConfig) error {
 	// TODO could identify volume by label vs name
 	// TODO could identify volume by label vs name
 	_, err := s.apiClient.VolumeInspect(ctx, volume.Name)
 	_, err := s.apiClient.VolumeInspect(ctx, volume.Name)
 	if err != nil {
 	if err != nil {
-		labels := volume.Labels
-		if labels == nil {
-			labels = map[string]string{}
-		}
-		labels[projectLabel] = project.Name
-		labels[volumeLabel] = volume.Name
-
 		if errdefs.IsNotFound(err) {
 		if errdefs.IsNotFound(err) {
 			w := progress.ContextWriter(ctx)
 			w := progress.ContextWriter(ctx)
 			w.Event(progress.Event{
 			w.Event(progress.Event{
@@ -611,7 +607,7 @@ func (s *composeService) ensureVolume(ctx context.Context, project *types.Projec
 			})
 			})
 			// TODO we miss support for driver_opts and labels
 			// TODO we miss support for driver_opts and labels
 			_, err := s.apiClient.VolumeCreate(ctx, mobyvolume.VolumeCreateBody{
 			_, err := s.apiClient.VolumeCreate(ctx, mobyvolume.VolumeCreateBody{
-				Labels:     labels,
+				Labels:     volume.Labels,
 				Name:       volume.Name,
 				Name:       volume.Name,
 				Driver:     volume.Driver,
 				Driver:     volume.Driver,
 				DriverOpts: volume.DriverOpts,
 				DriverOpts: volume.DriverOpts,