Skip to content

Commit

Permalink
✨ add support to go 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Jun 8, 2022
1 parent df40adf commit a17e975
Show file tree
Hide file tree
Showing 60 changed files with 152 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/apidiff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.18"
- name: Execute go-apidiff
uses: joelanford/go-apidiff@v0.2.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'
- name: Remove pre-installed kustomize
# This step is needed as the following one tries to remove
# kustomize for each test but has no permission to do so
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/unit-tests-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# todo: remove this file when go/v2 be removed
name: Unit tests Legacy (go/v2)

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
pull_request:

jobs:
test:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
# the go/v2 cannot be updated and is scaffold with golang 1.13
# (version used by its dep version of the controller-runtime)
# however, we are unable to downgrade the version here
# because we will face errors
# So we are keeping the latest version where it works
# and highlighting that must be fixed
# Therefore, we probably will deprecate go/v2 soon since we cannot upgrade it
# to use the versions of controller-runtime > v0.9
# and controller-tools > v0.6 as k8s > 1.21 then it might not be valid we spend effort on this fix
go-version: "1.17"
# This step is needed as the following one tries to remove
# kustomize for each test but has no permission to do so
- name: Remove pre-installed kustomize
run: sudo rm -f /usr/local/bin/kustomize
- name: Perform the test
run: make test-legacy
- name: Report failure
uses: nashmaniac/create-issue-action@v1.1
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
title: 🐛 Unit tests failed on ${{ matrix.os }} for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.18"
# This step is needed as the following one tries to remove
# kustomize for each test but has no permission to do so
- name: Remove pre-installed kustomize
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.18"
- name: Generate the coverage output
run: make test-coverage
- name: Send the coverage output
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ check-testdata: ## Run the script to ensure that the testdata is updated
test-testdata: ## Run the tests of the testdata directory
./test/testdata/test.sh

#todo(remove the test-legacy whne the go/v2 be removed from kubebuilder)

.PHONY: test-legacy
test-legacy: ## Run the legacy tests (go/v2) of the testdata directory
./test/testdata/test_legacy.sh

.PHONY: test-e2e-local
test-e2e-local: ## Run the end-to-end tests locally
## To keep the same kind cluster between test runs, use `SKIP_KIND_CLEANUP=1 make test-e2e-local`
Expand Down
2 changes: 1 addition & 1 deletion build/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ builds:
- darwin_amd64
- darwin_arm64
env:
- KUBERNETES_VERSION=1.23.5
- KUBERNETES_VERSION=1.24.1
- CGO_ENABLED=0

# Only binaries of the form "kubebuilder_${goos}_${goarch}" will be released.
Expand Down
2 changes: 1 addition & 1 deletion build/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ steps:
git checkout $${BRANCH_NAME}
git branch --set-upstream-to=origin/$${BRANCH_NAME}
git tag -d ${TAG_NAME}
- name: "goreleaser/goreleaser:v1.8.3"
- name: "goreleaser/goreleaser:v1.9.2"
entrypoint: "bash"
args: ["build/build_kubebuilder.sh"]
secretEnv: ["GITHUB_TOKEN"]
Expand Down
2 changes: 1 addition & 1 deletion build/cloudbuild_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Release tar will be in ./cloudbuild

steps:
- name: "goreleaser/goreleaser:v1.8.3"
- name: "goreleaser/goreleaser:v1.9.2"
entrypoint: "bash"
env: ["SNAPSHOT=1"]
args: ["build/build_kubebuilder.sh"]
2 changes: 1 addition & 1 deletion build/cloudbuild_snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Release tar will be in ./cloudbuild

steps:
- name: "goreleaser/goreleaser:v1.8.3"
- name: "goreleaser/goreleaser:v1.9.2"
entrypoint: "bash"
env: ["SNAPSHOT=1"]
args: ["build/build_kubebuilder.sh"]
Expand Down
3 changes: 2 additions & 1 deletion docs/book/src/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ This Quick Start guide will cover:

- [go](https://golang.org/dl/) version v1.15+ (kubebuilder v3.0 < v3.1).
- [go](https://golang.org/dl/) version v1.16+ (kubebuilder v3.1 < v3.3).
- [go](https://golang.org/dl/) version v1.17+ < v1.18 (kubebuilder v3.3+).
- [go](https://golang.org/dl/) version v1.17+ < v1.18 (kubebuilder v3.4.1).
- [go](https://golang.org/dl/) version v1.17.9+ (kubebuilder v3.5+).
- [docker](https://docs.docker.com/install/) version 17.03+.
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) version v1.11.3+.
- Access to a Kubernetes v1.11.3+ cluster.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/alpha/config-gen/testdata/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module config-gen/testdata

go 1.17
go 1.18

require (
k8s.io/apimachinery v0.23.5
Expand Down
1 change: 1 addition & 0 deletions pkg/plugins/golang/go_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ var _ = Describe("checkGoVersion", func() {
Entry("for go 1.17.3", "go1.17.3"),
Entry("for go 1.17.4", "go1.17.4"),
Entry("for go 1.17.5", "go1.17.5"),
Entry("for go 1.18.1", "go1.18.1"),
)

DescribeTable("should return an error for non-supported go versions",
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v3/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ manifests: controller-gen`
}

if err := util.ReplaceInFile("Makefile",
"ENVTEST_K8S_VERSION = 1.23",
"ENVTEST_K8S_VERSION = 1.24.1",
"ENVTEST_K8S_VERSION = 1.21"); err != nil {
log.Warnf("unable to update the Makefile with %s: %s", "ENVTEST_K8S_VERSION = 1.21", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

// Variables and function to check Go version requirements.
var (
goVerMin = golang.MustParse("go1.17")
goVerMin = golang.MustParse("go1.17.9")
goVerMax = golang.MustParse("go2.0alpha1")
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v3/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
// ControllerRuntimeVersion is the kubernetes-sigs/controller-runtime version to be used in the project
ControllerRuntimeVersion = "v0.12.1"
// ControllerToolsVersion is the kubernetes-sigs/controller-tools version to be used in the project
ControllerToolsVersion = "v0.8.0"
ControllerToolsVersion = "v0.9.0"
// KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project
// @Deprecated. This information ought to come from kustomize plugin
// Note that by updating the following value nothing will change for the go/3 plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (f *Dockerfile) SetTemplateDefaults() error {
}

const dockerfileTemplate = `# Build the manager binary
FROM golang:1.17 as builder
FROM golang:1.18 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (f *GoMod) SetTemplateDefaults() error {
const goModTemplate = `
module {{ .Repo }}
go 1.17
go 1.18
require (
sigs.k8s.io/controller-runtime {{ .ControllerRuntimeVersion }}
Expand Down
2 changes: 1 addition & 1 deletion test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if [ -n "$TRACE" ]; then
set -x
fi

export KIND_K8S_VERSION="${KIND_K8S_VERSION:-"v1.23.3"}"
export KIND_K8S_VERSION="${KIND_K8S_VERSION:-"v1.24.1"}"
tools_k8s_version=$(convert_to_tools_ver "${KIND_K8S_VERSION#v*}")
kind_version=0.11.1
goarch=amd64
Expand Down
6 changes: 0 additions & 6 deletions test/testdata/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,3 @@ test_project project-v3-multigroup
test_project project-v3-addon
test_project project-v3-config

# Test project v2, which relies on pre-installed envtest tools to run 'make test'.
tools_k8s_version="1.19.2"
fetch_tools
test_project project-v2
test_project project-v2-multigroup
test_project project-v2-addon
38 changes: 38 additions & 0 deletions test/testdata/test_legacy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# todo: remove this file when go/v2 be removed
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

source "$(dirname "$0")/../common.sh"

# Executes the test of the testdata directories
function test_project {
rm -f "$(command -v controller-gen)"
rm -f "$(command -v kustomize)"

header_text "Performing tests in dir $1"
pushd "$(dirname "$0")/../../testdata/$1"
go mod tidy
make test
popd
}

build_kb

# Test project v2, which relies on pre-installed envtest tools to run 'make test'.
tools_k8s_version="1.19.2"
fetch_tools
test_project project-v2
test_project project-v2-multigroup
test_project project-v2-addon
2 changes: 1 addition & 1 deletion testdata/project-v3-addon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.17 as builder
FROM golang:1.18 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v3-addon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.8.0
CONTROLLER_TOOLS_VERSION ?= v0.9.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: admirals.crew.testproject.org
spec:
Expand Down Expand Up @@ -67,9 +67,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: captains.crew.testproject.org
spec:
Expand Down Expand Up @@ -67,9 +67,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: firstmates.crew.testproject.org
spec:
Expand Down Expand Up @@ -67,9 +67,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 1 addition & 1 deletion testdata/project-v3-addon/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sigs.k8s.io/kubebuilder/testdata/project-v3-addon

go 1.17
go 1.18

require (
github.com/go-logr/logr v1.2.0
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v3-config/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.17 as builder
FROM golang:1.18 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v3-config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.8.0
CONTROLLER_TOOLS_VERSION ?= v0.9.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: admirals.crew.testproject.org
spec:
Expand Down Expand Up @@ -48,9 +48,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: captains.crew.testproject.org
spec:
Expand Down Expand Up @@ -48,9 +48,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit a17e975

Please sign in to comment.