diff --git a/apis/contour/v1beta1/register.go b/apis/contour/v1beta1/register.go index dd46acc8bb5..84855044fc7 100644 --- a/apis/contour/v1beta1/register.go +++ b/apis/contour/v1beta1/register.go @@ -1,4 +1,4 @@ -// Copyright © 2019 VMware +// Copyright © 2020 // 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 @@ -24,22 +24,43 @@ const ( GroupName = "contour.heptio.com" ) -// SchemeGroupVersion is the GroupVersion for the Contour API -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} -var IngressRouteGVR = SchemeGroupVersion.WithResource("ingressroutes") -var TLSCertificateDelegationGVR = SchemeGroupVersion.WithResource("tlscertificatedelegations") +// SchemeGroupVersion is a compatibility name for the GroupVersion. +// New code should use GroupVersion. +var SchemeGroupVersion = GroupVersion + +var IngressRouteGVR = GroupVersion.WithResource("ingressroutes") +var TLSCertificateDelegationGVR = GroupVersion.WithResource("tlscertificatedelegations") // Resource gets an Contour GroupResource for a specified resource func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() + return GroupVersion.WithResource(resource).GroupResource() } -func AddKnownTypes(scheme *runtime.Scheme) { - scheme.AddKnownTypes(SchemeGroupVersion, +// AddKnownTypes is exported for backwards compatibility with third +// parties who depend on this symbol, but all new code should use +// AddToScheme. +func AddKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes( + GroupVersion, &IngressRoute{}, &IngressRouteList{}, &TLSCertificateDelegation{}, &TLSCertificateDelegationList{}, ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + metav1.AddToGroupVersion(scheme, GroupVersion) + return nil } + +// The following declarations are kubebuilder-compatible and will be expected +// by third parties who import the Contour API types. + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = runtime.NewSchemeBuilder(AddKnownTypes) + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/apis/projectcontour/v1/register.go b/apis/projectcontour/v1/register.go index 7f49df2270e..3b3dc1053d3 100644 --- a/apis/projectcontour/v1/register.go +++ b/apis/projectcontour/v1/register.go @@ -1,4 +1,4 @@ -// Copyright © 2019 VMware +// Copyright © 2020 VMware // 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 @@ -23,22 +23,43 @@ const ( GroupName = "projectcontour.io" ) -// SchemeGroupVersion is the GroupVersion for the Contour API -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} -var HTTPProxyGVR = SchemeGroupVersion.WithResource("httpproxies") -var TLSCertificateDelegationGVR = SchemeGroupVersion.WithResource("tlscertificatedelegations") +// SchemeGroupVersion is a compatibility name for the GroupVersion. +// New code should use GroupVersion. +var SchemeGroupVersion = GroupVersion + +var HTTPProxyGVR = GroupVersion.WithResource("httpproxies") +var TLSCertificateDelegationGVR = GroupVersion.WithResource("tlscertificatedelegations") // Resource gets an Contour GroupResource for a specified resource func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() + return GroupVersion.WithResource(resource).GroupResource() } -func AddKnownTypes(scheme *runtime.Scheme) { - scheme.AddKnownTypes(SchemeGroupVersion, +// AddKnownTypes is exported for backwards compatibility with third +// parties who depend on this symbol, but all new code should use +// AddToScheme. +func AddKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes( + GroupVersion, &HTTPProxy{}, &HTTPProxyList{}, &TLSCertificateDelegation{}, &TLSCertificateDelegationList{}, ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + metav1.AddToGroupVersion(scheme, GroupVersion) + return nil } + +// The following declarations are kubebuilder-compatible and will be expected +// by third parties who import the Contour API types. + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = runtime.NewSchemeBuilder(AddKnownTypes) + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/internal/k8s/converter.go b/internal/k8s/converter.go index ed4a13f44d0..742d2d783e0 100644 --- a/internal/k8s/converter.go +++ b/internal/k8s/converter.go @@ -93,8 +93,8 @@ func NewUnstructuredConverter() (*UnstructuredConverter, error) { } // Setup converter to understand custom CRD types - projectcontour.AddKnownTypes(uc.scheme) - ingressroutev1.AddKnownTypes(uc.scheme) + projectcontour.AddToScheme(uc.scheme) // nolint:errcheck + ingressroutev1.AddToScheme(uc.scheme) // nolint:errcheck // Add the core types we need if err := scheme.AddToScheme(uc.scheme); err != nil { diff --git a/internal/k8s/status_test.go b/internal/k8s/status_test.go index d869a0160f3..3d862edf699 100644 --- a/internal/k8s/status_test.go +++ b/internal/k8s/status_test.go @@ -47,7 +47,7 @@ func TestSetIngressRouteStatus(t *testing.T) { t.Helper() var gotPatchBytes []byte s := runtime.NewScheme() - ingressroutev1.AddKnownTypes(s) + ingressroutev1.AddToScheme(s) // nolint:errcheck client := fake.NewSimpleDynamicClient(s, tc.existing) client.PrependReactor("patch", "ingressroutes", func(action k8stesting.Action) (bool, runtime.Object, error) { @@ -144,7 +144,7 @@ func TestSetHTTPProxyStatus(t *testing.T) { t.Helper() var gotObj runtime.Object s := runtime.NewScheme() - projcontour.AddKnownTypes(s) + projcontour.AddToScheme(s) // nolint:errcheck usc, err := NewUnstructuredConverter() if err != nil { t.Fatal(err)