@@ -22,6 +22,7 @@ import (
22
22
23
23
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
24
24
"k8s.io/client-go/rest"
25
+ "sigs.k8s.io/controller-runtime/pkg/client/config"
25
26
"sigs.k8s.io/testing_frameworks/integration"
26
27
)
27
28
@@ -70,38 +71,59 @@ type Environment struct {
70
71
71
72
// CRDDirectoryPaths is a list of paths containing CRD yaml or json configs.
72
73
CRDDirectoryPaths []string
74
+
75
+ // UseExisting indicates that this environments should use an
76
+ // existing kubeconfig, instead of trying to stand up a new control plane.
77
+ // This is useful in cases that need aggregated API servers and the like.
78
+ UseExistingCluster bool
73
79
}
74
80
75
81
// Stop stops a running server
76
82
func (te * Environment ) Stop () error {
83
+ if te .UseExistingCluster {
84
+ return nil
85
+ }
77
86
return te .ControlPlane .Stop ()
78
87
}
79
88
80
89
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
81
90
func (te * Environment ) Start () (* rest.Config , error ) {
82
- te .ControlPlane = integration.ControlPlane {}
83
- te .ControlPlane .APIServer = & integration.APIServer {Args : defaultKubeAPIServerFlags }
84
- if os .Getenv (envKubeAPIServerBin ) == "" {
85
- te .ControlPlane .APIServer .Path = defaultAssetPath ("kube-apiserver" )
86
- }
87
- if os .Getenv (envEtcdBin ) == "" {
88
- te .ControlPlane .Etcd = & integration.Etcd {Path : defaultAssetPath ("etcd" )}
89
- }
90
- if os .Getenv (envKubectlBin ) == "" {
91
- // we can't just set the path manually (it's behind a function), so set the environment variable instead
92
- if err := os .Setenv (envKubectlBin , defaultAssetPath ("kubectl" )); err != nil {
93
- return nil , err
91
+ if te .UseExistingCluster {
92
+ if te .Config == nil {
93
+ // we want to allow people to pass in their own config, so
94
+ // only load a config if it hasn't already been set.
95
+
96
+ var err error
97
+ te .Config , err = config .GetConfig ()
98
+ if err != nil {
99
+ return nil , err
100
+ }
101
+ }
102
+ } else {
103
+ te .ControlPlane = integration.ControlPlane {}
104
+ te .ControlPlane .APIServer = & integration.APIServer {Args : defaultKubeAPIServerFlags }
105
+ if os .Getenv (envKubeAPIServerBin ) == "" {
106
+ te .ControlPlane .APIServer .Path = defaultAssetPath ("kube-apiserver" )
107
+ }
108
+ if os .Getenv (envEtcdBin ) == "" {
109
+ te .ControlPlane .Etcd = & integration.Etcd {Path : defaultAssetPath ("etcd" )}
110
+ }
111
+ if os .Getenv (envKubectlBin ) == "" {
112
+ // we can't just set the path manually (it's behind a function), so set the environment variable instead
113
+ if err := os .Setenv (envKubectlBin , defaultAssetPath ("kubectl" )); err != nil {
114
+ return nil , err
115
+ }
94
116
}
95
- }
96
117
97
- // Start the control plane - retry if it fails
98
- if err := te .ControlPlane .Start (); err != nil {
99
- return nil , err
100
- }
118
+ // Start the control plane - retry if it fails
119
+ if err := te .ControlPlane .Start (); err != nil {
120
+ return nil , err
121
+ }
101
122
102
- // Create the *rest.Config for creating new clients
103
- te .Config = & rest.Config {
104
- Host : te .ControlPlane .APIURL ().Host ,
123
+ // Create the *rest.Config for creating new clients
124
+ te .Config = & rest.Config {
125
+ Host : te .ControlPlane .APIURL ().Host ,
126
+ }
105
127
}
106
128
107
129
_ , err := InstallCRDs (te .Config , CRDInstallOptions {
0 commit comments