diff --git a/go.mod b/go.mod index a138080..9a6fc3a 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/spf13/pflag v1.0.3 // indirect github.com/stretchr/testify v1.3.0 + github.com/subosito/gotenv v1.2.0 // indirect golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 // indirect golang.org/x/text v0.3.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 4f08314..bd72cdf 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= diff --git a/pkg/acceptance/acceptance.go b/pkg/acceptance/acceptance.go new file mode 100644 index 0000000..bdb49c3 --- /dev/null +++ b/pkg/acceptance/acceptance.go @@ -0,0 +1,71 @@ +package acceptance + +import ( + "bytes" + "fmt" + "log" + "os" + "os/exec" + + "github.com/subosito/gotenv" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/clientcmd" +) + +func buildEnv(makefile string) error { + cmd := exec.Command("make", "local-env", "-f", makefile) + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &stderr + err := cmd.Run() + log.Printf("%q", out.String()) + log.Printf("%q", stderr.String()) + if err != nil { + log.Fatal(err) + return err + } + env, err := gotenv.StrictParse(&out) + if err != nil { + return err + } + + for key, val := range env { + fmt.Println(fmt.Sprintf("%s: %s", key, val)) + if _, present := os.LookupEnv(key); !present { + os.Setenv(key, val) + } + } + return nil +} + +func KubernetesCluster(makefile string) (kubernetes.ClientSet, error) { + err := buildEnv(makefile) + if err != nil { + log.Fatal(err) + return nil, err + } + cmd := exec.Command("make", "local-cluster", "-f", makefile) + var out bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &stderr + err = cmd.Run() + log.Printf("%q", out.String()) + log.Printf("%q", stderr.String()) + if err != nil { + log.Fatal(err) + return nil, err + } + + loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() + configOverrides := &clientcmd.ConfigOverrides{} + kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides) + config, err := kubeConfig.ClientConfig() + if err != nil { + log.Fatal(err) + return nil, err + } + clientset, err := kubernetes.NewForConfig(config) + return clientset, nil +} diff --git a/pkg/acceptance/acceptance_test.go b/pkg/acceptance/acceptance_test.go new file mode 100644 index 0000000..7250a95 --- /dev/null +++ b/pkg/acceptance/acceptance_test.go @@ -0,0 +1 @@ +package acceptance \ No newline at end of file diff --git a/config/config.go b/pkg/config/config.go similarity index 100% rename from config/config.go rename to pkg/config/config.go diff --git a/config/config_test.go b/pkg/config/config_test.go similarity index 100% rename from config/config_test.go rename to pkg/config/config_test.go diff --git a/containerspec/containerspec.go b/pkg/containerspec/containerspec.go similarity index 100% rename from containerspec/containerspec.go rename to pkg/containerspec/containerspec.go diff --git a/containerspec/containerspec_test.go b/pkg/containerspec/containerspec_test.go similarity index 100% rename from containerspec/containerspec_test.go rename to pkg/containerspec/containerspec_test.go diff --git a/deployments/deployments.go b/pkg/deployments/deployments.go similarity index 98% rename from deployments/deployments.go rename to pkg/deployments/deployments.go index 6c661ab..b4d1e13 100644 --- a/deployments/deployments.go +++ b/pkg/deployments/deployments.go @@ -17,7 +17,7 @@ package deployments import ( "fmt" - paastaconfig "github.com/Yelp/paasta-tools-go/config" + paastaconfig "github.com/Yelp/paasta-tools-go/pkg/config" ) // V2DeploymentGroup ... diff --git a/deployments/deployments_test.go b/pkg/deployments/deployments_test.go similarity index 97% rename from deployments/deployments_test.go rename to pkg/deployments/deployments_test.go index e65d40d..1ea8bd5 100644 --- a/deployments/deployments_test.go +++ b/pkg/deployments/deployments_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - paastaconfig "github.com/Yelp/paasta-tools-go/config" + paastaconfig "github.com/Yelp/paasta-tools-go/pkg/config" ) const ( diff --git a/environment/environment.go b/pkg/environment/environment.go similarity index 100% rename from environment/environment.go rename to pkg/environment/environment.go diff --git a/environment/environment_test.go b/pkg/environment/environment_test.go similarity index 100% rename from environment/environment_test.go rename to pkg/environment/environment_test.go diff --git a/hashing/hashing.go b/pkg/hashing/hashing.go similarity index 100% rename from hashing/hashing.go rename to pkg/hashing/hashing.go diff --git a/hashing/hashing_test.go b/pkg/hashing/hashing_test.go similarity index 100% rename from hashing/hashing_test.go rename to pkg/hashing/hashing_test.go diff --git a/volumes/converter.go b/pkg/volumes/converter.go similarity index 96% rename from volumes/converter.go rename to pkg/volumes/converter.go index 6830336..354485f 100644 --- a/volumes/converter.go +++ b/pkg/volumes/converter.go @@ -2,7 +2,7 @@ package volumes import ( "fmt" - paastaconfig "github.com/Yelp/paasta-tools-go/config" + paastaconfig "github.com/Yelp/paasta-tools-go/pkg/config" corev1 "k8s.io/api/core/v1" "log" "strings" diff --git a/volumes/converter_test.go b/pkg/volumes/converter_test.go similarity index 100% rename from volumes/converter_test.go rename to pkg/volumes/converter_test.go diff --git a/volumes/volumes.go b/pkg/volumes/volumes.go similarity index 90% rename from volumes/volumes.go rename to pkg/volumes/volumes.go index e1ebf70..395ae88 100644 --- a/volumes/volumes.go +++ b/pkg/volumes/volumes.go @@ -1,7 +1,7 @@ package volumes import ( - "github.com/Yelp/paasta-tools-go/config" + "github.com/Yelp/paasta-tools-go/pkg/config" ) type VolumeConfig struct { diff --git a/volumes/volumes_test.go b/pkg/volumes/volumes_test.go similarity index 100% rename from volumes/volumes_test.go rename to pkg/volumes/volumes_test.go