Skip to content

Commit 2071f44

Browse files
authored
Merge pull request #858 from jbw976/conform
api: modern XRs do not have connection details
2 parents 1e3dba9 + 54d45e8 commit 2071f44

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

pkg/event/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (r *APIRecorder) Event(obj runtime.Object, e Event) {
9999
return
100100
}
101101
}
102+
102103
r.kube.AnnotatedEventf(obj, r.annotations, string(e.Type), string(e.Reason), "%s", e.Message)
103104
}
104105

pkg/reconciler/customresourcesgate/reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package customresourcesgate
2020

2121
import (
2222
"context"
23+
2324
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2425
"k8s.io/apimachinery/pkg/runtime/schema"
2526
ctrl "sigs.k8s.io/controller-runtime"

pkg/reconciler/customresourcesgate/reconciler_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ func (m *MockGate) Set(gvk schema.GroupVersionKind, value bool) bool {
287287

288288
m.FalseCalls = append(m.FalseCalls, gvk)
289289
}
290+
290291
return true
291292
}
292293

@@ -538,6 +539,7 @@ func TestReconcile(t *testing.T) {
538539
slices.SortFunc(tc.fields.gate.TrueCalls, func(a, b schema.GroupVersionKind) int {
539540
return strings.Compare(a.Kind, b.Kind)
540541
})
542+
541543
if diff := cmp.Diff(tc.want.trueCalls, tc.fields.gate.TrueCalls); diff != "" {
542544
t.Errorf("\n%s\ngate.True calls: -want, +got:\n%s", tc.reason, diff)
543545
}
@@ -548,6 +550,7 @@ func TestReconcile(t *testing.T) {
548550
slices.SortFunc(tc.fields.gate.FalseCalls, func(a, b schema.GroupVersionKind) int {
549551
return strings.Compare(a.Kind, b.Kind)
550552
})
553+
551554
if diff := cmp.Diff(tc.want.falseCalls, tc.fields.gate.FalseCalls); diff != "" {
552555
t.Errorf("\n%s\ngate.False calls: -want, +got:\n%s", tc.reason, diff)
553556
}

pkg/reconciler/managed/reconciler_modern_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ func TestModernReconciler(t *testing.T) {
888888
want.SetConditions(xpv1.ReconcileSuccess().WithObservedGeneration(42))
889889
want.SetConditions(xpv1.Creating().WithObservedGeneration(42))
890890
if diff := cmp.Diff(want, obj, test.EquateConditions(), cmpopts.EquateApproxTime(1*time.Second)); diff != "" {
891-
reason := "Successful managed resource creation should be reported as a conditioned status." //nolint:goconst // used only in tests
891+
reason := "Successful managed resource creation should be reported as a conditioned status."
892892
t.Errorf("\nReason: %s\n-want, +got:\n%s", reason, diff)
893893
}
894894
return nil
@@ -1246,7 +1246,7 @@ func TestModernReconciler(t *testing.T) {
12461246
want := newModernManaged(42)
12471247
want.SetConditions(xpv1.ReconcileSuccess().WithObservedGeneration(42))
12481248
if diff := cmp.Diff(want, obj, test.EquateConditions()); diff != "" {
1249-
reason := "A successful managed resource update should be reported as a conditioned status." //nolint:goconst // used only in tests
1249+
reason := "A successful managed resource update should be reported as a conditioned status."
12501250
t.Errorf("\nReason: %s\n-want, +got:\n%s", reason, diff)
12511251
}
12521252
return nil

pkg/resource/unstructured/composite/composite.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ func (c *Unstructured) GetConditions() []xpv1.Condition {
358358

359359
// GetConnectionDetailsLastPublishedTime of this composite resource.
360360
func (c *Unstructured) GetConnectionDetailsLastPublishedTime() *metav1.Time {
361-
path := "status.crossplane.connectionDetails.lastPublishedTime"
362-
if c.Schema == SchemaLegacy {
363-
path = "status.connectionDetails.lastPublishedTime"
361+
// Only legacy XRs support connection details.
362+
if c.Schema != SchemaLegacy {
363+
return nil
364364
}
365365

366366
out := &metav1.Time{}
367-
if err := fieldpath.Pave(c.Object).GetValueInto(path, out); err != nil {
367+
if err := fieldpath.Pave(c.Object).GetValueInto("status.connectionDetails.lastPublishedTime", out); err != nil {
368368
return nil
369369
}
370370

@@ -373,12 +373,12 @@ func (c *Unstructured) GetConnectionDetailsLastPublishedTime() *metav1.Time {
373373

374374
// SetConnectionDetailsLastPublishedTime of this composite resource.
375375
func (c *Unstructured) SetConnectionDetailsLastPublishedTime(t *metav1.Time) {
376-
path := "status.crossplane.connectionDetails.lastPublishedTime"
377-
if c.Schema == SchemaLegacy {
378-
path = "status.connectionDetails.lastPublishedTime"
376+
// Only legacy XRs support connection details.
377+
if c.Schema != SchemaLegacy {
378+
return
379379
}
380380

381-
_ = fieldpath.Pave(c.Object).SetValue(path, t)
381+
_ = fieldpath.Pave(c.Object).SetValue("status.connectionDetails.lastPublishedTime", t)
382382
}
383383

384384
// SetObservedGeneration of this composite resource claim.

pkg/resource/unstructured/composite/composite_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,16 @@ func TestConnectionDetailsLastPublishedTime(t *testing.T) {
440440
set *metav1.Time
441441
want *metav1.Time
442442
}{
443-
"NewTime": {
444-
u: New(),
443+
"NewTimeLegacy": {
444+
u: New(WithSchema(SchemaLegacy)),
445445
set: now,
446446
want: lores(now),
447447
},
448+
"NewTimeModern": {
449+
u: New(WithSchema(SchemaModern)),
450+
set: now,
451+
want: nil, // modern schema doesn't support connection details
452+
},
448453
}
449454

450455
for name, tc := range cases {

0 commit comments

Comments
 (0)