-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple Kubernetes clusters by supporting kubeconfig in test…
… steps - Follow up for #266 (#291) * Support multiple Kubernetes clusters by supporting kubeconfig in test steps Adds a `kubeconfig` setting to the TestStep API allowing an alternative kubeconfig path to be used for asserts and applies in a test step. Signed-off-by: [email protected] <[email protected]> * Resolve relative kubeconfig path against test step dir. Signed-off-by: Tarun Gupta Akirala <[email protected]> * fix linter errors Signed-off-by: Tarun Gupta Akirala <[email protected]> * fix variable name collision with package imports Signed-off-by: Tarun Gupta Akirala <[email protected]> Co-authored-by: [email protected] <[email protected]> Co-authored-by: chhsia0 <[email protected]>
- Loading branch information
1 parent
654174f
commit fc8c0f2
Showing
8 changed files
with
199 additions
and
34 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
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
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,105 @@ | ||
// +build integration | ||
|
||
package test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"k8s.io/client-go/discovery" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/kudobuilder/kuttl/pkg/report" | ||
testutils "github.com/kudobuilder/kuttl/pkg/test/utils" | ||
) | ||
|
||
// Create two test environments, ensure that the second environment is used when | ||
// Kubeconfig is set on a Step. | ||
func TestMultiClusterCase(t *testing.T) { | ||
testenv, err := testutils.StartTestEnvironment(testutils.APIServerDefaultArgs, false) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
defer testenv.Environment.Stop() | ||
|
||
testenv2, err := testutils.StartTestEnvironment(testutils.APIServerDefaultArgs, false) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
defer testenv2.Environment.Stop() | ||
|
||
podSpec := map[string]interface{}{ | ||
"restartPolicy": "Never", | ||
"containers": []map[string]interface{}{ | ||
{ | ||
"name": "nginx", | ||
"image": "nginx:1.7.9", | ||
}, | ||
}, | ||
} | ||
|
||
tmpfile, err := ioutil.TempFile("", "kubeconfig") | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
defer os.Remove(tmpfile.Name()) | ||
if err := testutils.Kubeconfig(testenv2.Config, tmpfile); err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
c := Case{ | ||
Logger: testutils.NewTestLogger(t, ""), | ||
Steps: []*Step{ | ||
{ | ||
Name: "initialize-testenv", | ||
Index: 0, | ||
Apply: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello", ""), podSpec), | ||
}, | ||
Asserts: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello", ""), podSpec), | ||
}, | ||
Timeout: 2, | ||
}, | ||
{ | ||
Name: "use-testenv2", | ||
Index: 1, | ||
Apply: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello2", ""), podSpec), | ||
}, | ||
Asserts: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello2", ""), podSpec), | ||
}, | ||
Errors: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello", ""), podSpec), | ||
}, | ||
Timeout: 2, | ||
Kubeconfig: tmpfile.Name(), | ||
}, | ||
{ | ||
Name: "verify-testenv-does-not-have-testenv2-resources", | ||
Index: 2, | ||
Asserts: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello", ""), podSpec), | ||
}, | ||
Errors: []client.Object{ | ||
testutils.WithSpec(t, testutils.NewPod("hello2", ""), podSpec), | ||
}, | ||
Timeout: 2, | ||
}, | ||
}, | ||
Client: func(bool) (client.Client, error) { | ||
return testenv.Client, nil | ||
}, | ||
DiscoveryClient: func() (discovery.DiscoveryInterface, error) { | ||
return testenv.DiscoveryClient, nil | ||
}, | ||
} | ||
|
||
c.Run(t, &report.Testcase{}) | ||
} |
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
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
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
Oops, something went wrong.