diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 16aae26af930c..cb15aaa57faa9 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -84007,7 +84007,6 @@ "description": "CustomResourceDefinitionSpec describes how a user wants their resource to appear", "required": [ "group", - "version", "names", "scope" ], @@ -84033,8 +84032,15 @@ "$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceValidation" }, "version": { - "description": "Version is the version this resource belongs in", + "description": "Version is the version this resource belongs in Should be always first item in Versions field if provided. If Versions field is provided, this field is optional.", "type": "string" + }, + "versions": { + "description": "Versions is the list of all supported versions for this resource. If Version field is provided, this field is optional. Validation: All versions must use the same validation schema for now. i.e., top level Validation field is applied to all of these versions. Order: The order of these versions is used to determine the order in discovery API (preferred version first).", + "type": "array", + "items": { + "$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionVersion" + } } } }, @@ -84042,9 +84048,17 @@ "description": "CustomResourceDefinitionStatus indicates the state of the CustomResourceDefinition", "required": [ "conditions", - "acceptedNames" + "acceptedNames", + "StoredVersions" ], "properties": { + "StoredVersions": { + "description": "StoredVersions are all versions ever marked as storage in spec. Tracking these versions allow a migration path for stored version in etcd. The field is mutable so the migration controller can first make sure a version is certified (i.e. all stored objects is that version) then remove the rest of the versions from this list. None of the versions in this list can be removed from the spec.Versions field.", + "type": "array", + "items": { + "type": "string" + } + }, "acceptedNames": { "description": "AcceptedNames are the names that are actually being used to serve discovery They may be different than the names in spec.", "$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionNames" @@ -84058,6 +84072,25 @@ } } }, + "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionVersion": { + "required": [ + "name" + ], + "properties": { + "name": { + "description": "Name is the version name, e.g. “v1”, “v2beta1”, etc.", + "type": "string" + }, + "served": { + "description": "Served is a flag enabling/disabling this version from being served via REST APIs Default is True.", + "type": "boolean" + }, + "storage": { + "description": "Storage flags the version as a storage version. There must be exactly one flagged as storage version. Default is False.", + "type": "boolean" + } + } + }, "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceSubresourceScale": { "description": "CustomResourceSubresourceScale defines how to serve the scale subresource for CustomResources.", "required": [ diff --git a/pkg/master/controller/crdregistration/crdregistration_controller.go b/pkg/master/controller/crdregistration/crdregistration_controller.go index c3a87b418a408..9104a8bc9f501 100644 --- a/pkg/master/controller/crdregistration/crdregistration_controller.go +++ b/pkg/master/controller/crdregistration/crdregistration_controller.go @@ -120,8 +120,10 @@ func (c *crdRegistrationController) Run(threadiness int, stopCh <-chan struct{}) utilruntime.HandleError(err) } else { for _, crd := range crds { - if err := c.syncHandler(schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version}); err != nil { - utilruntime.HandleError(err) + for _, version := range crd.Spec.Versions { + if err := c.syncHandler(schema.GroupVersion{Group: crd.Spec.Group, Version: version.Name}); err != nil { + utilruntime.HandleError(err) + } } } } @@ -182,11 +184,12 @@ func (c *crdRegistrationController) processNextWorkItem() bool { } func (c *crdRegistrationController) enqueueCRD(crd *apiextensions.CustomResourceDefinition) { - c.queue.Add(schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version}) + for _, version := range crd.Spec.Versions { + c.queue.Add(schema.GroupVersion{Group: crd.Spec.Group, Version: version.Name}) + } } func (c *crdRegistrationController) handleVersionUpdate(groupVersion schema.GroupVersion) error { - found := false apiServiceName := groupVersion.Version + "." + groupVersion.Group // check all CRDs. There shouldn't that many, but if we have problems later we can index them @@ -195,26 +198,25 @@ func (c *crdRegistrationController) handleVersionUpdate(groupVersion schema.Grou return err } for _, crd := range crds { - if crd.Spec.Version == groupVersion.Version && crd.Spec.Group == groupVersion.Group { - found = true - break + if crd.Spec.Group != groupVersion.Group { + continue + } + for _, version := range crd.Spec.Versions { + if version.Name == groupVersion.Version && version.Served { + c.apiServiceRegistration.AddAPIServiceToSync(&apiregistration.APIService{ + ObjectMeta: metav1.ObjectMeta{Name: apiServiceName}, + Spec: apiregistration.APIServiceSpec{ + Group: groupVersion.Group, + Version: groupVersion.Version, + GroupPriorityMinimum: 1000, // CRDs should have relatively low priority + VersionPriority: 100, // CRDs should have relatively low priority + }, + }) + return nil + } } } - if !found { - c.apiServiceRegistration.RemoveAPIServiceToSync(apiServiceName) - return nil - } - - c.apiServiceRegistration.AddAPIServiceToSync(&apiregistration.APIService{ - ObjectMeta: metav1.ObjectMeta{Name: apiServiceName}, - Spec: apiregistration.APIServiceSpec{ - Group: groupVersion.Group, - Version: groupVersion.Version, - GroupPriorityMinimum: 1000, // CRDs should have relatively low priority - VersionPriority: 100, // CRDs should have relatively low priority - }, - }) - + c.apiServiceRegistration.RemoveAPIServiceToSync(apiServiceName) return nil } diff --git a/pkg/master/controller/crdregistration/crdregistration_controller_test.go b/pkg/master/controller/crdregistration/crdregistration_controller_test.go index 1e2d8df587955..d2662134e26dd 100644 --- a/pkg/master/controller/crdregistration/crdregistration_controller_test.go +++ b/pkg/master/controller/crdregistration/crdregistration_controller_test.go @@ -42,8 +42,16 @@ func TestHandleVersionUpdate(t *testing.T) { startingCRDs: []*apiextensions.CustomResourceDefinition{ { Spec: apiextensions.CustomResourceDefinitionSpec{ - Group: "group.com", - Version: "v1", + Group: "group.com", + // Version field is deprecated and crd registration won't rely on it at all. + // defaulting route will fill up Versions field if user only provided version field. + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "v1", + Served: true, + Storage: true, + }, + }, }, }, }, @@ -66,8 +74,14 @@ func TestHandleVersionUpdate(t *testing.T) { startingCRDs: []*apiextensions.CustomResourceDefinition{ { Spec: apiextensions.CustomResourceDefinitionSpec{ - Group: "group.com", - Version: "v1", + Group: "group.com", + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "v1", + Served: true, + Storage: true, + }, + }, }, }, }, diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go index f6b246cf93a61..a6b9962318238 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go @@ -42,6 +42,22 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} { if len(obj.Names.ListKind) == 0 && len(obj.Names.Kind) > 0 { obj.Names.ListKind = obj.Names.Kind + "List" } + if len(obj.Versions) == 0 && len(obj.Version) != 0 { + obj.Versions = []apiextensions.CustomResourceDefinitionVersion{ + { + Name: obj.Version, + Served: true, + Storage: true, + }, + } + } else if len(obj.Versions) != 0 && len(obj.Version) == 0 { + for _, v := range obj.Versions { + if v.Served { + obj.Version = v.Name + break + } + } + } }, func(obj *apiextensions.JSONSchemaProps, c fuzz.Continue) { // we cannot use c.FuzzNoCustom because of the interface{} fields. So let's loop with reflection. diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/helpers.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/helpers.go index 8dc7f72d6603c..56ee3714a9b3b 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/helpers.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/helpers.go @@ -116,3 +116,22 @@ func CRDRemoveFinalizer(crd *CustomResourceDefinition, needle string) { } crd.Finalizers = newFinalizers } + +func HasCRDVersion(crd *CustomResourceDefinition, version string) bool { + for _, v := range crd.Spec.Versions { + if v.Name == version { + return true + } + } + return false +} + +func GetCRDStorageVersion(crd *CustomResourceDefinition) string { + for _, v := range crd.Spec.Versions { + if v.Storage { + return v.Name + } + } + // This should not happened if crd is valid + return "" +} diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go index 0deb7cbd0816d..2982d9d7d76d3 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go @@ -25,6 +25,8 @@ type CustomResourceDefinitionSpec struct { // Group is the group this resource belongs in Group string // Version is the version this resource belongs in + // Should be always first item in Versions field if provided. + // If Versions field is provided, this field is optional. Version string // Names are the names used to describe this custom resource Names CustomResourceDefinitionNames @@ -34,6 +36,23 @@ type CustomResourceDefinitionSpec struct { Validation *CustomResourceValidation // Subresources describes the subresources for CustomResources Subresources *CustomResourceSubresources + // Versions is the list of all supported versions for this resource. + // If Version field is provided, this field is optional. + // Validation: All versions must use the same validation schema for now. i.e., top + // level Validation field is applied to all of these versions. + // Order: The order of these versions is used to determine the order in discovery API + // (preferred version first). + Versions []CustomResourceDefinitionVersion +} + +type CustomResourceDefinitionVersion struct { + // Name is the version name, e.g. “v1”, “v2beta1”, etc. + Name string + // Served is a flag enabling/disabling this version from being served via REST APIs + Served bool + // Storage flags the version as a storage version. There must be exactly one flagged + // as storage version. + Storage bool } // CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition @@ -115,6 +134,13 @@ type CustomResourceDefinitionStatus struct { // AcceptedNames are the names that are actually being used to serve discovery // They may be different than the names in spec. AcceptedNames CustomResourceDefinitionNames + + // StoredVersions are all versions ever marked as storage in spec. Tracking these + // versions allows a migration path for stored version in etcd. The field is mutable + // so the migration controller can first make sure a version is certified (i.e. all + // stored objects is that version) then remove the rest of the versions from this list. + // None of the versions in this list can be removed from the spec.Versions field. + StoredVersions []string } // CustomResourceCleanupFinalizer is the name of the finalizer which will delete instances of diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/defaults.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/defaults.go index edffaed55f082..6b3ba0bc8af2d 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/defaults.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/defaults.go @@ -43,4 +43,16 @@ func SetDefaults_CustomResourceDefinitionSpec(obj *CustomResourceDefinitionSpec) if len(obj.Names.ListKind) == 0 && len(obj.Names.Kind) > 0 { obj.Names.ListKind = obj.Names.Kind + "List" } + // If there is no list of versions, create on using deprecated Version field. + if len(obj.Versions) == 0 && len(obj.Version) != 0 { + obj.Versions = []CustomResourceDefinitionVersion{{ + Name: obj.Version, + Storage: true, + Served: true, + }} + } + // For backward compatibility set the version field to the first item in versions list. + if len(obj.Version) == 0 && len(obj.Versions) != 0 { + obj.Version = obj.Versions[0].Name + } } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.pb.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.pb.go index a6268abb78407..b5a8c0e000273 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.pb.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.pb.go @@ -31,6 +31,7 @@ limitations under the License. CustomResourceDefinitionNames CustomResourceDefinitionSpec CustomResourceDefinitionStatus + CustomResourceDefinitionVersion CustomResourceSubresourceScale CustomResourceSubresourceStatus CustomResourceSubresources @@ -102,54 +103,60 @@ func (*CustomResourceDefinitionStatus) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{5} } +func (m *CustomResourceDefinitionVersion) Reset() { *m = CustomResourceDefinitionVersion{} } +func (*CustomResourceDefinitionVersion) ProtoMessage() {} +func (*CustomResourceDefinitionVersion) Descriptor() ([]byte, []int) { + return fileDescriptorGenerated, []int{6} +} + func (m *CustomResourceSubresourceScale) Reset() { *m = CustomResourceSubresourceScale{} } func (*CustomResourceSubresourceScale) ProtoMessage() {} func (*CustomResourceSubresourceScale) Descriptor() ([]byte, []int) { - return fileDescriptorGenerated, []int{6} + return fileDescriptorGenerated, []int{7} } func (m *CustomResourceSubresourceStatus) Reset() { *m = CustomResourceSubresourceStatus{} } func (*CustomResourceSubresourceStatus) ProtoMessage() {} func (*CustomResourceSubresourceStatus) Descriptor() ([]byte, []int) { - return fileDescriptorGenerated, []int{7} + return fileDescriptorGenerated, []int{8} } func (m *CustomResourceSubresources) Reset() { *m = CustomResourceSubresources{} } func (*CustomResourceSubresources) ProtoMessage() {} func (*CustomResourceSubresources) Descriptor() ([]byte, []int) { - return fileDescriptorGenerated, []int{8} + return fileDescriptorGenerated, []int{9} } func (m *CustomResourceValidation) Reset() { *m = CustomResourceValidation{} } func (*CustomResourceValidation) ProtoMessage() {} func (*CustomResourceValidation) Descriptor() ([]byte, []int) { - return fileDescriptorGenerated, []int{9} + return fileDescriptorGenerated, []int{10} } func (m *ExternalDocumentation) Reset() { *m = ExternalDocumentation{} } func (*ExternalDocumentation) ProtoMessage() {} -func (*ExternalDocumentation) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{10} } +func (*ExternalDocumentation) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{11} } func (m *JSON) Reset() { *m = JSON{} } func (*JSON) ProtoMessage() {} -func (*JSON) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{11} } +func (*JSON) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{12} } func (m *JSONSchemaProps) Reset() { *m = JSONSchemaProps{} } func (*JSONSchemaProps) ProtoMessage() {} -func (*JSONSchemaProps) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{12} } +func (*JSONSchemaProps) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{13} } func (m *JSONSchemaPropsOrArray) Reset() { *m = JSONSchemaPropsOrArray{} } func (*JSONSchemaPropsOrArray) ProtoMessage() {} -func (*JSONSchemaPropsOrArray) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{13} } +func (*JSONSchemaPropsOrArray) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{14} } func (m *JSONSchemaPropsOrBool) Reset() { *m = JSONSchemaPropsOrBool{} } func (*JSONSchemaPropsOrBool) ProtoMessage() {} -func (*JSONSchemaPropsOrBool) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{14} } +func (*JSONSchemaPropsOrBool) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{15} } func (m *JSONSchemaPropsOrStringArray) Reset() { *m = JSONSchemaPropsOrStringArray{} } func (*JSONSchemaPropsOrStringArray) ProtoMessage() {} func (*JSONSchemaPropsOrStringArray) Descriptor() ([]byte, []int) { - return fileDescriptorGenerated, []int{15} + return fileDescriptorGenerated, []int{16} } func init() { @@ -159,6 +166,7 @@ func init() { proto.RegisterType((*CustomResourceDefinitionNames)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionNames") proto.RegisterType((*CustomResourceDefinitionSpec)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionSpec") proto.RegisterType((*CustomResourceDefinitionStatus)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionStatus") + proto.RegisterType((*CustomResourceDefinitionVersion)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionVersion") proto.RegisterType((*CustomResourceSubresourceScale)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceSubresourceScale") proto.RegisterType((*CustomResourceSubresourceStatus)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceSubresourceStatus") proto.RegisterType((*CustomResourceSubresources)(nil), "k8s.io.apiextensions_apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceSubresources") @@ -411,6 +419,18 @@ func (m *CustomResourceDefinitionSpec) MarshalTo(dAtA []byte) (int, error) { } i += n8 } + if len(m.Versions) > 0 { + for _, msg := range m.Versions { + dAtA[i] = 0x3a + i++ + i = encodeVarintGenerated(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } return i, nil } @@ -449,6 +469,59 @@ func (m *CustomResourceDefinitionStatus) MarshalTo(dAtA []byte) (int, error) { return 0, err } i += n9 + if len(m.StoredVersions) > 0 { + for _, s := range m.StoredVersions { + dAtA[i] = 0x1a + i++ + l = len(s) + for l >= 1<<7 { + dAtA[i] = uint8(uint64(l)&0x7f | 0x80) + l >>= 7 + i++ + } + dAtA[i] = uint8(l) + i++ + i += copy(dAtA[i:], s) + } + } + return i, nil +} + +func (m *CustomResourceDefinitionVersion) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CustomResourceDefinitionVersion) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + dAtA[i] = 0xa + i++ + i = encodeVarintGenerated(dAtA, i, uint64(len(m.Name))) + i += copy(dAtA[i:], m.Name) + dAtA[i] = 0x10 + i++ + if m.Served { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + dAtA[i] = 0x18 + i++ + if m.Storage { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ return i, nil } @@ -1271,6 +1344,12 @@ func (m *CustomResourceDefinitionSpec) Size() (n int) { l = m.Subresources.Size() n += 1 + l + sovGenerated(uint64(l)) } + if len(m.Versions) > 0 { + for _, e := range m.Versions { + l = e.Size() + n += 1 + l + sovGenerated(uint64(l)) + } + } return n } @@ -1285,6 +1364,22 @@ func (m *CustomResourceDefinitionStatus) Size() (n int) { } l = m.AcceptedNames.Size() n += 1 + l + sovGenerated(uint64(l)) + if len(m.StoredVersions) > 0 { + for _, s := range m.StoredVersions { + l = len(s) + n += 1 + l + sovGenerated(uint64(l)) + } + } + return n +} + +func (m *CustomResourceDefinitionVersion) Size() (n int) { + var l int + _ = l + l = len(m.Name) + n += 1 + l + sovGenerated(uint64(l)) + n += 2 + n += 2 return n } @@ -1619,6 +1714,7 @@ func (this *CustomResourceDefinitionSpec) String() string { `Scope:` + fmt.Sprintf("%v", this.Scope) + `,`, `Validation:` + strings.Replace(fmt.Sprintf("%v", this.Validation), "CustomResourceValidation", "CustomResourceValidation", 1) + `,`, `Subresources:` + strings.Replace(fmt.Sprintf("%v", this.Subresources), "CustomResourceSubresources", "CustomResourceSubresources", 1) + `,`, + `Versions:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Versions), "CustomResourceDefinitionVersion", "CustomResourceDefinitionVersion", 1), `&`, ``, 1) + `,`, `}`, }, "") return s @@ -1630,6 +1726,19 @@ func (this *CustomResourceDefinitionStatus) String() string { s := strings.Join([]string{`&CustomResourceDefinitionStatus{`, `Conditions:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Conditions), "CustomResourceDefinitionCondition", "CustomResourceDefinitionCondition", 1), `&`, ``, 1) + `,`, `AcceptedNames:` + strings.Replace(strings.Replace(this.AcceptedNames.String(), "CustomResourceDefinitionNames", "CustomResourceDefinitionNames", 1), `&`, ``, 1) + `,`, + `StoredVersions:` + fmt.Sprintf("%v", this.StoredVersions) + `,`, + `}`, + }, "") + return s +} +func (this *CustomResourceDefinitionVersion) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&CustomResourceDefinitionVersion{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Served:` + fmt.Sprintf("%v", this.Served) + `,`, + `Storage:` + fmt.Sprintf("%v", this.Storage) + `,`, `}`, }, "") return s @@ -2706,6 +2815,37 @@ func (m *CustomResourceDefinitionSpec) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Versions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Versions = append(m.Versions, CustomResourceDefinitionVersion{}) + if err := m.Versions[len(m.Versions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenerated(dAtA[iNdEx:]) @@ -2817,6 +2957,154 @@ func (m *CustomResourceDefinitionStatus) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoredVersions", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StoredVersions = append(m.StoredVersions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CustomResourceDefinitionVersion) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CustomResourceDefinitionVersion: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CustomResourceDefinitionVersion: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Served", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.Served = bool(v != 0) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Storage", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.Storage = bool(v != 0) default: iNdEx = preIndex skippy, err := skipGenerated(dAtA[iNdEx:]) @@ -5241,137 +5529,143 @@ func init() { } var fileDescriptorGenerated = []byte{ - // 2102 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x58, 0xcb, 0x6f, 0x63, 0x49, - 0xd5, 0x4f, 0xd9, 0x79, 0x56, 0x92, 0x49, 0x52, 0xdd, 0xe9, 0xef, 0x76, 0xbe, 0x6e, 0x3b, 0xf1, - 0x30, 0xa3, 0x00, 0xd3, 0x36, 0x3d, 0x0f, 0x66, 0x40, 0x62, 0x11, 0x27, 0x01, 0xf5, 0x90, 0x74, - 0xa2, 0x72, 0x77, 0x23, 0x98, 0x67, 0xe5, 0xba, 0xec, 0x54, 0xe7, 0xbe, 0xfa, 0x56, 0x5d, 0x77, - 0x22, 0x01, 0xe2, 0xa1, 0x11, 0x12, 0x12, 0x0f, 0x41, 0x6f, 0x90, 0xd8, 0x80, 0xc4, 0x06, 0x21, - 0x58, 0xc0, 0x92, 0x25, 0x8b, 0x5e, 0x8e, 0xc4, 0x66, 0x56, 0x16, 0x6d, 0xfe, 0x05, 0x24, 0xa4, - 0xac, 0x50, 0x3d, 0xee, 0xcb, 0x8e, 0x67, 0x5a, 0x1a, 0x7b, 0x7a, 0xe7, 0x7b, 0x5e, 0xbf, 0x5f, - 0x9d, 0x3a, 0x75, 0xea, 0x94, 0x61, 0xeb, 0xe4, 0x0d, 0x5e, 0x65, 0x7e, 0xed, 0x24, 0x3a, 0xa2, - 0xa1, 0x47, 0x05, 0xe5, 0xb5, 0x0e, 0xf5, 0x9a, 0x7e, 0x58, 0x33, 0x0a, 0x12, 0x30, 0x7a, 0x2a, - 0xa8, 0xc7, 0x99, 0xef, 0xf1, 0x1b, 0x24, 0x60, 0x9c, 0x86, 0x1d, 0x1a, 0xd6, 0x82, 0x93, 0xb6, - 0xd4, 0xf1, 0xbc, 0x41, 0xad, 0x73, 0xf3, 0x88, 0x0a, 0x72, 0xb3, 0xd6, 0xa6, 0x1e, 0x0d,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0x6d, 0x58, 0xd6, 0xf6, 0x18, 0x17, 0xe8, - 0xed, 0x81, 0x03, 0x50, 0x7d, 0xba, 0x15, 0x4a, 0x6f, 0x55, 0xfe, 0xcb, 0x06, 0x7c, 0x36, 0x96, - 0x64, 0x8a, 0xff, 0xbb, 0x70, 0x8a, 0x09, 0xea, 0xca, 0x3d, 0x28, 0x6e, 0xce, 0xbf, 0xfc, 0xad, - 0x31, 0xd5, 0x5e, 0x7d, 0xd1, 0x70, 0x98, 0xba, 0x25, 0xd1, 0xb0, 0x06, 0xad, 0xfc, 0xa1, 0x00, - 0xaf, 0x0f, 0x73, 0xb9, 0x4d, 0x5c, 0xca, 0x65, 0xc6, 0x03, 0x27, 0x0a, 0x89, 0x63, 0x2a, 0x2e, - 0xc9, 0xf8, 0xa1, 0x92, 0x62, 0xa3, 0x45, 0x2f, 0xc1, 0x59, 0xce, 0xbc, 0x76, 0xe4, 0x90, 0xd0, - 0x94, 0x53, 0xb2, 0xea, 0x86, 0x91, 0xe3, 0xc4, 0x02, 0x55, 0x21, 0xe4, 0xc7, 0x7e, 0x28, 0x14, - 0x86, 0x55, 0x5c, 0x2f, 0xca, 0xc8, 0xb2, 0x41, 0x34, 0x12, 0x29, 0xce, 0x58, 0xa0, 0x75, 0x38, - 0x79, 0xc2, 0xbc, 0xa6, 0xd9, 0xf5, 0xe4, 0x14, 0x7f, 0x93, 0x79, 0x4d, 0xac, 0x34, 0x12, 0xdf, - 0x61, 0x5c, 0x48, 0x89, 0xd9, 0xf2, 0x5c, 0xd6, 0x95, 0x65, 0x62, 0x21, 0xf1, 0x6d, 0x22, 0x68, - 0xdb, 0x0f, 0x19, 0xe5, 0xd6, 0x74, 0x8a, 0xbf, 0x9d, 0x48, 0x71, 0xc6, 0xa2, 0xf2, 0x8f, 0xc9, - 0xe1, 0x45, 0x22, 0x5b, 0x09, 0x7a, 0x1e, 0x4e, 0xb5, 0x43, 0x3f, 0x0a, 0x4c, 0x96, 0x92, 0x6c, - 0x7f,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e5, 0x13, 0x94, 0x38, 0x8e, - 0xff, 0x50, 0xff, 0x45, 0x33, 0x9b, 0x3e, 0x41, 0xb7, 0x94, 0x14, 0x1b, 0x6d, 0x26, 0x7b, 0x85, - 0xcf, 0x2a, 0x7b, 0x95, 0xbf, 0x03, 0x78, 0xed, 0xe3, 0x2a, 0xf1, 0x99, 0x6c, 0xe9, 0x26, 0x9c, - 0x35, 0x43, 0xd1, 0x99, 0xda, 0x4e, 0xf3, 0x0e, 0x30, 0x4d, 0xe3, 0x0c, 0x27, 0xda, 0xfa, 0x8d, - 0xc7, 0x4f, 0x4a, 0x13, 0x1f, 0x3e, 0x29, 0x4d, 0x7c, 0xf4, 0xa4, 0x34, 0xf1, 0x83, 0x5e, 0x09, - 0x3c, 0xee, 0x95, 0xc0, 0x87, 0xbd, 0x12, 0xf8, 0xa8, 0x57, 0x02, 0xff, 0xea, 0x95, 0xc0, 0x2f, - 0xff, 0x5d, 0x9a, 0xf8, 0xce, 0x8c, 0x01, 0xff, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0a, 0x6f, - 0x04, 0x49, 0xd3, 0x1e, 0x00, 0x00, + // 2200 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x59, 0xcd, 0x6f, 0x1c, 0x49, + 0x15, 0x77, 0xcf, 0x78, 0xfc, 0x51, 0xb6, 0x63, 0xbb, 0x12, 0x87, 0x8e, 0x49, 0x66, 0xec, 0x59, + 0x76, 0x65, 0x60, 0x33, 0x43, 0xf6, 0x83, 0x5d, 0x56, 0xe2, 0xe0, 0xb1, 0x0d, 0xca, 0x62, 0xc7, + 0x56, 0x4d, 0x12, 0x04, 0xfb, 0x59, 0xee, 0xae, 0x19, 0x77, 0xdc, 0x5f, 0xe9, 0xaa, 0x9e, 0xd8, + 0x12, 0x20, 0x3e, 0xb4, 0x42, 0x42, 0xc0, 0x22, 0x88, 0x90, 0x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30, 0xd4, 0xf5, + 0xa8, 0x29, 0xc5, 0x28, 0xd1, 0x57, 0xff, 0x67, 0xf4, 0xa7, 0x4a, 0x26, 0xcd, 0x9b, 0x16, 0x76, + 0x09, 0xdc, 0x06, 0x4b, 0xbc, 0x9f, 0x42, 0x24, 0x74, 0x1d, 0x0b, 0xd3, 0x03, 0xcc, 0x8e, 0x14, + 0x47, 0x53, 0xb9, 0x5d, 0x6a, 0xf6, 0xe9, 0xd1, 0xc0, 0x0a, 0xf8, 0x26, 0x80, 0xb2, 0xc7, 0xc8, + 0xf9, 0x91, 0xe5, 0x52, 0x77, 0x0b, 0xcd, 0x01, 0x0b, 0x74, 0xce, 0x2a, 0xb8, 0x05, 0x96, 0x5d, + 0x7c, 0x48, 0xdc, 0x26, 0x71, 0x89, 0xc5, 0x82, 0x48, 0xb8, 0x2a, 0x0a, 0x57, 0x2b, 0xbd, 0x6e, + 0x65, 0x79, 0xb7, 0x5f, 0x89, 0x06, 0xed, 0xab, 0xeb, 0xfd, 0x27, 0x92, 0xdd, 0xb8, 0xec, 0xdc, + 0xfe, 0x50, 0x00, 0xab, 0xc3, 0xab, 0x02, 0xfc, 0x71, 0xda, 0x60, 0xca, 0xfe, 0xe1, 0xdd, 0x71, + 0x55, 0x20, 0xd5, 0x61, 0x82, 0xc1, 0xee, 0x12, 0xfe, 0x80, 0x17, 0x73, 0xec, 0x12, 0x75, 0x51, + 0xde, 0x19, 0x1b, 0x05, 0x0e, 0xd2, 0x98, 0x95, 0xef, 0x04, 0x76, 0xc5, 0xb3, 0x80, 0x5d, 0x52, + 0xfd, 0xb3, 0xd1, 0x3f, 0x63, 0xa4, 0x55, 0x1b, 0xfe, 0xc2, 0x00, 0x8b, 0x41, 0x48, 0xfc, 0xcd, + 0x83, 0x9b, 0x77, 0x5f, 0x6e, 0x8a, 0xc9, 0x46, 0x85, 0xea, 0xd6, 0xa7, 0xe4, 0xf9, 0x66, 0x73, + 0xff, 0x96, 0x74, 0x78, 0x10, 0x05, 0x21, 0x6d, 0x5c, 0xec, 0x75, 0x2b, 0x8b, 0xfb, 0x79, 0x28, + 0xd4, 0x8f, 0x5d, 0xf5, 0xc0, 0xca, 0xce, 0x09, 0x23, 0x91, 0x8f, 0xdd, 0xed, 0xc0, 0x8a, 0x3d, + 0xe2, 0x33, 0x49, 0xf4, 0x55, 0x30, 0x67, 0x13, 0x6a, 0x45, 0x4e, 0x28, 0x1e, 0x37, 0x99, 0xde, + 0x17, 0x55, 0x5a, 0xce, 0x6d, 0xa7, 0x2a, 0x94, 0xb5, 0x83, 0xd7, 0x40, 0x31, 0x8e, 0x5c, 0x95, + 0xc5, 0x73, 0xca, 0xbc, 0x78, 0x07, 0xed, 0x22, 0x2e, 0xaf, 0xae, 0x83, 0x49, 0xce, 0x13, 0x5e, + 0x01, 0xc5, 0x08, 0x3f, 0x10, 0x5e, 0xe7, 0x1b, 0xd3, 0xdc, 0x04, 0xe1, 0x07, 0x88, 0xcb, 0xaa, + 0x7f, 0xb9, 0x0a, 0x16, 0xfb, 0xf6, 0x02, 0x57, 0x41, 0xc1, 0xb1, 0x15, 0x07, 0xa0, 0x9c, 0x16, + 0x6e, 0x6e, 0xa3, 0x82, 0x63, 0xc3, 0xd7, 0xc0, 0x94, 0x9c, 0x10, 0x15, 0x68, 0x45, 0x97, 0x00, + 0x21, 0xe5, 0xaf, 0x77, 0xea, 0x8e, 0x13, 0x51, 0xe6, 0x82, 0x03, 0x69, 0xa9, 0x5b, 0x22, 0x39, + 0x90, 0x16, 0xe2, 0xb2, 0xfe, 0xcd, 0x4f, 0x3e, 0xe5, 0xe6, 0xd7, 0xd4, 0xc4, 0x52, 0xca, 0xd7, + 0xab, 0xcc, 0x20, 0xf2, 0x02, 0x98, 0x6a, 0x05, 0x91, 0x87, 0x99, 0x78, 0xa1, 0x33, 0x3d, 0xe6, + 0x37, 0x84, 0x14, 0x29, 0x2d, 0x6f, 0xb2, 0x98, 0xc3, 0x5c, 0x62, 0x4e, 0xe7, 0x9b, 0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0x80, 0x95, 0x73, 0x0b, 0x2b, 0x1f, 0x41, + 0xb1, 0xeb, 0x06, 0x0f, 0xe4, 0x4f, 0x34, 0x99, 0x9f, 0xcc, 0x36, 0x85, 0x14, 0x29, 0x6d, 0x26, + 0x7a, 0x85, 0xcf, 0x2a, 0x7a, 0xd5, 0x7f, 0x1a, 0xe0, 0xea, 0x27, 0x65, 0xe2, 0x33, 0x39, 0xd2, + 0x0d, 0x30, 0xa3, 0x9a, 0xa2, 0x53, 0x71, 0x9c, 0x6a, 0x0e, 0x50, 0x45, 0xe3, 0x14, 0x69, 0x6d, + 0xe3, 0xfa, 0xa3, 0xc7, 0xe5, 0x89, 0x8f, 0x1e, 0x97, 0x27, 0x3e, 0x7e, 0x5c, 0x9e, 0xf8, 0x61, + 0xaf, 0x6c, 0x3c, 0xea, 0x95, 0x8d, 0x8f, 0x7a, 0x65, 0xe3, 0xe3, 0x5e, 0xd9, 0xf8, 0x77, 0xaf, + 0x6c, 0xfc, 0xea, 0x3f, 0xe5, 0x89, 0xef, 0x4e, 0x2b, 0xf0, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, + 0x8c, 0x3a, 0x89, 0x32, 0x37, 0x20, 0x00, 0x00, } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto index b4399130521f9..c8cd0f8375c98 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto @@ -100,6 +100,9 @@ message CustomResourceDefinitionSpec { optional string group = 1; // Version is the version this resource belongs in + // Should be always first item in Versions field if provided. + // If Versions field is provided, this field is optional. + // +optional optional string version = 2; // Names are the names used to describe this custom resource @@ -117,6 +120,14 @@ message CustomResourceDefinitionSpec { // subresources via the CustomResourceSubresources feature gate. // +optional optional CustomResourceSubresources subresources = 6; + + // Versions is the list of all supported versions for this resource. + // If Version field is provided, this field is optional. + // Validation: All versions must use the same validation schema for now. i.e., top + // level Validation field is applied to all of these versions. + // Order: The order of these versions is used to determine the order in discovery API + // (preferred version first). + repeated CustomResourceDefinitionVersion versions = 7; } // CustomResourceDefinitionStatus indicates the state of the CustomResourceDefinition @@ -127,6 +138,29 @@ message CustomResourceDefinitionStatus { // AcceptedNames are the names that are actually being used to serve discovery // They may be different than the names in spec. optional CustomResourceDefinitionNames acceptedNames = 2; + + // StoredVersions are all versions ever marked as storage in spec. Tracking these + // versions allow a migration path for stored version in etcd. The field is mutable + // so the migration controller can first make sure a version is certified (i.e. all + // stored objects is that version) then remove the rest of the versions from this list. + // None of the versions in this list can be removed from the spec.Versions field. + repeated string storedVersions = 3; +} + +message CustomResourceDefinitionVersion { + // Name is the version name, e.g. “v1”, “v2beta1”, etc. + optional string name = 1; + + // Served is a flag enabling/disabling this version from being served via REST APIs + // Default is True. + // +optional + optional bool served = 2; + + // Storage flags the version as a storage version. There must be exactly one + // flagged as storage version. + // Default is False. + // +optional + optional bool storage = 3; } // CustomResourceSubresourceScale defines how to serve the scale subresource for CustomResources. diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go index 3a4da9aea8a40..3468f4b1c844e 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go @@ -25,7 +25,10 @@ type CustomResourceDefinitionSpec struct { // Group is the group this resource belongs in Group string `json:"group" protobuf:"bytes,1,opt,name=group"` // Version is the version this resource belongs in - Version string `json:"version" protobuf:"bytes,2,opt,name=version"` + // Should be always first item in Versions field if provided. + // If Versions field is provided, this field is optional. + // +optional + Version string `json:"version,omitempty" protobuf:"bytes,2,opt,name=version"` // Names are the names used to describe this custom resource Names CustomResourceDefinitionNames `json:"names" protobuf:"bytes,3,opt,name=names"` // Scope indicates whether this resource is cluster or namespace scoped. Default is namespaced @@ -38,6 +41,27 @@ type CustomResourceDefinitionSpec struct { // subresources via the CustomResourceSubresources feature gate. // +optional Subresources *CustomResourceSubresources `json:"subresources,omitempty" protobuf:"bytes,6,opt,name=subresources"` + // Versions is the list of all supported versions for this resource. + // If Version field is provided, this field is optional. + // Validation: All versions must use the same validation schema for now. i.e., top + // level Validation field is applied to all of these versions. + // Order: The order of these versions is used to determine the order in discovery API + // (preferred version first). + Versions []CustomResourceDefinitionVersion `json:"versions,omitempty" protobuf:"bytes,7,rep,name=versions"` +} + +type CustomResourceDefinitionVersion struct { + // Name is the version name, e.g. “v1”, “v2beta1”, etc. + Name string `json:"name" protobuf:"bytes,1,opt,name=name"` + // Served is a flag enabling/disabling this version from being served via REST APIs + // Default is True. + // +optional + Served bool `json:"served" protobuf:"varint,2,opt,name=served"` + // Storage flags the version as a storage version. There must be exactly one + // flagged as storage version. + // Default is False. + // +optional + Storage bool `json:"storage" protobuf:"varint,3,opt,name=storage"` } // CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition @@ -119,6 +143,13 @@ type CustomResourceDefinitionStatus struct { // AcceptedNames are the names that are actually being used to serve discovery // They may be different than the names in spec. AcceptedNames CustomResourceDefinitionNames `json:"acceptedNames" protobuf:"bytes,2,opt,name=acceptedNames"` + + // StoredVersions are all versions ever marked as storage in spec. Tracking these + // versions allow a migration path for stored version in etcd. The field is mutable + // so the migration controller can first make sure a version is certified (i.e. all + // stored objects is that version) then remove the rest of the versions from this list. + // None of the versions in this list can be removed from the spec.Versions field. + StoredVersions []string `protobuf:"bytes,3,rep,name=storedVersions"` } // CustomResourceCleanupFinalizer is the name of the finalizer which will delete instances of diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.conversion.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.conversion.go index feee95feac1b4..db2340e73336f 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.conversion.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.conversion.go @@ -48,6 +48,8 @@ func RegisterConversions(scheme *runtime.Scheme) error { Convert_apiextensions_CustomResourceDefinitionSpec_To_v1beta1_CustomResourceDefinitionSpec, Convert_v1beta1_CustomResourceDefinitionStatus_To_apiextensions_CustomResourceDefinitionStatus, Convert_apiextensions_CustomResourceDefinitionStatus_To_v1beta1_CustomResourceDefinitionStatus, + Convert_v1beta1_CustomResourceDefinitionVersion_To_apiextensions_CustomResourceDefinitionVersion, + Convert_apiextensions_CustomResourceDefinitionVersion_To_v1beta1_CustomResourceDefinitionVersion, Convert_v1beta1_CustomResourceSubresourceScale_To_apiextensions_CustomResourceSubresourceScale, Convert_apiextensions_CustomResourceSubresourceScale_To_v1beta1_CustomResourceSubresourceScale, Convert_v1beta1_CustomResourceSubresourceStatus_To_apiextensions_CustomResourceSubresourceStatus, @@ -220,6 +222,7 @@ func autoConvert_v1beta1_CustomResourceDefinitionSpec_To_apiextensions_CustomRes out.Validation = nil } out.Subresources = (*apiextensions.CustomResourceSubresources)(unsafe.Pointer(in.Subresources)) + out.Versions = *(*[]apiextensions.CustomResourceDefinitionVersion)(unsafe.Pointer(&in.Versions)) return nil } @@ -245,6 +248,7 @@ func autoConvert_apiextensions_CustomResourceDefinitionSpec_To_v1beta1_CustomRes out.Validation = nil } out.Subresources = (*CustomResourceSubresources)(unsafe.Pointer(in.Subresources)) + out.Versions = *(*[]CustomResourceDefinitionVersion)(unsafe.Pointer(&in.Versions)) return nil } @@ -258,6 +262,7 @@ func autoConvert_v1beta1_CustomResourceDefinitionStatus_To_apiextensions_CustomR if err := Convert_v1beta1_CustomResourceDefinitionNames_To_apiextensions_CustomResourceDefinitionNames(&in.AcceptedNames, &out.AcceptedNames, s); err != nil { return err } + out.StoredVersions = *(*[]string)(unsafe.Pointer(&in.StoredVersions)) return nil } @@ -271,6 +276,7 @@ func autoConvert_apiextensions_CustomResourceDefinitionStatus_To_v1beta1_CustomR if err := Convert_apiextensions_CustomResourceDefinitionNames_To_v1beta1_CustomResourceDefinitionNames(&in.AcceptedNames, &out.AcceptedNames, s); err != nil { return err } + out.StoredVersions = *(*[]string)(unsafe.Pointer(&in.StoredVersions)) return nil } @@ -279,6 +285,30 @@ func Convert_apiextensions_CustomResourceDefinitionStatus_To_v1beta1_CustomResou return autoConvert_apiextensions_CustomResourceDefinitionStatus_To_v1beta1_CustomResourceDefinitionStatus(in, out, s) } +func autoConvert_v1beta1_CustomResourceDefinitionVersion_To_apiextensions_CustomResourceDefinitionVersion(in *CustomResourceDefinitionVersion, out *apiextensions.CustomResourceDefinitionVersion, s conversion.Scope) error { + out.Name = in.Name + out.Served = in.Served + out.Storage = in.Storage + return nil +} + +// Convert_v1beta1_CustomResourceDefinitionVersion_To_apiextensions_CustomResourceDefinitionVersion is an autogenerated conversion function. +func Convert_v1beta1_CustomResourceDefinitionVersion_To_apiextensions_CustomResourceDefinitionVersion(in *CustomResourceDefinitionVersion, out *apiextensions.CustomResourceDefinitionVersion, s conversion.Scope) error { + return autoConvert_v1beta1_CustomResourceDefinitionVersion_To_apiextensions_CustomResourceDefinitionVersion(in, out, s) +} + +func autoConvert_apiextensions_CustomResourceDefinitionVersion_To_v1beta1_CustomResourceDefinitionVersion(in *apiextensions.CustomResourceDefinitionVersion, out *CustomResourceDefinitionVersion, s conversion.Scope) error { + out.Name = in.Name + out.Served = in.Served + out.Storage = in.Storage + return nil +} + +// Convert_apiextensions_CustomResourceDefinitionVersion_To_v1beta1_CustomResourceDefinitionVersion is an autogenerated conversion function. +func Convert_apiextensions_CustomResourceDefinitionVersion_To_v1beta1_CustomResourceDefinitionVersion(in *apiextensions.CustomResourceDefinitionVersion, out *CustomResourceDefinitionVersion, s conversion.Scope) error { + return autoConvert_apiextensions_CustomResourceDefinitionVersion_To_v1beta1_CustomResourceDefinitionVersion(in, out, s) +} + func autoConvert_v1beta1_CustomResourceSubresourceScale_To_apiextensions_CustomResourceSubresourceScale(in *CustomResourceSubresourceScale, out *apiextensions.CustomResourceSubresourceScale, s conversion.Scope) error { out.SpecReplicasPath = in.SpecReplicasPath out.StatusReplicasPath = in.StatusReplicasPath diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.deepcopy.go index 4092f6dab39fe..c990055d03a3a 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/zz_generated.deepcopy.go @@ -150,6 +150,11 @@ func (in *CustomResourceDefinitionSpec) DeepCopyInto(out *CustomResourceDefiniti (*in).DeepCopyInto(*out) } } + if in.Versions != nil { + in, out := &in.Versions, &out.Versions + *out = make([]CustomResourceDefinitionVersion, len(*in)) + copy(*out, *in) + } return } @@ -174,6 +179,11 @@ func (in *CustomResourceDefinitionStatus) DeepCopyInto(out *CustomResourceDefini } } in.AcceptedNames.DeepCopyInto(&out.AcceptedNames) + if in.StoredVersions != nil { + in, out := &in.StoredVersions, &out.StoredVersions + *out = make([]string, len(*in)) + copy(*out, *in) + } return } @@ -187,6 +197,22 @@ func (in *CustomResourceDefinitionStatus) DeepCopy() *CustomResourceDefinitionSt return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomResourceDefinitionVersion) DeepCopyInto(out *CustomResourceDefinitionVersion) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomResourceDefinitionVersion. +func (in *CustomResourceDefinitionVersion) DeepCopy() *CustomResourceDefinitionVersion { + if in == nil { + return nil + } + out := new(CustomResourceDefinitionVersion) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomResourceSubresourceScale) DeepCopyInto(out *CustomResourceSubresourceScale) { *out = *in diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go index 644557837c67f..44c6ea89be230 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go @@ -53,6 +53,27 @@ func ValidateCustomResourceDefinitionUpdate(obj, oldObj *apiextensions.CustomRes allErrs := genericvalidation.ValidateObjectMetaUpdate(&obj.ObjectMeta, &oldObj.ObjectMeta, field.NewPath("metadata")) allErrs = append(allErrs, ValidateCustomResourceDefinitionSpecUpdate(&obj.Spec, &oldObj.Spec, apiextensions.IsCRDConditionTrue(oldObj, apiextensions.Established), field.NewPath("spec"))...) allErrs = append(allErrs, ValidateCustomResourceDefinitionStatus(&obj.Status, field.NewPath("status"))...) + allErrs = append(allErrs, ValidateCustomResourceDefinitionStoredVersions(obj.Status.StoredVersions, obj.Spec.Versions, field.NewPath("status").Child("storedVersions"))...) + return allErrs +} + +// ValidateCustomResourceDefinitionStoredVersions statically validates +func ValidateCustomResourceDefinitionStoredVersions(storedVersions []string, versions []apiextensions.CustomResourceDefinitionVersion, fldPath *field.Path) field.ErrorList { + allErrs := field.ErrorList{} + storedVersionsMap := map[string]int{} + for i, v := range storedVersions { + storedVersionsMap[v] = i + } + for _, v := range versions { + if _, ok := storedVersionsMap[v.Name]; v.Served && ok { + delete(storedVersionsMap, v.Name) + } + } + + for v, i := range storedVersionsMap { + allErrs = append(allErrs, field.Invalid(fldPath.Index(i), v, "Cannot delete this version from Spec.Versions")) + } + return allErrs } @@ -75,10 +96,10 @@ func ValidateCustomResourceDefinitionSpec(spec *apiextensions.CustomResourceDefi allErrs = append(allErrs, field.Invalid(fldPath.Child("group"), spec.Group, "should be a domain with at least one dot")) } - if len(spec.Version) == 0 { - allErrs = append(allErrs, field.Required(fldPath.Child("version"), "")) - } else if errs := validationutil.IsDNS1035Label(spec.Version); len(errs) > 0 { - allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), spec.Version, strings.Join(errs, ","))) + if len(spec.Version) != 0 { + if errs := validationutil.IsDNS1035Label(spec.Version); len(errs) > 0 { + allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), spec.Version, strings.Join(errs, ","))) + } } switch spec.Scope { @@ -89,6 +110,30 @@ func ValidateCustomResourceDefinitionSpec(spec *apiextensions.CustomResourceDefi allErrs = append(allErrs, field.NotSupported(fldPath.Child("scope"), spec.Scope, []string{string(apiextensions.ClusterScoped), string(apiextensions.NamespaceScoped)})) } + storageFlagCount := 0 + versionsMap := map[string]bool{} + for i, version := range spec.Versions { + if version.Storage { + storageFlagCount++ + } + if versionsMap[version.Name] { + allErrs = append(allErrs, field.Invalid(fldPath.Child("versions").Index(i), spec.Versions[i], "duplicate version name "+version.Name)) + } else { + versionsMap[version.Name] = true + } + if errs := validationutil.IsDNS1035Label(version.Name); len(errs) > 0 { + allErrs = append(allErrs, field.Invalid(fldPath.Child("versions").Index(i), spec.Versions[i], strings.Join(errs, ","))) + } + } + if storageFlagCount != 1 { + allErrs = append(allErrs, field.Invalid(fldPath.Child("versions"), spec.Versions, "one and only one version should be marked as storage version")) + } + if len(spec.Version) != 0 && len(spec.Versions) > 1 { + if spec.Versions[0].Name != spec.Version { + allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), spec.Version, "spec.version should be the first item in spec.versions")) + } + } + // in addition to the basic name restrictions, some names are required for spec, but not for status if len(spec.Names.Plural) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("names", "plural"), "")) @@ -126,7 +171,6 @@ func ValidateCustomResourceDefinitionSpecUpdate(spec, oldSpec *apiextensions.Cus if established { // these effect the storage and cannot be changed therefore - allErrs = append(allErrs, genericvalidation.ValidateImmutableField(spec.Version, oldSpec.Version, fldPath.Child("version"))...) allErrs = append(allErrs, genericvalidation.ValidateImmutableField(spec.Scope, oldSpec.Scope, fldPath.Child("scope"))...) allErrs = append(allErrs, genericvalidation.ValidateImmutableField(spec.Names.Kind, oldSpec.Names.Kind, fldPath.Child("names", "kind"))...) } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation_test.go index c7c9b6d494b3d..ad5cf5de265a8 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation_test.go @@ -68,7 +68,7 @@ func TestValidateCustomResourceDefinition(t *testing.T) { }, errors: []validationMatch{ invalid("metadata", "name"), - required("spec", "version"), + invalid("spec", "versions"), required("spec", "scope"), required("spec", "names", "singular"), required("spec", "names", "kind"), @@ -82,8 +82,8 @@ func TestValidateCustomResourceDefinition(t *testing.T) { }, errors: []validationMatch{ invalid("metadata", "name"), + invalid("spec", "versions"), required("spec", "group"), - required("spec", "version"), required("spec", "scope"), required("spec", "names", "plural"), required("spec", "names", "singular"), @@ -118,7 +118,6 @@ func TestValidateCustomResourceDefinition(t *testing.T) { errors: []validationMatch{ invalid("metadata", "name"), invalid("spec", "group"), - invalid("spec", "version"), unsupported("spec", "scope"), invalid("spec", "names", "plural"), invalid("spec", "names", "singular"), @@ -130,6 +129,8 @@ func TestValidateCustomResourceDefinition(t *testing.T) { invalid("status", "acceptedNames", "kind"), invalid("status", "acceptedNames", "listKind"), // invalid format invalid("status", "acceptedNames", "listKind"), // kind == listKind + invalid("spec", "versions"), + invalid("spec", "version"), }, }, { @@ -161,6 +162,7 @@ func TestValidateCustomResourceDefinition(t *testing.T) { required("spec", "scope"), invalid("spec", "names", "listKind"), invalid("status", "acceptedNames", "listKind"), + invalid("spec", "versions"), }, }, { @@ -170,7 +172,14 @@ func TestValidateCustomResourceDefinition(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.NamespaceScoped, + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.NamespaceScoped, Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -198,7 +207,14 @@ func TestValidateCustomResourceDefinition(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.NamespaceScoped, + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.NamespaceScoped, Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -265,7 +281,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.ResourceScope("Cluster"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -290,7 +313,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.ResourceScope("Cluster"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -319,7 +349,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.ResourceScope("Cluster"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -347,7 +384,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.ResourceScope("Cluster"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -366,6 +410,86 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { }, errors: []validationMatch{}, }, + { + name: "version-deleted", + old: &apiextensions.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "plural.group.com", + ResourceVersion: "42", + }, + Spec: apiextensions.CustomResourceDefinitionSpec{ + Group: "group.com", + Version: "version", + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + { + Name: "version2", + Served: true, + Storage: false, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), + Names: apiextensions.CustomResourceDefinitionNames{ + Plural: "plural", + Singular: "singular", + Kind: "kind", + ListKind: "listkind", + }, + }, + Status: apiextensions.CustomResourceDefinitionStatus{ + AcceptedNames: apiextensions.CustomResourceDefinitionNames{ + Plural: "plural", + Singular: "singular", + Kind: "kind", + ListKind: "listkind", + }, + StoredVersions: []string{"version", "version2"}, + Conditions: []apiextensions.CustomResourceDefinitionCondition{ + {Type: apiextensions.Established, Status: apiextensions.ConditionTrue}, + }, + }, + }, + resource: &apiextensions.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "plural.group.com", + ResourceVersion: "42", + }, + Spec: apiextensions.CustomResourceDefinitionSpec{ + Group: "group.com", + Version: "version", + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), + Names: apiextensions.CustomResourceDefinitionNames{ + Plural: "plural", + Singular: "singular", + Kind: "kind", + ListKind: "listkind", + }, + }, + Status: apiextensions.CustomResourceDefinitionStatus{ + AcceptedNames: apiextensions.CustomResourceDefinitionNames{ + Plural: "plural", + Singular: "singular", + Kind: "kind", + ListKind: "listkind", + }, + StoredVersions: []string{"version", "version2"}, + }, + }, + errors: []validationMatch{ + invalid("status", "storedVersions[1]"), + }, + }, { name: "changes", old: &apiextensions.CustomResourceDefinition{ @@ -376,7 +500,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.ResourceScope("Cluster"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -404,7 +535,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "abc.com", Version: "version2", - Scope: apiextensions.ResourceScope("Namespaced"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version2", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Namespaced"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural2", Singular: "singular2", @@ -436,7 +574,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "group.com", Version: "version", - Scope: apiextensions.ResourceScope("Cluster"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Cluster"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural", Singular: "singular", @@ -464,7 +609,14 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { Spec: apiextensions.CustomResourceDefinitionSpec{ Group: "abc.com", Version: "version2", - Scope: apiextensions.ResourceScope("Namespaced"), + Versions: []apiextensions.CustomResourceDefinitionVersion{ + { + Name: "version2", + Served: true, + Storage: true, + }, + }, + Scope: apiextensions.ResourceScope("Namespaced"), Names: apiextensions.CustomResourceDefinitionNames{ Plural: "plural2", Singular: "singular2", @@ -483,7 +635,6 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) { }, errors: []validationMatch{ immutable("spec", "group"), - immutable("spec", "version"), immutable("spec", "scope"), immutable("spec", "names", "kind"), immutable("spec", "names", "plural"), diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/zz_generated.deepcopy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/zz_generated.deepcopy.go index 6b906d2cf3120..9284bbc81c4d2 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/zz_generated.deepcopy.go @@ -150,6 +150,11 @@ func (in *CustomResourceDefinitionSpec) DeepCopyInto(out *CustomResourceDefiniti (*in).DeepCopyInto(*out) } } + if in.Versions != nil { + in, out := &in.Versions, &out.Versions + *out = make([]CustomResourceDefinitionVersion, len(*in)) + copy(*out, *in) + } return } @@ -174,6 +179,11 @@ func (in *CustomResourceDefinitionStatus) DeepCopyInto(out *CustomResourceDefini } } in.AcceptedNames.DeepCopyInto(&out.AcceptedNames) + if in.StoredVersions != nil { + in, out := &in.StoredVersions, &out.StoredVersions + *out = make([]string, len(*in)) + copy(*out, *in) + } return } @@ -187,6 +197,22 @@ func (in *CustomResourceDefinitionStatus) DeepCopy() *CustomResourceDefinitionSt return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomResourceDefinitionVersion) DeepCopyInto(out *CustomResourceDefinitionVersion) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomResourceDefinitionVersion. +func (in *CustomResourceDefinitionVersion) DeepCopy() *CustomResourceDefinitionVersion { + if in == nil { + return nil + } + out := new(CustomResourceDefinitionVersion) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomResourceSubresourceScale) DeepCopyInto(out *CustomResourceSubresourceScale) { *out = *in diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/BUILD b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/BUILD index 8bd53039ddd37..435376419178e 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/BUILD +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/BUILD @@ -24,9 +24,11 @@ go_library( "//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library", + "//vendor/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/apiserver/validation:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset:go_default_library", + "//vendor/k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion:go_default_library", "//vendor/k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion/apiextensions/internalversion:go_default_library", @@ -85,6 +87,7 @@ filegroup( name = "all-srcs", srcs = [ ":package-srcs", + "//staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion:all-srcs", "//staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation:all-srcs", ], tags = ["automanaged"], @@ -94,5 +97,5 @@ go_test( name = "go_default_test", srcs = ["customresource_handler_test.go"], embed = [":go_default_library"], - deps = ["//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library"], + deps = ["//vendor/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion:go_default_library"], ) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/apiserver.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/apiserver.go index 6803b5c7a15f7..2a4316b6d2b28 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/apiserver.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/apiserver.go @@ -171,6 +171,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget) delegateHandler, c.ExtraConfig.CRDRESTOptionsGetter, c.GenericConfig.AdmissionControl, + crdClient.Apiextensions(), ) s.GenericAPIServer.Handler.NonGoRestfulMux.Handle("/apis", crdHandler) s.GenericAPIServer.Handler.NonGoRestfulMux.HandlePrefix("/apis/", crdHandler) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/BUILD b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/BUILD new file mode 100644 index 0000000000000..d23aa214b3cc7 --- /dev/null +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/BUILD @@ -0,0 +1,32 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "cr.go", + "noconversion.go", + ], + importpath = "k8s.io/apiextensions-apiserver/pkg/apiserver/conversion", + visibility = ["//visibility:public"], + deps = [ + "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/schema: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/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/noconversion.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/noconversion.go new file mode 100644 index 0000000000000..08d779dfd2c0d --- /dev/null +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/conversion/noconversion.go @@ -0,0 +1,89 @@ +/* +Copyright 2018 The Kubernetes 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. +*/ + +package conversion + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// NoConversionConverter is a converter that does only set the apiVersion and kind, but without actual conversions. +type NoConversionConverter struct { + ClusterScoped bool +} + +// NewNoConversionConverter create a NoConversionConverter. +func NewNoConversionConverter(clusterScoped bool) NoConversionConverter { + return NoConversionConverter{ + ClusterScoped: clusterScoped, + } +} + +func (NoConversionConverter) Convert(in, out, context interface{}) error { + unstructIn, ok := in.(*unstructured.Unstructured) + if !ok { + return fmt.Errorf("input type %T in not valid for unstructured conversion", in) + } + + unstructOut, ok := out.(*unstructured.Unstructured) + if !ok { + return fmt.Errorf("output type %T in not valid for unstructured conversion", out) + } + + // maybe deep copy the map? It is documented in the + // ObjectConverter interface that this function is not + // guaranteed to not mutate the input. Or maybe set the input + // object to nil. + unstructOut.Object = unstructIn.Object + return nil +} + +func (c NoConversionConverter) ConvertToVersion(in runtime.Object, target runtime.GroupVersioner) (runtime.Object, error) { + if kind := in.GetObjectKind().GroupVersionKind(); !kind.Empty() { + gvk, ok := target.KindForGroupVersionKinds([]schema.GroupVersionKind{kind}) + if !ok { + // TODO: should this be a typed error? + return nil, fmt.Errorf("%v is unstructured and is not suitable for converting to %q", kind, target) + } + in.GetObjectKind().SetGroupVersionKind(gvk) + + if meta.IsListType(in) { + return in, meta.EachListItem(in, func(item runtime.Object) error { + item.GetObjectKind().SetGroupVersionKind(gvk) + return nil + }) + } + } + + return in, nil +} + +func (c NoConversionConverter) ConvertFieldLabel(version, kind, label, value string) (string, string, error) { + // We currently only support metadata.namespace and metadata.name. + switch { + case label == "metadata.name": + return label, value, nil + case !c.ClusterScoped && label == "metadata.namespace": + return label, value, nil + default: + return "", "", fmt.Errorf("field label not supported: %s", label) + } +} diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_discovery_controller.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_discovery_controller.go index 976d54754a172..a84c5c5ce2819 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_discovery_controller.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_discovery_controller.go @@ -96,7 +96,21 @@ func (c *DiscoveryController) sync(version schema.GroupVersion) error { Version: crd.Spec.Version, }) - if crd.Spec.Version != version.Version { + foundThisVersion := false + for _, v := range crd.Spec.Versions { + if !v.Served { + continue + } + apiVersionsForDiscovery = append(apiVersionsForDiscovery, metav1.GroupVersionForDiscovery{ + GroupVersion: crd.Spec.Group + "/" + v.Name, + Version: v.Name, + }) + if v.Name == version.Version { + foundThisVersion = true + } + } + + if !foundThisVersion { continue } foundVersion = true @@ -207,7 +221,9 @@ func (c *DiscoveryController) processNextWorkItem() bool { } func (c *DiscoveryController) enqueue(obj *apiextensions.CustomResourceDefinition) { - c.queue.Add(schema.GroupVersion{Group: obj.Spec.Group, Version: obj.Spec.Version}) + for _, v := range obj.Spec.Versions { + c.queue.Add(schema.GroupVersion{Group: obj.Spec.Group, Version: v.Name}) + } } func (c *DiscoveryController) addCustomResourceDefinition(obj interface{}) { diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go index 4c0c01ba20d03..5cb352bbfa9b9 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go @@ -58,7 +58,9 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + "k8s.io/apiextensions-apiserver/pkg/apiserver/conversion" apiservervalidation "k8s.io/apiextensions-apiserver/pkg/apiserver/validation" + apiextensionsinternalversion "k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion" informers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion/apiextensions/internalversion" listers "k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/internalversion" "k8s.io/apiextensions-apiserver/pkg/controller/finalizer" @@ -67,6 +69,13 @@ import ( "k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor" ) +const ( + // This version is being used instead of any provided version by the CRD author to make sure + // the list object will go through conversion. Listed object may have different versions than + // request or storage version. This name should be unique. + CrdListVersion = "crd_list_version_A173D508-268B-4654-BEF2-2A943F379F9C" +) + // crdHandler serves the `/apis` endpoint. // This is registered as a filter so that it never collides with any explicitly registered endpoints type crdHandler struct { @@ -85,6 +94,7 @@ type crdHandler struct { delegate http.Handler restOptionsGetter generic.RESTOptionsGetter admission admission.Interface + crdClient apiextensionsinternalversion.ApiextensionsInterface } // crdInfo stores enough information to serve the storage for the custom resource @@ -94,11 +104,20 @@ type crdInfo struct { spec *apiextensions.CustomResourceDefinitionSpec acceptedNames *apiextensions.CustomResourceDefinitionNames - storage customresource.CustomResourceStorage + // Storage per version + storages map[string]customresource.CustomResourceStorage + + // Request scope per version + requestScopes map[string]handlers.RequestScope + + // Scale scope per version + scaleRequestScopes map[string]handlers.RequestScope + + // Status scope per version + statusRequestScopes map[string]handlers.RequestScope - requestScope handlers.RequestScope - scaleRequestScope handlers.RequestScope - statusRequestScope handlers.RequestScope + // storageVersion is the CRD version used when storing the object in etcd. + storageVersion string } // crdStorageMap goes from customresourcedefinition to its storage @@ -110,7 +129,8 @@ func NewCustomResourceDefinitionHandler( crdInformer informers.CustomResourceDefinitionInformer, delegate http.Handler, restOptionsGetter generic.RESTOptionsGetter, - admission admission.Interface) *crdHandler { + admission admission.Interface, + crdClient apiextensionsinternalversion.ApiextensionsInterface) *crdHandler { ret := &crdHandler{ versionDiscoveryHandler: versionDiscoveryHandler, groupDiscoveryHandler: groupDiscoveryHandler, @@ -119,8 +139,8 @@ func NewCustomResourceDefinitionHandler( delegate: delegate, restOptionsGetter: restOptionsGetter, admission: admission, + crdClient: crdClient, } - crdInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ UpdateFunc: ret.updateCustomResourceDefinition, DeleteFunc: func(obj interface{}) { @@ -168,7 +188,7 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - if crd.Spec.Version != requestInfo.APIVersion { + if !apiextensions.HasCRDVersion(crd, requestInfo.APIVersion) { r.delegate.ServeHTTP(w, req) return } @@ -185,6 +205,24 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } + // synchronously ensure that status.storedVersions is complete + switch requestInfo.Verb { + case "create", "update", "patch": + if !isStoragedVersion(crd, crdInfo.storageVersion) { + _, err := updateCustomResourceDefinitionStatus(r.crdClient, crd.Name, func(crd *apiextensions.CustomResourceDefinition) bool { + if isStoragedVersion(crd, crdInfo.storageVersion) { + return true + } + crd.Status.StoredVersions = append(crd.Status.StoredVersions, crdInfo.storageVersion) + return false + }) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + } + verb := strings.ToUpper(requestInfo.Verb) resource := requestInfo.Resource subresource := requestInfo.Subresource @@ -197,11 +235,11 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var handler http.HandlerFunc switch { case subresource == "status" && crd.Spec.Subresources != nil && crd.Spec.Subresources.Status != nil: - handler = r.serveStatus(w, req, requestInfo, crdInfo, terminating, supportedTypes) + handler = r.serveStatus(w, req, crd, requestInfo, crdInfo, terminating, supportedTypes) case subresource == "scale" && crd.Spec.Subresources != nil && crd.Spec.Subresources.Scale != nil: - handler = r.serveScale(w, req, requestInfo, crdInfo, terminating, supportedTypes) + handler = r.serveScale(w, req, crd, requestInfo, crdInfo, terminating, supportedTypes) case len(subresource) == 0: - handler = r.serveResource(w, req, requestInfo, crdInfo, terminating, supportedTypes) + handler = r.serveResource(w, req, crd, requestInfo, crdInfo, terminating, supportedTypes) default: http.Error(w, "the server could not find the requested resource", http.StatusNotFound) } @@ -213,9 +251,11 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } } -func (r *crdHandler) serveResource(w http.ResponseWriter, req *http.Request, requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { - requestScope := crdInfo.requestScope - storage := crdInfo.storage.CustomResource +func (r *crdHandler) serveResource(w http.ResponseWriter, req *http.Request, crd *apiextensions.CustomResourceDefinition, + requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { + + requestScope := crdInfo.requestScopes[requestInfo.APIVersion] + storage := crdInfo.storages[requestInfo.APIVersion].CustomResource minRequestTimeout := 1 * time.Minute switch requestInfo.Verb { @@ -249,9 +289,11 @@ func (r *crdHandler) serveResource(w http.ResponseWriter, req *http.Request, req } } -func (r *crdHandler) serveStatus(w http.ResponseWriter, req *http.Request, requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { - requestScope := crdInfo.statusRequestScope - storage := crdInfo.storage.Status +func (r *crdHandler) serveStatus(w http.ResponseWriter, req *http.Request, crd *apiextensions.CustomResourceDefinition, + requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { + + requestScope := crdInfo.statusRequestScopes[requestInfo.APIVersion] + storage := crdInfo.storages[requestInfo.APIVersion].Status switch requestInfo.Verb { case "get": @@ -266,9 +308,11 @@ func (r *crdHandler) serveStatus(w http.ResponseWriter, req *http.Request, reque } } -func (r *crdHandler) serveScale(w http.ResponseWriter, req *http.Request, requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { - requestScope := crdInfo.scaleRequestScope - storage := crdInfo.storage.Scale +func (r *crdHandler) serveScale(w http.ResponseWriter, req *http.Request, crd *apiextensions.CustomResourceDefinition, + requestInfo *apirequest.RequestInfo, crdInfo *crdInfo, terminating bool, supportedTypes []string) http.HandlerFunc { + + requestScope := crdInfo.scaleRequestScopes[requestInfo.APIVersion] + storage := crdInfo.storages[requestInfo.APIVersion].Scale switch requestInfo.Verb { case "get": @@ -306,8 +350,10 @@ func (r *crdHandler) updateCustomResourceDefinition(oldObj, newObj interface{}) // as it is used without locking elsewhere. storageMap2 := storageMap.clone() if oldInfo, ok := storageMap2[types.UID(oldCRD.UID)]; ok { - // destroy only the main storage. Those for the subresources share cacher and etcd clients. - oldInfo.storage.CustomResource.DestroyFunc() + for _, storage := range oldInfo.storages { + // destroy only the main storage. Those for the subresources share cacher and etcd clients. + storage.CustomResource.DestroyFunc() + } delete(storageMap2, types.UID(oldCRD.UID)) } @@ -338,9 +384,11 @@ func (r *crdHandler) removeDeadStorage() { } } if !found { - glog.V(4).Infof("Removing dead CRD storage for %v", s.requestScope.Resource) - // destroy only the main storage. Those for the subresources share cacher and etcd clients. - s.storage.CustomResource.DestroyFunc() + for version, storage := range s.storages { + glog.V(4).Infof("Removing dead CRD storage for %v", s.requestScopes[version].Resource) + // destroy only the main storage. Those for the subresources share cacher and etcd clients. + storage.CustomResource.DestroyFunc() + } delete(storageMap2, uid) } } @@ -354,7 +402,7 @@ func (r *crdHandler) GetCustomResourceListerCollectionDeleter(crd *apiextensions if err != nil { return nil, err } - return info.storage.CustomResource, nil + return info.storages[info.storageVersion].CustomResource, nil } func (r *crdHandler) getOrCreateServingInfoFor(crd *apiextensions.CustomResourceDefinition) (*crdInfo, error) { @@ -371,140 +419,149 @@ func (r *crdHandler) getOrCreateServingInfoFor(crd *apiextensions.CustomResource return ret, nil } - // In addition to Unstructured objects (Custom Resources), we also may sometimes need to - // decode unversioned Options objects, so we delegate to parameterScheme for such types. - parameterScheme := runtime.NewScheme() - parameterScheme.AddUnversionedTypes(schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version}, - &metav1.ListOptions{}, - &metav1.ExportOptions{}, - &metav1.GetOptions{}, - &metav1.DeleteOptions{}, - ) - parameterCodec := runtime.NewParameterCodec(parameterScheme) - - kind := schema.GroupVersionKind{Group: crd.Spec.Group, Version: crd.Spec.Version, Kind: crd.Status.AcceptedNames.Kind} - typer := UnstructuredObjectTyper{ - Delegate: parameterScheme, - UnstructuredTyper: discovery.NewUnstructuredObjectTyper(nil), - } - creator := unstructuredCreator{} - - validator, _, err := apiservervalidation.NewSchemaValidator(crd.Spec.Validation) - if err != nil { - return nil, err - } - - var statusSpec *apiextensions.CustomResourceSubresourceStatus - var statusValidator *validate.SchemaValidator - if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && crd.Spec.Subresources != nil && crd.Spec.Subresources.Status != nil { - statusSpec = crd.Spec.Subresources.Status + storageVersion := apiextensions.GetCRDStorageVersion(crd) + requestScopes := map[string]handlers.RequestScope{} + storages := map[string]customresource.CustomResourceStorage{} + statusScopes := map[string]handlers.RequestScope{} + scaleScopes := map[string]handlers.RequestScope{} + for _, v := range crd.Spec.Versions { + converter := conversion.NewNoConversionConverter(crd.Spec.Scope == apiextensions.ClusterScoped) + // In addition to Unstructured objects (Custom Resources), we also may sometimes need to + // decode unversioned Options objects, so we delegate to parameterScheme for such types. + parameterScheme := runtime.NewScheme() + parameterScheme.AddUnversionedTypes(schema.GroupVersion{Group: crd.Spec.Group, Version: storageVersion}, + &metav1.ListOptions{}, + &metav1.ExportOptions{}, + &metav1.GetOptions{}, + &metav1.DeleteOptions{}, + ) + parameterCodec := runtime.NewParameterCodec(parameterScheme) + + kind := schema.GroupVersionKind{Group: crd.Spec.Group, Version: v.Name, Kind: crd.Status.AcceptedNames.Kind} + typer := newUnstructuredObjectTyper(parameterScheme) + creator := unstructuredCreator{} + + validator, _, err := apiservervalidation.NewSchemaValidator(crd.Spec.Validation) + if err != nil { + return nil, err + } - // for the status subresource, validate only against the status schema - if crd.Spec.Validation != nil && crd.Spec.Validation.OpenAPIV3Schema != nil && crd.Spec.Validation.OpenAPIV3Schema.Properties != nil { - if statusSchema, ok := crd.Spec.Validation.OpenAPIV3Schema.Properties["status"]; ok { - openapiSchema := &spec.Schema{} - if err := apiservervalidation.ConvertJSONSchemaProps(&statusSchema, openapiSchema); err != nil { - return nil, err + var statusSpec *apiextensions.CustomResourceSubresourceStatus + var statusValidator *validate.SchemaValidator + if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && crd.Spec.Subresources != nil && crd.Spec.Subresources.Status != nil { + statusSpec = crd.Spec.Subresources.Status + + // for the status subresource, validate only against the status schema + if crd.Spec.Validation != nil && crd.Spec.Validation.OpenAPIV3Schema != nil && crd.Spec.Validation.OpenAPIV3Schema.Properties != nil { + if statusSchema, ok := crd.Spec.Validation.OpenAPIV3Schema.Properties["status"]; ok { + openapiSchema := &spec.Schema{} + if err := apiservervalidation.ConvertJSONSchemaProps(&statusSchema, openapiSchema); err != nil { + return nil, err + } + statusValidator = validate.NewSchemaValidator(openapiSchema, nil, "", strfmt.Default) } - statusValidator = validate.NewSchemaValidator(openapiSchema, nil, "", strfmt.Default) } } - } - var scaleSpec *apiextensions.CustomResourceSubresourceScale - if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && crd.Spec.Subresources != nil && crd.Spec.Subresources.Scale != nil { - scaleSpec = crd.Spec.Subresources.Scale - } + var scaleSpec *apiextensions.CustomResourceSubresourceScale + if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && crd.Spec.Subresources != nil && crd.Spec.Subresources.Scale != nil { + scaleSpec = crd.Spec.Subresources.Scale + } - // TODO: identify how to pass printer specification from the CRD - table, err := tableconvertor.New(nil) - if err != nil { - glog.V(2).Infof("The CRD for %v has an invalid printer specification, falling back to default printing: %v", kind, err) - } - - customResourceStorage := customresource.NewStorage( - schema.GroupResource{Group: crd.Spec.Group, Resource: crd.Status.AcceptedNames.Plural}, - schema.GroupVersionKind{Group: crd.Spec.Group, Version: crd.Spec.Version, Kind: crd.Status.AcceptedNames.ListKind}, - customresource.NewStrategy( - typer, - crd.Spec.Scope == apiextensions.NamespaceScoped, - kind, - validator, - statusValidator, - statusSpec, - scaleSpec, - ), - r.restOptionsGetter, - crd.Status.AcceptedNames.Categories, - table, - ) - - selfLinkPrefix := "" - switch crd.Spec.Scope { - case apiextensions.ClusterScoped: - selfLinkPrefix = "/" + path.Join("apis", crd.Spec.Group, crd.Spec.Version) + "/" + crd.Status.AcceptedNames.Plural + "/" - case apiextensions.NamespaceScoped: - selfLinkPrefix = "/" + path.Join("apis", crd.Spec.Group, crd.Spec.Version, "namespaces") + "/" - } - - clusterScoped := crd.Spec.Scope == apiextensions.ClusterScoped - - requestScope := handlers.RequestScope{ - Namer: handlers.ContextBasedNaming{ - SelfLinker: meta.NewAccessor(), - ClusterScoped: clusterScoped, - SelfLinkPathPrefix: selfLinkPrefix, - }, + // TODO: identify how to pass printer specification from the CRD + table, err := tableconvertor.New(nil) + if err != nil { + glog.V(2).Infof("The CRD for %v has an invalid printer specification, falling back to default printing: %v", kind, err) + } - Serializer: unstructuredNegotiatedSerializer{typer: typer, creator: creator}, - ParameterCodec: parameterCodec, + storages[v.Name] = customresource.NewStorage( + schema.GroupResource{Group: crd.Spec.Group, Resource: crd.Status.AcceptedNames.Plural}, + schema.GroupVersionKind{Group: crd.Spec.Group, Version: v.Name, Kind: crd.Status.AcceptedNames.ListKind}, + customresource.NewStrategy( + typer, + crd.Spec.Scope == apiextensions.NamespaceScoped, + kind, + validator, + statusValidator, + statusSpec, + scaleSpec, + ), + CRDRESTOptionsGetterWrapper{ + RESTOptionsGetter: r.restOptionsGetter, + decoderVersion: schema.GroupVersion{Group: crd.Spec.Group, Version: v.Name}, + encoderVersion: schema.GroupVersion{Group: crd.Spec.Group, Version: storageVersion}, + }, + crd.Status.AcceptedNames.Categories, + table, + ) + + selfLinkPrefix := "" + switch crd.Spec.Scope { + case apiextensions.ClusterScoped: + selfLinkPrefix = "/" + path.Join("apis", crd.Spec.Group, crd.Spec.Version) + "/" + crd.Status.AcceptedNames.Plural + "/" + case apiextensions.NamespaceScoped: + selfLinkPrefix = "/" + path.Join("apis", crd.Spec.Group, crd.Spec.Version, "namespaces") + "/" + } - Creater: creator, - Convertor: crdObjectConverter{ - UnstructuredObjectConverter: unstructured.UnstructuredObjectConverter{}, - clusterScoped: clusterScoped, - }, - Defaulter: unstructuredDefaulter{parameterScheme}, - Typer: typer, - UnsafeConvertor: unstructured.UnstructuredObjectConverter{}, + clusterScoped := crd.Spec.Scope == apiextensions.ClusterScoped - Resource: schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Status.AcceptedNames.Plural}, - Kind: kind, + requestScopes[v.Name] = handlers.RequestScope{ + Namer: handlers.ContextBasedNaming{ + SelfLinker: meta.NewAccessor(), + ClusterScoped: clusterScoped, + SelfLinkPathPrefix: selfLinkPrefix, + }, + Serializer: unstructuredNegotiatedSerializer{typer: typer, creator: creator, converter: converter}, + ParameterCodec: parameterCodec, - MetaGroupVersion: metav1.SchemeGroupVersion, + Creater: creator, + Convertor: converter, + Defaulter: unstructuredDefaulter{parameterScheme}, + Typer: typer, + UnsafeConvertor: converter, - TableConvertor: customResourceStorage.CustomResource, - } + Resource: schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Status.AcceptedNames.Plural}, + Kind: kind, - ret := &crdInfo{ - spec: &crd.Spec, - acceptedNames: &crd.Status.AcceptedNames, + MetaGroupVersion: metav1.SchemeGroupVersion, - storage: customResourceStorage, - requestScope: requestScope, - scaleRequestScope: requestScope, // shallow copy - statusRequestScope: requestScope, // shallow copy - } + TableConvertor: storages[v.Name].CustomResource, + } + + // override scaleSpec subresource values + scaleScope := requestScopes[v.Name] + scaleConverter := scale.NewScaleConverter() + scaleScope.Subresource = "scale" + scaleScope.Serializer = serializer.NewCodecFactory(scaleConverter.Scheme()) + scaleScope.Kind = autoscalingv1.SchemeGroupVersion.WithKind("Scale") + scaleScope.Namer = handlers.ContextBasedNaming{ + SelfLinker: meta.NewAccessor(), + ClusterScoped: clusterScoped, + SelfLinkPathPrefix: selfLinkPrefix, + SelfLinkPathSuffix: "/scale", + } + scaleScopes[v.Name] = scaleScope - // override scaleSpec subresource values - scaleConverter := scale.NewScaleConverter() - ret.scaleRequestScope.Subresource = "scale" - ret.scaleRequestScope.Serializer = serializer.NewCodecFactory(scaleConverter.Scheme()) - ret.scaleRequestScope.Kind = autoscalingv1.SchemeGroupVersion.WithKind("Scale") - ret.scaleRequestScope.Namer = handlers.ContextBasedNaming{ - SelfLinker: meta.NewAccessor(), - ClusterScoped: clusterScoped, - SelfLinkPathPrefix: selfLinkPrefix, - SelfLinkPathSuffix: "/scale", + // override status subresource values + statusScope := requestScopes[v.Name] + statusScope.Subresource = "status" + statusScope.Namer = handlers.ContextBasedNaming{ + SelfLinker: meta.NewAccessor(), + ClusterScoped: clusterScoped, + SelfLinkPathPrefix: selfLinkPrefix, + SelfLinkPathSuffix: "/status", + } + statusScopes[v.Name] = statusScope } - // override status subresource values - ret.statusRequestScope.Subresource = "status" - ret.statusRequestScope.Namer = handlers.ContextBasedNaming{ - SelfLinker: meta.NewAccessor(), - ClusterScoped: clusterScoped, - SelfLinkPathPrefix: selfLinkPrefix, - SelfLinkPathSuffix: "/status", + ret := &crdInfo{ + spec: &crd.Spec, + acceptedNames: &crd.Status.AcceptedNames, + storages: storages, + requestScopes: requestScopes, + scaleRequestScopes: scaleScopes, + statusRequestScopes: statusScopes, + storageVersion: storageVersion, } // Copy because we cannot write to storageMap without a race @@ -517,27 +574,10 @@ func (r *crdHandler) getOrCreateServingInfoFor(crd *apiextensions.CustomResource return ret, nil } -// crdObjectConverter is a converter that supports field selectors for CRDs. -type crdObjectConverter struct { - unstructured.UnstructuredObjectConverter - clusterScoped bool -} - -func (c crdObjectConverter) ConvertFieldLabel(version, kind, label, value string) (string, string, error) { - // We currently only support metadata.namespace and metadata.name. - switch { - case label == "metadata.name": - return label, value, nil - case !c.clusterScoped && label == "metadata.namespace": - return label, value, nil - default: - return "", "", fmt.Errorf("field label not supported: %s", label) - } -} - type unstructuredNegotiatedSerializer struct { - typer runtime.ObjectTyper - creator runtime.ObjectCreater + typer runtime.ObjectTyper + creator runtime.ObjectCreater + converter runtime.ObjectConvertor } func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInfo { @@ -562,7 +602,7 @@ func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.Serial } func (s unstructuredNegotiatedSerializer) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder { - return versioning.NewDefaultingCodecForScheme(Scheme, encoder, nil, gv, nil) + return versioning.NewCodec(encoder, nil, s.converter, Scheme, Scheme, Scheme, gv, nil) } func (s unstructuredNegotiatedSerializer) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder { @@ -574,6 +614,13 @@ type UnstructuredObjectTyper struct { UnstructuredTyper runtime.ObjectTyper } +func newUnstructuredObjectTyper(Delegate runtime.ObjectTyper) UnstructuredObjectTyper { + return UnstructuredObjectTyper{ + Delegate: Delegate, + UnstructuredTyper: discovery.NewUnstructuredObjectTyper(nil), + } +} + func (t UnstructuredObjectTyper) ObjectKinds(obj runtime.Object) ([]schema.GroupVersionKind, bool, error) { // Delegate for things other than Unstructured. if _, ok := obj.(runtime.Unstructured); !ok { @@ -640,3 +687,22 @@ func (in crdStorageMap) clone() crdStorageMap { } return out } + +type CRDRESTOptionsGetterWrapper struct { + generic.RESTOptionsGetter + customCodec runtime.Codec + encoderVersion schema.GroupVersion + decoderVersion schema.GroupVersion +} + +type DebugCodec struct { + delegate runtime.Codec +} + +func (t CRDRESTOptionsGetterWrapper) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) { + ret, err := t.RESTOptionsGetter.GetRESTOptions(resource) + if err == nil { + ret.StorageConfig.Codec = versioning.NewCodec(ret.StorageConfig.Codec, ret.StorageConfig.Codec, conversion.NewNoConversionConverter(true), &unstructuredCreator{}, discovery.NewUnstructuredObjectTyper(nil), &unstructuredDefaulter{delegate: Scheme}, t.encoderVersion, t.decoderVersion) + } + return ret, err +} diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go index 81c3ac7050b1e..c7328935ef67e 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler_test.go @@ -19,7 +19,7 @@ package apiserver import ( "testing" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + conversion "k8s.io/apiextensions-apiserver/pkg/apiserver/conversion" ) func TestConvertFieldLabel(t *testing.T) { @@ -64,10 +64,7 @@ func TestConvertFieldLabel(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - c := crdObjectConverter{ - UnstructuredObjectConverter: unstructured.UnstructuredObjectConverter{}, - clusterScoped: test.clusterScoped, - } + c := conversion.NewNoConversionConverter(test.clusterScoped) label, value, err := c.ConvertFieldLabel("", "", test.label, "value") if e, a := test.expectError, err != nil; e != a { diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/helpers.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/helpers.go new file mode 100644 index 0000000000000..5f9885f98158a --- /dev/null +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/helpers.go @@ -0,0 +1,58 @@ +/* +Copyright 2018 The Kubernetes 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. +*/ + +package apiserver + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + apiextensionsinternalversion "k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion" +) + +// updateCustomResourceDefinitionStatus updates a CRD's status, retrying up to 5 times on version conflict errors. +// It stops retrying when either the update succeeds or the update func returns true. +func updateCustomResourceDefinitionStatus(client apiextensionsinternalversion.ApiextensionsInterface, name string, update func(definition *apiextensions.CustomResourceDefinition) bool) (*apiextensions.CustomResourceDefinition, error) { + for i := 0; i < 5; i++ { + crd, err := client.CustomResourceDefinitions().Get(name, metav1.GetOptions{}) + if err != nil { + return nil, fmt.Errorf("failed to get Service %q: %v", name, err) + } + if update(crd) { + return crd, nil + } + crd, err = client.CustomResourceDefinitions().UpdateStatus(crd) + if err == nil { + return crd, nil + } + if !errors.IsConflict(err) && !errors.IsServerTimeout(err) { + return nil, fmt.Errorf("failed to update CustomResourceDefinition %q: %v", name, err) + } + } + return nil, fmt.Errorf("too many retries updating CustomResourceDefinition %q", name) +} + +func isStoragedVersion(crd *apiextensions.CustomResourceDefinition, version string) bool { + for _, v := range crd.Status.StoredVersions { + if version == v { + return true + } + } + return false +} diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/BUILD b/staging/src/k8s.io/apiextensions-apiserver/test/integration/BUILD index b9617e41a3e06..4bf7b9f51683f 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/BUILD +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/BUILD @@ -2,6 +2,7 @@ package(default_visibility = ["//visibility:public"]) load( "@io_bazel_rules_go//go:def.bzl", + "go_library", "go_test", ) @@ -15,6 +16,7 @@ go_test( "validation_test.go", "yaml_test.go", ], + embed = [":go_default_library"], tags = ["integration"], deps = [ "//vendor/github.com/coreos/etcd/clientv3:go_default_library", @@ -56,3 +58,15 @@ filegroup( ], tags = ["automanaged"], ) + +go_library( + name = "go_default_library", + srcs = ["helpers.go"], + importpath = "k8s.io/apiextensions-apiserver/test/integration", + deps = [ + "//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library", + "//vendor/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + ], +) diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go index 3b21ad339d127..e0d4d42970854 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/basic_test.go @@ -25,6 +25,7 @@ import ( apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" "k8s.io/apiextensions-apiserver/test/integration/testserver" "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -79,6 +80,336 @@ func TestClusterScopedCRUD(t *testing.T) { testFieldSelector(t, ns, noxuDefinition, dynamicClient) } +func TestVersionedNamspacedScopedCRD(t *testing.T) { + stopCh, apiExtensionClient, dynamicClient, err := testserver.StartDefaultServerWithClients() + if err != nil { + t.Fatal(err) + } + defer close(stopCh) + + noxuDefinition := testserver.NewMultipleVersionNoxuCRD(apiextensionsv1beta1.NamespaceScoped) + err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient) + if err != nil { + t.Fatal(err) + } + + ns := "not-the-default" + testSimpleVersionedCRUD(t, ns, noxuDefinition, dynamicClient) +} + +func TestVersionedClusterScopedCRD(t *testing.T) { + stopCh, apiExtensionClient, dynamicClient, err := testserver.StartDefaultServerWithClients() + if err != nil { + t.Fatal(err) + } + defer close(stopCh) + + noxuDefinition := testserver.NewMultipleVersionNoxuCRD(apiextensionsv1beta1.ClusterScoped) + err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient) + if err != nil { + t.Fatal(err) + } + + ns := "" + testSimpleVersionedCRUD(t, ns, noxuDefinition, dynamicClient) +} + +func TestStoragedVersionInNamespacedCRDStatus(t *testing.T) { + noxuDefinition := testserver.NewMultipleVersionNoxuCRD(apiextensionsv1beta1.NamespaceScoped) + ns := "not-the-default" + testStoragedVersionInCRDStatus(t, ns, noxuDefinition) +} + +func TestStoragedVersionInClusterScopedCRDStatus(t *testing.T) { + noxuDefinition := testserver.NewMultipleVersionNoxuCRD(apiextensionsv1beta1.ClusterScoped) + ns := "" + testStoragedVersionInCRDStatus(t, ns, noxuDefinition) +} + +func testStoragedVersionInCRDStatus(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition) { + versionsV1Beta1Storage := []apiextensionsv1beta1.CustomResourceDefinitionVersion{ + { + Name: "v1beta1", + Served: true, + Storage: true, + }, + { + Name: "v1beta2", + Served: true, + Storage: false, + }, + } + versionsV1Beta2Storage := []apiextensionsv1beta1.CustomResourceDefinitionVersion{ + { + Name: "v1beta1", + Served: true, + Storage: false, + }, + { + Name: "v1beta2", + Served: true, + Storage: true, + }, + } + stopCh, apiExtensionClient, dynamicClient, err := testserver.StartDefaultServerWithClients() + if err != nil { + t.Fatal(err) + } + defer close(stopCh) + + noxuDefinition.Spec.Versions = versionsV1Beta1Storage + err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient) + if err != nil { + t.Fatal(err) + } + + // The storage version list should be empty + crd, err := testserver.GetCustomResourceDefinition(noxuDefinition, apiExtensionClient) + if err != nil { + t.Fatal(err) + } + if len(crd.Status.StoredVersions) > 0 { + crd.Status.StoredVersions = []string{} + crd, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().UpdateStatus(crd) + if err != nil { + t.Fatal(err) + } + } + + // Changing CRD without any writes should keep the list empty + crd.Spec.Versions = versionsV1Beta2Storage + _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd) + if err != nil { + t.Fatal(err) + } + crd, err = testserver.GetCustomResourceDefinition(noxuDefinition, apiExtensionClient) + if err != nil { + t.Fatal(err) + } + if e, a := []string{}, crd.Status.StoredVersions; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } + + version := "v1beta1" // This version should not matter as the storage version is what we are testing here + noxuResourceClient := NewNamespacedCustomResourceVersionedClient(ns, dynamicClient, noxuDefinition, version) + + // Writing when storage is v1beta2 should update the list + _, err = instantiateVersionedCustomResource(t, testserver.NewVersionedNoxuInstance(ns, "foo", version), noxuResourceClient, noxuDefinition, version) + if err != nil { + t.Fatalf("unable to create noxu Instance:%v", err) + } + crd, err = testserver.GetCustomResourceDefinition(noxuDefinition, apiExtensionClient) + if err != nil { + t.Fatal(err) + } + if e, a := []string{"v1beta2"}, crd.Status.StoredVersions; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } + + // Changing CRD storage to v1beta1 and another write should update stored version. + crd.Spec.Versions = versionsV1Beta1Storage + _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd) + if err != nil { + t.Fatal(err) + } + crd, err = testserver.GetCustomResourceDefinition(noxuDefinition, apiExtensionClient) + if err != nil { + t.Fatal(err) + } + if e, a := []string{"v1beta2"}, crd.Status.StoredVersions; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } + _, err = instantiateVersionedCustomResource(t, testserver.NewVersionedNoxuInstance(ns, "bar", version), noxuResourceClient, noxuDefinition, version) + if err != nil { + t.Fatalf("unable to create noxu Instance:%v", err) + } + crd, err = testserver.GetCustomResourceDefinition(noxuDefinition, apiExtensionClient) + if err != nil { + t.Fatal(err) + } + if e, a := []string{"v1beta2", "v1beta1"}, crd.Status.StoredVersions; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } +} + +func TestVersionedNamspacedScopedCRDListOperationOnly(t *testing.T) { + stopCh, apiExtensionClient, dynamicClient, err := testserver.StartDefaultServerWithClients() + if err != nil { + t.Fatal(err) + } + defer close(stopCh) + + noxuDefinition := testserver.NewMultipleVersionNoxuCRD(apiextensionsv1beta1.NamespaceScoped) + err = testserver.CreateNewCustomResourceDefinition(noxuDefinition, apiExtensionClient, dynamicClient) + if err != nil { + t.Fatal(err) + } + + ns := "not-the-default" + noxuResourceClients := map[string]dynamic.DynamicResourceInterface{} + noxuWatchs := map[string]watch.Interface{} + //storageVersion := "" + for _, v := range noxuDefinition.Spec.Versions { + if v.Served { + noxuResourceClients[v.Name] = NewNamespacedCustomResourceVersionedClient(ns, dynamicClient, noxuDefinition, v.Name) + noxuWatchs[v.Name], err = noxuResourceClients[v.Name].Watch(metav1.ListOptions{}) + if err != nil { + t.Fatal(err) + } + } + } + version := "v1beta1" + createdNoxuInstance, err := instantiateVersionedCustomResource(t, testserver.NewVersionedNoxuInstance(ns, "foo", version), noxuResourceClients[version], noxuDefinition, version) + if err != nil { + t.Fatalf("unable to create noxu Instance:%v", err) + } + gottenNoxuInstance, err := noxuResourceClients[version].Get("foo", metav1.GetOptions{}) + if err != nil { + t.Fatal(err) + } + if e, a := createdNoxuInstance, gottenNoxuInstance; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } + listWithItem, err := noxuResourceClients[version].List(metav1.ListOptions{}) + if err != nil { + t.Fatal(err) + } + if e, a := 1, len(listWithItem.Items); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := *createdNoxuInstance, listWithItem.Items[0]; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } +} + +func testSimpleVersionedCRUD(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition, dynamicClient dynamic.DynamicInterface) { + var err error + noxuResourceClients := map[string]dynamic.DynamicResourceInterface{} + noxuWatchs := map[string]watch.Interface{} + for _, v := range noxuDefinition.Spec.Versions { + if v.Served { + noxuResourceClients[v.Name] = NewNamespacedCustomResourceVersionedClient(ns, dynamicClient, noxuDefinition, v.Name) + noxuWatchs[v.Name], err = noxuResourceClients[v.Name].Watch(metav1.ListOptions{}) + if err != nil { + t.Fatal(err) + } + } + } + defer func() { + for _, w := range noxuWatchs { + w.Stop() + } + }() + + for version, noxuResourceClient := range noxuResourceClients { + createdNoxuInstance, err := instantiateVersionedCustomResource(t, testserver.NewVersionedNoxuInstance(ns, "foo", version), noxuResourceClient, noxuDefinition, version) + if err != nil { + t.Fatalf("unable to create noxu Instance:%v", err) + } + if e, a := noxuDefinition.Spec.Group+"/"+version, createdNoxuInstance.GetAPIVersion(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + for watchVersion, noxuWatch := range noxuWatchs { + select { + case watchEvent := <-noxuWatch.ResultChan(): + if e, a := watch.Added, watchEvent.Type; e != a { + t.Errorf("expected %v, got %v", e, a) + break + } + createdObjectMeta, err := meta.Accessor(watchEvent.Object) + if err != nil { + t.Fatal(err) + } + // it should have a UUID + if len(createdObjectMeta.GetUID()) == 0 { + t.Errorf("missing uuid: %#v", watchEvent.Object) + } + if e, a := ns, createdObjectMeta.GetNamespace(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + createdTypeMeta, err := meta.TypeAccessor(watchEvent.Object) + if err != nil { + t.Fatal(err) + } + if e, a := noxuDefinition.Spec.Group+"/"+watchVersion, createdTypeMeta.GetAPIVersion(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := noxuDefinition.Spec.Names.Kind, createdTypeMeta.GetKind(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + case <-time.After(5 * time.Second): + t.Errorf("missing watch event") + } + } + + // Get test + // TODO(mehdy): This should be a loop getting all versions. + gottenNoxuInstance, err := noxuResourceClient.Get("foo", metav1.GetOptions{}) + if err != nil { + t.Fatal(err) + } + if e, a := createdNoxuInstance, gottenNoxuInstance; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } + + // List test + listWithItem, err := noxuResourceClient.List(metav1.ListOptions{}) + if err != nil { + t.Fatal(err) + } + if e, a := 1, len(listWithItem.Items); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := *createdNoxuInstance, listWithItem.Items[0]; !reflect.DeepEqual(e, a) { + t.Errorf("expected %v, got %v", e, a) + } + + // Delete test + if err := noxuResourceClient.Delete("foo", v1.NewDeleteOptions(0)); err != nil { + t.Fatal(err) + } + + listWithoutItem, err := noxuResourceClient.List(metav1.ListOptions{}) + if err != nil { + t.Fatal(err) + } + if e, a := 0, len(listWithoutItem.Items); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + for _, noxuWatch := range noxuWatchs { + select { + case watchEvent := <-noxuWatch.ResultChan(): + if e, a := watch.Deleted, watchEvent.Type; e != a { + t.Errorf("expected %v, got %v", e, a) + break + } + deletedObjectMeta, err := meta.Accessor(watchEvent.Object) + if err != nil { + t.Fatal(err) + } + // it should have a UUID + createdObjectMeta, err := meta.Accessor(createdNoxuInstance) + if err != nil { + t.Fatal(err) + } + if e, a := createdObjectMeta.GetUID(), deletedObjectMeta.GetUID(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + + case <-time.After(5 * time.Second): + t.Errorf("missing watch event") + } + } + + // Delete test + if err := noxuResourceClient.DeleteCollection(v1.NewDeleteOptions(0), v1.ListOptions{}); err != nil { + t.Fatal(err) + } + + } +} + func testSimpleCRUD(t *testing.T, ns string, noxuDefinition *apiextensionsv1beta1.CustomResourceDefinition, dynamicClient dynamic.DynamicInterface) { noxuResourceClient := NewNamespacedCustomResourceClient(ns, dynamicClient, noxuDefinition) initialList, err := noxuResourceClient.List(metav1.ListOptions{}) diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/helpers.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/helpers.go new file mode 100644 index 0000000000000..6c0b46933d169 --- /dev/null +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/helpers.go @@ -0,0 +1,46 @@ +/* +Copyright 2018 The Kubernetes 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. +*/ + +package integration + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" +) + +// UpdateCustomResourceDefinition updates a CRD, retrying up to 5 times on version conflict errors. +func UpdateCustomResourceDefinition(client clientset.Interface, name string, update func(*apiextensionsv1beta1.CustomResourceDefinition)) (*apiextensionsv1beta1.CustomResourceDefinition, error) { + for i := 0; i < 5; i++ { + crd, err := client.ApiextensionsV1beta1().CustomResourceDefinitions().Get(name, metav1.GetOptions{}) + if err != nil { + return nil, fmt.Errorf("failed to get Service %q: %v", name, err) + } + update(crd) + crd, err = client.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd) + if err == nil { + return crd, nil + } + if !errors.IsConflict(err) && !errors.IsServerTimeout(err) { + return nil, fmt.Errorf("failed to update CustomResourceDefinition %q: %v", name, err) + } + } + return nil, fmt.Errorf("too many retries updating CustomResourceDefinition %q", name) +} diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go index 9b5aa7bf39003..773a041fd9448 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go @@ -68,6 +68,42 @@ func instantiateCustomResource(t *testing.T, instanceToCreate *unstructured.Unst return createdInstance, nil } +func instantiateVersionedCustomResource(t *testing.T, instanceToCreate *unstructured.Unstructured, client dynamic.DynamicResourceInterface, definition *apiextensionsv1beta1.CustomResourceDefinition, version string) (*unstructured.Unstructured, error) { + createdInstance, err := client.Create(instanceToCreate) + if err != nil { + t.Logf("%#v", createdInstance) + return nil, err + } + createdObjectMeta, err := meta.Accessor(createdInstance) + if err != nil { + t.Fatal(err) + } + // it should have a UUID + if len(createdObjectMeta.GetUID()) == 0 { + t.Errorf("missing uuid: %#v", createdInstance) + } + createdTypeMeta, err := meta.TypeAccessor(createdInstance) + if err != nil { + t.Fatal(err) + } + if e, a := definition.Spec.Group+"/"+version, createdTypeMeta.GetAPIVersion(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + if e, a := definition.Spec.Names.Kind, createdTypeMeta.GetKind(); e != a { + t.Errorf("expected %v, got %v", e, a) + } + return createdInstance, nil +} + +func NewNamespacedCustomResourceVersionedClient(ns string, client dynamic.DynamicInterface, crd *apiextensionsv1beta1.CustomResourceDefinition, version string) dynamic.DynamicResourceInterface { + gvr := schema.GroupVersionResource{Group: crd.Spec.Group, Version: version, Resource: crd.Spec.Names.Plural} + + if crd.Spec.Scope != apiextensionsv1beta1.ClusterScoped { + return client.Resource(gvr).Namespace(ns) + } + return client.Resource(gvr) +} + func NewNamespacedCustomResourceClient(ns string, client dynamic.DynamicInterface, crd *apiextensionsv1beta1.CustomResourceDefinition) dynamic.DynamicResourceInterface { gvr := schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Spec.Names.Plural} diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/subresources_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/subresources_test.go index 763c0f9abf33c..8caa067578f7f 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/subresources_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/subresources_test.go @@ -22,7 +22,6 @@ import ( "sort" "strings" "testing" - "time" autoscaling "k8s.io/api/autoscaling/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -30,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" "k8s.io/client-go/dynamic" @@ -443,58 +441,31 @@ func TestValidateOnlyStatus(t *testing.T) { t.Fatalf("unable to create noxu instance: %v", err) } - gottenCRD, err := apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get("noxus.mygroup.example.com", metav1.GetOptions{}) + // update the spec with .spec.num = 5, expecting no error + err = unstructured.SetNestedField(createdNoxuInstance.Object, int64(5), "spec", "num") if err != nil { - t.Fatal(err) - } - - // update the crd so that max value of spec.num = 5 and status.num = 10 - gottenCRD.Spec.Validation.OpenAPIV3Schema = &apiextensionsv1beta1.JSONSchemaProps{ - Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{ - "spec": { - Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{ - "num": { - Type: "integer", - Maximum: float64Ptr(5), - }, - }, - }, - "status": { - Properties: map[string]apiextensionsv1beta1.JSONSchemaProps{ - "num": { - Type: "integer", - Maximum: float64Ptr(10), - }, - }, - }, - }, - } - - if _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(gottenCRD); err != nil { - t.Fatal(err) + t.Fatalf("unexpected error setting .spec.num: %v", err) } - - // update the status with .status.num = 5 - err = unstructured.SetNestedField(createdNoxuInstance.Object, int64(5), "status", "num") + createdNoxuInstance, err = noxuStatusResourceClient.Update(createdNoxuInstance) if err != nil { - t.Fatalf("unexpected error: %v", err) + t.Errorf("unexpected error: %v", err) } - // cr is updated even though spec is invalid - err = wait.Poll(500*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) { - _, err := noxuStatusResourceClient.Update(createdNoxuInstance) - if statusError, isStatus := err.(*apierrors.StatusError); isStatus { - if strings.Contains(statusError.Error(), "is invalid") { - return false, nil - } - } - if err != nil { - return false, err - } - return true, nil - }) + // update with .status.num = 15, expecting an error + err = unstructured.SetNestedField(createdNoxuInstance.Object, int64(15), "status", "num") if err != nil { - t.Fatal(err) + t.Fatalf("unexpected error setting .status.num: %v", err) + } + createdNoxuInstance, err = noxuStatusResourceClient.Update(createdNoxuInstance) + if err == nil { + t.Fatal("expected error, but got none") + } + statusError, isStatus := err.(*apierrors.StatusError) + if !isStatus || statusError == nil { + t.Fatalf("expected status error, got %T: %v", err, err) + } + if !strings.Contains(statusError.Error(), "cannot be handled as") { + t.Fatalf("expected 'is invalid' in error, got: %v", err) } } diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go index bb7060e38f863..e5a3c9d868043 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go @@ -99,6 +99,57 @@ func NewNoxuInstance(namespace, name string) *unstructured.Unstructured { } } +func NewMultipleVersionNoxuCRD(scope apiextensionsv1beta1.ResourceScope) *apiextensionsv1beta1.CustomResourceDefinition { + return &apiextensionsv1beta1.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{Name: "noxus.mygroup.example.com"}, + Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ + Group: "mygroup.example.com", + Version: "v1beta1", + Names: apiextensionsv1beta1.CustomResourceDefinitionNames{ + Plural: "noxus", + Singular: "nonenglishnoxu", + Kind: "WishIHadChosenNoxu", + ShortNames: []string{"foo", "bar", "abc", "def"}, + ListKind: "NoxuItemList", + Categories: []string{"all"}, + }, + Scope: scope, + Versions: []apiextensionsv1beta1.CustomResourceDefinitionVersion{ + { + Name: "v1beta1", + Served: true, + Storage: false, + }, + { + Name: "v1beta2", + Served: true, + Storage: true, + }, + }, + }, + } +} + +func NewVersionedNoxuInstance(namespace, name, version string) *unstructured.Unstructured { + return &unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": "mygroup.example.com/" + version, + "kind": "WishIHadChosenNoxu", + "metadata": map[string]interface{}{ + "namespace": namespace, + "name": name, + }, + "content": map[string]interface{}{ + "key": "value", + }, + "num": map[string]interface{}{ + "num1": noxuInstanceNum, + "num2": 1000000, + }, + }, + } +} + func NewNoxu2CustomResourceDefinition(scope apiextensionsv1beta1.ResourceScope) *apiextensionsv1beta1.CustomResourceDefinition { return &apiextensionsv1beta1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{Name: "noxus2.mygroup.example.com"}, @@ -160,20 +211,33 @@ func CreateNewCustomResourceDefinitionWatchUnsafe(crd *apiextensionsv1beta1.Cust return err } - // wait until the resource appears in discovery - err = wait.PollImmediate(500*time.Millisecond, 30*time.Second, func() (bool, error) { - resourceList, err := apiExtensionsClient.Discovery().ServerResourcesForGroupVersion(crd.Spec.Group + "/" + crd.Spec.Version) - if err != nil { - return false, nil - } - for _, resource := range resourceList.APIResources { - if resource.Name == crd.Spec.Names.Plural { - return true, nil + versions := []string{} + + if len(crd.Spec.Versions) != 0 { + for _, v := range crd.Spec.Versions { + if v.Served { + versions = append(versions, v.Name) } } - return false, nil - }) + } else { + versions = append(versions, crd.Spec.Version) + } + for _, version := range versions { + // wait until all the resource versions appear in discovery + err = wait.PollImmediate(500*time.Millisecond, 30*time.Second, func() (bool, error) { + resourceList, err := apiExtensionsClient.Discovery().ServerResourcesForGroupVersion(crd.Spec.Group + "/" + version) + if err != nil { + return false, nil + } + for _, resource := range resourceList.APIResources { + if resource.Name == crd.Spec.Names.Plural { + return true, nil + } + } + return false, nil + }) + } return err } diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go index aa5984aa2a39d..7892ce80a27a2 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go @@ -348,17 +348,14 @@ func TestCRValidationOnCRDUpdate(t *testing.T) { t.Fatalf("unexpected non-error: CR should be rejected") } - gottenCRD, err := apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get("noxus.mygroup.example.com", metav1.GetOptions{}) + _, err = UpdateCustomResourceDefinition(apiExtensionClient, "noxus.mygroup.example.com", func(crd *apiextensionsv1beta1.CustomResourceDefinition) { + // update the CRD to a less stricter schema + crd.Spec.Validation.OpenAPIV3Schema.Required = []string{"alpha", "beta"} + }) if err != nil { t.Fatal(err) } - // update the CRD to a less stricter schema - gottenCRD.Spec.Validation.OpenAPIV3Schema.Required = []string{"alpha", "beta"} - if _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(gottenCRD); err != nil { - t.Fatal(err) - } - // CR is now accepted err = wait.Poll(500*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) { _, err := noxuResourceClient.Create(newNoxuValidationInstance(ns, "foo")) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go index 60f0573623ae7..cf868603d3930 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/helpers.go @@ -18,11 +18,11 @@ package unstructured import ( gojson "encoding/json" - "errors" "fmt" "io" "strings" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -450,44 +450,3 @@ func (c JSONFallbackEncoder) Encode(obj runtime.Object, w io.Writer) error { } return err } - -// UnstructuredObjectConverter is an ObjectConverter for use with -// Unstructured objects. Since it has no schema or type information, -// it will only succeed for no-op conversions. This is provided as a -// sane implementation for APIs that require an object converter. -type UnstructuredObjectConverter struct{} - -func (UnstructuredObjectConverter) Convert(in, out, context interface{}) error { - unstructIn, ok := in.(*Unstructured) - if !ok { - return fmt.Errorf("input type %T in not valid for unstructured conversion", in) - } - - unstructOut, ok := out.(*Unstructured) - if !ok { - return fmt.Errorf("output type %T in not valid for unstructured conversion", out) - } - - // maybe deep copy the map? It is documented in the - // ObjectConverter interface that this function is not - // guaranteed to not mutate the input. Or maybe set the input - // object to nil. - unstructOut.Object = unstructIn.Object - return nil -} - -func (UnstructuredObjectConverter) ConvertToVersion(in runtime.Object, target runtime.GroupVersioner) (runtime.Object, error) { - if kind := in.GetObjectKind().GroupVersionKind(); !kind.Empty() { - gvk, ok := target.KindForGroupVersionKinds([]schema.GroupVersionKind{kind}) - if !ok { - // TODO: should this be a typed error? - return nil, fmt.Errorf("%v is unstructured and is not suitable for converting to %q", kind, target) - } - in.GetObjectKind().SetGroupVersionKind(gvk) - } - return in, nil -} - -func (UnstructuredObjectConverter) ConvertFieldLabel(version, kind, label, value string) (string, string, error) { - return "", "", errors.New("unstructured cannot convert field labels") -} diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go index 48df6b5dd1826..b9d363cd0f008 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go @@ -170,17 +170,20 @@ func (c *codec) Encode(obj runtime.Object, w io.Writer) error { case *runtime.Unknown: return c.encoder.Encode(obj, w) case runtime.Unstructured: - // avoid conversion roundtrip if GVK is the right one already or is empty (yes, this is a hack, but the old behaviour we rely on in kubectl) - objGVK := obj.GetObjectKind().GroupVersionKind() - if len(objGVK.Version) == 0 { - return c.encoder.Encode(obj, w) - } - targetGVK, ok := c.encodeVersion.KindForGroupVersionKinds([]schema.GroupVersionKind{objGVK}) - if !ok { - return runtime.NewNotRegisteredGVKErrForTarget(objGVK, c.encodeVersion) - } - if targetGVK == objGVK { - return c.encoder.Encode(obj, w) + // Only avoid conversion if unstructed is not a list, giving the converter a chance to convert list items. + if !obj.IsList() { + // avoid conversion roundtrip if GVK is the right one already or is empty (yes, this is a hack, but the old behaviour we rely on in kubectl) + objGVK := obj.GetObjectKind().GroupVersionKind() + if len(objGVK.Version) == 0 { + return c.encoder.Encode(obj, w) + } + targetGVK, ok := c.encodeVersion.KindForGroupVersionKinds([]schema.GroupVersionKind{objGVK}) + if !ok { + return runtime.NewNotRegisteredGVKErrForTarget(objGVK, c.encodeVersion) + } + if targetGVK == objGVK { + return c.encoder.Encode(obj, w) + } } }