Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CRD compatibility fixtures #116039

Merged
merged 5 commits into from Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion api/api-rules/aggregator_violation_exceptions.list
Expand Up @@ -34,4 +34,3 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,Raw
1 change: 0 additions & 1 deletion api/api-rules/apiextensions_violation_exceptions.list
Expand Up @@ -34,4 +34,3 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,Raw
1 change: 0 additions & 1 deletion api/api-rules/codegen_violation_exceptions.list
Expand Up @@ -34,7 +34,6 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,Raw
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example/v1,TestTypeStatus,Blah
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example2/v1,TestTypeStatus,Blah
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example3.io/v1,TestTypeStatus,Blah
1 change: 0 additions & 1 deletion api/api-rules/sample_apiserver_violation_exceptions.list
Expand Up @@ -35,4 +35,3 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,Raw
3 changes: 0 additions & 3 deletions api/api-rules/violation_exceptions.list
Expand Up @@ -378,7 +378,6 @@ API rule violation: names_match,k8s.io/api/core/v1,VolumeSource,CephFS
API rule violation: names_match,k8s.io/api/core/v1,VolumeSource,StorageOS
API rule violation: names_match,k8s.io/api/networking/v1alpha1,ClusterCIDRSpec,IPv4
API rule violation: names_match,k8s.io/api/networking/v1alpha1,ClusterCIDRSpec,IPv6
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSON,Raw
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaProps,Ref
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaProps,Schema
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaProps,XEmbeddedResource
Expand All @@ -395,7 +394,6 @@ API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiexten
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaPropsOrStringArray,Property
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaPropsOrStringArray,Schema
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,CustomResourceColumnDefinition,JSONPath
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSON,Raw
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,Ref
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,Schema
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,XEmbeddedResource
Expand Down Expand Up @@ -426,7 +424,6 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,Raw
API rule violation: names_match,k8s.io/apimachinery/pkg/util/intstr,IntOrString,IntVal
API rule violation: names_match,k8s.io/apimachinery/pkg/util/intstr,IntOrString,StrVal
API rule violation: names_match,k8s.io/apimachinery/pkg/util/intstr,IntOrString,Type
Expand Down
3 changes: 3 additions & 0 deletions hack/update-generated-api-compatibility-data.sh
Expand Up @@ -28,12 +28,15 @@ export GO111MODULE=on

# Nuke old files so we don't accidentally carry stuff forward.
rm -f staging/src/k8s.io/api/testdata/HEAD/*.{yaml,json,pb}
rm -f staging/src/k8s.io/apiextensions-apiserver/pkg/apis/testdata/HEAD/*.{yaml,json,pb}

# UPDATE_COMPATIBILITY_FIXTURE_DATA=true regenerates fixture data if needed.
# -run //HEAD only runs the test cases comparing against testdata for HEAD.
# We suppress the output because we are expecting to have changes.
# We suppress the test failure that occurs when there are changes.
UPDATE_COMPATIBILITY_FIXTURE_DATA=true go test k8s.io/api -run //HEAD >/dev/null 2>&1 || true
UPDATE_COMPATIBILITY_FIXTURE_DATA=true go test k8s.io/apiextensions-apiserver/pkg/apis -run //HEAD >/dev/null 2>&1 || true

# Now that we have regenerated data at HEAD, run the test without suppressing output or failures
go test k8s.io/api -run //HEAD -count=1
go test k8s.io/apiextensions-apiserver/pkg/apis -run //HEAD -count=1
9 changes: 1 addition & 8 deletions pkg/generated/openapi/zz_generated.openapi.go

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

Expand Up @@ -240,7 +240,7 @@ type ValidationRule struct {
// JSON represents any valid JSON value.
// These types are supported: bool, int64, float64, string, []interface{}, map[string]interface{} and nil.
type JSON struct {
Raw []byte `protobuf:"bytes,1,opt,name=raw"`
Raw []byte `json:"-" protobuf:"bytes,1,opt,name=raw"`
}

// OpenAPISchemaType is used by the kube-openapi generator when constructing
Expand Down
Expand Up @@ -240,7 +240,7 @@ type ValidationRule struct {
// JSON represents any valid JSON value.
// These types are supported: bool, int64, float64, string, []interface{}, map[string]interface{} and nil.
type JSON struct {
Raw []byte `protobuf:"bytes,1,opt,name=raw"`
Raw []byte `json:"-" protobuf:"bytes,1,opt,name=raw"`
}

// OpenAPISchemaType is used by the kube-openapi generator when constructing
Expand Down
@@ -0,0 +1,69 @@
/*
Copyright 2023 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 api

import (
"reflect"
"strconv"
"testing"

"github.com/stretchr/testify/require"

apiextensionv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
_ "k8s.io/apimachinery/pkg/runtime/serializer"
)

var groups = []runtime.SchemeBuilder{
apiextensionv1.SchemeBuilder,
apiextensionv1beta1.SchemeBuilder,
}

func TestCompatibility(t *testing.T) {
scheme := runtime.NewScheme()
for _, builder := range groups {
require.NoError(t, builder.AddToScheme(scheme))
}

opts := roundtrip.NewCompatibilityTestOptions(scheme)

// Fill unstructured JSON field types
opts.FillFuncs = map[reflect.Type]roundtrip.FillFunc{
reflect.TypeOf(&apiextensionv1.JSON{}): func(s string, i int, obj interface{}) {
obj.(*apiextensionv1.JSON).Raw = []byte(strconv.Quote(s + "Value"))
},
reflect.TypeOf(&apiextensionv1beta1.JSON{}): func(s string, i int, obj interface{}) {
obj.(*apiextensionv1beta1.JSON).Raw = []byte(strconv.Quote(s + "Value"))
},
}

opts.Complete(t)

// limit to types in apiextensions.k8s.io
filteredKinds := []schema.GroupVersionKind{}
for _, gvk := range opts.Kinds {
if gvk.Group == apiextensionv1.SchemeGroupVersion.Group {
filteredKinds = append(filteredKinds, gvk)
}
}
opts.Kinds = filteredKinds

opts.Run(t)
}
@@ -0,0 +1,61 @@
{
"kind": "ConversionReview",
"apiVersion": "apiextensions.k8s.io/v1",
"request": {
"uid": "uidValue",
"desiredAPIVersion": "desiredAPIVersionValue",
"objects": [
{
"apiVersion": "example.com/v1",
"kind": "CustomType",
"spec": {
"replicas": 1
},
"status": {
"available": 1
}
}
]
},
"response": {
"uid": "uidValue",
"convertedObjects": [
{
"apiVersion": "example.com/v1",
"kind": "CustomType",
"spec": {
"replicas": 1
},
"status": {
"available": 1
}
}
],
"result": {
"metadata": {
"selfLink": "selfLinkValue",
"resourceVersion": "resourceVersionValue",
"continue": "continueValue",
"remainingItemCount": 4
},
"status": "statusValue",
"message": "messageValue",
"reason": "reasonValue",
"details": {
"name": "nameValue",
"group": "groupValue",
"kind": "kindValue",
"uid": "uidValue",
"causes": [
{
"reason": "reasonValue",
"message": "messageValue",
"field": "fieldValue"
}
],
"retryAfterSeconds": 5
},
"code": 6
}
}
}
Binary file not shown.
@@ -0,0 +1,41 @@
apiVersion: apiextensions.k8s.io/v1
kind: ConversionReview
request:
desiredAPIVersion: desiredAPIVersionValue
objects:
- apiVersion: example.com/v1
kind: CustomType
spec:
replicas: 1
status:
available: 1
uid: uidValue
response:
convertedObjects:
- apiVersion: example.com/v1
kind: CustomType
spec:
replicas: 1
status:
available: 1
result:
code: 6
details:
causes:
- field: fieldValue
message: messageValue
reason: reasonValue
group: groupValue
kind: kindValue
name: nameValue
retryAfterSeconds: 5
uid: uidValue
message: messageValue
metadata:
continue: continueValue
remainingItemCount: 4
resourceVersion: resourceVersionValue
selfLink: selfLinkValue
reason: reasonValue
status: statusValue
uid: uidValue