Skip to content

Commit

Permalink
deps: bump go/v3-alpha to controller-runtime v0.7.0-alpha.6
Browse files Browse the repository at this point in the history
pkg/plugin/v3: make changes to controller and test suite related to
controller-runtime API changes
  • Loading branch information
estroz committed Nov 9, 2020
1 parent b6a0bf1 commit 522fbf8
Show file tree
Hide file tree
Showing 31 changed files with 108 additions and 92 deletions.
2 changes: 1 addition & 1 deletion pkg/plugin/v3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
// KbDeclarativePatternVersion is the sigs.k8s.io/kubebuilder-declarative-pattern version
// (used only to gen api with --pattern=addon)
// TODO: remove this when a better solution for using addons is implemented.
const KbDeclarativePatternVersion = "v0.0.0-20200522144838-848d48e5b073"
const KbDeclarativePatternVersion = "1cbf859290cab81ae8e73fc5caebe792280175d1"

// DefaultMainPath is default file path of main.go
const DefaultMainPath = "main.go"
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/v3/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

const (
// ControllerRuntimeVersion is the kubernetes-sigs/controller-runtime version to be used in the project
ControllerRuntimeVersion = "v0.6.3"
ControllerRuntimeVersion = "v0.7.0-alpha.6"
// ControllerToolsVersion is the kubernetes-sigs/controller-tools version to be used in the project
ControllerToolsVersion = "v0.4.0"
// KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const (
package {{ .Resource.Version }}
import (
"context"
"path/filepath"
"testing"
"fmt"
Expand All @@ -144,7 +145,8 @@ import (
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var stopCh = make(chan struct{})
var ctx context.Context
var cancel context.CancelFunc
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -157,11 +159,13 @@ func TestAPIs(t *testing.T) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
ctx, cancel = context.WithCancel(context.TODO())
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "crd", "bases")},
WebhookInstallOptions: envtest.WebhookInstallOptions{
DirectoryPaths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "webhook")},
Paths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "webhook")},
},
}
Expand All @@ -174,7 +178,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
%s
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand All @@ -194,7 +198,7 @@ var _ = BeforeSuite(func() {
%s
go func() {
err = mgr.Start(stopCh)
err = mgr.Start(ctx)
if err != nil {
Expect(err).NotTo(HaveOccurred())
}
Expand All @@ -215,7 +219,7 @@ var _ = BeforeSuite(func() {
}, 60)
var _ = AfterSuite(func() {
close(stopCh)
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ type {{ .Resource.Kind }}Reconciler struct {
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@{{ .ControllerRuntimeVersion }}/pkg/reconcile
func (r *{{ .Resource.Kind }}Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
func (r *{{ .Resource.Kind }}Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("{{ .Resource.Kind | lower }}", req.NamespacedName)
// your logic here
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 @@ -17,7 +17,7 @@ all: manager
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.6.3/hack/setup-envtest.sh
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0-alpha.6/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

# Build manager binary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ spec:
type: array
healthy:
type: boolean
phase:
type: string
required:
- healthy
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ spec:
type: array
healthy:
type: boolean
phase:
type: string
required:
- healthy
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ spec:
type: array
healthy:
type: boolean
phase:
type: string
required:
- healthy
type: object
Expand Down
14 changes: 7 additions & 7 deletions testdata/project-v3-addon/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module sigs.k8s.io/kubebuilder/testdata/project-v3-addon
go 1.15

require (
github.com/go-logr/logr v0.1.0
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
k8s.io/apimachinery v0.18.6
k8s.io/client-go v0.18.6
sigs.k8s.io/controller-runtime v0.6.3
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20200522144838-848d48e5b073
github.com/go-logr/logr v0.2.1
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
k8s.io/apimachinery v0.19.2
k8s.io/client-go v0.19.2
sigs.k8s.io/controller-runtime v0.7.0-alpha.6
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20201109180626-1cbf859290ca
)
2 changes: 1 addition & 1 deletion testdata/project-v3-multigroup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all: manager
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.6.3/hack/setup-envtest.sh
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0-alpha.6/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

# Build manager binary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -45,7 +46,8 @@ import (
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var stopCh = make(chan struct{})
var ctx context.Context
var cancel context.CancelFunc

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -58,11 +60,13 @@ func TestAPIs(t *testing.T) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
WebhookInstallOptions: envtest.WebhookInstallOptions{
DirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
},
}

Expand Down Expand Up @@ -101,7 +105,7 @@ var _ = BeforeSuite(func() {
// +kubebuilder:scaffold:webhook

go func() {
err = mgr.Start(stopCh)
err = mgr.Start(ctx)
if err != nil {
Expect(err).NotTo(HaveOccurred())
}
Expand All @@ -122,7 +126,7 @@ var _ = BeforeSuite(func() {
}, 60)

var _ = AfterSuite(func() {
close(stopCh)
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -45,7 +46,8 @@ import (
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var stopCh = make(chan struct{})
var ctx context.Context
var cancel context.CancelFunc

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -58,11 +60,13 @@ func TestAPIs(t *testing.T) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
WebhookInstallOptions: envtest.WebhookInstallOptions{
DirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
},
}

Expand Down Expand Up @@ -101,7 +105,7 @@ var _ = BeforeSuite(func() {
// +kubebuilder:scaffold:webhook

go func() {
err = mgr.Start(stopCh)
err = mgr.Start(ctx)
if err != nil {
Expect(err).NotTo(HaveOccurred())
}
Expand All @@ -122,7 +126,7 @@ var _ = BeforeSuite(func() {
}, 60)

var _ = AfterSuite(func() {
close(stopCh)
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v2alpha1

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -45,7 +46,8 @@ import (
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var stopCh = make(chan struct{})
var ctx context.Context
var cancel context.CancelFunc

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -58,11 +60,13 @@ func TestAPIs(t *testing.T) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
WebhookInstallOptions: envtest.WebhookInstallOptions{
DirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
},
}

Expand Down Expand Up @@ -101,7 +105,7 @@ var _ = BeforeSuite(func() {
// +kubebuilder:scaffold:webhook

go func() {
err = mgr.Start(stopCh)
err = mgr.Start(ctx)
if err != nil {
Expect(err).NotTo(HaveOccurred())
}
Expand All @@ -122,7 +126,7 @@ var _ = BeforeSuite(func() {
}, 60)

var _ = AfterSuite(func() {
close(stopCh)
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
Expand Down
12 changes: 8 additions & 4 deletions testdata/project-v3-multigroup/apis/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -45,7 +46,8 @@ import (
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var stopCh = make(chan struct{})
var ctx context.Context
var cancel context.CancelFunc

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand All @@ -58,11 +60,13 @@ func TestAPIs(t *testing.T) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
WebhookInstallOptions: envtest.WebhookInstallOptions{
DirectoryPaths: []string{filepath.Join("..", "..", "config", "webhook")},
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
},
}

Expand Down Expand Up @@ -101,7 +105,7 @@ var _ = BeforeSuite(func() {
// +kubebuilder:scaffold:webhook

go func() {
err = mgr.Start(stopCh)
err = mgr.Start(ctx)
if err != nil {
Expect(err).NotTo(HaveOccurred())
}
Expand All @@ -122,7 +126,7 @@ var _ = BeforeSuite(func() {
}, 60)

var _ = AfterSuite(func() {
close(stopCh)
cancel()
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ type PodReconciler struct {
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.6.3/pkg/reconcile
func (r *PodReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.7.0-alpha.6/pkg/reconcile
func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("pod", req.NamespacedName)

// your logic here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ type CaptainReconciler struct {
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.6.3/pkg/reconcile
func (r *CaptainReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.7.0-alpha.6/pkg/reconcile
func (r *CaptainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("captain", req.NamespacedName)

// your logic here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ type HealthCheckPolicyReconciler struct {
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.6.3/pkg/reconcile
func (r *HealthCheckPolicyReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.7.0-alpha.6/pkg/reconcile
func (r *HealthCheckPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("healthcheckpolicy", req.NamespacedName)

// your logic here
Expand Down
Loading

0 comments on commit 522fbf8

Please sign in to comment.