Skip to content

Commit

Permalink
Merge pull request #6071 from turkenh/backport-6064-to-release-1.18
Browse files Browse the repository at this point in the history
[release-1.18] Backport fix unknown field warnings & bump runtime to v1.18.0
  • Loading branch information
turkenh authored Nov 5, 2024
2 parents fea3709 + 12135a0 commit e663a43
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 87 deletions.
1 change: 0 additions & 1 deletion cmd/crank/beta/trace/internal/resource/xrm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func getResourceChildrenRefs(r *resource.Resource, getConnectionSecrets bool) []
APIVersion: ref.APIVersion,
Kind: ref.Kind,
Name: ref.Name,
Namespace: ref.Namespace,
})
}
if getConnectionSecrets {
Expand Down
9 changes: 5 additions & 4 deletions cmd/crank/beta/trace/internal/resource/xrm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (
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/composite"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"

resource2 "github.com/crossplane/crossplane/cmd/crank/beta/trace/internal/resource"
)

type xrcOpt func(c *claim.Unstructured)

func withXRCRef(ref *v1.ObjectReference) xrcOpt {
func withXRCRef(ref *reference.Composite) xrcOpt {
return func(c *claim.Unstructured) {
c.SetResourceReference(ref)
}
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestGetResourceChildrenRefs(t *testing.T) {
reason: "Should return the XR child for an XRC.",
args: args{
resource: &resource2.Resource{
Unstructured: *buildXRC("ns-1", "xrc", withXRCRef(&v1.ObjectReference{
Unstructured: *buildXRC("ns-1", "xrc", withXRCRef(&reference.Composite{
APIVersion: "example.com/v1",
Kind: "XR",
Name: "xr-1",
Expand Down Expand Up @@ -171,7 +172,7 @@ func TestGetResourceChildrenRefs(t *testing.T) {
resource: &resource2.Resource{
Unstructured: *buildXRC("ns-1", "xrc", withXRCSecretRef(&xpv1.LocalSecretReference{
Name: "secret-1",
}), withXRCRef(&v1.ObjectReference{
}), withXRCRef(&reference.Composite{
APIVersion: "example.com/v1",
Kind: "XR",
Name: "xr-1",
Expand Down Expand Up @@ -201,7 +202,7 @@ func TestGetResourceChildrenRefs(t *testing.T) {
resource: &resource2.Resource{
Unstructured: *buildXRC("ns-1", "xrc", withXRCSecretRef(&xpv1.LocalSecretReference{
Name: "secret-1",
}), withXRCRef(&v1.ObjectReference{
}), withXRCRef(&reference.Composite{
APIVersion: "example.com/v1",
Kind: "XR",
Name: "xr-1",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
github.com/Masterminds/semver v1.5.0
github.com/alecthomas/kong v0.9.0
github.com/crossplane/crossplane-runtime v1.18.0-rc.1
github.com/crossplane/crossplane-runtime v1.18.0
github.com/docker/docker v27.1.1+incompatible
github.com/docker/go-connections v0.5.0
github.com/emicklei/dot v1.6.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/crossplane/crossplane-runtime v1.18.0-rc.1 h1:E4WMn33yM59SbYEH8WaYWAtaIroIISyxELRdqKvs01s=
github.com/crossplane/crossplane-runtime v1.18.0-rc.1/go.mod h1:p7nVVsLn0CWjsLvLCtr7T40ErbTgNWKRxmYnwFdfXb4=
github.com/crossplane/crossplane-runtime v1.18.0 h1:aAQIMNOgPbbXaqj9CUSv+gPl3QnVbn33YlzSe145//0=
github.com/crossplane/crossplane-runtime v1.18.0/go.mod h1:p7nVVsLn0CWjsLvLCtr7T40ErbTgNWKRxmYnwFdfXb4=
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46 h1:2Dx4IHfC1yHWI12AxQDJM1QbRCDfk6M+blLzlZCXdrc=
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/apiextensions/claim/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -348,7 +349,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
record = record.WithAnnotations("composite-name", cm.GetResourceReference().Name)
log = log.WithValues("composite-name", cm.GetResourceReference().Name)

if err := r.client.Get(ctx, meta.NamespacedNameOf(ref), xr); resource.IgnoreNotFound(err) != nil {
if err := r.client.Get(ctx, types.NamespacedName{Name: ref.Name}, xr); resource.IgnoreNotFound(err) != nil {
err = errors.Wrap(err, errGetComposite)
record.Event(cm, event.Warning(reasonBind, err))
cm.SetConditions(xpv1.ReconcileError(err))
Expand Down
49 changes: 25 additions & 24 deletions internal/controller/apiextensions/claim/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/composite"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
"github.com/crossplane/crossplane-runtime/pkg/test"
)

Expand Down Expand Up @@ -141,7 +142,7 @@ func TestReconcile(t *testing.T) {
case *claim.Unstructured:
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
case *composite.Unstructured:
// Return an error getting the XR.
return errBoom
Expand All @@ -150,7 +151,7 @@ func TestReconcile(t *testing.T) {
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConditions(xpv1.ReconcileError(errors.Wrap(errBoom, errGetComposite)))
})),
},
Expand All @@ -168,18 +169,18 @@ func TestReconcile(t *testing.T) {
case *claim.Unstructured:
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
case *composite.Unstructured:
// This XR was created, and references another
// claim.
o.SetCreationTimestamp(now)
o.SetClaimReference(&claim.Reference{Name: "some-other-claim"})
o.SetClaimReference(&reference.Claim{Name: "some-other-claim"})
}
return nil
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConditions(xpv1.ReconcileError(errors.Errorf(errFmtUnbound, "", "some-other-claim")))
})),
},
Expand All @@ -198,7 +199,7 @@ func TestReconcile(t *testing.T) {
o.SetDeletionTimestamp(&now)
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
case *composite.Unstructured:
// Pretend the XR exists.
o.SetCreationTimestamp(now)
Expand All @@ -209,7 +210,7 @@ func TestReconcile(t *testing.T) {
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetDeletionTimestamp(&now)
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConditions(xpv1.Deleting())
cm.SetConditions(xpv1.ReconcileError(errors.Wrap(errBoom, errDeleteComposite)))
})),
Expand Down Expand Up @@ -312,14 +313,14 @@ func TestReconcile(t *testing.T) {
o.SetDeletionTimestamp(&now)
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
// We want to foreground delete.
fg := xpv1.CompositeDeleteForeground
o.SetCompositeDeletePolicy(&fg)
case *composite.Unstructured:
// Pretend the XR exists and is bound.
o.SetCreationTimestamp(now)
o.SetClaimReference(&claim.Reference{})
o.SetClaimReference(&reference.Claim{})
}
return nil
}),
Expand All @@ -345,7 +346,7 @@ func TestReconcile(t *testing.T) {
o.SetDeletionTimestamp(&now)
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
// We want to foreground delete.
fg := xpv1.CompositeDeleteForeground
o.SetCompositeDeletePolicy(&fg)
Expand All @@ -354,12 +355,12 @@ func TestReconcile(t *testing.T) {
// being deleted.
o.SetCreationTimestamp(now)
o.SetDeletionTimestamp(&now)
o.SetClaimReference(&claim.Reference{})
o.SetClaimReference(&reference.Claim{})
}
return nil
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
// We want to foreground delete.
fg := xpv1.CompositeDeleteForeground
cm.SetCompositeDeletePolicy(&fg)
Expand Down Expand Up @@ -429,19 +430,19 @@ func TestReconcile(t *testing.T) {
case *claim.Unstructured:
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
case *composite.Unstructured:
// Pretend the XR exists and is bound, but is
// still being created.
o.SetCreationTimestamp(now)
o.SetClaimReference(&claim.Reference{})
o.SetClaimReference(&reference.Claim{})
o.SetConditions(xpv1.Creating())
}
return nil
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConditions(xpv1.ReconcileSuccess())
cm.SetConditions(Waiting())
})),
Expand All @@ -466,18 +467,18 @@ func TestReconcile(t *testing.T) {
case *claim.Unstructured:
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
case *composite.Unstructured:
// Pretend the XR exists and is available.
o.SetCreationTimestamp(now)
o.SetClaimReference(&claim.Reference{})
o.SetClaimReference(&reference.Claim{})
o.SetConditions(xpv1.Available())
}
return nil
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConditions(xpv1.ReconcileError(errors.Wrap(errBoom, errPropagateCDs)))
})),
},
Expand All @@ -504,18 +505,18 @@ func TestReconcile(t *testing.T) {
case *claim.Unstructured:
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
case *composite.Unstructured:
// Pretend the XR exists and is available.
o.SetCreationTimestamp(now)
o.SetClaimReference(&claim.Reference{})
o.SetClaimReference(&reference.Claim{})
o.SetConditions(xpv1.Available())
}
return nil
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConnectionDetailsLastPublishedTime(&now)
cm.SetConditions(xpv1.ReconcileSuccess())
cm.SetConditions(xpv1.Available())
Expand Down Expand Up @@ -544,7 +545,7 @@ func TestReconcile(t *testing.T) {
case *claim.Unstructured:
// We won't try to get an XR unless the claim
// references one.
o.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
o.SetResourceReference(&reference.Composite{Name: "cool-composite"})
// The system conditions are already set.
o.SetConditions(xpv1.ReconcileSuccess())
o.SetConditions(xpv1.Available())
Expand All @@ -557,7 +558,7 @@ func TestReconcile(t *testing.T) {
case *composite.Unstructured:
// Pretend the XR exists and is available.
o.SetCreationTimestamp(now)
o.SetClaimReference(&claim.Reference{})
o.SetClaimReference(&reference.Claim{})
o.SetConditions(xpv1.Available())
o.SetConditions(
// Database has become ready.
Expand Down Expand Up @@ -588,7 +589,7 @@ func TestReconcile(t *testing.T) {
}),
MockStatusUpdate: WantClaim(t, NewClaim(func(cm *claim.Unstructured) {
// Check that we set our status condition.
cm.SetResourceReference(&corev1.ObjectReference{Name: "cool-composite"})
cm.SetResourceReference(&reference.Composite{Name: "cool-composite"})
cm.SetConnectionDetailsLastPublishedTime(&now)
cm.SetConditions(xpv1.ReconcileSuccess())
cm.SetConditions(xpv1.Available())
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/apiextensions/claim/syncer_csa.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *ClientSideCompositeSyncer) Sync(ctx context.Context, cm *claim.Unstruct
// then crashed before saving a reference to it. We'd create another XR on
// the next reconcile.
existing := cm.GetResourceReference()
proposed := meta.ReferenceTo(xr, xr.GetObjectKind().GroupVersionKind())
proposed := xr.GetReference()
if !cmp.Equal(existing, proposed) {
cm.SetResourceReference(proposed)
if err := s.client.Update(ctx, cm); err != nil {
Expand Down
19 changes: 10 additions & 9 deletions internal/controller/apiextensions/claim/syncer_csa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/composite"
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
"github.com/crossplane/crossplane-runtime/pkg/test"

"github.com/crossplane/crossplane/internal/names"
Expand Down Expand Up @@ -118,7 +119,7 @@ func TestClientSideSync(t *testing.T) {
xcrd.LabelKeyClaimNamespace: "default",
xcrd.LabelKeyClaimName: "cool-claim",
})
xr.SetClaimReference(&claim.Reference{
xr.SetClaimReference(&reference.Claim{
Namespace: "default",
Name: "cool-claim",
})
Expand Down Expand Up @@ -159,7 +160,7 @@ func TestClientSideSync(t *testing.T) {
cm.SetCompositionReference(&corev1.ObjectReference{
Name: "some-composition",
})
cm.SetResourceReference(&corev1.ObjectReference{
cm.SetResourceReference(&reference.Composite{
Name: "cool-claim-random",
})
}),
Expand All @@ -170,7 +171,7 @@ func TestClientSideSync(t *testing.T) {
xcrd.LabelKeyClaimNamespace: "default",
xcrd.LabelKeyClaimName: "cool-claim",
})
xr.SetClaimReference(&claim.Reference{
xr.SetClaimReference(&reference.Claim{
Namespace: "default",
Name: "cool-claim",
})
Expand Down Expand Up @@ -214,7 +215,7 @@ func TestClientSideSync(t *testing.T) {
cm.SetCompositionReference(&corev1.ObjectReference{
Name: "some-composition",
})
cm.SetResourceReference(&corev1.ObjectReference{
cm.SetResourceReference(&reference.Composite{
Name: "cool-claim-random",
})
}),
Expand All @@ -225,7 +226,7 @@ func TestClientSideSync(t *testing.T) {
xcrd.LabelKeyClaimNamespace: "default",
xcrd.LabelKeyClaimName: "cool-claim",
})
xr.SetClaimReference(&claim.Reference{
xr.SetClaimReference(&reference.Claim{
Namespace: "default",
Name: "cool-claim",
})
Expand Down Expand Up @@ -271,7 +272,7 @@ func TestClientSideSync(t *testing.T) {
cm.SetCompositionReference(&corev1.ObjectReference{
Name: "some-composition",
})
cm.SetResourceReference(&corev1.ObjectReference{
cm.SetResourceReference(&reference.Composite{
Name: "cool-claim-random",
})
}),
Expand All @@ -282,7 +283,7 @@ func TestClientSideSync(t *testing.T) {
xcrd.LabelKeyClaimNamespace: "default",
xcrd.LabelKeyClaimName: "cool-claim",
})
xr.SetClaimReference(&claim.Reference{
xr.SetClaimReference(&reference.Claim{
Namespace: "default",
Name: "cool-claim",
})
Expand Down Expand Up @@ -358,7 +359,7 @@ func TestClientSideSync(t *testing.T) {
cm.SetCompositionReference(&corev1.ObjectReference{
Name: "some-composition",
})
cm.SetResourceReference(&corev1.ObjectReference{
cm.SetResourceReference(&reference.Composite{
Name: "cool-claim-random",
})

Expand All @@ -377,7 +378,7 @@ func TestClientSideSync(t *testing.T) {
"example.org/propagate-me": "true",
})

xr.SetClaimReference(&claim.Reference{
xr.SetClaimReference(&reference.Claim{
Namespace: "default",
Name: "cool-claim",
})
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/apiextensions/claim/syncer_ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (s *ServerSideCompositeSyncer) Sync(ctx context.Context, cm *claim.Unstruct
// apply the claim before we create it. This ensures we don't leak an XR. We
// could leak an XR if we created an XR then crashed before saving a
// reference to it. We'd create another XR on the next reconcile.
cm.SetResourceReference(meta.ReferenceTo(xrPatch, xrPatch.GroupVersionKind()))
cm.SetResourceReference(xrPatch.GetReference())

// Propagate the actual external name back from the composite to the
// claim if it's set. The name we're propagating here will may be a name
Expand Down
Loading

0 comments on commit e663a43

Please sign in to comment.