From 8ddadfca881e2434d8ec338fcc4e22880ca522b7 Mon Sep 17 00:00:00 2001 From: Tuna Date: Sat, 6 Aug 2016 23:44:56 +0700 Subject: [PATCH 1/2] enhance warning: networks, network config, volume config. Fixes #88, #71 --- cli/app/app.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cli/app/app.go b/cli/app/app.go index 5ffec0e7..95f99749 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -854,8 +854,25 @@ func loadComposeFile(file string, opt convertOptions) KomposeObject { // transform composeObject into komposeObject composeServiceNames := composeObject.ServiceConfigs.Keys() + + // volume config and network config has not supported + if len(composeObject.NetworkConfigs) > 0 { + logrus.Warningf("Unsupported network configuration of compose v2 - ignoring") + } + if len(composeObject.VolumeConfigs) > 0 { + logrus.Warningf("Unsupported volume configuration of compose v2 - ignoring") + } + + count := 0 for _, name := range composeServiceNames { if composeServiceConfig, ok := composeObject.ServiceConfigs.Get(name); ok { + //FIXME: networks always contains one default element, even it isn't declared in compose v2. + if len(composeServiceConfig.Networks.Networks) > 0 && + strings.Compare(composeServiceConfig.Networks.Networks[0].Name, "default") != 0 && + count == 0 { + logrus.Warningf("Unsupported key networks - ignoring") + count++ + } checkUnsupportedKey(composeServiceConfig) serviceConfig := ServiceConfig{} serviceConfig.Image = composeServiceConfig.Image @@ -1165,9 +1182,9 @@ func Convert(c *cli.Context) { func checkUnsupportedKey(service interface{}) { s := structs.New(service) for _, f := range s.Fields() { - if f.IsExported() && !f.IsZero() { + if f.IsExported() && !f.IsZero() && strings.Compare(f.Name(), "Networks") != 0 { if count, ok := unsupportedKey[f.Name()]; ok && count == 0 { - logrus.Warningf("Unsupported key " + composeOptions[f.Name()] + " - ignoring") + logrus.Warningf("Unsupported key %s - ignoring", composeOptions[f.Name()]) unsupportedKey[f.Name()]++ } } From 908a2563f106ebe98ec5229d4d9e466cb100a12c Mon Sep 17 00:00:00 2001 From: Tuna Date: Wed, 10 Aug 2016 10:09:27 +0700 Subject: [PATCH 2/2] fixing typos --- cli/app/app.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/app/app.go b/cli/app/app.go index 95f99749..069144b6 100644 --- a/cli/app/app.go +++ b/cli/app/app.go @@ -855,7 +855,7 @@ func loadComposeFile(file string, opt convertOptions) KomposeObject { // transform composeObject into komposeObject composeServiceNames := composeObject.ServiceConfigs.Keys() - // volume config and network config has not supported + // volume config and network config are not supported if len(composeObject.NetworkConfigs) > 0 { logrus.Warningf("Unsupported network configuration of compose v2 - ignoring") } @@ -863,15 +863,15 @@ func loadComposeFile(file string, opt convertOptions) KomposeObject { logrus.Warningf("Unsupported volume configuration of compose v2 - ignoring") } - count := 0 + networksWarningFound := false for _, name := range composeServiceNames { if composeServiceConfig, ok := composeObject.ServiceConfigs.Get(name); ok { //FIXME: networks always contains one default element, even it isn't declared in compose v2. if len(composeServiceConfig.Networks.Networks) > 0 && - strings.Compare(composeServiceConfig.Networks.Networks[0].Name, "default") != 0 && - count == 0 { + composeServiceConfig.Networks.Networks[0].Name != "default" && + !networksWarningFound { logrus.Warningf("Unsupported key networks - ignoring") - count++ + networksWarningFound = true } checkUnsupportedKey(composeServiceConfig) serviceConfig := ServiceConfig{} @@ -1182,7 +1182,7 @@ func Convert(c *cli.Context) { func checkUnsupportedKey(service interface{}) { s := structs.New(service) for _, f := range s.Fields() { - if f.IsExported() && !f.IsZero() && strings.Compare(f.Name(), "Networks") != 0 { + if f.IsExported() && !f.IsZero() && f.Name() != "Networks" { if count, ok := unsupportedKey[f.Name()]; ok && count == 0 { logrus.Warningf("Unsupported key %s - ignoring", composeOptions[f.Name()]) unsupportedKey[f.Name()]++