Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update k8s dependencies to 4.14 and controller-runtime to v0.15 #376

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ea978bc
add test cases for Status update
ranakan19 Feb 28, 2024
9500324
merge master, and resolve conflict
ranakan19 Feb 29, 2024
cdff82a
fix version name in replace
ranakan19 Feb 29, 2024
12913a5
add context to MapToOwnerByLabel as eventHandlers now need context
ranakan19 Feb 29, 2024
5f7e00e
replace runtimeObject with clientObject
ranakan19 Feb 29, 2024
9cc566c
update to latest api version in replace
ranakan19 Mar 18, 2024
67b340d
merge master, resolve merge conflict
ranakan19 Mar 18, 2024
bfa0fdf
Merge branch 'master' into k8s_1_27_common
mfrancisc Mar 20, 2024
645d7d8
Merge branch 'master' into k8s_1_27_common
ranakan19 Apr 5, 2024
daf1f51
mod tidy
ranakan19 Apr 5, 2024
41a4992
extend changes to new controller added
ranakan19 Apr 5, 2024
cb20b5d
fix linter error, use requre.Len instead
ranakan19 Apr 5, 2024
0986552
fix remainig linter issues
ranakan19 Apr 5, 2024
0f45101
add finalizer for nsTemplateSetOption
ranakan19 Apr 23, 2024
4d73885
Merge branch 'master' into k8s_1_27_common
ranakan19 Apr 23, 2024
b37379a
mod tidy
ranakan19 May 1, 2024
5ed243f
Merge branch 'master' into k8s_1_27_common
ranakan19 May 1, 2024
4bff8de
tidy after merge conflict resolved
ranakan19 May 1, 2024
6e615a7
update api
ranakan19 Jun 27, 2024
6dfea01
add all toolchain resources to fake client's sub status resource
ranakan19 Aug 2, 2024
95f5f65
Merge branch 'master' of github.com:codeready-toolchain/toolchain-com…
ranakan19 Aug 2, 2024
631693e
update api
ranakan19 Aug 2, 2024
e3932d3
lint check
ranakan19 Aug 7, 2024
1741afb
add comment explaining why assert is used here instead of require
ranakan19 Aug 9, 2024
b1d75a2
Update pkg/test/client.go
ranakan19 Aug 9, 2024
82e5050
UI commit broke something
ranakan19 Aug 9, 2024
9e0f843
merge conflict resolve
ranakan19 Aug 9, 2024
5dda997
Merge branch 'master' into k8s_1_27_common
ranakan19 Aug 15, 2024
ab92ad8
Merge branch 'master' of github.com:codeready-toolchain/toolchain-com…
ranakan19 Aug 15, 2024
d488ba4
Merge branch 'k8s_1_27_common' of github.com:ranakan19/toolchain-comm…
ranakan19 Aug 15, 2024
0701663
update api replace version
ranakan19 Aug 27, 2024
8a89255
merge conflict resolve
ranakan19 Aug 27, 2024
007ae28
update api
ranakan19 Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions controllers/label_event_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"context"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand All @@ -10,8 +11,8 @@ import (
// another resource whose name if found in a given label
// it maps the namespace to a request on the "owner" (or "associated") resource
// (if the label exists)
func MapToOwnerByLabel(namespace, label string) func(object client.Object) []reconcile.Request {
return func(obj client.Object) []reconcile.Request {
func MapToOwnerByLabel(namespace, label string) func(context context.Context, object client.Object) []reconcile.Request {
return func(ctx context.Context, obj client.Object) []reconcile.Request {
if name, exists := obj.GetLabels()[label]; exists {
return []reconcile.Request{
{
Expand All @@ -30,8 +31,8 @@ func MapToOwnerByLabel(namespace, label string) func(object client.Object) []rec
// MapToControllerByMatchingLabel returns an event handler will convert events on a resource to requests
// if the resource matches a given label key and value
// (if the label exists)
func MapToControllerByMatchingLabel(labelKey, labelValue string) func(object client.Object) []reconcile.Request {
return func(obj client.Object) []reconcile.Request {
func MapToControllerByMatchingLabel(labelKey, labelValue string) func(ctx context.Context, object client.Object) []reconcile.Request {
return func(ctx context.Context, obj client.Object) []reconcile.Request {
if labelValueFound, exists := obj.GetLabels()[labelKey]; exists && labelValue == labelValueFound {
return []reconcile.Request{
{
Expand Down
15 changes: 9 additions & 6 deletions controllers/label_event_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -15,6 +16,7 @@ func TestMapToOwnerByLabel(t *testing.T) {

t.Run("resource with expected label", func(t *testing.T) {
// given
ctx := context.TODO()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor - we could move the context creation up in the parent test

objMeta := metav1.ObjectMeta{
Name: "bar",
Labels: map[string]string{
Expand All @@ -27,7 +29,7 @@ func TestMapToOwnerByLabel(t *testing.T) {
ObjectMeta: objMeta,
}
// when
result := MapToOwnerByLabel("ns", "owner")(obj)
result := MapToOwnerByLabel("ns", "owner")(ctx, obj)
// then
require.Len(t, result, 1)
assert.Equal(t, reconcile.Request{
Expand All @@ -40,6 +42,7 @@ func TestMapToOwnerByLabel(t *testing.T) {

t.Run("resource without expected label", func(t *testing.T) {
// given
ctx := context.TODO()
objMeta := metav1.ObjectMeta{
Name: "bar",
Labels: map[string]string{
Expand All @@ -50,7 +53,7 @@ func TestMapToOwnerByLabel(t *testing.T) {
ObjectMeta: objMeta,
}
// when
result := MapToOwnerByLabel("ns", "owner")(&obj)
result := MapToOwnerByLabel("ns", "owner")(ctx, &obj)
// then
require.Empty(t, result)
})
Expand All @@ -73,7 +76,7 @@ func TestMapToControllerByMatchingLabel(t *testing.T) {
ObjectMeta: objMeta,
}
// when
result := MapToControllerByMatchingLabel("owner", "foo")(obj)
result := MapToControllerByMatchingLabel("owner", "foo")(context.TODO(), obj)
// then
require.Len(t, result, 1)
assert.Equal(t, reconcile.Request{
Expand All @@ -96,7 +99,7 @@ func TestMapToControllerByMatchingLabel(t *testing.T) {
ObjectMeta: objMeta,
}
// when
result := MapToControllerByMatchingLabel("owner", "foo")(&obj)
result := MapToControllerByMatchingLabel("owner", "foo")(context.TODO(), &obj)
// then
require.Empty(t, result)
})
Expand All @@ -113,7 +116,7 @@ func TestMapToControllerByMatchingLabel(t *testing.T) {
ObjectMeta: objMeta,
}
// when
result := MapToControllerByMatchingLabel("owner", "bar")(&obj)
result := MapToControllerByMatchingLabel("owner", "bar")(context.TODO(), &obj)
// then
require.Empty(t, result)
})
Expand All @@ -128,7 +131,7 @@ func TestMapToControllerByMatchingLabel(t *testing.T) {
ObjectMeta: objMeta,
}
// when
result := MapToControllerByMatchingLabel("owner", "bar")(&obj)
result := MapToControllerByMatchingLabel("owner", "bar")(context.TODO(), &obj)
// then
require.Empty(t, result)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestClusterControllerChecks(t *testing.T) {
stable, _ := newToolchainCluster(t, "stable", tcNs, "https://cluster.com")

cl := test.NewFakeClient(t, stable)
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
return fmt.Errorf("mock error")
}
controller, req := prepareReconcile(stable, cl, requeAfter)
Expand All @@ -139,7 +139,7 @@ func TestClusterControllerChecks(t *testing.T) {
stable, sec := newToolchainCluster(t, "stable", tcNs, "https://cluster.com")
expectedErr := fmt.Errorf("my test error")
cl := test.NewFakeClient(t, stable, sec)
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
cl.MockStatusUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.SubResourceUpdateOption) error {
return expectedErr
}
reset := setupCachedClusters(t, cl, stable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// ResourceControllerLabelValue is being added to all the resources managed by this controller.
Expand All @@ -44,7 +43,7 @@
}
mapToOwnerByLabel := handler.EnqueueRequestsFromMapFunc(commoncontroller.MapToControllerByMatchingLabel(toolchainv1alpha1.ProviderLabelKey, ResourceControllerLabelValue))
for _, obj := range r.templateObjects {
build = build.Watches(&source.Kind{Type: obj.DeepCopyObject().(runtimeclient.Object)}, mapToOwnerByLabel, builder.WithPredicates(commonpredicates.LabelsAndGenerationPredicate{}))
build = build.Watches(obj.DeepCopyObject().(runtimeclient.Object), mapToOwnerByLabel, builder.WithPredicates(commonpredicates.LabelsAndGenerationPredicate{}))

Check warning on line 46 in controllers/toolchainclusterresources/toolchaincluster_resources_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/toolchainclusterresources/toolchaincluster_resources_controller.go#L46

Added line #L46 was not covered by tests
}
return build.Complete(r)
}
Expand Down
74 changes: 31 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.20

require (
github.com/codeready-toolchain/api v0.0.0-20240909145803-3b27dcfb3ded
github.com/go-logr/logr v1.2.3
github.com/go-logr/logr v1.2.4
github.com/golang-jwt/jwt/v5 v5.2.0
github.com/lestrrat-go/jwx v1.2.29
github.com/magiconair/properties v1.8.5
// using latest commit from 'github.com/openshift/api branch release-4.12'
github.com/openshift/api v0.0.0-20230213134911-7ba313770556
github.com/openshift/api v0.0.0-20240304080513-3e8192a10b13
// using latest commit from 'github.com/openshift/library-go branch release-4.12'
github.com/openshift/library-go v0.0.0-20230301092340-c13b89190a26
github.com/pkg/errors v0.9.1
Expand All @@ -18,10 +18,10 @@ require (
gopkg.in/h2non/gock.v1 v1.0.14
gopkg.in/square/go-jose.v2 v2.3.0
gotest.tools v2.2.0+incompatible
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/client-go v0.25.0
sigs.k8s.io/controller-runtime v0.13.0
k8s.io/api v0.27.2
k8s.io/apimachinery v0.27.2
k8s.io/client-go v0.27.2
sigs.k8s.io/controller-runtime v0.15.0
)

require (
Expand All @@ -30,11 +30,11 @@ require (
github.com/google/go-github/v52 v52.0.0
github.com/google/uuid v1.6.0
github.com/migueleliasweb/go-github-mock v0.0.18
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/client_golang v1.15.1
golang.org/x/oauth2 v0.7.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/kubectl v0.24.0
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
)

require (
Expand All @@ -43,84 +43,72 @@ require (
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/go-logr/zapr v1.2.3 // 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/gobuffalo/flect v0.2.5 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.12 // 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/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/code-generator v0.25.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
sigs.k8s.io/controller-tools v0.10.0 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/codeready-toolchain/api v0.0.0-20240909145803-3b27dcfb3ded => github.com/ranakan19/api v0.0.0-20240923151833-647d61ba6f05
Loading
Loading