Skip to content

Commit

Permalink
Merge pull request #603 from crossplane/backport-599-to-release-1.14
Browse files Browse the repository at this point in the history
[Backport release-1.14] Give unstructured types their own DeepCopy methods
  • Loading branch information
negz authored Nov 13, 2023
2 parents aaa202d + 94a1bbf commit 0310786
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/resource/unstructured/claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func New(opts ...Option) *Unstructured {
return c
}

// +k8s:deepcopy-gen=true
// +kubebuilder:object:root=true

// An Unstructured composite resource claim.
type Unstructured struct {
unstructured.Unstructured
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/unstructured/claim/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

var (
_ client.Object = &Unstructured{}
)

func TestWithGroupVersionKind(t *testing.T) {
gvk := schema.GroupVersionKind{
Group: "g",
Expand Down
49 changes: 49 additions & 0 deletions pkg/resource/unstructured/claim/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions pkg/resource/unstructured/composed/composed.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func New(opts ...Option) *Unstructured {
return cr
}

// +k8s:deepcopy-gen=true
// +kubebuilder:object:root=true

// An Unstructured composed resource.
type Unstructured struct {
unstructured.Unstructured
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/unstructured/composed/composed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ import (
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

var (
_ client.Object = &Unstructured{}
)

func TestFromReference(t *testing.T) {
ref := corev1.ObjectReference{
APIVersion: "a/v1",
Expand Down
49 changes: 49 additions & 0 deletions pkg/resource/unstructured/composed/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions pkg/resource/unstructured/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func New(opts ...Option) *Unstructured {
return c
}

// +k8s:deepcopy-gen=true
// +kubebuilder:object:root=true

// An Unstructured composed resource.
type Unstructured struct {
unstructured.Unstructured
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/unstructured/composite/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"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"
)

var (
_ client.Object = &Unstructured{}
)

func TestWithGroupVersionKind(t *testing.T) {
gvk := schema.GroupVersionKind{
Group: "g",
Expand Down
49 changes: 49 additions & 0 deletions pkg/resource/unstructured/composite/zz_generated.deepcopy.go

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

30 changes: 30 additions & 0 deletions pkg/resource/unstructured/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build generate
// +build generate

/*
Copyright 2019 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE(negz): See the below link for details on what is happening here.
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module

// Generate deepcopy methodsets
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=../../../hack/boilerplate.go.txt paths=./...

package unstructured

import (
_ "sigs.k8s.io/controller-tools/cmd/controller-gen" //nolint:typecheck
)

0 comments on commit 0310786

Please sign in to comment.