Skip to content

Commit 19d95a6

Browse files
authored
Merge pull request #786 from turkenh/fix-unknown-fields
Fix unknown fields warnings and possibility to suppress finalizer ones
2 parents e66c7ab + 70499a4 commit 19d95a6

File tree

7 files changed

+116
-61
lines changed

7 files changed

+116
-61
lines changed

pkg/resource/fake/mocks.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/manager"
3636

3737
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
38-
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
38+
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
3939
)
4040

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

5252
// ClaimReferencer is a mock that implements ClaimReferencer interface.
53-
type ClaimReferencer struct{ Ref *claim.Reference }
53+
type ClaimReferencer struct{ Ref *reference.Claim }
5454

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

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

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

186186
// CompositionRevisionReferencer is a mock that implements CompositionRevisionReferencer interface.
187-
type CompositionRevisionReferencer struct{ Ref *corev1.ObjectReference }
187+
type CompositionRevisionReferencer struct{ Ref *corev1.LocalObjectReference }
188188

189189
// SetCompositionRevisionReference sets the CompositionRevisionReference.
190-
func (m *CompositionRevisionReferencer) SetCompositionRevisionReference(r *corev1.ObjectReference) {
190+
func (m *CompositionRevisionReferencer) SetCompositionRevisionReference(r *corev1.LocalObjectReference) {
191191
m.Ref = r
192192
}
193193

194194
// GetCompositionRevisionReference gets the CompositionRevisionReference.
195-
func (m *CompositionRevisionReferencer) GetCompositionRevisionReference() *corev1.ObjectReference {
195+
func (m *CompositionRevisionReferencer) GetCompositionRevisionReference() *corev1.LocalObjectReference {
196196
return m.Ref
197197
}
198198

@@ -236,13 +236,13 @@ func (m *CompositeResourceDeleter) GetCompositeDeletePolicy() *xpv1.CompositeDel
236236
}
237237

238238
// CompositeResourceReferencer is a mock that implements CompositeResourceReferencer interface.
239-
type CompositeResourceReferencer struct{ Ref *corev1.ObjectReference }
239+
type CompositeResourceReferencer struct{ Ref *reference.Composite }
240240

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

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

247247
// ComposedResourcesReferencer is a mock that implements ComposedResourcesReferencer interface.
248248
type ComposedResourcesReferencer struct{ Refs []corev1.ObjectReference }

pkg/resource/interfaces.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626

2727
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
28-
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
28+
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
2929
)
3030

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

3838
// A ClaimReferencer may reference a resource claim.
3939
type ClaimReferencer interface {
40-
SetClaimReference(r *claim.Reference)
41-
GetClaimReference() *claim.Reference
40+
SetClaimReference(r *reference.Claim)
41+
GetClaimReference() *reference.Claim
4242
}
4343

4444
// A ManagedResourceReferencer may reference a concrete managed resource.
@@ -120,8 +120,8 @@ type CompositionReferencer interface {
120120
// A CompositionRevisionReferencer may reference a specific revision of a
121121
// composition of resources.
122122
type CompositionRevisionReferencer interface {
123-
SetCompositionRevisionReference(ref *corev1.ObjectReference)
124-
GetCompositionRevisionReference() *corev1.ObjectReference
123+
SetCompositionRevisionReference(ref *corev1.LocalObjectReference)
124+
GetCompositionRevisionReference() *corev1.LocalObjectReference
125125
}
126126

127127
// A CompositionRevisionSelector may reference a set of
@@ -153,8 +153,8 @@ type ComposedResourcesReferencer interface {
153153

154154
// A CompositeResourceReferencer can reference a composite resource.
155155
type CompositeResourceReferencer interface {
156-
SetResourceReference(r *corev1.ObjectReference)
157-
GetResourceReference() *corev1.ObjectReference
156+
SetResourceReference(r *reference.Composite)
157+
GetResourceReference() *reference.Composite
158158
}
159159

160160
// An EnvironmentConfigReferencer references a list of EnvironmentConfigs.

pkg/resource/unstructured/claim/claim.go

+9-23
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
2727
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
28+
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
2829
)
2930

3031
// An Option modifies an unstructured composite resource claim.
@@ -63,21 +64,6 @@ type Unstructured struct {
6364
unstructured.Unstructured
6465
}
6566

66-
// Reference to a claim.
67-
type Reference struct {
68-
// APIVersion of the referenced claim.
69-
APIVersion string `json:"apiVersion"`
70-
71-
// Kind of the referenced claim.
72-
Kind string `json:"kind"`
73-
74-
// Name of the referenced claim.
75-
Name string `json:"name"`
76-
77-
// Namespace of the referenced claim.
78-
Namespace string `json:"namespace"`
79-
}
80-
8167
// GetUnstructured returns the underlying *unstructured.Unstructured.
8268
func (c *Unstructured) GetUnstructured() *unstructured.Unstructured {
8369
return &c.Unstructured
@@ -112,16 +98,16 @@ func (c *Unstructured) SetCompositionReference(ref *corev1.ObjectReference) {
11298
}
11399

114100
// GetCompositionRevisionReference of this resource claim.
115-
func (c *Unstructured) GetCompositionRevisionReference() *corev1.ObjectReference {
116-
out := &corev1.ObjectReference{}
101+
func (c *Unstructured) GetCompositionRevisionReference() *corev1.LocalObjectReference {
102+
out := &corev1.LocalObjectReference{}
117103
if err := fieldpath.Pave(c.Object).GetValueInto("spec.compositionRevisionRef", out); err != nil {
118104
return nil
119105
}
120106
return out
121107
}
122108

123109
// SetCompositionRevisionReference of this resource claim.
124-
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.ObjectReference) {
110+
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.LocalObjectReference) {
125111
_ = fieldpath.Pave(c.Object).SetValue("spec.compositionRevisionRef", ref)
126112
}
127113

@@ -170,22 +156,22 @@ func (c *Unstructured) GetCompositeDeletePolicy() *xpv1.CompositeDeletePolicy {
170156
}
171157

172158
// GetResourceReference of this composite resource claim.
173-
func (c *Unstructured) GetResourceReference() *corev1.ObjectReference {
174-
out := &corev1.ObjectReference{}
159+
func (c *Unstructured) GetResourceReference() *reference.Composite {
160+
out := &reference.Composite{}
175161
if err := fieldpath.Pave(c.Object).GetValueInto("spec.resourceRef", out); err != nil {
176162
return nil
177163
}
178164
return out
179165
}
180166

181167
// SetResourceReference of this composite resource claim.
182-
func (c *Unstructured) SetResourceReference(ref *corev1.ObjectReference) {
168+
func (c *Unstructured) SetResourceReference(ref *reference.Composite) {
183169
_ = fieldpath.Pave(c.Object).SetValue("spec.resourceRef", ref)
184170
}
185171

186172
// GetReference returns reference to this claim.
187-
func (c *Unstructured) GetReference() *Reference {
188-
return &Reference{
173+
func (c *Unstructured) GetReference() *reference.Claim {
174+
return &reference.Claim{
189175
APIVersion: c.GetAPIVersion(),
190176
Kind: c.GetKind(),
191177
Name: c.GetName(),

pkg/resource/unstructured/claim/claim_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030

3131
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
32+
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
3233
)
3334

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

174175
func TestCompositionRevisionReference(t *testing.T) {
175-
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
176+
ref := &corev1.LocalObjectReference{Name: "cool"}
176177
cases := map[string]struct {
177178
u *Unstructured
178-
set *corev1.ObjectReference
179-
want *corev1.ObjectReference
179+
set *corev1.LocalObjectReference
180+
want *corev1.LocalObjectReference
180181
}{
181182
"NewRef": {
182183
u: New(),
@@ -272,11 +273,11 @@ func TestCompositeDeletePolicy(t *testing.T) {
272273
}
273274

274275
func TestResourceReference(t *testing.T) {
275-
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
276+
ref := &reference.Composite{Name: "cool"}
276277
cases := map[string]struct {
277278
u *Unstructured
278-
set *corev1.ObjectReference
279-
want *corev1.ObjectReference
279+
set *reference.Composite
280+
want *reference.Composite
280281
}{
281282
"NewRef": {
282283
u: New(),
@@ -297,7 +298,7 @@ func TestResourceReference(t *testing.T) {
297298
}
298299

299300
func TestClaimReference(t *testing.T) {
300-
ref := &Reference{Namespace: "ns", Name: "cool", APIVersion: "foo.com/v1", Kind: "Foo"}
301+
ref := &reference.Claim{Namespace: "ns", Name: "cool", APIVersion: "foo.com/v1", Kind: "Foo"}
301302
u := &Unstructured{}
302303
u.SetName(ref.Name)
303304
u.SetNamespace(ref.Namespace)

pkg/resource/unstructured/composite/composite.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
2727
"github.com/crossplane/crossplane-runtime/pkg/errors"
2828
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
29-
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
29+
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
3030
)
3131

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

101101
// GetCompositionRevisionReference of this Composite resource.
102-
func (c *Unstructured) GetCompositionRevisionReference() *corev1.ObjectReference {
103-
out := &corev1.ObjectReference{}
102+
func (c *Unstructured) GetCompositionRevisionReference() *corev1.LocalObjectReference {
103+
out := &corev1.LocalObjectReference{}
104104
if err := fieldpath.Pave(c.Object).GetValueInto("spec.compositionRevisionRef", out); err != nil {
105105
return nil
106106
}
107107
return out
108108
}
109109

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

@@ -142,16 +142,16 @@ func (c *Unstructured) GetCompositionUpdatePolicy() *xpv1.UpdatePolicy {
142142
}
143143

144144
// GetClaimReference of this Composite resource.
145-
func (c *Unstructured) GetClaimReference() *claim.Reference {
146-
out := &claim.Reference{}
145+
func (c *Unstructured) GetClaimReference() *reference.Claim {
146+
out := &reference.Claim{}
147147
if err := fieldpath.Pave(c.Object).GetValueInto("spec.claimRef", out); err != nil {
148148
return nil
149149
}
150150
return out
151151
}
152152

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

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

180+
// GetReference returns reference to this composite.
181+
func (c *Unstructured) GetReference() *reference.Composite {
182+
return &reference.Composite{
183+
APIVersion: c.GetAPIVersion(),
184+
Kind: c.GetKind(),
185+
Name: c.GetName(),
186+
}
187+
}
188+
180189
// GetWriteConnectionSecretToReference of this Composite resource.
181190
func (c *Unstructured) GetWriteConnectionSecretToReference() *xpv1.SecretReference {
182191
out := &xpv1.SecretReference{}

pkg/resource/unstructured/composite/composite_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131

3232
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
33-
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/claim"
33+
"github.com/crossplane/crossplane-runtime/pkg/resource/unstructured/reference"
3434
"github.com/crossplane/crossplane-runtime/pkg/test"
3535
)
3636

@@ -259,11 +259,11 @@ func TestCompositionReference(t *testing.T) {
259259
}
260260

261261
func TestCompositionRevisionReference(t *testing.T) {
262-
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
262+
ref := &corev1.LocalObjectReference{Name: "cool"}
263263
cases := map[string]struct {
264264
u *Unstructured
265-
set *corev1.ObjectReference
266-
want *corev1.ObjectReference
265+
set *corev1.LocalObjectReference
266+
want *corev1.LocalObjectReference
267267
}{
268268
"NewRef": {
269269
u: New(),
@@ -334,11 +334,11 @@ func TestCompositionUpdatePolicy(t *testing.T) {
334334
}
335335

336336
func TestClaimReference(t *testing.T) {
337-
ref := &claim.Reference{Namespace: "ns", Name: "cool", APIVersion: "acme.com/v1", Kind: "Foo"}
337+
ref := &reference.Claim{Namespace: "ns", Name: "cool", APIVersion: "acme.com/v1", Kind: "Foo"}
338338
cases := map[string]struct {
339339
u *Unstructured
340-
set *claim.Reference
341-
want *claim.Reference
340+
set *reference.Claim
341+
want *reference.Claim
342342
}{
343343
"NewRef": {
344344
u: New(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2024 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package reference contains references to resources.
18+
package reference
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
)
23+
24+
// A Claim is a reference to a claim.
25+
type Claim struct {
26+
// APIVersion of the referenced claim.
27+
APIVersion string `json:"apiVersion"`
28+
29+
// Kind of the referenced claim.
30+
Kind string `json:"kind"`
31+
32+
// Name of the referenced claim.
33+
Name string `json:"name"`
34+
35+
// Namespace of the referenced claim.
36+
Namespace string `json:"namespace"`
37+
}
38+
39+
// A Composite is a reference to a composite.
40+
type Composite struct {
41+
// APIVersion of the referenced composite.
42+
APIVersion string `json:"apiVersion"`
43+
44+
// Kind of the referenced composite.
45+
Kind string `json:"kind"`
46+
47+
// Name of the referenced composite.
48+
Name string `json:"name"`
49+
}
50+
51+
// GroupVersionKind returns the GroupVersionKind of the claim reference.
52+
func (c *Claim) GroupVersionKind() schema.GroupVersionKind {
53+
return schema.FromAPIVersionAndKind(c.APIVersion, c.Kind)
54+
}
55+
56+
// GroupVersionKind returns the GroupVersionKind of the composite reference.
57+
func (c *Composite) GroupVersionKind() schema.GroupVersionKind {
58+
return schema.FromAPIVersionAndKind(c.APIVersion, c.Kind)
59+
}

0 commit comments

Comments
 (0)