Skip to content

Commit

Permalink
Flag logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Nov 17, 2023
1 parent d8c58cb commit 974e60b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
41 changes: 21 additions & 20 deletions .github/workflows/k8scompat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ jobs:
strategy:
fail-fast: false
matrix:
downstreamApiserverVersion:
- "1.28.x"
- "1.27.x"
- "1.26.x"
- "1.25.x"
- "1.24.x"
- "1.23.x"
- "1.22.x"
- "1.21.x"
- "1.20.x"
- "1.19.x"
- "1.17.x"
- "1.16.x"
- "1.15.x"
- "1.14.x"
- "1.13.x"
- "1.12.x"
- "1.11.x"
- "1.10.x"
downstreamApiserverMinorVersion:
- "28"
- "27"
- "26"
- "25"
- "24"
- "23"
- "22"
- "21"
- "20"
- "19"
- "17"
- "16"
- "15"
- "14"
- "13"
- "12"
- "11"
- "10"
steps:
- uses: actions/checkout@v3

Expand All @@ -39,9 +39,10 @@ jobs:
- name: Download kubebuilder assets
run: |
echo "UPSTREAM_KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path ${{ env.upstreamApiserverVersion }})" >> $GITHUB_ENV
echo "DOWNSTREAM_KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path ${{ matrix.downstreamApiserverVersion }})" >> $GITHUB_ENV
echo "DOWNSTREAM_KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path 1.${{ matrix.downstreamApiserverMinorVersion }}).x" >> $GITHUB_ENV
- name: Run tests
run: go test -v ./internal/controllers/reconciliation
env:
KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT: "true"
DOWNSTREAM_VERSION_MINOR: "${{ matrix.downstreamApiserverMinorVersion }}"
16 changes: 11 additions & 5 deletions internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
goruntime "runtime"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -56,6 +57,9 @@ func NewContext(t *testing.T) context.Context {
return logr.NewContext(ctx, testr.NewWithOptions(t, testr.Options{Verbosity: 2}))
}

// NewManager starts one or two envtest environments depending on the configuration of the env.
// This should work seamlessly when run locally assuming some binaries have been fetched with setup-envtest.
// In CI the second environment is used to compatibility test against a matrix of k8s versions.
func NewManager(t *testing.T) *Manager {
_, b, _, _ := goruntime.Caller(0)
root := filepath.Join(filepath.Dir(b), "..", "..")
Expand Down Expand Up @@ -90,16 +94,18 @@ func NewManager(t *testing.T) *Manager {
DownstreamRestConfig: cfg, // possible override below
}

// Support starting a second apiserver if requested by the environment.
// Allows matrix testing against different versions of the upstream control plane.
if dir := os.Getenv("DOWNSTREAM_KUBEBUILDER_ASSETS"); dir != "" {
downstreamEnv := &envtest.Environment{
BinaryAssetsDirectory: dir,
}

// k8s <1.12 requires this flag
conf := downstreamEnv.ControlPlane.GetAPIServer().Configure()
conf.Append("service-account-api-audiences", "anything")
// 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")
}

t.Cleanup(func() {
err := downstreamEnv.Stop()
Expand Down

0 comments on commit 974e60b

Please sign in to comment.