Просмотр исходного кода

remove unused utils pkg

Signed-off-by: aiordache <[email protected]>
aiordache 5 лет назад
Родитель
Сommit
f09a57351f
6 измененных файлов с 12 добавлено и 270 удалено
  1. 0 1
      go.mod
  2. 12 2
      kube/charts/charts.go
  3. 0 142
      kube/utils/config.go
  4. 0 56
      kube/utils/errors.go
  5. 0 35
      kube/utils/labels.go
  6. 0 34
      kube/utils/utils.go

+ 0 - 1
go.mod

@@ -45,7 +45,6 @@ require (
 	github.com/opencontainers/go-digest v1.0.0
 	github.com/opencontainers/image-spec v1.0.1
 	github.com/pkg/errors v0.9.1
-	github.com/prometheus/common v0.10.0
 	github.com/prometheus/tsdb v0.10.0
 	github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b
 	github.com/sirupsen/logrus v1.7.0

+ 12 - 2
kube/charts/charts.go

@@ -20,6 +20,7 @@ package charts
 
 import (
 	"context"
+	"os"
 	"path/filepath"
 	"strings"
 
@@ -28,7 +29,6 @@ import (
 	"github.com/docker/compose-cli/api/context/store"
 	"github.com/docker/compose-cli/kube/charts/helm"
 	"github.com/docker/compose-cli/kube/charts/kubernetes"
-	kubeutils "github.com/docker/compose-cli/kube/utils"
 	chart "helm.sh/helm/v3/pkg/chart"
 	util "helm.sh/helm/v3/pkg/chartutil"
 	helmenv "helm.sh/helm/v3/pkg/cli"
@@ -57,7 +57,7 @@ var _ API = sdk{}
 
 func NewSDK(ctx store.KubeContext) (sdk, error) {
 	return sdk{
-		environment: kubeutils.Environment(),
+		environment: environment(),
 		h:           helm.NewHelmActions(nil),
 	}, nil
 }
@@ -124,3 +124,13 @@ func (s sdk) GenerateChart(project *types.Project, dirname string) error {
 	dirname = filepath.Dir(dirname)
 	return s.SaveChart(project, dirname)
 }
+
+func environment() map[string]string {
+	vars := make(map[string]string)
+	env := os.Environ()
+	for _, v := range env {
+		k := strings.SplitN(v, "=", 2)
+		vars[k[0]] = k[1]
+	}
+	return vars
+}

+ 0 - 142
kube/utils/config.go

@@ -1,142 +0,0 @@
-// +build kube
-
-/*
-   Copyright 2020 Docker Compose CLI authors
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-
-package utils
-
-import (
-	"io/ioutil"
-	"os"
-	"path/filepath"
-	"regexp"
-	"strings"
-
-	"github.com/compose-spec/compose-go/loader"
-	"github.com/compose-spec/compose-go/types"
-	"github.com/prometheus/common/log"
-)
-
-var SupportedFilenames = []string{"compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml"}
-
-func GetConfigs(name string, configPaths []string) (string, []types.ConfigFile, error) {
-	configPath, err := getConfigPaths(configPaths)
-	if err != nil {
-		return "", nil, err
-	}
-	if configPath == nil {
-		return "", nil, nil
-	}
-	workingDir := filepath.Dir(configPath[0])
-
-	if name == "" {
-		name = os.Getenv("COMPOSE_PROJECT_NAME")
-	}
-	if name == "" {
-		r := regexp.MustCompile(`[^a-z0-9\\-_]+`)
-		name = r.ReplaceAllString(strings.ToLower(filepath.Base(workingDir)), "")
-	}
-
-	configs, err := parseConfigs(configPath)
-	if err != nil {
-		return "", nil, err
-	}
-	return workingDir, configs, nil
-}
-
-func getConfigPaths(configPaths []string) ([]string, error) {
-	paths := []string{}
-	pwd, err := os.Getwd()
-	if err != nil {
-		return nil, err
-	}
-
-	if len(configPaths) != 0 {
-		for _, f := range configPaths {
-			if f == "-" {
-				paths = append(paths, f)
-				continue
-			}
-			if !filepath.IsAbs(f) {
-				f = filepath.Join(pwd, f)
-			}
-			if _, err := os.Stat(f); err != nil {
-				return nil, err
-			}
-			paths = append(paths, f)
-		}
-		return paths, nil
-	}
-
-	sep := os.Getenv("COMPOSE_FILE_SEPARATOR")
-	if sep == "" {
-		sep = string(os.PathListSeparator)
-	}
-	f := os.Getenv("COMPOSE_FILE")
-	if f != "" {
-		return strings.Split(f, sep), nil
-	}
-
-	for {
-		candidates := []string{}
-		for _, n := range SupportedFilenames {
-			f := filepath.Join(pwd, n)
-			if _, err := os.Stat(f); err == nil {
-				candidates = append(candidates, f)
-			}
-		}
-		if len(candidates) > 0 {
-			winner := candidates[0]
-			if len(candidates) > 1 {
-				log.Warnf("Found multiple config files with supported names: %s", strings.Join(candidates, ", "))
-				log.Warnf("Using %s\n", winner)
-			}
-			return []string{winner}, nil
-		}
-		parent := filepath.Dir(pwd)
-		if parent == pwd {
-			return nil, nil
-		}
-		pwd = parent
-	}
-}
-
-func parseConfigs(configPaths []string) ([]types.ConfigFile, error) {
-	files := []types.ConfigFile{}
-	for _, f := range configPaths {
-		var (
-			b   []byte
-			err error
-		)
-		if f == "-" {
-			b, err = ioutil.ReadAll(os.Stdin)
-		} else {
-			if _, err := os.Stat(f); err != nil {
-				return nil, err
-			}
-			b, err = ioutil.ReadFile(f)
-		}
-		if err != nil {
-			return nil, err
-		}
-		config, err := loader.ParseYAML(b)
-		if err != nil {
-			return nil, err
-		}
-		files = append(files, types.ConfigFile{Filename: f, Config: config})
-	}
-	return files, nil
-}

+ 0 - 56
kube/utils/errors.go

@@ -1,56 +0,0 @@
-// +build kube
-
-/*
-   Copyright 2020 Docker Compose CLI authors
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-
-package utils
-
-import (
-	"fmt"
-	"strings"
-)
-
-func CombineErrors(errors []error) error {
-	if len(errors) == 0 {
-		return nil
-	}
-	if len(errors) == 1 {
-		return errors[0]
-	}
-	err := combinedError{}
-	for _, e := range errors {
-		if c, ok := e.(combinedError); ok {
-			err.errors = append(err.errors, c.errors...)
-		} else {
-			err.errors = append(err.errors, e)
-		}
-	}
-	return combinedError{errors}
-}
-
-type combinedError struct {
-	errors []error
-}
-
-func (c combinedError) Error() string {
-	points := make([]string, len(c.errors))
-	for i, err := range c.errors {
-		points[i] = fmt.Sprintf("* %s", err.Error())
-	}
-	return fmt.Sprintf(
-		"%d errors occurred:\n\t%s",
-		len(c.errors), strings.Join(points, "\n\t"))
-}

+ 0 - 35
kube/utils/labels.go

@@ -1,35 +0,0 @@
-// +build kube
-
-/*
-   Copyright 2020 Docker Compose CLI authors
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-
-package utils
-
-const (
-	LabelDockerComposePrefix = "com.docker.compose"
-	LabelService             = LabelDockerComposePrefix + ".service"
-	LabelVersion             = LabelDockerComposePrefix + ".version"
-	LabelContainerNumber     = LabelDockerComposePrefix + ".container-number"
-	LabelOneOff              = LabelDockerComposePrefix + ".oneoff"
-	LabelNetwork             = LabelDockerComposePrefix + ".network"
-	LabelSlug                = LabelDockerComposePrefix + ".slug"
-	LabelVolume              = LabelDockerComposePrefix + ".volume"
-	LabelConfigHash          = LabelDockerComposePrefix + ".config-hash"
-	LabelProject             = LabelDockerComposePrefix + ".project"
-	LabelWorkingDir          = LabelDockerComposePrefix + ".working_dir"
-	LabelConfigFiles         = LabelDockerComposePrefix + ".config_files"
-	LabelEnvironmentFile     = LabelDockerComposePrefix + ".environment_file"
-)

+ 0 - 34
kube/utils/utils.go

@@ -1,34 +0,0 @@
-// +build kube
-
-/*
-   Copyright 2020 Docker Compose CLI authors
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-
-package utils
-
-import (
-	"os"
-	"strings"
-)
-
-func Environment() map[string]string {
-	vars := make(map[string]string)
-	env := os.Environ()
-	for _, v := range env {
-		k := strings.SplitN(v, "=", 2)
-		vars[k[0]] = k[1]
-	}
-	return vars
-}