Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Nov 17, 2023
1 parent 974e60b commit 8e4d217
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,37 @@ func NewManager(t *testing.T) *Manager {
DownstreamRestConfig: cfg, // possible override below
}

if dir := os.Getenv("DOWNSTREAM_KUBEBUILDER_ASSETS"); dir != "" {
downstreamEnv := &envtest.Environment{
BinaryAssetsDirectory: dir,
}
dir := os.Getenv("DOWNSTREAM_KUBEBUILDER_ASSETS")
if dir == "" {
return m // only one env needed
}

// k8s <1.13 will not start if these flags are set
version, _ := strconv.Atoi(os.Getenv("DOWNSTREAM_VERSION_MINOR"))
if version < 13 {
conf := downstreamEnv.ControlPlane.GetAPIServer().Configure()
conf.Disable("service-account-signing-key-file")
conf.Disable("service-account-issuer")
}
downstreamEnv := &envtest.Environment{
BinaryAssetsDirectory: dir,
}

t.Cleanup(func() {
err := downstreamEnv.Stop()
if err != nil {
panic(err)
}
})
m.DownstreamRestConfig, err = downstreamEnv.Start()
require.NoError(t, err)
// k8s <1.13 will not start if these flags are set
version, _ := strconv.Atoi(os.Getenv("DOWNSTREAM_VERSION_MINOR"))
if version < 13 {
conf := downstreamEnv.ControlPlane.GetAPIServer().Configure()
conf.Disable("service-account-signing-key-file")
conf.Disable("service-account-issuer")
}

disc, err := discovery.NewDiscoveryClientForConfig(m.DownstreamRestConfig)
t.Cleanup(func() {
err := downstreamEnv.Stop()
if err != nil {
panic(err)
}
})
m.DownstreamRestConfig, err = downstreamEnv.Start()
require.NoError(t, err)

disc, err := discovery.NewDiscoveryClientForConfig(m.DownstreamRestConfig)
if err == nil {
version, err := disc.ServerVersion()
if err == nil {
version, err := disc.ServerVersion()
if err == nil {
t.Logf("downstream control plane version: %s", version.String())
}
t.Logf("downstream control plane version: %s", version.String())
}
}

Expand Down

0 comments on commit 8e4d217

Please sign in to comment.