Skip to content

Commit 20997b1

Browse files
committed
deepcopy/testdata: Add an UntypedBlob type
1 parent 1ea0e62 commit 20997b1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pkg/deepcopy/testdata/cronjob_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ limitations under the License.
2121
package cronjob
2222

2323
import (
24+
"encoding/json"
25+
2426
batchv1beta1 "k8s.io/api/batch/v1beta1"
2527
corev1 "k8s.io/api/core/v1"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -301,3 +303,21 @@ type CronJobList struct {
301303
metav1.ListMeta `json:"metadata,omitempty"`
302304
Items []CronJob `json:"items"`
303305
}
306+
307+
// UntypedBlob tests that the "crd" typechecking cache doesn't prevent
308+
// the "deepcopy" generator from properly handling types that the
309+
// "crd" generator doesn't check. Nothing the "crd" generator checks
310+
// makes uses of anything from "encoding/json", so let's define some
311+
// silly type that makes use of a type from "encoding/json".
312+
type UntypedBlob struct {
313+
raw json.RawMessage
314+
}
315+
316+
func (u UntypedBlob) MarshalJSON() ([]byte, error) {
317+
return u.raw.MarshalJSON()
318+
}
319+
320+
func (u *UntypedBlob) UnmarshalJSON(data []byte) error {
321+
*u = UntypedBlob{raw: json.RawMessage(data)}
322+
return nil
323+
}

pkg/deepcopy/testdata/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)