Skip to content

Commit

Permalink
Update client-go version & improve test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
iximiuz committed Nov 5, 2023
1 parent 9514405 commit b041809
Show file tree
Hide file tree
Showing 78 changed files with 574 additions and 14,348 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test-one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: "1.18.x"
- name: Create k8s cluster (using kind)
uses: helm/kind-action@v1.3.0
go-version: "1.21.3"
- name: Create test Kubernetes cluster (using kind)
uses: helm/kind-action@v1.5.0
with:
node_image: kindest/node:v${{ inputs.k8s_cluster_ver }}
- name: Run mini-program ${{ inputs.example_program }} on k8s v${{ inputs.k8s_cluster_ver }} using client-go ${{ inputs.k8s_package_ver }}
- name: Run mini-program ${{ inputs.example_program }} on Kubernetes v${{ inputs.k8s_cluster_ver }} using client-go v${{ inputs.k8s_package_ver }}
run: |
cd ${{ inputs.example_program }}
go mod edit -replace k8s.io/client-go=k8s.io/client-go@v${{ inputs.k8s_package_ver }}
Expand Down
55 changes: 37 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
outputs:
dirs: ${{ steps.make-list.outputs.dirs }}

client_go_0_23:
client_go_0_25:
needs: prepare
strategy:
fail-fast: false
Expand All @@ -31,17 +31,17 @@ jobs:
matrix:
example_program: ${{ fromJson(needs.prepare.outputs.dirs) }}
k8s_cluster_ver:
- "1.22.15"
- "1.23.12"
- "1.24.6"
- "1.25.2"
- "1.25.11"
- "1.26.6"
- "1.27.3"
- "1.28.0"
uses: ./.github/workflows/test-one.yml
with:
example_program: ${{ matrix.example_program }}
k8s_cluster_ver: ${{ matrix.k8s_cluster_ver }}
k8s_package_ver: "0.23.1"
k8s_package_ver: "0.25.15"

client_go_0_24:
client_go_0_26:
needs: prepare
strategy:
fail-fast: false
Expand All @@ -50,17 +50,36 @@ jobs:
matrix:
example_program: ${{ fromJson(needs.prepare.outputs.dirs) }}
k8s_cluster_ver:
- "1.22.15"
- "1.23.12"
- "1.24.6"
- "1.25.2"
- "1.25.11"
- "1.26.6"
- "1.27.3"
- "1.28.0"
uses: ./.github/workflows/test-one.yml
with:
example_program: ${{ matrix.example_program }}
k8s_cluster_ver: ${{ matrix.k8s_cluster_ver }}
k8s_package_ver: "0.24.7"
k8s_package_ver: "0.26.10"

client_go_0_25:
client_go_0_27:
needs: prepare
strategy:
fail-fast: false
# A matrix can produce no more than 256 elements,
# so testing too many k8s versions is unfeasible.
matrix:
example_program: ${{ fromJson(needs.prepare.outputs.dirs) }}
k8s_cluster_ver:
- "1.25.11"
- "1.26.6"
- "1.27.3"
- "1.28.0"
uses: ./.github/workflows/test-one.yml
with:
example_program: ${{ matrix.example_program }}
k8s_cluster_ver: ${{ matrix.k8s_cluster_ver }}
k8s_package_ver: "0.27.7"

client_go_0_28:
needs: prepare
strategy:
fail-fast: false
Expand All @@ -69,12 +88,12 @@ jobs:
matrix:
example_program: ${{ fromJson(needs.prepare.outputs.dirs) }}
k8s_cluster_ver:
- "1.22.15"
- "1.23.12"
- "1.24.6"
- "1.25.2"
- "1.25.11"
- "1.26.6"
- "1.27.3"
- "1.28.0"
uses: ./.github/workflows/test-one.yml
with:
example_program: ${{ matrix.example_program }}
k8s_cluster_ver: ${{ matrix.k8s_cluster_ver }}
k8s_package_ver: "0.25.3"
k8s_package_ver: "0.28.3"
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CUR_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

MINI_PROGRAMS_DIRS := $(shell find $(CUR_DIR) -type f -name go.mod -exec dirname {} \; | xargs -n 1 basename | sort -u)


.PHONY: test-%
test-%:
@echo "\033[0;32m-- Test $*\033[0m"
@cd ${CUR_DIR}/$* && make test && echo "\t--- PASS" || echo "\t--- FAILED"

.PHONY: test-all
test-all: $(addprefix test-, $(MINI_PROGRAMS_DIRS))
@echo "\033[0;32mDone all!\033[0m"

.PHONY: go-mod-tidy-%
go-mod-tidy-%:
@cd ${CUR_DIR}/$* && make go-mod-tidy

.PHONY: go-mod-tidy-all
go-mod-tidy-all: $(addprefix go-mod-tidy-, $(MINI_PROGRAMS_DIRS))
@echo "\033[0;32mDone all!\033[0m"
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@

A collection of mini-programs demonstrating various [client-go](https://github.com/kubernetes/client-go) use cases augmented by a [preconfigured online development environment](https://labs.iximiuz.com/playgrounds/k8s-client-go/). Inspired by [client-go/examples](https://github.com/kubernetes/client-go/tree/master/examples).

The intention (at least so far) is to test a (more or less) fresh version of Go and packages against a few latest
Kubernetes versions.
The intention is to test a (more or less) fresh version of Go and `k8s.io` packages against the [currently maintained Kubernetes release branches](https://kubernetes.io/releases/).

What is tested at the moment:

- `go 1.18`
- `k8s.io/client-go v0.23.1 v0.24.7 v0.25.3`
- `Kubernetes v1.22.15 1.23.12 v1.24.6 v1.25.2`
- `go 1.21.3`
- `k8s.io/client-go 0.25.15 0.26.10 0.27.7 0.28.3` (maintained release branches)
- `Kubernetes 1.25.11 1.26.6 1.27.3 1.28.0` (best-effort match with versions supported by `kind`)

## Setup

Most examples expect `minikube` with at least two Kubernetes clusters - `shared1` and `shared2`.
Most examples expect at least two Kubernetes clusters - `shared1` and `shared2`.

```bash
curl -sLS https://get.arkade.dev | sudo sh
arkade get minikube kubectl
arkade get kind kubectl

minikube start --profile shared1
minikube start --profile shared2
kind create cluster --name shared1
kind create cluster --name shared2
```

## Run
Expand All @@ -33,7 +32,10 @@ Oversimplified (for now):

```bash
cd <program>
go run main.go
make test

# or from the root folder:
make test-all
```

## TODO
Expand Down
12 changes: 10 additions & 2 deletions cli-runtime-flags/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
test:
go run main.go
CUR_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))


.PHONY: test
test: go-mod-tidy
go run ${CUR_DIR}/main.go

.PHONY: go-mod-tidy
go-mod-tidy:
cd ${CUR_DIR} && go mod tidy
65 changes: 2 additions & 63 deletions cli-runtime-flags/go.mod
Original file line number Diff line number Diff line change
@@ -1,68 +1,7 @@
module github.com/iximiuz/client-go-examples/cli-runtime-flags

go 1.18
go 1.21.3

require (
k8s.io/cli-runtime v0.23.1
k8s.io/client-go v0.23.1 // indirect
)

require github.com/spf13/cobra v1.2.1

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.23.1 // indirect
k8s.io/apimachinery v0.23.1 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/kustomize/api v0.10.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
k8s.io/cli-runtime v0.28.3
)
Loading

0 comments on commit b041809

Please sign in to comment.