Skip to content

Commit

Permalink
Bump controller-runtime to v0.17.0
Browse files Browse the repository at this point in the history
- Bump controller-runtime to v0.17.0
- Introduce a few minor fixes for new fakeclient behaviour, see:
kubernetes-sigs/controller-runtime#2633

Signed-off-by: Simone Tiraboschi <[email protected]>
  • Loading branch information
tiraboschi committed Jan 31, 2024
1 parent bef108b commit 2e3479b
Show file tree
Hide file tree
Showing 33 changed files with 534 additions and 170 deletions.
2 changes: 1 addition & 1 deletion controllers/commontestutils/testClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *HcoTestClient) InitiateCreateErrors(f FakeWriteErrorGenerator) {
}

func (c *HcoTestClient) Scheme() *runtime.Scheme {
return &runtime.Scheme{}
return c.client.Scheme()
}

func (c *HcoTestClient) RESTMapper() meta.RESTMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ var _ = Describe("HyperconvergedController", func() {
hco.Spec.Workloads = hcov1beta1.HyperConvergedConfig{NodePlacement: commontestutils.NewNodePlacement()}
existingResource, err := operands.NewKubeVirt(hco, namespace)
Expect(err).ToNot(HaveOccurred())
existingResource.Kind = kubevirtcorev1.KubeVirtGroupVersionKind.Kind // necessary for metrics
existingResource.APIVersion, existingResource.Kind = kubevirtcorev1.KubeVirtGroupVersionKind.ToAPIVersionAndKind() // necessary for metrics

// now, modify KV's node placement
existingResource.Spec.Infra.NodePlacement.Tolerations = append(hco.Spec.Infra.NodePlacement.Tolerations, corev1.Toleration{
Expand Down
1 change: 0 additions & 1 deletion controllers/hyperconverged/testUtils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ func getBasicDeployment() *BasicExpected {
expectedCDI, err := operands.NewCDI(hco)
ExpectWithOffset(1, err).ToNot(HaveOccurred())
expectedCDI.Status.Conditions = getGenericCompletedConditions()
expectedCDI.Kind = cdiv1beta1.CDIGroupVersionKind.Kind
res.cdi = expectedCDI

expectedCNA, err := operands.NewNetworkAddons(hco)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
kubevirt.io/controller-lifecycle-operator-sdk/api v0.2.4
kubevirt.io/managed-tenant-quota v1.2.0
kubevirt.io/ssp-operator/api v0.19.0
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/controller-runtime v0.17.0
sigs.k8s.io/controller-tools v0.14.0
)

Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
Expand Down Expand Up @@ -465,8 +465,8 @@ kubevirt.io/managed-tenant-quota v1.2.0 h1:AE+rmmVfwzvUrWlBfplr/Mhw60YDDEI3j0/Ty
kubevirt.io/managed-tenant-quota v1.2.0/go.mod h1:oiTB7mMAOXacveW9rbZYoWieMxKvnF+vEyueEN+KCEQ=
kubevirt.io/ssp-operator/api v0.19.0 h1:K1sBY1nIdQO1CoUkYRuz6CepZU97u4dlhqv1ldRyaxs=
kubevirt.io/ssp-operator/api v0.19.0/go.mod h1:7lHBbaTsT5pBgrvipn+ZaoQR4t6TQHMlbcq2Wh5o714=
sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigwG62c4=
sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0=
sigs.k8s.io/controller-runtime v0.17.0 h1:fjJQf8Ukya+VjogLO6/bNX9HE6Y2xpsO5+fyS26ur/s=
sigs.k8s.io/controller-runtime v0.17.0/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s=
sigs.k8s.io/controller-tools v0.14.0 h1:rnNoCC5wSXlrNoBKKzL70LNJKIQKEzT6lloG6/LF73A=
sigs.k8s.io/controller-tools v0.14.0/go.mod h1:TV7uOtNNnnR72SpzhStvPkoS/U5ir0nMudrkrC4M9Sc=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
Expand Down
34 changes: 24 additions & 10 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package util

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -23,6 +22,7 @@ import (
"k8s.io/client-go/tools/reference"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

// ForceRunModeEnv indicates if the operator should be forced to run in either local
Expand Down Expand Up @@ -79,13 +79,26 @@ var GetOperatorNamespace = func(logger logr.Logger) (string, error) {

// ToUnstructured converts an arbitrary object (which MUST obey the
// k8s object conventions) to an Unstructured
func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error) {
b, err := json.Marshal(obj)
if err != nil {
return nil, err
func ToUnstructured(obj runtime.Object, c client.Client) (*unstructured.Unstructured, error) {
apiVersion, kind := obj.GetObjectKind().GroupVersionKind().ToAPIVersionAndKind()
if apiVersion == "" || kind == "" {
gvk, err := apiutil.GVKForObject(obj, c.Scheme())
if err != nil {
return nil, err
}
ta, err := meta.TypeAccessor(obj)
if err != nil {
return nil, err
}
ta.SetKind(gvk.Kind)
ta.SetAPIVersion(gvk.GroupVersion().String())
}

u := &unstructured.Unstructured{}
if err := json.Unmarshal(b, u); err != nil {
var err error
u.Object, err = runtime.DefaultUnstructuredConverter.ToUnstructured(obj)

if err != nil {
return nil, err
}
return u, nil
Expand All @@ -99,15 +112,16 @@ func GetRuntimeObject(ctx context.Context, c client.Client, obj client.Object) e

// ComponentResourceRemoval removes the resource `obj` if it exists and belongs to the HCO
// with wait=true it will wait, (util ctx timeout, please set it!) for the resource to be effectively deleted
func ComponentResourceRemoval(ctx context.Context, c client.Client, obj interface{}, hcoName string, logger logr.Logger, dryRun bool, wait bool, protectNonHCOObjects bool) (bool, error) {
resource, err := ToUnstructured(obj)
func ComponentResourceRemoval(ctx context.Context, c client.Client, obj client.Object, hcoName string, logger logr.Logger, dryRun bool, wait bool, protectNonHCOObjects bool) (bool, error) {

logger.Info("Removing resource", "name", obj.GetName(), "namespace", obj.GetNamespace(), "GVK", obj.GetObjectKind().GroupVersionKind(), "dryRun", dryRun)

resource, err := ToUnstructured(obj, c)
if err != nil {
logger.Error(err, "Failed to convert object to Unstructured")
return false, err
}

logger.Info("Removing resource", "name", resource.GetName(), "namespace", resource.GetNamespace(), "GVK", resource.GetObjectKind().GroupVersionKind(), "dryRun", dryRun)

ok, err := getResourceForDeletion(ctx, c, resource, logger)
if !ok {
return false, err
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ kubevirt.io/managed-tenant-quota/staging/src/kubevirt.io/managed-tenant-quota-ap
# kubevirt.io/ssp-operator/api v0.19.0
## explicit; go 1.20
kubevirt.io/ssp-operator/api/v1beta2
# sigs.k8s.io/controller-runtime v0.16.3
## explicit; go 1.20
# sigs.k8s.io/controller-runtime v0.17.0
## explicit; go 1.21
sigs.k8s.io/controller-runtime
sigs.k8s.io/controller-runtime/pkg/builder
sigs.k8s.io/controller-runtime/pkg/cache
Expand Down Expand Up @@ -722,6 +722,7 @@ sigs.k8s.io/controller-runtime/pkg/internal/log
sigs.k8s.io/controller-runtime/pkg/internal/objectutil
sigs.k8s.io/controller-runtime/pkg/internal/recorder
sigs.k8s.io/controller-runtime/pkg/internal/source
sigs.k8s.io/controller-runtime/pkg/internal/syncs
sigs.k8s.io/controller-runtime/pkg/leaderelection
sigs.k8s.io/controller-runtime/pkg/log
sigs.k8s.io/controller-runtime/pkg/log/zap
Expand Down
4 changes: 2 additions & 2 deletions vendor/sigs.k8s.io/controller-runtime/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions vendor/sigs.k8s.io/controller-runtime/RELEASE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions vendor/sigs.k8s.io/controller-runtime/pkg/cache/cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/sigs.k8s.io/controller-runtime/pkg/cache/informer_cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2e3479b

Please sign in to comment.