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

[Backport release-1.18] Fix unknown fields warnings and possibility to suppress finalizer ones #787

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions pkg/reconciler/managed/reconciler_typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (c *typedExternalClientWrapper[managed]) Create(ctx context.Context, mg res
}
return c.c.Create(ctx, cr)
}

func (c *typedExternalClientWrapper[managed]) Update(ctx context.Context, mg resource.Managed) (ExternalUpdate, error) {
cr, ok := mg.(managed)
if !ok {
Expand Down
20 changes: 10 additions & 10 deletions pkg/resource/fake/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
)

// Conditioned is a mock that implements Conditioned interface.
Expand All @@ -50,13 +50,13 @@ func (m *Conditioned) GetCondition(ct xpv1.ConditionType) xpv1.Condition {
}

// ClaimReferencer is a mock that implements ClaimReferencer interface.
type ClaimReferencer struct{ Ref *claim.Reference }
type ClaimReferencer struct{ Ref *reference.Claim }

// SetClaimReference sets the ClaimReference.
func (m *ClaimReferencer) SetClaimReference(r *claim.Reference) { m.Ref = r }
func (m *ClaimReferencer) SetClaimReference(r *reference.Claim) { m.Ref = r }

// GetClaimReference gets the ClaimReference.
func (m *ClaimReferencer) GetClaimReference() *claim.Reference { return m.Ref }
func (m *ClaimReferencer) GetClaimReference() *reference.Claim { return m.Ref }

// ManagedResourceReferencer is a mock that implements ManagedResourceReferencer interface.
type ManagedResourceReferencer struct{ Ref *corev1.ObjectReference }
Expand Down Expand Up @@ -184,15 +184,15 @@ func (m *CompositionSelector) SetCompositionSelector(s *metav1.LabelSelector) {
func (m *CompositionSelector) GetCompositionSelector() *metav1.LabelSelector { return m.Sel }

// CompositionRevisionReferencer is a mock that implements CompositionRevisionReferencer interface.
type CompositionRevisionReferencer struct{ Ref *corev1.ObjectReference }
type CompositionRevisionReferencer struct{ Ref *corev1.LocalObjectReference }

// SetCompositionRevisionReference sets the CompositionRevisionReference.
func (m *CompositionRevisionReferencer) SetCompositionRevisionReference(r *corev1.ObjectReference) {
func (m *CompositionRevisionReferencer) SetCompositionRevisionReference(r *corev1.LocalObjectReference) {
m.Ref = r
}

// GetCompositionRevisionReference gets the CompositionRevisionReference.
func (m *CompositionRevisionReferencer) GetCompositionRevisionReference() *corev1.ObjectReference {
func (m *CompositionRevisionReferencer) GetCompositionRevisionReference() *corev1.LocalObjectReference {
return m.Ref
}

Expand Down Expand Up @@ -236,13 +236,13 @@ func (m *CompositeResourceDeleter) GetCompositeDeletePolicy() *xpv1.CompositeDel
}

// CompositeResourceReferencer is a mock that implements CompositeResourceReferencer interface.
type CompositeResourceReferencer struct{ Ref *corev1.ObjectReference }
type CompositeResourceReferencer struct{ Ref *reference.Composite }

// SetResourceReference sets the composite resource reference.
func (m *CompositeResourceReferencer) SetResourceReference(p *corev1.ObjectReference) { m.Ref = p }
func (m *CompositeResourceReferencer) SetResourceReference(p *reference.Composite) { m.Ref = p }

// GetResourceReference gets the composite resource reference.
func (m *CompositeResourceReferencer) GetResourceReference() *corev1.ObjectReference { return m.Ref }
func (m *CompositeResourceReferencer) GetResourceReference() *reference.Composite { return m.Ref }

// ComposedResourcesReferencer is a mock that implements ComposedResourcesReferencer interface.
type ComposedResourcesReferencer struct{ Refs []corev1.ObjectReference }
Expand Down
14 changes: 7 additions & 7 deletions pkg/resource/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
)

// A Conditioned may have conditions set or retrieved. Conditions are typically
Expand All @@ -37,8 +37,8 @@ type Conditioned interface {

// A ClaimReferencer may reference a resource claim.
type ClaimReferencer interface {
SetClaimReference(r *claim.Reference)
GetClaimReference() *claim.Reference
SetClaimReference(r *reference.Claim)
GetClaimReference() *reference.Claim
}

// A ManagedResourceReferencer may reference a concrete managed resource.
Expand Down Expand Up @@ -120,8 +120,8 @@ type CompositionReferencer interface {
// A CompositionRevisionReferencer may reference a specific revision of a
// composition of resources.
type CompositionRevisionReferencer interface {
SetCompositionRevisionReference(ref *corev1.ObjectReference)
GetCompositionRevisionReference() *corev1.ObjectReference
SetCompositionRevisionReference(ref *corev1.LocalObjectReference)
GetCompositionRevisionReference() *corev1.LocalObjectReference
}

// A CompositionRevisionSelector may reference a set of
Expand Down Expand Up @@ -153,8 +153,8 @@ type ComposedResourcesReferencer interface {

// A CompositeResourceReferencer can reference a composite resource.
type CompositeResourceReferencer interface {
SetResourceReference(r *corev1.ObjectReference)
GetResourceReference() *corev1.ObjectReference
SetResourceReference(r *reference.Composite)
GetResourceReference() *reference.Composite
}

// An EnvironmentConfigReferencer references a list of EnvironmentConfigs.
Expand Down
32 changes: 9 additions & 23 deletions pkg/resource/unstructured/claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
)

// An Option modifies an unstructured composite resource claim.
Expand Down Expand Up @@ -63,21 +64,6 @@ type Unstructured struct {
unstructured.Unstructured
}

// Reference to a claim.
type Reference struct {
// APIVersion of the referenced claim.
APIVersion string `json:"apiVersion"`

// Kind of the referenced claim.
Kind string `json:"kind"`

// Name of the referenced claim.
Name string `json:"name"`

// Namespace of the referenced claim.
Namespace string `json:"namespace"`
}

// GetUnstructured returns the underlying *unstructured.Unstructured.
func (c *Unstructured) GetUnstructured() *unstructured.Unstructured {
return &c.Unstructured
Expand Down Expand Up @@ -112,16 +98,16 @@ func (c *Unstructured) SetCompositionReference(ref *corev1.ObjectReference) {
}

// GetCompositionRevisionReference of this resource claim.
func (c *Unstructured) GetCompositionRevisionReference() *corev1.ObjectReference {
out := &corev1.ObjectReference{}
func (c *Unstructured) GetCompositionRevisionReference() *corev1.LocalObjectReference {
out := &corev1.LocalObjectReference{}
if err := fieldpath.Pave(c.Object).GetValueInto("spec.compositionRevisionRef", out); err != nil {
return nil
}
return out
}

// SetCompositionRevisionReference of this resource claim.
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.ObjectReference) {
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.LocalObjectReference) {
_ = fieldpath.Pave(c.Object).SetValue("spec.compositionRevisionRef", ref)
}

Expand Down Expand Up @@ -170,22 +156,22 @@ func (c *Unstructured) GetCompositeDeletePolicy() *xpv1.CompositeDeletePolicy {
}

// GetResourceReference of this composite resource claim.
func (c *Unstructured) GetResourceReference() *corev1.ObjectReference {
out := &corev1.ObjectReference{}
func (c *Unstructured) GetResourceReference() *reference.Composite {
out := &reference.Composite{}
if err := fieldpath.Pave(c.Object).GetValueInto("spec.resourceRef", out); err != nil {
return nil
}
return out
}

// SetResourceReference of this composite resource claim.
func (c *Unstructured) SetResourceReference(ref *corev1.ObjectReference) {
func (c *Unstructured) SetResourceReference(ref *reference.Composite) {
_ = fieldpath.Pave(c.Object).SetValue("spec.resourceRef", ref)
}

// GetReference returns reference to this claim.
func (c *Unstructured) GetReference() *Reference {
return &Reference{
func (c *Unstructured) GetReference() *reference.Claim {
return &reference.Claim{
APIVersion: c.GetAPIVersion(),
Kind: c.GetKind(),
Name: c.GetName(),
Expand Down
15 changes: 8 additions & 7 deletions pkg/resource/unstructured/claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
)

var _ client.Object = &Unstructured{}
Expand Down Expand Up @@ -172,11 +173,11 @@ func TestCompositionReference(t *testing.T) {
}

func TestCompositionRevisionReference(t *testing.T) {
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
ref := &corev1.LocalObjectReference{Name: "cool"}
cases := map[string]struct {
u *Unstructured
set *corev1.ObjectReference
want *corev1.ObjectReference
set *corev1.LocalObjectReference
want *corev1.LocalObjectReference
}{
"NewRef": {
u: New(),
Expand Down Expand Up @@ -272,11 +273,11 @@ func TestCompositeDeletePolicy(t *testing.T) {
}

func TestResourceReference(t *testing.T) {
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
ref := &reference.Composite{Name: "cool"}
cases := map[string]struct {
u *Unstructured
set *corev1.ObjectReference
want *corev1.ObjectReference
set *reference.Composite
want *reference.Composite
}{
"NewRef": {
u: New(),
Expand All @@ -297,7 +298,7 @@ func TestResourceReference(t *testing.T) {
}

func TestClaimReference(t *testing.T) {
ref := &Reference{Namespace: "ns", Name: "cool", APIVersion: "foo.com/v1", Kind: "Foo"}
ref := &reference.Claim{Namespace: "ns", Name: "cool", APIVersion: "foo.com/v1", Kind: "Foo"}
u := &Unstructured{}
u.SetName(ref.Name)
u.SetNamespace(ref.Namespace)
Expand Down
23 changes: 16 additions & 7 deletions pkg/resource/unstructured/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/errors"
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
)

// An Option modifies an unstructured composite resource.
Expand Down Expand Up @@ -99,16 +99,16 @@ func (c *Unstructured) SetCompositionReference(ref *corev1.ObjectReference) {
}

// GetCompositionRevisionReference of this Composite resource.
func (c *Unstructured) GetCompositionRevisionReference() *corev1.ObjectReference {
out := &corev1.ObjectReference{}
func (c *Unstructured) GetCompositionRevisionReference() *corev1.LocalObjectReference {
out := &corev1.LocalObjectReference{}
if err := fieldpath.Pave(c.Object).GetValueInto("spec.compositionRevisionRef", out); err != nil {
return nil
}
return out
}

// SetCompositionRevisionReference of this Composite resource.
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.ObjectReference) {
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.LocalObjectReference) {
_ = fieldpath.Pave(c.Object).SetValue("spec.compositionRevisionRef", ref)
}

Expand Down Expand Up @@ -142,16 +142,16 @@ func (c *Unstructured) GetCompositionUpdatePolicy() *xpv1.UpdatePolicy {
}

// GetClaimReference of this Composite resource.
func (c *Unstructured) GetClaimReference() *claim.Reference {
out := &claim.Reference{}
func (c *Unstructured) GetClaimReference() *reference.Claim {
out := &reference.Claim{}
if err := fieldpath.Pave(c.Object).GetValueInto("spec.claimRef", out); err != nil {
return nil
}
return out
}

// SetClaimReference of this Composite resource.
func (c *Unstructured) SetClaimReference(ref *claim.Reference) {
func (c *Unstructured) SetClaimReference(ref *reference.Claim) {
_ = fieldpath.Pave(c.Object).SetValue("spec.claimRef", ref)
}

Expand All @@ -177,6 +177,15 @@ func (c *Unstructured) SetResourceReferences(refs []corev1.ObjectReference) {
_ = fieldpath.Pave(c.Object).SetValue("spec.resourceRefs", filtered)
}

// GetReference returns reference to this composite.
func (c *Unstructured) GetReference() *reference.Composite {
return &reference.Composite{
APIVersion: c.GetAPIVersion(),
Kind: c.GetKind(),
Name: c.GetName(),
}
}

// GetWriteConnectionSecretToReference of this Composite resource.
func (c *Unstructured) GetWriteConnectionSecretToReference() *xpv1.SecretReference {
out := &xpv1.SecretReference{}
Expand Down
14 changes: 7 additions & 7 deletions pkg/resource/unstructured/composite/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
"github.com/crossplane/crossplane-runtime/pkg/test"
)

Expand Down Expand Up @@ -259,11 +259,11 @@ func TestCompositionReference(t *testing.T) {
}

func TestCompositionRevisionReference(t *testing.T) {
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
ref := &corev1.LocalObjectReference{Name: "cool"}
cases := map[string]struct {
u *Unstructured
set *corev1.ObjectReference
want *corev1.ObjectReference
set *corev1.LocalObjectReference
want *corev1.LocalObjectReference
}{
"NewRef": {
u: New(),
Expand Down Expand Up @@ -334,11 +334,11 @@ func TestCompositionUpdatePolicy(t *testing.T) {
}

func TestClaimReference(t *testing.T) {
ref := &claim.Reference{Namespace: "ns", Name: "cool", APIVersion: "acme.com/v1", Kind: "Foo"}
ref := &reference.Claim{Namespace: "ns", Name: "cool", APIVersion: "acme.com/v1", Kind: "Foo"}
cases := map[string]struct {
u *Unstructured
set *claim.Reference
want *claim.Reference
set *reference.Claim
want *reference.Claim
}{
"NewRef": {
u: New(),
Expand Down
Loading