Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#10832 from chrischdi/test-clusterp…
Browse files Browse the repository at this point in the history
…roxy-restconfigmodifier

🌱 test: add restConfigModifier Option to clusterProxy
  • Loading branch information
k8s-ci-robot authored Jul 4, 2024
2 parents 1544568 + 31f2938 commit b08f0ab
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 b08f0ab

Please sign in to comment.