Skip to content

Commit 4f25b88

Browse files
committed
Update controller-runtime to v0.14.4
controller-runtime deprecated the envtest/printer package in v0.14.0. They don't needed anymore since they upgraded to ginko v2. In order to keep the scope contained, I just copied the code we needed, it's quite simple. This allow us to maintain the same version of ginko while bumping controller-runtime. The fake client provided by controller-runtime was updated to allow for field selectors in List operations. This requires to define the index prior to its use. Since the Job controller uses ".metadata.controller" for a List query, we now set this index in the tests client. kubernetes-sigs/controller-runtime#2025 Signed-off-by: Guillermo Gaston <gaslor@amazon.com>
1 parent dee5b26 commit 4f25b88

File tree

6 files changed

+133
-287
lines changed

6 files changed

+133
-287
lines changed

controllers/helpers_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package controllers_test
33
import (
44
"github.com/go-logr/logr"
55
"github.com/go-logr/zapr"
6+
bmcv1alpha1 "github.com/tinkerbell/rufio/api/v1alpha1"
67
rufiov1alpha1 "github.com/tinkerbell/rufio/api/v1alpha1"
8+
"github.com/tinkerbell/rufio/controllers"
79
"go.uber.org/zap"
810
corev1 "k8s.io/api/core/v1"
911
"k8s.io/apimachinery/pkg/runtime"
@@ -36,6 +38,15 @@ func createKubeClientWithObjects(objects ...client.Object) client.WithWatch {
3638
Build()
3739
}
3840

41+
// createKubeClientWithObjectsForJobController creates a kubernetes client with the given objects
42+
// and the indexes required by the Job controller.
43+
func createKubeClientWithObjectsForJobController(objects ...client.Object) client.WithWatch {
44+
return createKubeClientBuilder().
45+
WithObjects(objects...).
46+
WithIndex(&bmcv1alpha1.Task{}, ".metadata.controller", controllers.TaskOwnerIndexFunc).
47+
Build()
48+
}
49+
3950
// mustCreateLogr creates a logr.Logger implementation backed by a debug style sink. It panics
4051
// if the logger fails to create.
4152
func mustCreateLogr(name ...string) logr.Logger {

controllers/job_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (r *JobReconciler) reconcile(ctx context.Context, job *bmcv1alpha1.Job, job
113113
tasks := &bmcv1alpha1.TaskList{}
114114
err = r.client.List(ctx, tasks, client.MatchingFields{jobOwnerKey: job.Name})
115115
if err != nil {
116-
return ctrl.Result{}, fmt.Errorf("failed to list owned Tasks for Job %s/%s", job.Namespace, job.Name)
116+
return ctrl.Result{}, fmt.Errorf("failed to list owned Tasks for Job %s/%s: %v", job.Namespace, job.Name, err)
117117
}
118118

119119
completedTasksCount := 0
@@ -230,7 +230,7 @@ func (r *JobReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager)
230230
ctx,
231231
&bmcv1alpha1.Task{},
232232
jobOwnerKey,
233-
taskOwnerIndexFunc,
233+
TaskOwnerIndexFunc,
234234
); err != nil {
235235
return err
236236
}
@@ -246,8 +246,8 @@ func (r *JobReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager)
246246
Complete(r)
247247
}
248248

249-
// taskOwnerIndexFunc is Indexer func which returns the owner name for obj.
250-
func taskOwnerIndexFunc(obj client.Object) []string {
249+
// TaskOwnerIndexFunc is Indexer func which returns the owner name for obj.
250+
func TaskOwnerIndexFunc(obj client.Object) []string {
251251
task, ok := obj.(*bmcv1alpha1.Task)
252252
if !ok {
253253
return nil

controllers/job_controller_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ func TestJobReconciler_TasklessJob(t *testing.T) {
2121
secret := createSecret()
2222
job := createJob("test", machine)
2323

24-
builder := createKubeClientBuilder()
25-
builder.WithObjects(machine, secret, job)
26-
kubeClient := builder.Build()
24+
kubeClient := createKubeClientWithObjectsForJobController(machine, secret, job)
2725

2826
reconciler := controllers.NewJobReconciler(kubeClient, logger)
2927

@@ -77,7 +75,6 @@ func TestJobReconciler_UnknownMachine(t *testing.T) {
7775
}
7876

7977
func TestJobReconciler_Reconcile(t *testing.T) {
80-
8178
for name, action := range map[string]bmcv1alpha1.Action{
8279
"PowerAction": {PowerAction: bmcv1alpha1.PowerOn.Ptr()},
8380
"OneTimeBootDeviceAction": {
@@ -95,7 +92,7 @@ func TestJobReconciler_Reconcile(t *testing.T) {
9592
job := createJob(name, machine)
9693
job.Spec.Tasks = append(job.Spec.Tasks, action)
9794

98-
cluster := createKubeClientWithObjects(machine, secret, job)
95+
cluster := createKubeClientWithObjectsForJobController(machine, secret, job)
9996

10097
request := reconcile.Request{
10198
NamespacedName: types.NamespacedName{

controllers/suite_test.go

+30-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ limitations under the License.
1919
package controllers
2020

2121
import (
22+
"fmt"
2223
"path/filepath"
2324
"testing"
2425

2526
. "github.com/onsi/ginkgo"
27+
"github.com/onsi/ginkgo/config"
28+
"github.com/onsi/ginkgo/types"
2629
. "github.com/onsi/gomega"
2730
"k8s.io/client-go/kubernetes/scheme"
2831
"k8s.io/client-go/rest"
2932
"sigs.k8s.io/controller-runtime/pkg/client"
3033
"sigs.k8s.io/controller-runtime/pkg/envtest"
31-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3234
logf "sigs.k8s.io/controller-runtime/pkg/log"
3335
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3436

@@ -48,7 +50,7 @@ func TestAPIs(t *testing.T) {
4850

4951
RunSpecsWithDefaultAndCustomReporters(t,
5052
"Controller Suite",
51-
[]Reporter{printer.NewlineReporter{}})
53+
[]Reporter{newlineReporter{}})
5254
}
5355

5456
var _ = BeforeSuite(func() {
@@ -73,11 +75,36 @@ var _ = BeforeSuite(func() {
7375
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
7476
Expect(err).NotTo(HaveOccurred())
7577
Expect(k8sClient).NotTo(BeNil())
76-
7778
}, 60)
7879

7980
var _ = AfterSuite(func() {
8081
By("tearing down the test environment")
8182
err := testEnv.Stop()
8283
Expect(err).NotTo(HaveOccurred())
8384
})
85+
86+
// newlineReporter is Reporter that Prints a newline after the default Reporter output so that the results
87+
// are correctly parsed by test automation.
88+
// See issue https://github.com/jstemmer/go-junit-report/issues/31
89+
// This is copied from sigs.k8s.io/controller-runtime/pkg/envtest/printer since controller-runtime
90+
// doesn't include this starting with version v0.14.0
91+
type newlineReporter struct{}
92+
93+
// SpecSuiteWillBegin implements ginkgo.Reporter.
94+
func (newlineReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
95+
}
96+
97+
// BeforeSuiteDidRun implements ginkgo.Reporter.
98+
func (newlineReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {}
99+
100+
// AfterSuiteDidRun implements ginkgo.Reporter.
101+
func (newlineReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {}
102+
103+
// SpecWillRun implements ginkgo.Reporter.
104+
func (newlineReporter) SpecWillRun(specSummary *types.SpecSummary) {}
105+
106+
// SpecDidComplete implements ginkgo.Reporter.
107+
func (newlineReporter) SpecDidComplete(specSummary *types.SpecSummary) {}
108+
109+
// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:".
110+
func (newlineReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) { fmt.Printf("\n") }

go.mod

+25-38
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,29 @@ require (
1010
github.com/onsi/ginkgo v1.16.5
1111
github.com/onsi/gomega v1.24.1
1212
github.com/spf13/pflag v1.0.5
13-
go.uber.org/zap v1.23.0
13+
go.uber.org/zap v1.24.0
1414
golang.org/x/tools v0.3.0
15-
k8s.io/api v0.25.4
16-
k8s.io/apimachinery v0.25.4
17-
k8s.io/client-go v0.25.4
18-
sigs.k8s.io/controller-runtime v0.13.1
15+
k8s.io/api v0.26.1
16+
k8s.io/apimachinery v0.26.1
17+
k8s.io/client-go v0.26.1
18+
sigs.k8s.io/controller-runtime v0.14.4
1919
)
2020

2121
require (
22-
cloud.google.com/go v0.97.0 // indirect
23-
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
24-
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
25-
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
26-
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
27-
github.com/Azure/go-autorest/logger v0.2.1 // indirect
28-
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
29-
github.com/PuerkitoBio/purell v1.1.1 // indirect
30-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
3122
github.com/VictorLowther/simplexml v0.0.0-20180716164440-0bff93621230 // indirect
3223
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 // indirect
33-
github.com/ammmze/go-amt v0.0.4 // indirect
34-
github.com/ammmze/wsman v0.0.2 // indirect
3524
github.com/beorn7/perks v1.0.1 // indirect
3625
github.com/bmc-toolbox/common v0.0.0-20221115135648-0b584f504396 // indirect
3726
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3827
github.com/davecgh/go-spew v1.1.1 // indirect
39-
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
28+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
4029
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
4130
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
42-
github.com/fsnotify/fsnotify v1.5.4 // indirect
31+
github.com/fsnotify/fsnotify v1.6.0 // indirect
4332
github.com/go-openapi/jsonpointer v0.19.5 // indirect
44-
github.com/go-openapi/jsonreference v0.19.5 // indirect
33+
github.com/go-openapi/jsonreference v0.20.0 // indirect
4534
github.com/go-openapi/swag v0.19.14 // indirect
4635
github.com/gogo/protobuf v1.3.2 // indirect
47-
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
4836
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4937
github.com/golang/protobuf v1.5.2 // indirect
5038
github.com/google/gnostic v0.5.7-v3refs // indirect
@@ -60,41 +48,40 @@ require (
6048
github.com/josharian/intern v1.0.0 // indirect
6149
github.com/json-iterator/go v1.1.12 // indirect
6250
github.com/mailru/easyjson v0.7.6 // indirect
63-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
51+
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
6452
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6553
github.com/modern-go/reflect2 v1.0.2 // indirect
6654
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6755
github.com/nxadm/tail v1.4.8 // indirect
6856
github.com/pkg/errors v0.9.1 // indirect
69-
github.com/prometheus/client_golang v1.12.2 // indirect
70-
github.com/prometheus/client_model v0.2.0 // indirect
71-
github.com/prometheus/common v0.32.1 // indirect
72-
github.com/prometheus/procfs v0.7.3 // indirect
57+
github.com/prometheus/client_golang v1.14.0 // indirect
58+
github.com/prometheus/client_model v0.3.0 // indirect
59+
github.com/prometheus/common v0.37.0 // indirect
60+
github.com/prometheus/procfs v0.8.0 // indirect
7361
github.com/satori/go.uuid v1.2.0 // indirect
7462
github.com/stmcginnis/gofish v0.13.1-0.20221107140645-5cc43fad050f // indirect
7563
go.uber.org/atomic v1.7.0 // indirect
7664
go.uber.org/multierr v1.6.0 // indirect
77-
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
7865
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
7966
golang.org/x/mod v0.7.0 // indirect
80-
golang.org/x/net v0.2.0 // indirect
81-
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
82-
golang.org/x/sys v0.2.0 // indirect
83-
golang.org/x/term v0.2.0 // indirect
84-
golang.org/x/text v0.4.0 // indirect
85-
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
67+
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
68+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
69+
golang.org/x/sys v0.3.0 // indirect
70+
golang.org/x/term v0.3.0 // indirect
71+
golang.org/x/text v0.5.0 // indirect
72+
golang.org/x/time v0.3.0 // indirect
8673
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
8774
google.golang.org/appengine v1.6.7 // indirect
88-
google.golang.org/protobuf v1.28.0 // indirect
75+
google.golang.org/protobuf v1.28.1 // indirect
8976
gopkg.in/inf.v0 v0.9.1 // indirect
9077
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
9178
gopkg.in/yaml.v2 v2.4.0 // indirect
9279
gopkg.in/yaml.v3 v3.0.1 // indirect
93-
k8s.io/apiextensions-apiserver v0.25.0 // indirect
94-
k8s.io/component-base v0.25.0 // indirect
95-
k8s.io/klog/v2 v2.70.1 // indirect
96-
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
97-
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
80+
k8s.io/apiextensions-apiserver v0.26.1 // indirect
81+
k8s.io/component-base v0.26.1 // indirect
82+
k8s.io/klog/v2 v2.80.1 // indirect
83+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
84+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
9885
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
9986
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
10087
sigs.k8s.io/yaml v1.3.0 // indirect

0 commit comments

Comments
 (0)