Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow insecure clusters #800

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion testsupport/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/cluster"
appstudiov1 "github.com/codeready-toolchain/toolchain-e2e/testsupport/appstudio/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-e2e/testsupport/util"
"github.com/codeready-toolchain/toolchain-e2e/testsupport/wait"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -53,7 +54,8 @@ func WaitForDeployments(t *testing.T) wait.Awaitilities {

apiConfig, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
require.NoError(t, err)
kubeconfig, err := clientcmd.NewDefaultClientConfig(*apiConfig, &clientcmd.ConfigOverrides{}).ClientConfig()

kubeconfig, err := util.BuildKubernetesClient(*apiConfig)
require.NoError(t, err)

cl, err := client.New(kubeconfig, client.Options{
Expand Down
3 changes: 2 additions & 1 deletion testsupport/space/spacerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ func newKubeClientFromSecret(t *testing.T, cl client.Client, secretName, secretN
require.False(t, api.IsConfigEmpty(apiConfig))

// create a new client with the given kubeconfig
kubeconfig, err := clientcmd.NewDefaultClientConfig(*apiConfig, &clientcmd.ConfigOverrides{}).ClientConfig()
kubeconfig, err := util.BuildKubernetesClient(*apiConfig)
require.NoError(t, err)

s := scheme.Scheme
builder := append(runtime.SchemeBuilder{},
corev1.AddToScheme,
Expand Down
30 changes: 30 additions & 0 deletions testsupport/util/kube_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package util

import (
"os"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
)

const EnvDisableKubeClientTLSVerify string = "DISABLE_KUBE_CLIENT_TLS_VERIFY"

func BuildKubernetesClient(apiConfig api.Config) (*rest.Config, error) {
if os.Getenv(EnvDisableKubeClientTLSVerify) == "true" {
apiConfig = setInsecureSkipTLSVerify(apiConfig)
}

configOverrides := clientcmd.ConfigOverrides{}
return clientcmd.NewDefaultClientConfig(apiConfig, &configOverrides).ClientConfig()
}

func setInsecureSkipTLSVerify(apiConfig api.Config) api.Config {
for _, c := range apiConfig.Clusters {
if c != nil {
c.CertificateAuthorityData = nil
c.InsecureSkipTLSVerify = true
}
}
return apiConfig
}
4 changes: 3 additions & 1 deletion testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/codeready-toolchain/toolchain-common/pkg/spacebinding"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"
testutil "github.com/codeready-toolchain/toolchain-e2e/testsupport/util"

"github.com/davecgh/go-spew/spew"
"github.com/ghodss/yaml"
Expand Down Expand Up @@ -1664,7 +1665,8 @@ func (a *HostAwaitility) GetHostOperatorPod() (corev1.Pod, error) {
func (a *HostAwaitility) CreateAPIProxyConfig(t *testing.T, usertoken, proxyURL string) *rest.Config {
apiConfig, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
require.NoError(t, err)
defaultConfig, err := clientcmd.NewDefaultClientConfig(*apiConfig, &clientcmd.ConfigOverrides{}).ClientConfig()

defaultConfig, err := testutil.BuildKubernetesClient(*apiConfig)
require.NoError(t, err)

return &rest.Config{
Expand Down