From 0209686ed7edcd3f2dfb3dcbd729ce0d263f623b Mon Sep 17 00:00:00 2001 From: James Munnelly Date: Thu, 22 Aug 2019 16:50:27 +0100 Subject: [PATCH] Add v2 version to testgroup API Signed-off-by: James Munnelly --- hack/update-codegen.sh | 3 + .../testdata/apis/testgroup/BUILD.bazel | 1 + .../apis/testgroup/install/BUILD.bazel | 1 + .../apis/testgroup/install/install.go | 2 + .../testdata/apis/testgroup/v1/types.go | 2 +- .../testdata/apis/testgroup/v2/BUILD.bazel | 39 ++++++++++ .../testdata/apis/testgroup/v2/convert.go | 41 +++++++++++ .../testdata/apis/testgroup/v2/defaults.go | 32 ++++++++ .../testdata/apis/testgroup/v2/doc.go | 22 ++++++ .../testdata/apis/testgroup/v2/register.go | 55 ++++++++++++++ .../testdata/apis/testgroup/v2/types.go | 38 ++++++++++ .../testgroup/v2/zz_generated.conversion.go | 73 +++++++++++++++++++ .../testgroup/v2/zz_generated.deepcopy.go | 56 ++++++++++++++ .../testgroup/v2/zz_generated.defaults.go | 37 ++++++++++ 14 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/BUILD.bazel create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/convert.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/defaults.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/doc.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/register.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/types.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.conversion.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.deepcopy.go create mode 100644 pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.defaults.go diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index e5e6464fc..e971c866c 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -41,6 +41,7 @@ deepcopy_inputs=( pkg/internal/apis/acme \ pkg/apis/meta/v1 \ pkg/internal/apis/meta \ + pkg/webhook/handlers/testdata/apis/testgroup/v2 \ pkg/webhook/handlers/testdata/apis/testgroup/v1 \ pkg/webhook/handlers/testdata/apis/testgroup \ pkg/acme/webhook/apis/acme/v1alpha1 \ @@ -59,6 +60,7 @@ defaulter_inputs=( pkg/internal/apis/certmanager/v1alpha2 \ pkg/internal/apis/acme/v1alpha2 \ pkg/internal/apis/meta/v1 \ + pkg/webhook/handlers/testdata/apis/testgroup/v2 \ pkg/webhook/handlers/testdata/apis/testgroup/v1 \ ) @@ -67,6 +69,7 @@ conversion_inputs=( pkg/internal/apis/certmanager/v1alpha2 \ pkg/internal/apis/acme/v1alpha2 \ pkg/internal/apis/meta/v1 \ + pkg/webhook/handlers/testdata/apis/testgroup/v2 \ pkg/webhook/handlers/testdata/apis/testgroup/v1 \ ) diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/BUILD.bazel b/pkg/webhook/handlers/testdata/apis/testgroup/BUILD.bazel index 30aef1a0a..134d7f9a4 100644 --- a/pkg/webhook/handlers/testdata/apis/testgroup/BUILD.bazel +++ b/pkg/webhook/handlers/testdata/apis/testgroup/BUILD.bazel @@ -31,6 +31,7 @@ filegroup( "//pkg/webhook/handlers/testdata/apis/testgroup/fuzzer:all-srcs", "//pkg/webhook/handlers/testdata/apis/testgroup/install:all-srcs", "//pkg/webhook/handlers/testdata/apis/testgroup/v1:all-srcs", + "//pkg/webhook/handlers/testdata/apis/testgroup/v2:all-srcs", "//pkg/webhook/handlers/testdata/apis/testgroup/validation:all-srcs", ], tags = ["automanaged"], diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/install/BUILD.bazel b/pkg/webhook/handlers/testdata/apis/testgroup/install/BUILD.bazel index 0051816cf..ddf471a60 100644 --- a/pkg/webhook/handlers/testdata/apis/testgroup/install/BUILD.bazel +++ b/pkg/webhook/handlers/testdata/apis/testgroup/install/BUILD.bazel @@ -8,6 +8,7 @@ go_library( deps = [ "//pkg/webhook/handlers/testdata/apis/testgroup:go_default_library", "//pkg/webhook/handlers/testdata/apis/testgroup/v1:go_default_library", + "//pkg/webhook/handlers/testdata/apis/testgroup/v2:go_default_library", "@io_k8s_apimachinery//pkg/runtime:go_default_library", "@io_k8s_apimachinery//pkg/util/runtime:go_default_library", ], diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/install/install.go b/pkg/webhook/handlers/testdata/apis/testgroup/install/install.go index edf816606..27bf86185 100644 --- a/pkg/webhook/handlers/testdata/apis/testgroup/install/install.go +++ b/pkg/webhook/handlers/testdata/apis/testgroup/install/install.go @@ -24,10 +24,12 @@ import ( "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup" "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup/v1" + "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup/v2" ) // Install registers the API group and adds types to a scheme func Install(scheme *runtime.Scheme) { utilruntime.Must(testgroup.AddToScheme(scheme)) utilruntime.Must(v1.AddToScheme(scheme)) + utilruntime.Must(v2.AddToScheme(scheme)) } diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v1/types.go b/pkg/webhook/handlers/testdata/apis/testgroup/v1/types.go index 9d2c908b7..b7ae90a70 100644 --- a/pkg/webhook/handlers/testdata/apis/testgroup/v1/types.go +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v1/types.go @@ -29,7 +29,7 @@ type TestType struct { // TestField is used in tests. // Validation doesn't allow this to be set to the value of TestFieldValueNotAllowed. TestField string `json:"testField"` - TestFieldPtr *string `json:"testFieldPtr"` + TestFieldPtr *string `json:"testFieldPtr,omitempty"` // TestFieldImmutable cannot be changed after being set to a non-zero value TestFieldImmutable string `json:"testFieldImmutable"` diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/BUILD.bazel b/pkg/webhook/handlers/testdata/apis/testgroup/v2/BUILD.bazel new file mode 100644 index 000000000..a70c461d4 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/BUILD.bazel @@ -0,0 +1,39 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "convert.go", + "defaults.go", + "doc.go", + "register.go", + "types.go", + "zz_generated.conversion.go", + "zz_generated.deepcopy.go", + "zz_generated.defaults.go", + ], + importpath = "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup/v2", + visibility = ["//visibility:public"], + deps = [ + "//pkg/webhook/handlers/testdata/apis/testgroup:go_default_library", + "@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library", + "@io_k8s_apimachinery//pkg/conversion:go_default_library", + "@io_k8s_apimachinery//pkg/runtime:go_default_library", + "@io_k8s_apimachinery//pkg/runtime/schema:go_default_library", + "@io_k8s_utils//pointer:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/convert.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/convert.go new file mode 100644 index 000000000..4d659a91d --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/convert.go @@ -0,0 +1,41 @@ +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +package v2 + +import ( + "unsafe" + + "k8s.io/apimachinery/pkg/conversion" + + "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup" +) + +func Convert_v2_TestType_To_testgroup_TestType(in *TestType, out *testgroup.TestType, s conversion.Scope) error { + if err := autoConvert_v2_TestType_To_testgroup_TestType(in, out, s); err != nil { + return err + } + out.TestFieldPtr = (*string)(unsafe.Pointer(in.TestFieldPtrAlt)) + return nil +} + +func Convert_testgroup_TestType_To_v2_TestType(in *testgroup.TestType, out *TestType, s conversion.Scope) error { + if err := autoConvert_testgroup_TestType_To_v2_TestType(in, out, s); err != nil { + return err + } + out.TestFieldPtrAlt = (*string)(unsafe.Pointer(in.TestFieldPtr)) + return nil +} diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/defaults.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/defaults.go new file mode 100644 index 000000000..97013c065 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/defaults.go @@ -0,0 +1,32 @@ +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +package v2 + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" +) + +func addDefaultingFuncs(scheme *runtime.Scheme) error { + return RegisterDefaults(scheme) +} + +func SetDefaults_TestType(obj *TestType) { + if obj.TestFieldPtrAlt == nil { + obj.TestFieldPtrAlt = pointer.StringPtr("teststr") + } +} diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/doc.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/doc.go new file mode 100644 index 000000000..cac5c4a70 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +// +k8s:conversion-gen=github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup +// +k8s:deepcopy-gen=package,register +// +k8s:defaulter-gen=TypeMeta + +// +groupName=testgroup.testing.cert-manager.io +package v2 diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/register.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/register.go new file mode 100644 index 000000000..5ebbf2498 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/register.go @@ -0,0 +1,55 @@ +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +package v2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: testgroup.GroupName, Version: "v2"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes, addDefaultingFuncs) +} + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/types.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/types.go new file mode 100644 index 000000000..acb5dd4a1 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/types.go @@ -0,0 +1,38 @@ +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +package v2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestType in v2 is identical to v1, except TestFieldPtr has been renamed to TestFieldPtrAlt +type TestType struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + + // TestField is used in tests. + // Validation doesn't allow this to be set to the value of TestFieldValueNotAllowed. + TestField string `json:"testField"` + // +optional + TestFieldPtrAlt *string `json:"testFieldPtrAlt,omitempty"` + + // TestFieldImmutable cannot be changed after being set to a non-zero value + TestFieldImmutable string `json:"testFieldImmutable"` +} diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.conversion.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.conversion.go new file mode 100644 index 000000000..42d237660 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.conversion.go @@ -0,0 +1,73 @@ +// +build !ignore_autogenerated + +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +// Code generated by conversion-gen. DO NOT EDIT. + +package v2 + +import ( + testgroup "github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*TestType)(nil), (*testgroup.TestType)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v2_TestType_To_testgroup_TestType(a.(*TestType), b.(*testgroup.TestType), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*testgroup.TestType)(nil), (*TestType)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_testgroup_TestType_To_v2_TestType(a.(*testgroup.TestType), b.(*TestType), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*testgroup.TestType)(nil), (*TestType)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_testgroup_TestType_To_v2_TestType(a.(*testgroup.TestType), b.(*TestType), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*TestType)(nil), (*testgroup.TestType)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v2_TestType_To_testgroup_TestType(a.(*TestType), b.(*testgroup.TestType), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v2_TestType_To_testgroup_TestType(in *TestType, out *testgroup.TestType, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.TestField = in.TestField + // WARNING: in.TestFieldPtrAlt requires manual conversion: does not exist in peer-type + out.TestFieldImmutable = in.TestFieldImmutable + return nil +} + +func autoConvert_testgroup_TestType_To_v2_TestType(in *testgroup.TestType, out *TestType, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.TestField = in.TestField + // WARNING: in.TestFieldPtr requires manual conversion: does not exist in peer-type + out.TestFieldImmutable = in.TestFieldImmutable + return nil +} diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.deepcopy.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.deepcopy.go new file mode 100644 index 000000000..2340eab7c --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.deepcopy.go @@ -0,0 +1,56 @@ +// +build !ignore_autogenerated + +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v2 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestType) DeepCopyInto(out *TestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.TestFieldPtrAlt != nil { + in, out := &in.TestFieldPtrAlt, &out.TestFieldPtrAlt + *out = new(string) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. +func (in *TestType) DeepCopy() *TestType { + if in == nil { + return nil + } + out := new(TestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.defaults.go b/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.defaults.go new file mode 100644 index 000000000..52fc28635 --- /dev/null +++ b/pkg/webhook/handlers/testdata/apis/testgroup/v2/zz_generated.defaults.go @@ -0,0 +1,37 @@ +// +build !ignore_autogenerated + +/* +Copyright 2019 The Jetstack cert-manager contributors. + +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. +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v2 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&TestType{}, func(obj interface{}) { SetObjectDefaults_TestType(obj.(*TestType)) }) + return nil +} + +func SetObjectDefaults_TestType(in *TestType) { + SetDefaults_TestType(in) +}