File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ import (
2828 "k8s.io/apimachinery/pkg/runtime"
2929 "k8s.io/apimachinery/pkg/types"
3030 "k8s.io/client-go/kubernetes/scheme"
31-
31+ "k8s.io/client-go/tools/clientcmd"
3232 "sigs.k8s.io/controller-runtime/pkg/client"
3333)
3434
@@ -682,6 +682,14 @@ var _ = Describe("Test", func() {
682682 })
683683 })
684684
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+
685693 It ("should update CRDs if already present in the cluster" , func () {
686694
687695 // Install only the CRDv1 multi-version example
Original file line number Diff line number Diff line change @@ -126,6 +126,11 @@ type Environment struct {
126126 // loading.
127127 Config * rest.Config
128128
129+ // KubeConfig provides []byte of a kubeconfig file to talk to the apiserver
130+ // It's automatically populated if not set using the standard controller-runtime
131+ // config loading.
132+ KubeConfig []byte
133+
129134 // CRDInstallOptions are the options for installing CRDs.
130135 CRDInstallOptions CRDInstallOptions
131136
@@ -291,6 +296,14 @@ func (te *Environment) Start() (*rest.Config, error) {
291296 te .Config = adminUser .Config ()
292297 }
293298
299+ if len (te .KubeConfig ) == 0 {
300+ var err error
301+ te .KubeConfig , err = controlplane .KubeConfigFromREST (te .Config )
302+ if err != nil {
303+ return nil , fmt .Errorf ("unable to set KubeConfig field: %w" , err )
304+ }
305+ }
306+
294307 // Set the default scheme if nil.
295308 if te .Scheme == nil {
296309 te .Scheme = scheme .Scheme
You can’t perform that action at this time.
0 commit comments