From 0252213efb1adb5eb4ea9ec023d264095e1b681e Mon Sep 17 00:00:00 2001 From: Xianlu Bird Date: Thu, 2 Aug 2018 03:09:00 +0800 Subject: [PATCH 1/6] Add support for Config, endpoint_mode and 3.3 support (#994) * Add support for Config * Add deployment endpoint_mode support * Add docker compose 3.3 support * Add compose v3.3 support for openshift --- docs/conversion.md | 11 +- pkg/kobject/kobject.go | 6 + pkg/loader/compose/compose.go | 2 +- pkg/loader/compose/v3.go | 51 ++++++- pkg/transformer/kubernetes/k8sutils.go | 26 +++- pkg/transformer/kubernetes/kubernetes.go | 111 ++++++++++++++- pkg/transformer/openshift/openshift.go | 9 +- script/test/cmd/tests.sh | 40 +++++- .../compose-config-long-warning.yaml | 17 +++ .../compose-config-long.yaml | 15 ++ .../compose-config-short-warning.yaml | 14 ++ .../compose-config-short.yaml | 11 ++ .../compose-endpoint-mode-1.yaml | 11 ++ .../compose-endpoint-mode-2.yaml | 11 ++ .../fixtures/compose-v3.3-test/my_config.txt | 1 + .../output-k8s-config-long-warning.json | 74 ++++++++++ .../output-k8s-config-long.json | 74 ++++++++++ .../output-k8s-config-short-warning.json | 59 ++++++++ .../output-k8s-config-short.json | 59 ++++++++ .../output-k8s-endpoint-mode-1.json | 81 +++++++++++ .../output-k8s-endpoint-mode-2.json | 80 +++++++++++ .../output-os-config-long.json | 126 +++++++++++++++++ .../output-os-config-short.json | 111 +++++++++++++++ .../compose-v3.3-test/output-os-mode-1.json | 133 ++++++++++++++++++ 24 files changed, 1117 insertions(+), 16 deletions(-) create mode 100644 script/test/fixtures/compose-v3.3-test/compose-config-long-warning.yaml create mode 100644 script/test/fixtures/compose-v3.3-test/compose-config-long.yaml create mode 100644 script/test/fixtures/compose-v3.3-test/compose-config-short-warning.yaml create mode 100644 script/test/fixtures/compose-v3.3-test/compose-config-short.yaml create mode 100644 script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-1.yaml create mode 100644 script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-2.yaml create mode 100644 script/test/fixtures/compose-v3.3-test/my_config.txt create mode 100644 script/test/fixtures/compose-v3.3-test/output-k8s-config-long-warning.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-k8s-config-long.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-k8s-config-short-warning.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-k8s-config-short.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-1.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-2.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-os-config-long.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-os-config-short.json create mode 100644 script/test/fixtures/compose-v3.3-test/output-os-mode-1.json diff --git a/docs/conversion.md b/docs/conversion.md index c942b7a5b..bb9268a71 100644 --- a/docs/conversion.md +++ b/docs/conversion.md @@ -4,7 +4,7 @@ This document outlines all possible conversion details regarding `docker-compose The current table covers all **current** possible Docker Compose keys. -__Note:__ due to the fast-pace nature of Docker Compose version revisions, minor versions such as 2.1, 2.2, 3.3 are not supported until they are cut into a major version release such as 2 or 3. +__Note:__ We don't support anything 3.4 and above at the moment. __Glossary:__ @@ -22,9 +22,9 @@ __Glossary:__ | build: cache_from | - | - | n | | | | cap_add, cap_drop | ✓ | ✓ | ✓ | Pod.Spec.Container.SecurityContext.Capabilities.Add/Drop | | | command | ✓ | ✓ | ✓ | Pod.Spec.Container.Command | | -| configs | n | n | n | | | -| configs: short-syntax | n | n | n | | | -| configs: long-syntax | n | n | n | | | +| configs | n | n | ✓ | | | +| configs: short-syntax | n | n | n | | Only create configMap | +| configs: long-syntax | n | n | ✓ | | If target path is /, ignore this and only create configMap | | cgroup_parent | x | x | x | | Not supported within Kubernetes. See issue https://github.com/kubernetes/kubernetes/issues/11986 | | container_name | ✓ | ✓ | ✓ | Metadata.Name + Deployment.Spec.Containers.Name | | | credential_spec | x | x | x | | Only applicable to Windows containers | @@ -45,7 +45,8 @@ __Glossary:__ | entrypoint | ✓ | ✓ | ✓ | Pod.Spec.Container.Command | Same as command | | env_file | n | n | ✓ | | | | environment | ✓ | ✓ | ✓ | Pod.Spec.Container.Env | | -| expose | ✓ | ✓ | ✓ | Service.Spec.Ports | | +| expose | ✓ | ✓ | ✓ | Service.Spec.Ports +| endpoint_mode | n | n | ✓ | | | | extends | ✓ | ✓ | ✓ | | Extends by utilizing the same image supplied | | external_links | x | x | x | | Kubernetes uses a flat-structure for all containers and thus external_links does not have a 1-1 conversion | | extra_hosts | n | n | n | | | diff --git a/pkg/kobject/kobject.go b/pkg/kobject/kobject.go index 7952fb53c..a6166e997 100644 --- a/pkg/kobject/kobject.go +++ b/pkg/kobject/kobject.go @@ -17,6 +17,7 @@ limitations under the License. package kobject import ( + dockerCliTypes "github.com/docker/cli/cli/compose/types" "github.com/docker/libcompose/yaml" "k8s.io/kubernetes/pkg/api" ) @@ -94,6 +95,7 @@ type ServiceConfig struct { Build string `compose:"build"` BuildArgs map[string]*string `compose:"build-args"` ExposeService string `compose:"kompose.service.expose"` + BuildLabels map[string]string `compose:"build-labels"` ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"` Stdin bool `compose:"stdin_open"` Tty bool `compose:"tty"` @@ -107,6 +109,10 @@ type ServiceConfig struct { Volumes []Volumes `compose:""` HealthChecks HealthCheck `compose:""` Placement map[string]string `compose:""` + //This is for long LONG SYNTAX link(https://docs.docker.com/compose/compose-file/#long-syntax) + Configs []dockerCliTypes.ServiceConfigObjConfig `compose:""` + //This is for SHORT SYNTAX link(https://docs.docker.com/compose/compose-file/#configs) + ConfigsMetaData map[string]dockerCliTypes.ConfigObjConfig `compose:""` } // HealthCheck the healthcheck configuration for a service diff --git a/pkg/loader/compose/compose.go b/pkg/loader/compose/compose.go index 810eb9285..2dabee42b 100644 --- a/pkg/loader/compose/compose.go +++ b/pkg/loader/compose/compose.go @@ -183,7 +183,7 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { } return komposeObject, nil // Use docker/cli for 3 - case "3", "3.0", "3.1", "3.2": + case "3", "3.0", "3.1", "3.2", "3.3": komposeObject, err := parseV3(files) if err != nil { return kobject.KomposeObject{}, err diff --git a/pkg/loader/compose/v3.go b/pkg/loader/compose/v3.go index b1ec26528..75030c20a 100644 --- a/pkg/loader/compose/v3.go +++ b/pkg/loader/compose/v3.go @@ -119,8 +119,10 @@ func parseV3(files []string) (kobject.KomposeObject, error) { } } - // TODO: Check all "unsupported" keys and output details - // Specifically, keys such as "volumes_from" are not supported in V3. + noSupKeys := checkUnsupportedKeyForV3(config) + for _, keyName := range noSupKeys { + log.Warningf("Unsupported %s key - ignoring", keyName) + } // Finally, we convert the object from docker/cli's ServiceConfig to our appropriate one komposeObject, err := dockerComposeToKomposeMapping(config) @@ -350,6 +352,7 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose serviceConfig.Build = composeServiceConfig.Build.Context serviceConfig.Dockerfile = composeServiceConfig.Build.Dockerfile serviceConfig.BuildArgs = composeServiceConfig.Build.Args + serviceConfig.BuildLabels = composeServiceConfig.Build.Labels // Gather the environment values // DockerCompose uses map[string]*string while we use []string @@ -411,9 +414,15 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose log.Infof("Service name in docker-compose has been changed from %q to %q", name, normalizeServiceNames(name)) } + serviceConfig.Configs = composeServiceConfig.Configs + serviceConfig.ConfigsMetaData = composeObject.Configs + if composeServiceConfig.Deploy.EndpointMode == "vip" { + serviceConfig.ServiceType = string(api.ServiceTypeNodePort) + } // Final step, add to the array! komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig } + handleVolume(&komposeObject) return komposeObject, nil @@ -580,3 +589,41 @@ func mergeComposeObject(oldCompose *types.Config, newCompose *types.Config) (*ty return oldCompose, nil } + +func checkUnsupportedKeyForV3(composeObject *types.Config) []string { + if composeObject == nil { + return []string{} + } + + var keysFound []string + + for _, service := range composeObject.Services { + //For short syntax, volume mount path must be /, but this will cause pod create fail in kubernetes + //So we ignore this attribute + for _, tmpConfig := range service.Configs { + if tmpConfig.Mode == nil { + keysFound = append(keysFound, "short syntax config") + } else { + if tmpConfig.GID != "" { + keysFound = append(keysFound, "long syntax config gid") + } + if tmpConfig.UID != "" { + keysFound = append(keysFound, "long syntax config uid") + } + } + } + + if service.CredentialSpec.Registry != "" || service.CredentialSpec.File != "" { + keysFound = append(keysFound, "credential_spec") + + } + } + + for _, config := range composeObject.Configs { + if config.External.External { + keysFound = append(keysFound, "external config") + } + } + + return keysFound +} diff --git a/pkg/transformer/kubernetes/k8sutils.go b/pkg/transformer/kubernetes/k8sutils.go index d84cb43ca..4223b70fe 100644 --- a/pkg/transformer/kubernetes/k8sutils.go +++ b/pkg/transformer/kubernetes/k8sutils.go @@ -386,10 +386,10 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic template.Spec.Containers[0].Command = service.Command template.Spec.Containers[0].Args = service.Args template.Spec.Containers[0].WorkingDir = service.WorkingDir - template.Spec.Containers[0].VolumeMounts = volumesMount + template.Spec.Containers[0].VolumeMounts = append(template.Spec.Containers[0].VolumeMounts, volumesMount...) template.Spec.Containers[0].Stdin = service.Stdin template.Spec.Containers[0].TTY = service.Tty - template.Spec.Volumes = volumes + template.Spec.Volumes = append(template.Spec.Volumes, volumes...) template.Spec.NodeSelector = service.Placement // Configure the HealthCheck // We check to see if it's blank @@ -608,6 +608,21 @@ func GetEnvsFromFile(file string, opt kobject.ConvertOptions) (map[string]string return envLoad, nil } +// GetContentFromFile get content from file +func GetContentFromFile(file string, opt kobject.ConvertOptions) (string, error) { + // Get the correct file context / directory + composeDir, err := transformer.GetComposeFileDir(opt.InputFiles) + if err != nil { + return "", errors.Wrap(err, "Unable to load file context") + } + fileLocation := path.Join(composeDir, file) + fileBytes, err := ioutil.ReadFile(fileLocation) + if err != nil { + return "", errors.Wrap(err, "Unable to read file") + } + return string(fileBytes), nil +} + // FormatEnvName format env name func FormatEnvName(name string) string { envName := strings.Trim(name, "./") @@ -615,3 +630,10 @@ func FormatEnvName(name string) string { envName = strings.Replace(envName, "/", "-", -1) return envName } + +// FormatFileName format file name +func FormatFileName(name string) string { + envName := strings.Trim(name, "./") + envName = strings.Replace(envName, "_", "-", -1) + return envName +} diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 618cf5de4..c8618f78a 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -127,6 +127,52 @@ func (k *Kubernetes) InitPodSpec(name string, image string) api.PodSpec { return pod } +//InitPodSpecWithConfigMap creates the pod specification +func (k *Kubernetes) InitPodSpecWithConfigMap(name string, image string, service kobject.ServiceConfig) api.PodSpec { + var volumeMounts []api.VolumeMount + var volumes []api.Volume + + if len(service.Configs) > 0 && service.Configs[0].Mode != nil { + //This is for LONG SYNTAX + for _, value := range service.Configs { + if value.Target == "/" { + log.Warnf("Long syntax config, target path can not be /") + continue + } + tmpKey := FormatFileName(value.Source) + volumeMounts = append(volumeMounts, + api.VolumeMount{ + Name: tmpKey, + MountPath: "/" + FormatFileName(value.Target), + }) + + tmpVolume := api.Volume{ + Name: tmpKey, + } + tmpVolume.ConfigMap = &api.ConfigMapVolumeSource{} + tmpVolume.ConfigMap.Name = tmpKey + var tmpMode int32 + tmpMode = int32(*value.Mode) + tmpVolume.ConfigMap.DefaultMode = &tmpMode + volumes = append(volumes, tmpVolume) + } + } else { + //This is for SHORT SYNTAX, unsupported + } + + pod := api.PodSpec{ + Containers: []api.Container{ + { + Name: name, + Image: image, + VolumeMounts: volumeMounts, + }, + }, + Volumes: volumes, + } + return pod +} + // InitRC initializes Kubernetes ReplicationController object func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas int) *api.ReplicationController { rc := &api.ReplicationController{ @@ -169,8 +215,8 @@ func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Se return svc } -// InitConfigMap initializes a ConfigMap object -func (k *Kubernetes) InitConfigMap(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions, envFile string) *api.ConfigMap { +// InitConfigMapForEnv initializes a ConfigMap object +func (k *Kubernetes) InitConfigMapForEnv(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions, envFile string) *api.ConfigMap { envs, err := GetEnvsFromFile(envFile, opt) if err != nil { @@ -197,8 +243,46 @@ func (k *Kubernetes) InitConfigMap(name string, service kobject.ServiceConfig, o return configMap } +//InitConfigMapFromFile initializes a ConfigMap object +func (k *Kubernetes) InitConfigMapFromFile(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions, fileName string) *api.ConfigMap { + content, err := GetContentFromFile(fileName, opt) + if err != nil { + log.Fatalf("Unable to retrieve file: %s", err) + } + + originFileName := FormatFileName(fileName) + dataMap := make(map[string]string) + dataMap[originFileName] = content + configMapName := "" + for key, tmpConfig := range service.ConfigsMetaData { + if tmpConfig.File == fileName { + configMapName = key + } + } + configMap := &api.ConfigMap{ + TypeMeta: unversioned.TypeMeta{ + Kind: "ConfigMap", + APIVersion: "v1", + }, + ObjectMeta: api.ObjectMeta{ + Name: FormatFileName(configMapName), + Labels: transformer.ConfigLabels(name), + }, + Data: dataMap, + } + return configMap +} + // InitD initializes Kubernetes Deployment object func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas int) *extensions.Deployment { + + var podSpec api.PodSpec + if len(service.Configs) > 0 { + podSpec = k.InitPodSpecWithConfigMap(name, service.Image, service) + } else { + podSpec = k.InitPodSpec(name, service.Image) + } + dc := &extensions.Deployment{ TypeMeta: unversioned.TypeMeta{ Kind: "Deployment", @@ -211,7 +295,7 @@ func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas Spec: extensions.DeploymentSpec{ Replicas: int32(replicas), Template: api.PodTemplateSpec{ - Spec: k.InitPodSpec(name, service.Image), + Spec: podSpec, }, }, } @@ -660,9 +744,14 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic opt.Controller = val } + if len(service.Configs) > 0 { + objects = k.createConfigMapFromComposeConfig(name, opt, service, objects) + } + if opt.CreateD || opt.Controller == DeploymentController { objects = append(objects, k.InitD(name, service, replica)) } + if opt.CreateDS || opt.Controller == DaemonSetController { objects = append(objects, k.InitDS(name, service)) } @@ -672,7 +761,7 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic if len(service.EnvFile) > 0 { for _, envFile := range service.EnvFile { - configMap := k.InitConfigMap(name, service, opt, envFile) + configMap := k.InitConfigMapForEnv(name, service, opt, envFile) objects = append(objects, configMap) } } @@ -680,6 +769,20 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic return objects } +func (k *Kubernetes) createConfigMapFromComposeConfig(name string, opt kobject.ConvertOptions, service kobject.ServiceConfig, objects []runtime.Object) []runtime.Object { + for _, config := range service.Configs { + currentConfigName := config.Source + currentConfigObj := service.ConfigsMetaData[currentConfigName] + if currentConfigObj.External.External { + continue + } + currentFileName := currentConfigObj.File + configMap := k.InitConfigMapFromFile(name, service, opt, currentFileName) + objects = append(objects, configMap) + } + return objects +} + // InitPod initializes Kubernetes Pod object func (k *Kubernetes) InitPod(name string, service kobject.ServiceConfig) *api.Pod { pod := api.Pod{ diff --git a/pkg/transformer/openshift/openshift.go b/pkg/transformer/openshift/openshift.go index 97526d69f..1a906e9d1 100644 --- a/pkg/transformer/openshift/openshift.go +++ b/pkg/transformer/openshift/openshift.go @@ -183,6 +183,13 @@ func (o *OpenShift) initDeploymentConfig(name string, service kobject.ServiceCon containerName = []string{service.ContainerName} } + var podSpec kapi.PodSpec + if len(service.Configs) > 0 { + podSpec = o.InitPodSpecWithConfigMap(name, " ", service) + } else { + podSpec = o.InitPodSpec(name, " ") + } + dc := &deployapi.DeploymentConfig{ TypeMeta: unversioned.TypeMeta{ Kind: "DeploymentConfig", @@ -200,7 +207,7 @@ func (o *OpenShift) initDeploymentConfig(name string, service kobject.ServiceCon ObjectMeta: kapi.ObjectMeta{ Labels: transformer.ConfigLabels(name), }, - Spec: o.InitPodSpec(name, " "), + Spec: podSpec, }, Triggers: []deployapi.DeploymentTriggerPolicy{ // Trigger new deploy when DeploymentConfig is created (config change) diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index ba76298e9..8081268d8 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -766,6 +766,44 @@ cmd="kompose --provider=openshift convert --stdout -j -f $KOMPOSE_ROOT/script/te sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/controller/output-os-controller-v3-template.json > /tmp/output-os.json convert::expect_success "$cmd" "/tmp/output-os.json" +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-short.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-k8s-config-short.json > /tmp/output-k8s.json +convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json" + +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-short-warning.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-k8s-config-short-warning.json > /tmp/output-k8s.json +convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json" + +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-long.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-k8s-config-long.json > /tmp/output-k8s.json +convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json" + +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-long-warning.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-k8s-config-long-warning.json > /tmp/output-k8s.json +convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json" + +## Test compose v3.3 +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-1.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-1.json > /tmp/output-k8s.json +convert::expect_success "$cmd" "/tmp/output-k8s.json" + +cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-2.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-2.json > /tmp/output-k8s.json +convert::expect_success "$cmd" "/tmp/output-k8s.json" + +## Test OpenShift for compose v3.3 +cmd="kompose --provider openshift convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-long.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-os-config-long.json > /tmp/output-os.json +convert::expect_success_and_warning "$cmd" "/tmp/output-os.json" + +cmd="kompose --provider openshift convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-config-short.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-os-config-short.json > /tmp/output-os.json +convert::expect_success_and_warning "$cmd" "/tmp/output-os.json" + +cmd="kompose --provider openshift convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-1.yaml" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/compose-v3.3-test/output-os-mode-1.json > /tmp/output-os.json +convert::expect_success "$cmd" "/tmp/output-os.json" + # Testing stdin feature cmd="$KOMPOSE_ROOT/kompose convert --stdout -j -f -" sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/stdin/output.json > /tmp/output-k8s.json @@ -774,4 +812,4 @@ echo -e "\n" go test -v github.com/kubernetes/kompose/script/test/cmd rm /tmp/output-k8s.json /tmp/output-os.json -exit $EXIT_STATUS +exit $EXIT_STATUS \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/compose-config-long-warning.yaml b/script/test/fixtures/compose-v3.3-test/compose-config-long-warning.yaml new file mode 100644 index 000000000..f64f17f15 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/compose-config-long-warning.yaml @@ -0,0 +1,17 @@ +version: "3.3" +services: + redis: + image: redis:latest + deploy: + replicas: 1 + configs: + - source: my_config + target: /redis_config + uid: '103' + gid: '103' + mode: 0440 +configs: + my_config: + file: ./my_config.txt + my_other_config: + external: true \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/compose-config-long.yaml b/script/test/fixtures/compose-v3.3-test/compose-config-long.yaml new file mode 100644 index 000000000..3e8bd9ae1 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/compose-config-long.yaml @@ -0,0 +1,15 @@ +version: "3.3" +services: + redis: + image: redis:latest + deploy: + replicas: 1 + configs: + - source: my_config + target: /redis_config + uid: '103' + gid: '103' + mode: 0440 +configs: + my_config: + file: ./my_config.txt \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/compose-config-short-warning.yaml b/script/test/fixtures/compose-v3.3-test/compose-config-short-warning.yaml new file mode 100644 index 000000000..9fba229fc --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/compose-config-short-warning.yaml @@ -0,0 +1,14 @@ +version: "3.3" +services: + redis: + image: redis:latest + deploy: + replicas: 1 + configs: + - my_config + - my_other_config +configs: + my_config: + file: ./my_config.txt + my_other_config: + external: true \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/compose-config-short.yaml b/script/test/fixtures/compose-v3.3-test/compose-config-short.yaml new file mode 100644 index 000000000..cbdbc5c70 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/compose-config-short.yaml @@ -0,0 +1,11 @@ +version: "3.3" +services: + redis: + image: redis:latest + deploy: + replicas: 1 + configs: + - my_config +configs: + my_config: + file: ./my_config.txt \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-1.yaml b/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-1.yaml new file mode 100644 index 000000000..bcf8d3e72 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-1.yaml @@ -0,0 +1,11 @@ +version: "3.3" + +services: + wordpress: + image: wordpress + ports: + - "8080:80" + deploy: + mode: replicated + replicas: 2 + endpoint_mode: vip \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-2.yaml b/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-2.yaml new file mode 100644 index 000000000..1c9ac9e6e --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/compose-endpoint-mode-2.yaml @@ -0,0 +1,11 @@ +version: "3.3" + +services: + wordpress: + image: wordpress + ports: + - "8080:80" + deploy: + mode: replicated + replicas: 2 + endpoint_mode: dnsrr \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/my_config.txt b/script/test/fixtures/compose-v3.3-test/my_config.txt new file mode 100644 index 000000000..7284ab4d2 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/my_config.txt @@ -0,0 +1 @@ +aaaa \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-k8s-config-long-warning.json b/script/test/fixtures/compose-v3.3-test/output-k8s-config-long-warning.json new file mode 100644 index 000000000..14ec38a24 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-k8s-config-long-warning.json @@ -0,0 +1,74 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "my-config", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "data": { + "my-config.txt": "aaaa" + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "volumes": [ + { + "name": "my-config", + "configMap": { + "name": "my-config", + "defaultMode": 288 + } + } + ], + "containers": [ + { + "name": "redis", + "image": "redis:latest", + "resources": {}, + "volumeMounts": [ + { + "name": "my-config", + "mountPath": "/redis-config" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-k8s-config-long.json b/script/test/fixtures/compose-v3.3-test/output-k8s-config-long.json new file mode 100644 index 000000000..14ec38a24 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-k8s-config-long.json @@ -0,0 +1,74 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "my-config", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "data": { + "my-config.txt": "aaaa" + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "volumes": [ + { + "name": "my-config", + "configMap": { + "name": "my-config", + "defaultMode": 288 + } + } + ], + "containers": [ + { + "name": "redis", + "image": "redis:latest", + "resources": {}, + "volumeMounts": [ + { + "name": "my-config", + "mountPath": "/redis-config" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-k8s-config-short-warning.json b/script/test/fixtures/compose-v3.3-test/output-k8s-config-short-warning.json new file mode 100644 index 000000000..a7cb83239 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-k8s-config-short-warning.json @@ -0,0 +1,59 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "my-config", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "data": { + "my-config.txt": "aaaa" + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "redis:latest", + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-k8s-config-short.json b/script/test/fixtures/compose-v3.3-test/output-k8s-config-short.json new file mode 100644 index 000000000..a7cb83239 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-k8s-config-short.json @@ -0,0 +1,59 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "my-config", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "data": { + "my-config.txt": "aaaa" + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "redis:latest", + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-1.json b/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-1.json new file mode 100644 index 000000000..18895b3c6 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-1.json @@ -0,0 +1,81 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "port": 8080, + "targetPort": 80 + } + ], + "selector": { + "io.kompose.service": "wordpress" + }, + "type": "NodePort" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 2, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + } + }, + "spec": { + "containers": [ + { + "name": "wordpress", + "image": "wordpress", + "ports": [ + { + "containerPort": 80 + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} diff --git a/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-2.json b/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-2.json new file mode 100644 index 000000000..71342618c --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-k8s-endpoint-mode-2.json @@ -0,0 +1,80 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "port": 8080, + "targetPort": 80 + } + ], + "selector": { + "io.kompose.service": "wordpress" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 2, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + } + }, + "spec": { + "containers": [ + { + "name": "wordpress", + "image": "wordpress", + "ports": [ + { + "containerPort": 80 + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} diff --git a/script/test/fixtures/compose-v3.3-test/output-os-config-long.json b/script/test/fixtures/compose-v3.3-test/output-os-config-long.json new file mode 100644 index 000000000..0a90c9188 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-os-config-long.json @@ -0,0 +1,126 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "my-config", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "data": { + "my-config.txt": "aaaa" + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "redis" + ], + "from": { + "kind": "ImageStreamTag", + "name": "redis:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "volumes": [ + { + "name": "my-config", + "configMap": { + "name": "my-config", + "defaultMode": 288 + } + } + ], + "containers": [ + { + "name": "redis", + "image": " ", + "resources": {}, + "volumeMounts": [ + { + "name": "my-config", + "mountPath": "/redis-config" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "redis:latest" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-os-config-short.json b/script/test/fixtures/compose-v3.3-test/output-os-config-short.json new file mode 100644 index 000000000..3edbaa063 --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-os-config-short.json @@ -0,0 +1,111 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "my-config", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "data": { + "my-config.txt": "aaaa" + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "redis" + ], + "from": { + "kind": "ImageStreamTag", + "name": "redis:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": " ", + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "redis:latest" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + } + ] +} \ No newline at end of file diff --git a/script/test/fixtures/compose-v3.3-test/output-os-mode-1.json b/script/test/fixtures/compose-v3.3-test/output-os-mode-1.json new file mode 100644 index 000000000..18b8e2cea --- /dev/null +++ b/script/test/fixtures/compose-v3.3-test/output-os-mode-1.json @@ -0,0 +1,133 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "port": 8080, + "targetPort": 80 + } + ], + "selector": { + "io.kompose.service": "wordpress" + }, + "type": "NodePort" + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "wordpress" + ], + "from": { + "kind": "ImageStreamTag", + "name": "wordpress:latest" + } + } + } + ], + "replicas": 2, + "test": false, + "selector": { + "io.kompose.service": "wordpress" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + } + }, + "spec": { + "containers": [ + { + "name": "wordpress", + "image": " ", + "ports": [ + { + "containerPort": 80 + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "wordpress" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "wordpress" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } + } + ] +} \ No newline at end of file From a012fba1c23f3a3240eb199e6229436bd6dc2a17 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Thu, 9 Aug 2018 22:46:41 +0800 Subject: [PATCH 2/6] Support read data from stdin --- pkg/loader/compose/compose.go | 25 ++++------- pkg/loader/compose/utils.go | 16 +++++++ pkg/loader/compose/v3.go | 3 +- script/test/cmd/tests.sh | 6 ++- .../test/fixtures/stdin/docker-compose.yaml | 4 ++ script/test/fixtures/stdin/output-k8s.json | 45 +++++++++++++++++++ 6 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 script/test/fixtures/stdin/docker-compose.yaml create mode 100644 script/test/fixtures/stdin/output-k8s.json diff --git a/pkg/loader/compose/compose.go b/pkg/loader/compose/compose.go index 2dabee42b..9186f3765 100644 --- a/pkg/loader/compose/compose.go +++ b/pkg/loader/compose/compose.go @@ -18,14 +18,10 @@ package compose import ( "fmt" - "io/ioutil" "reflect" "strings" - yaml "gopkg.in/yaml.v2" - - "bufio" - "os" + "gopkg.in/yaml.v2" "github.com/docker/libcompose/project" "github.com/fatih/structs" @@ -34,6 +30,9 @@ import ( log "github.com/sirupsen/logrus" ) +// +var StdinData []byte + // Compose is docker compose file loader, implements Loader interface type Compose struct { } @@ -182,7 +181,7 @@ func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) { return kobject.KomposeObject{}, err } return komposeObject, nil - // Use docker/cli for 3 + // Use docker/cli for 3 case "3", "3.0", "3.1", "3.2", "3.3": komposeObject, err := parseV3(files) if err != nil { @@ -200,16 +199,10 @@ func getVersionFromFile(file string) (string, error) { Version string `json:"version"` // This affects YAML as well } var version ComposeVersion - var loadedFile []byte - var err error - if file == "-" { - data := bufio.NewScanner(os.Stdin) - loadedFile = data.Bytes() - } else { - loadedFile, err = ioutil.ReadFile(file) - if err != nil { - return "", err - } + loadedFile, err := ReadFile(file) + + if err != nil { + return "", err } err = yaml.Unmarshal(loadedFile, &version) diff --git a/pkg/loader/compose/utils.go b/pkg/loader/compose/utils.go index d67732e1a..e3ead7476 100644 --- a/pkg/loader/compose/utils.go +++ b/pkg/loader/compose/utils.go @@ -17,6 +17,7 @@ limitations under the License. package compose import ( + "io/ioutil" "os" "path/filepath" "strings" @@ -115,3 +116,18 @@ func handleServiceType(ServiceType string) (string, error) { func normalizeServiceNames(svcName string) string { return strings.Replace(svcName, "_", "-", -1) } + +// ReadFile read data from file or stdin +func ReadFile(fileName string) ([]byte, error) { + if fileName == "-" { + if StdinData == nil { + data, err := ioutil.ReadAll(os.Stdin) + StdinData = data + return data, err + } else { + return StdinData, nil + } + } + return ioutil.ReadFile(fileName) + +} diff --git a/pkg/loader/compose/v3.go b/pkg/loader/compose/v3.go index 75030c20a..27c7a22f8 100644 --- a/pkg/loader/compose/v3.go +++ b/pkg/loader/compose/v3.go @@ -17,7 +17,6 @@ limitations under the License. package compose import ( - "io/ioutil" "strconv" "strings" "time" @@ -77,7 +76,7 @@ func parseV3(files []string) (kobject.KomposeObject, error) { var config *types.Config for _, file := range files { // Load and then parse the YAML first! - loadedFile, err := ioutil.ReadFile(file) + loadedFile, err := ReadFile(file) if err != nil { return kobject.KomposeObject{}, err } diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 8081268d8..193cda377 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -805,8 +805,10 @@ sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/f convert::expect_success "$cmd" "/tmp/output-os.json" # Testing stdin feature -cmd="$KOMPOSE_ROOT/kompose convert --stdout -j -f -" -sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/stdin/output.json > /tmp/output-k8s.json +cmd="kompose convert --stdout -j -f -" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/stdin/output-k8s.json > /tmp/output-k8s.json +cat $KOMPOSE_ROOT/script/test/fixtures/stdin/docker-compose.yaml | $cmd | diff /tmp/output-k8s.json - +EXIT_STATUS=$? echo -e "\n" go test -v github.com/kubernetes/kompose/script/test/cmd diff --git a/script/test/fixtures/stdin/docker-compose.yaml b/script/test/fixtures/stdin/docker-compose.yaml new file mode 100644 index 000000000..8ba27bdab --- /dev/null +++ b/script/test/fixtures/stdin/docker-compose.yaml @@ -0,0 +1,4 @@ +version: '3' +services: + backend: + image: helloworld diff --git a/script/test/fixtures/stdin/output-k8s.json b/script/test/fixtures/stdin/output-k8s.json new file mode 100644 index 000000000..e67cf971d --- /dev/null +++ b/script/test/fixtures/stdin/output-k8s.json @@ -0,0 +1,45 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "backend", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "backend" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" + } + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "backend" + } + }, + "spec": { + "containers": [ + { + "name": "backend", + "image": "helloworld", + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +} From a788ab7a78f6fa602d45a1f1ed3b93503e938a88 Mon Sep 17 00:00:00 2001 From: Robert Crossfield Date: Fri, 7 Sep 2018 10:56:36 +1000 Subject: [PATCH 3/6] Use OS provided temporary directory Fix for #966 --- pkg/utils/docker/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/utils/docker/build.go b/pkg/utils/docker/build.go index a395eecf1..192a07c8d 100644 --- a/pkg/utils/docker/build.go +++ b/pkg/utils/docker/build.go @@ -43,7 +43,7 @@ func (c *Build) BuildImage(source string, image string, dockerfile string) error log.Infof("Building image '%s' from directory '%s'", image, path.Base(source)) // Create a temporary file for tarball image packaging - tmpFile, err := ioutil.TempFile("/tmp", "kompose-image-build-") + tmpFile, err := ioutil.TempFile(os.TempDir(), "kompose-image-build-") if err != nil { return err } From 424f1a9a2cc1ad5125129b910da520d956fea437 Mon Sep 17 00:00:00 2001 From: "Roberto C. Morano" Date: Fri, 28 Sep 2018 14:20:01 +0200 Subject: [PATCH 4/6] Propagate dots into valid service names (#1063) * normalize '.' (dot) to '-' (dash) in service names * added warning about the dot character replacements in service names * fix gofmt compliance * also normalize container names (need lowercase) * splitted normalization for volumes and service names into different functions (it conflicted with './' volumes replacement) * changed volume normalization to use the new own normalization function * changed container normalization to use its new own normalization function * updated as per discussed in PR #1063 review --- docs/user-guide.md | 2 +- pkg/loader/compose/utils.go | 10 ++++++++++ pkg/loader/compose/v1v2.go | 4 ++-- pkg/loader/compose/v3.go | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/user-guide.md b/docs/user-guide.md index f48e6c910..14b4e183a 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -429,7 +429,7 @@ services: If the Docker Compose file has a volume specified for a service, the Deployment (Kubernetes) or DeploymentConfig (OpenShift) strategy is changed to "Recreate" instead of "RollingUpdate" (default). This is done to avoid multiple instances of a service from accessing a volume at the same time. -If the Docker Compose file has service name with `_` in it (eg.`web_service`), then it will be replaced by `-` and the service name will be renamed accordingly (eg.`web-service`). Kompose does this because "Kubernetes" doesn't allow `_` in object name. +If the Docker Compose file has service name with `_` or `.` in it (eg.`web_service` or `web.service`), then it will be replaced by `-` and the service name will be renamed accordingly (eg.`web-service`). Kompose does this because "Kubernetes" doesn't allow `_` in object name. Please note that changing service name might break some `docker-compose` files. diff --git a/pkg/loader/compose/utils.go b/pkg/loader/compose/utils.go index d67732e1a..8c1bf9ff8 100644 --- a/pkg/loader/compose/utils.go +++ b/pkg/loader/compose/utils.go @@ -19,6 +19,7 @@ package compose import ( "os" "path/filepath" + "regexp" "strings" "github.com/kubernetes/kompose/pkg/kobject" @@ -112,6 +113,15 @@ func handleServiceType(ServiceType string) (string, error) { } } +func normalizeContainerNames(svcName string) string { + return strings.ToLower(svcName) +} + func normalizeServiceNames(svcName string) string { + re := regexp.MustCompile("[._]") + return strings.ToLower(re.ReplaceAllString(svcName, "-")) +} + +func normalizeVolumes(svcName string) string { return strings.Replace(svcName, "_", "-", -1) } diff --git a/pkg/loader/compose/v1v2.go b/pkg/loader/compose/v1v2.go index 9d9855644..324b3e425 100644 --- a/pkg/loader/compose/v1v2.go +++ b/pkg/loader/compose/v1v2.go @@ -193,7 +193,7 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose serviceConfig := kobject.ServiceConfig{} serviceConfig.Image = composeServiceConfig.Image serviceConfig.Build = composeServiceConfig.Build.Context - newName := normalizeServiceNames(composeServiceConfig.ContainerName) + newName := normalizeContainerNames(composeServiceConfig.ContainerName) serviceConfig.ContainerName = newName if newName != composeServiceConfig.ContainerName { log.Infof("Container name in service %q has been changed from %q to %q", name, composeServiceConfig.ContainerName, newName) @@ -224,7 +224,7 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose if composeServiceConfig.Volumes != nil { for _, volume := range composeServiceConfig.Volumes.Volumes { - v := normalizeServiceNames(volume.String()) + v := normalizeVolumes(volume.String()) serviceConfig.VolList = append(serviceConfig.VolList, v) } } diff --git a/pkg/loader/compose/v3.go b/pkg/loader/compose/v3.go index 75030c20a..dd79cfa32 100644 --- a/pkg/loader/compose/v3.go +++ b/pkg/loader/compose/v3.go @@ -160,7 +160,7 @@ func loadV3Volumes(volumes []types.ServiceVolumeConfig) []string { for _, vol := range volumes { // There will *always* be Source when parsing - v := normalizeServiceNames(vol.Source) + v := normalizeVolumes(vol.Source) if vol.Target != "" { v = v + ":" + vol.Target @@ -270,7 +270,7 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose serviceConfig.Stdin = composeServiceConfig.StdinOpen serviceConfig.Tty = composeServiceConfig.Tty serviceConfig.TmpFs = composeServiceConfig.Tmpfs - serviceConfig.ContainerName = composeServiceConfig.ContainerName + serviceConfig.ContainerName = normalizeContainerNames(composeServiceConfig.ContainerName) serviceConfig.Command = composeServiceConfig.Entrypoint serviceConfig.Args = composeServiceConfig.Command serviceConfig.Labels = composeServiceConfig.Labels From 2717f17e3b8d2415d0ffdd90eb512f1dd9467d60 Mon Sep 17 00:00:00 2001 From: Harald Nordgren Date: Tue, 23 Oct 2018 16:16:20 +0200 Subject: [PATCH 5/6] Bump Go versions (#1073) * Bump Go versions * Unbreak fetching of 'golang/lint' --- .travis.yml | 6 +++--- Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b05745358..da6a79225 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,14 @@ go_import_path: github.com/kubernetes/kompose matrix: include: - - go: 1.7 + - go: "1.9" env: # Only build docs once - BUILD_DOCS=yes # Test cross-compile as well - CROSS_COMPILE=yes - - go: 1.8 - - go: 1.9 + - go: "1.10" + - go: "1.11" install: - true diff --git a/Makefile b/Makefile index 8580ef4ef..576355365 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ test-dep: go get github.com/modocache/gover go get github.com/Masterminds/glide go get github.com/sgotti/glide-vc - go get github.com/golang/lint/golint + go get golang.org/x/lint/golint go get github.com/mitchellh/gox From a74acad03a0de0feba53d67bc2b601d04242f559 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Mon, 5 Nov 2018 10:34:31 -0500 Subject: [PATCH 6/6] 1.17.0 Release (#1075) --- CHANGELOG.md | 67 +++++++++++++++++++++++++++++++++++++++--- README.md | 6 ++-- build/VERSION | 2 +- docs/installation.md | 6 ++-- docs/introduction.md | 6 ++-- pkg/version/version.go | 2 +- 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c230e6f9..1221b4fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,63 @@ # Change Log +## [v1.17.0](https://github.com/kubernetes/kompose/tree/v1.17.0) (2018-11-05) +[Full Changelog](https://github.com/kubernetes/kompose/compare/v1.16.0...v1.17.0) + +**Closed issues:** + +- Use tide for PR merging [\#1069](https://github.com/kubernetes/kompose/issues/1069) +- kompose up - unmarshal errors when using docker compose version '3' [\#1064](https://github.com/kubernetes/kompose/issues/1064) +- dots get propagated into invalid names [\#1062](https://github.com/kubernetes/kompose/issues/1062) +- kompose webside is outdated [\#1057](https://github.com/kubernetes/kompose/issues/1057) +- read input from stdin does not work [\#1056](https://github.com/kubernetes/kompose/issues/1056) +- Init Containers [\#1053](https://github.com/kubernetes/kompose/issues/1053) +- Installation Instructions for openSUSE/SLE [\#1049](https://github.com/kubernetes/kompose/issues/1049) +- getsockopt: connection refused when executing kompose up [\#1023](https://github.com/kubernetes/kompose/issues/1023) +- Support specifying nodePort via label [\#1022](https://github.com/kubernetes/kompose/issues/1022) +- Failing with my Node.js, RabbitMQ app [\#1019](https://github.com/kubernetes/kompose/issues/1019) +- Create a SECURITY\_CONTACTS file. [\#1015](https://github.com/kubernetes/kompose/issues/1015) +- Add support for Docker stack files [\#1014](https://github.com/kubernetes/kompose/issues/1014) +- multiple containers in a pod sharing volume [\#1012](https://github.com/kubernetes/kompose/issues/1012) +- Missing service metadata.labels mapping [\#1010](https://github.com/kubernetes/kompose/issues/1010) +- when to support this parameter build: args? [\#1004](https://github.com/kubernetes/kompose/issues/1004) +- Glide update error [\#1003](https://github.com/kubernetes/kompose/issues/1003) +- Activate downward api [\#1002](https://github.com/kubernetes/kompose/issues/1002) +- FATA services.xxx.ports.0 must be a string or number [\#986](https://github.com/kubernetes/kompose/issues/986) +- Remove status field in the generated yaml [\#975](https://github.com/kubernetes/kompose/issues/975) +- Create Rolling updates using Kompose tool [\#965](https://github.com/kubernetes/kompose/issues/965) +- Support ubuntu's snap package format [\#964](https://github.com/kubernetes/kompose/issues/964) +- kompose up is not able to mount configmap volume [\#962](https://github.com/kubernetes/kompose/issues/962) +- How do I Specify the instance count via docker -compose file for Kompose [\#958](https://github.com/kubernetes/kompose/issues/958) +- Remove RC from supported workload [\#947](https://github.com/kubernetes/kompose/issues/947) +- Add HTTPS support for download URLs [\#945](https://github.com/kubernetes/kompose/issues/945) +- Coordinated efforts / centralized location for packages. [\#942](https://github.com/kubernetes/kompose/issues/942) +- docker-compose version 3.3 is not supported. [\#914](https://github.com/kubernetes/kompose/issues/914) +- extended env\_file capability to in-docker-compose.yml substitutions [\#909](https://github.com/kubernetes/kompose/issues/909) +- Allow specifying imagePullSecret [\#897](https://github.com/kubernetes/kompose/issues/897) +- Doesn't run on alpine? [\#890](https://github.com/kubernetes/kompose/issues/890) +- \[EPIC\] Improvements to volumes [\#884](https://github.com/kubernetes/kompose/issues/884) +- Refactor tests \(integration\) [\#877](https://github.com/kubernetes/kompose/issues/877) +- Not creation of `-service.yaml` when `restart` is present [\#851](https://github.com/kubernetes/kompose/issues/851) +- Update Kubernetes cluster tests with port testing [\#789](https://github.com/kubernetes/kompose/issues/789) +- Add testing documentation [\#781](https://github.com/kubernetes/kompose/issues/781) +- Update to annotations / cli tests + development document [\#770](https://github.com/kubernetes/kompose/issues/770) +- Adding compatibility matrix for different Kubernetes versions [\#726](https://github.com/kubernetes/kompose/issues/726) +- Add OpenShift specific examples for conversion [\#676](https://github.com/kubernetes/kompose/issues/676) +- Clean up and add current example files to integration tests. [\#675](https://github.com/kubernetes/kompose/issues/675) +- Add openshift tests for docker compose v3 [\#641](https://github.com/kubernetes/kompose/issues/641) +- duplicate info from multiple compose files not being overridden [\#624](https://github.com/kubernetes/kompose/issues/624) +- Add design decisions for contributors [\#607](https://github.com/kubernetes/kompose/issues/607) +- kompose logo [\#274](https://github.com/kubernetes/kompose/issues/274) +- add tests when converting to separate files [\#129](https://github.com/kubernetes/kompose/issues/129) + +**Merged pull requests:** + +- Bump Go versions [\#1073](https://github.com/kubernetes/kompose/pull/1073) ([HaraldNordgren](https://github.com/HaraldNordgren)) +- Use OS provided temporary directory [\#1068](https://github.com/kubernetes/kompose/pull/1068) ([segrax](https://github.com/segrax)) +- Propagate dots into valid service names [\#1063](https://github.com/kubernetes/kompose/pull/1063) ([rcmorano](https://github.com/rcmorano)) +- Support read data from stdin [\#1061](https://github.com/kubernetes/kompose/pull/1061) ([hangyan](https://github.com/hangyan)) +- Add support for Config, endpoint\_mode and 3.3 support [\#994](https://github.com/kubernetes/kompose/pull/994) ([xianlubird](https://github.com/xianlubird)) + ## [v1.16.0](https://github.com/kubernetes/kompose/tree/v1.16.0) (2018-07-24) [Full Changelog](https://github.com/kubernetes/kompose/compare/v1.15.0...v1.16.0) @@ -16,6 +74,7 @@ **Merged pull requests:** +- 1.16.0 Release [\#1055](https://github.com/kubernetes/kompose/pull/1055) ([cdrage](https://github.com/cdrage)) - Add installation instructions for openSUSE/SLE [\#1050](https://github.com/kubernetes/kompose/pull/1050) ([suntorytimed](https://github.com/suntorytimed)) - Add surajnarwade in OWNER file [\#1047](https://github.com/kubernetes/kompose/pull/1047) ([surajnarwade](https://github.com/surajnarwade)) - Support node.labels at placement [\#1041](https://github.com/kubernetes/kompose/pull/1041) ([jvitor83](https://github.com/jvitor83)) @@ -240,7 +299,7 @@ - 1.7.0 Release [\#906](https://github.com/kubernetes/kompose/pull/906) ([cdrage](https://github.com/cdrage)) - Convert registry to k8s.gcr.io [\#901](https://github.com/kubernetes/kompose/pull/901) ([thockin](https://github.com/thockin)) -- Added Case for Config Map in kompose down [\#900](https://github.com/kubernetes/kompose/pull/900) ([piyush1594](https://github.com/piyush1594)) +- Added Case for Config Map in kompose down [\#900](https://github.com/kubernetes/kompose/pull/900) ([piyush-garg](https://github.com/piyush-garg)) - Update code-of-conduct.md [\#899](https://github.com/kubernetes/kompose/pull/899) ([spiffxp](https://github.com/spiffxp)) - Add kompose.service.expose.tls-secret [\#896](https://github.com/kubernetes/kompose/pull/896) ([Code0x58](https://github.com/Code0x58)) - Fix pushing of image to a private repository [\#895](https://github.com/kubernetes/kompose/pull/895) ([Code0x58](https://github.com/Code0x58)) @@ -301,10 +360,10 @@ - 1.4.0 Release [\#858](https://github.com/kubernetes/kompose/pull/858) ([cdrage](https://github.com/cdrage)) - Updated `--help` page for `kompose up` [\#852](https://github.com/kubernetes/kompose/pull/852) ([surajnarwade](https://github.com/surajnarwade)) -- Fix Redirecting Error in README.md [\#849](https://github.com/kubernetes/kompose/pull/849) ([piyush1594](https://github.com/piyush1594)) +- Fix Redirecting Error in README.md [\#849](https://github.com/kubernetes/kompose/pull/849) ([piyush-garg](https://github.com/piyush-garg)) - Redirects not working [\#848](https://github.com/kubernetes/kompose/pull/848) ([cdrage](https://github.com/cdrage)) -- Fix Redirecting Error [\#847](https://github.com/kubernetes/kompose/pull/847) ([piyush1594](https://github.com/piyush1594)) -- Added Fabric8 Maven Plugin in Integration [\#836](https://github.com/kubernetes/kompose/pull/836) ([piyush1594](https://github.com/piyush1594)) +- Fix Redirecting Error [\#847](https://github.com/kubernetes/kompose/pull/847) ([piyush-garg](https://github.com/piyush-garg)) +- Added Fabric8 Maven Plugin in Integration [\#836](https://github.com/kubernetes/kompose/pull/836) ([piyush-garg](https://github.com/piyush-garg)) - Adding documentation for tests [\#819](https://github.com/kubernetes/kompose/pull/819) ([ashetty1](https://github.com/ashetty1)) ## [v1.3.0](https://github.com/kubernetes/kompose/tree/v1.3.0) (2017-10-10) diff --git a/README.md b/README.md index 6aa418293..170d4f863 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,10 @@ __Linux and macOS:__ ```sh # Linux -curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-linux-amd64 -o kompose +curl -L https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-linux-amd64 -o kompose # macOS -curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-darwin-amd64 -o kompose +curl -L https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-darwin-amd64 -o kompose chmod +x kompose sudo mv ./kompose /usr/local/bin/kompose @@ -56,7 +56,7 @@ sudo mv ./kompose /usr/local/bin/kompose __Windows:__ -Download from [GitHub](https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-windows-amd64.exe) and add the binary to your PATH. +Download from [GitHub](https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-windows-amd64.exe) and add the binary to your PATH. ## Shell autocompletion diff --git a/build/VERSION b/build/VERSION index 15b989e39..092afa15d 100644 --- a/build/VERSION +++ b/build/VERSION @@ -1 +1 @@ -1.16.0 +1.17.0 diff --git a/docs/installation.md b/docs/installation.md index 05d50f1e7..e4e39a836 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -10,10 +10,10 @@ __Linux and macOS:__ ```sh # Linux -curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-linux-amd64 -o kompose +curl -L https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-linux-amd64 -o kompose # macOS -curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-darwin-amd64 -o kompose +curl -L https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-darwin-amd64 -o kompose chmod +x kompose sudo mv ./kompose /usr/local/bin/kompose @@ -21,7 +21,7 @@ sudo mv ./kompose /usr/local/bin/kompose __Windows:__ -Download from [GitHub](https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-windows-amd64.exe) and add the binary to your PATH. +Download from [GitHub](https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-windows-amd64.exe) and add the binary to your PATH. #### Go diff --git a/docs/introduction.md b/docs/introduction.md index 81ee3f286..838c5de5e 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -47,13 +47,13 @@ Grab the Kompose binary! ```sh # Linux -curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-linux-amd64 -o kompose +curl -L https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-linux-amd64 -o kompose # macOS -curl -L https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-darwin-amd64 -o kompose +curl -L https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-darwin-amd64 -o kompose chmod +x kompose sudo mv ./kompose /usr/local/bin/kompose ``` -_Windows:_ Download from [GitHub](https://github.com/kubernetes/kompose/releases/download/v1.16.0/kompose-windows-amd64.exe) and add the binary to your PATH. +_Windows:_ Download from [GitHub](https://github.com/kubernetes/kompose/releases/download/v1.17.0/kompose-windows-amd64.exe) and add the binary to your PATH. diff --git a/pkg/version/version.go b/pkg/version/version.go index 33ee75056..9ca9f0d4e 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -2,7 +2,7 @@ package version var ( // VERSION is version number that will be displayed when running ./kompose version - VERSION = "1.16.0" + VERSION = "1.17.0" // GITCOMMIT is hash of the commit that will be displayed when running ./kompose version // this will be overwritten when running build like this: go build -ldflags="-X github.com/kubernetes/kompose/pkg/version.GITCOMMIT=$(GITCOMMIT)" // HEAD is default indicating that this was not set during build