@@ -91,7 +91,7 @@ type ClusterProxy interface {
91
91
Apply (ctx context.Context , resources []byte , args ... string ) error
92
92
93
93
// GetWorkloadCluster returns a proxy to a workload cluster defined in the Kubernetes cluster.
94
- GetWorkloadCluster (ctx context.Context , namespace , name string ) ClusterProxy
94
+ GetWorkloadCluster (ctx context.Context , namespace , name string , options ... Option ) ClusterProxy
95
95
96
96
// CollectWorkloadClusterLogs collects machines and infrastructure logs from the workload cluster.
97
97
CollectWorkloadClusterLogs (ctx context.Context , namespace , name , outputPath string )
@@ -156,7 +156,7 @@ func NewClusterProxy(name string, kubeconfigPath string, scheme *runtime.Scheme,
156
156
}
157
157
158
158
// newFromAPIConfig returns a clusterProxy given a api.Config and the scheme defining the types hosted in the cluster.
159
- func newFromAPIConfig (name string , config * api.Config , scheme * runtime.Scheme ) ClusterProxy {
159
+ func newFromAPIConfig (name string , config * api.Config , scheme * runtime.Scheme , options ... Option ) ClusterProxy {
160
160
// NB. the ClusterProvider is responsible for the cleanup of this file
161
161
f , err := os .CreateTemp ("" , "e2e-kubeconfig" )
162
162
Expect (err ).ToNot (HaveOccurred (), "Failed to create kubeconfig file for the kind cluster %q" )
@@ -165,12 +165,16 @@ func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme) C
165
165
err = clientcmd .WriteToFile (* config , kubeconfigPath )
166
166
Expect (err ).ToNot (HaveOccurred (), "Failed to write kubeconfig for the kind cluster to a file %q" )
167
167
168
- return & clusterProxy {
168
+ proxy := & clusterProxy {
169
169
name : name ,
170
170
kubeconfigPath : kubeconfigPath ,
171
171
scheme : scheme ,
172
172
shouldCleanupKubeconfig : true ,
173
173
}
174
+ for _ , o := range options {
175
+ o (proxy )
176
+ }
177
+ return proxy
174
178
}
175
179
176
180
// GetName returns the name of the cluster.
@@ -265,7 +269,7 @@ func (p *clusterProxy) GetLogCollector() ClusterLogCollector {
265
269
}
266
270
267
271
// GetWorkloadCluster returns ClusterProxy for the workload cluster.
268
- func (p * clusterProxy ) GetWorkloadCluster (ctx context.Context , namespace , name string ) ClusterProxy {
272
+ func (p * clusterProxy ) GetWorkloadCluster (ctx context.Context , namespace , name string , options ... Option ) ClusterProxy {
269
273
Expect (ctx ).NotTo (BeNil (), "ctx is required for GetWorkloadCluster" )
270
274
Expect (namespace ).NotTo (BeEmpty (), "namespace is required for GetWorkloadCluster" )
271
275
Expect (name ).NotTo (BeEmpty (), "name is required for GetWorkloadCluster" )
@@ -279,12 +283,13 @@ func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name s
279
283
p .fixConfig (ctx , name , config )
280
284
}
281
285
282
- return newFromAPIConfig (name , config , p .scheme )
286
+ return newFromAPIConfig (name , config , p .scheme , options ... )
283
287
}
284
288
285
289
// CollectWorkloadClusterLogs collects machines and infrastructure logs and from the workload cluster.
286
290
func (p * clusterProxy ) CollectWorkloadClusterLogs (ctx context.Context , namespace , name , outputPath string ) {
287
291
if p .logCollector == nil {
292
+ fmt .Printf ("Unable to get logs for workload Cluster %s: log collector is nil.\n " , klog .KRef (namespace , name ))
288
293
return
289
294
}
290
295
0 commit comments