Skip to content

Commit

Permalink
test: add restConfigModifier Option to clusterProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jul 4, 2024
1 parent a7f5043 commit 31f2938
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/framework/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ func WithMachineLogCollector(logCollector ClusterLogCollector) Option {
}
}

// WithRESTConfigModifier allows to modify the rest config in GetRESTConfig.
// Using this function it is possible to create ClusterProxy that can work with workload clusters hosted in places
// not directly accessible from the machine where we run the E2E tests, e.g. inside kind.
func WithRESTConfigModifier(f func(*rest.Config)) Option {
return func(c *clusterProxy) {
c.restConfigModifier = f
}
}

// clusterProxy provides a base implementation of the ClusterProxy interface.
type clusterProxy struct {
name string
Expand All @@ -150,6 +159,8 @@ type clusterProxy struct {
logCollector ClusterLogCollector
cache cache.Cache
onceCache sync.Once

restConfigModifier func(*rest.Config)
}

// NewClusterProxy returns a clusterProxy given a KubeconfigPath and the scheme defining the types hosted in the cluster.
Expand Down Expand Up @@ -321,6 +332,11 @@ func (p *clusterProxy) GetRESTConfig() *rest.Config {
Expect(err).ToNot(HaveOccurred(), "Failed to get ClientConfig from %q", p.kubeconfigPath)

restConfig.UserAgent = "cluster-api-e2e"

if p.restConfigModifier != nil {
p.restConfigModifier(restConfig)
}

return restConfig
}

Expand Down

0 comments on commit 31f2938

Please sign in to comment.