File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ import (
28
28
"k8s.io/apimachinery/pkg/runtime"
29
29
"k8s.io/apimachinery/pkg/types"
30
30
"k8s.io/client-go/kubernetes/scheme"
31
-
31
+ "k8s.io/client-go/tools/clientcmd"
32
32
"sigs.k8s.io/controller-runtime/pkg/client"
33
33
)
34
34
@@ -682,6 +682,14 @@ var _ = Describe("Test", func() {
682
682
})
683
683
})
684
684
685
+ It ("should set a working KubeConfig" , func () {
686
+ kubeconfigRESTConfig , err := clientcmd .RESTConfigFromKubeConfig (env .KubeConfig )
687
+ Expect (err ).ToNot (HaveOccurred ())
688
+ kubeconfigClient , err := client .New (kubeconfigRESTConfig , client.Options {Scheme : s })
689
+ Expect (err ).NotTo (HaveOccurred ())
690
+ Expect (kubeconfigClient .List (context .Background (), & apiextensionsv1.CustomResourceDefinitionList {})).To (Succeed ())
691
+ })
692
+
685
693
It ("should update CRDs if already present in the cluster" , func () {
686
694
687
695
// Install only the CRDv1 multi-version example
Original file line number Diff line number Diff line change @@ -126,6 +126,10 @@ type Environment struct {
126
126
// loading.
127
127
Config * rest.Config
128
128
129
+ // KubeConfig provides []byte of a kubeconfig file to talk to the apiserver
130
+ // It's automatically populated if not set based on the `Config`
131
+ KubeConfig []byte
132
+
129
133
// CRDInstallOptions are the options for installing CRDs.
130
134
CRDInstallOptions CRDInstallOptions
131
135
@@ -291,6 +295,14 @@ func (te *Environment) Start() (*rest.Config, error) {
291
295
te .Config = adminUser .Config ()
292
296
}
293
297
298
+ if len (te .KubeConfig ) == 0 {
299
+ var err error
300
+ te .KubeConfig , err = controlplane .KubeConfigFromREST (te .Config )
301
+ if err != nil {
302
+ return nil , fmt .Errorf ("unable to set KubeConfig field: %w" , err )
303
+ }
304
+ }
305
+
294
306
// Set the default scheme if nil.
295
307
if te .Scheme == nil {
296
308
te .Scheme = scheme .Scheme
You can’t perform that action at this time.
0 commit comments