-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:davidtam/terratest
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package k8s | ||
|
||
import "github.com/gruntwork-io/terratest/modules/testing" | ||
|
||
// GetKubernetesClusterVersion returns the Kubernetes cluster version. | ||
func GetKubernetesClusterVersionE(t testing.TestingT) (string, error) { | ||
kubeConfigPath, err := GetKubeConfigPathE(t) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
options := NewKubectlOptions("", kubeConfigPath, "default") | ||
|
||
return GetKubernetesClusterVersionWithOptionsE(t, options) | ||
} | ||
|
||
// GetKubernetesClusterVersion returns the Kubernetes cluster version given a configured KubectlOptions object. | ||
func GetKubernetesClusterVersionWithOptionsE(t testing.TestingT, kubectlOptions *KubectlOptions) (string, error) { | ||
clientset, err := GetKubernetesClientFromOptionsE(t, kubectlOptions) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
versionInfo, err := clientset.DiscoveryClient.ServerVersion() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return versionInfo.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// +build kubeall kubernetes | ||
|
||
// NOTE: we have build tags to differentiate kubernetes tests from non-kubernetes tests. This is done because minikube | ||
// is heavy and can interfere with docker related tests in terratest. Specifically, many of the tests start to fail with | ||
// `connection refused` errors from `minikube`. To avoid overloading the system, we run the kubernetes tests and helm | ||
// tests separately from the others. This may not be necessary if you have a sufficiently powerful machine. We | ||
// recommend at least 4 cores and 16GB of RAM if you want to run all the tests together. | ||
|
||
package k8s | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type KubectlVersion struct { | ||
ServerVersion struct { | ||
GitVersion string `json:"gitVersion"` | ||
} `json:"serverVersion"` | ||
} | ||
|
||
func TestGetKubernetesClusterVersionE(t *testing.T) { | ||
t.Parallel() | ||
|
||
kubernetesClusterVersion, err := GetKubernetesClusterVersionE(t) | ||
require.NoError(t, err) | ||
|
||
options := NewKubectlOptions("", "", "") | ||
kubernetesClusterVersionFromKubectl, err := RunKubectlAndGetOutputE(t, options, "version", "-o", "json") | ||
require.NoError(t, err) | ||
|
||
var kctlClusterVersion KubectlVersion | ||
require.NoError( | ||
t, | ||
json.Unmarshal([]byte(kubernetesClusterVersionFromKubectl), &kctlClusterVersion), | ||
) | ||
|
||
assert.EqualValues(t, kubernetesClusterVersion, kctlClusterVersion.ServerVersion.GitVersion) | ||
} | ||
|
||
func TestGetKubernetesClusterVersionWithOptionsE(t *testing.T) { | ||
t.Parallel() | ||
|
||
options := NewKubectlOptions("", "", "") | ||
kubernetesClusterVersion, err := GetKubernetesClusterVersionWithOptionsE(t, options) | ||
require.NoError(t, err) | ||
|
||
kubernetesClusterVersionFromKubectl, err := RunKubectlAndGetOutputE(t, options, "version", "-o", "json") | ||
require.NoError(t, err) | ||
|
||
var kctlClusterVersion KubectlVersion | ||
require.NoError( | ||
t, | ||
json.Unmarshal([]byte(kubernetesClusterVersionFromKubectl), &kctlClusterVersion), | ||
) | ||
|
||
assert.EqualValues(t, kubernetesClusterVersion, kctlClusterVersion.ServerVersion.GitVersion) | ||
} |