Merge pull request #88607 from caesarxuchao/add-storage-version-api

Add the storage version API
This commit is contained in:
Kubernetes Prow Robot 2020-06-03 19:20:43 -07:00 committed by GitHub
commit 1bc526aa6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 3569 additions and 0 deletions

View File

@ -86,6 +86,7 @@ tags_values_pkgs = {"openapi-gen": {
"staging/src/k8s.io/apimachinery/pkg/runtime", "staging/src/k8s.io/apimachinery/pkg/runtime",
"staging/src/k8s.io/apimachinery/pkg/util/intstr", "staging/src/k8s.io/apimachinery/pkg/util/intstr",
"staging/src/k8s.io/apimachinery/pkg/version", "staging/src/k8s.io/apimachinery/pkg/version",
"staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1",
"staging/src/k8s.io/apiserver/pkg/apis/audit/v1", "staging/src/k8s.io/apiserver/pkg/apis/audit/v1",
"staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1", "staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1",
"staging/src/k8s.io/apiserver/pkg/apis/audit/v1beta1", "staging/src/k8s.io/apiserver/pkg/apis/audit/v1beta1",
@ -168,6 +169,7 @@ tags_pkgs_values = {"openapi-gen": {
"staging/src/k8s.io/apimachinery/pkg/runtime": ["true"], "staging/src/k8s.io/apimachinery/pkg/runtime": ["true"],
"staging/src/k8s.io/apimachinery/pkg/util/intstr": ["true"], "staging/src/k8s.io/apimachinery/pkg/util/intstr": ["true"],
"staging/src/k8s.io/apimachinery/pkg/version": ["true"], "staging/src/k8s.io/apimachinery/pkg/version": ["true"],
"staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1": ["true"],
"staging/src/k8s.io/apiserver/pkg/apis/audit/v1": ["true"], "staging/src/k8s.io/apiserver/pkg/apis/audit/v1": ["true"],
"staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1": ["true"], "staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1": ["true"],
"staging/src/k8s.io/apiserver/pkg/apis/audit/v1beta1": ["true"], "staging/src/k8s.io/apiserver/pkg/apis/audit/v1beta1": ["true"],

View File

@ -309,6 +309,8 @@ staging/src/k8s.io/apiserver/pkg/apis/apiserver
staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1 staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1
staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1alpha1 staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1alpha1
staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1beta1 staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1beta1
staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal
staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1
staging/src/k8s.io/apiserver/pkg/apis/audit staging/src/k8s.io/apiserver/pkg/apis/audit
staging/src/k8s.io/apiserver/pkg/apis/audit/v1 staging/src/k8s.io/apiserver/pkg/apis/audit/v1
staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1 staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1

View File

@ -11,6 +11,7 @@ filegroup(
":package-srcs", ":package-srcs",
"//staging/src/k8s.io/apiserver/pkg/admission:all-srcs", "//staging/src/k8s.io/apiserver/pkg/admission:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserver:all-srcs", "//staging/src/k8s.io/apiserver/pkg/apis/apiserver:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/audit:all-srcs", "//staging/src/k8s.io/apiserver/pkg/apis/audit:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/config:all-srcs", "//staging/src/k8s.io/apiserver/pkg/apis/config:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/example:all-srcs", "//staging/src/k8s.io/apiserver/pkg/apis/example:all-srcs",

View File

@ -0,0 +1,42 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"register.go",
"types.go",
"zz_generated.deepcopy.go",
],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/apis/apiserverinternal",
importpath = "k8s.io/apiserver/pkg/apis/apiserverinternal",
deps = [
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/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",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/fuzzer:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/install:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1:all-srcs",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/validation:all-srcs",
],
tags = ["automanaged"],
)

View File

@ -0,0 +1,22 @@
/*
Copyright 2019 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.
*/
// +k8s:deepcopy-gen=package
// +groupName=internal.apiserver.k8s.io
// Package apiserverinternal contains the "internal" version of the API used by
// the apiservers themselves.
package apiserverinternal // import "k8s.io/apiserver/pkg/apis/apiserverinternal"

View File

@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["fuzzer.go"],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/apis/apiserverinternal/fuzzer",
importpath = "k8s.io/apiserver/pkg/apis/apiserverinternal/fuzzer",
visibility = ["//visibility:public"],
deps = ["//staging/src/k8s.io/apimachinery/pkg/runtime/serializer: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"],
)

View File

@ -0,0 +1,26 @@
/*
Copyright 2019 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 fuzzer
import (
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
)
// Funcs returns the fuzzer functions for the apiserverinternal api group.
func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{}
}

View File

@ -0,0 +1,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["install.go"],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/apis/apiserverinternal/install",
importpath = "k8s.io/apiserver/pkg/apis/apiserverinternal/install",
deps = [
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = ["roundtrip_test.go"],
embed = [":go_default_library"],
deps = [
"//staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal/fuzzer:go_default_library",
],
)

View File

@ -0,0 +1,33 @@
/*
Copyright 2019 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 install installs the experimental API group, making it available as
// an option to all of the API encoding/decoding machinery.
package install
import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apiserver/pkg/apis/apiserverinternal"
"k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1"
)
// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(apiserverinternal.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1alpha1.SchemeGroupVersion))
}

View File

@ -0,0 +1,29 @@
/*
Copyright 2019 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 install
import (
"testing"
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
"k8s.io/apiserver/pkg/apis/apiserverinternal/fuzzer"
)
func TestRoundTrip(t *testing.T) {
roundtrip.RoundTripTestForAPIGroup(t, Install, fuzzer.Funcs)
roundtrip.RoundTripProtobufTestForAPIGroup(t, Install, fuzzer.Funcs)
}

View File

@ -0,0 +1,53 @@
/*
Copyright 2019 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 apiserverinternal
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name use in this package
const GroupName = "internal.apiserver.k8s.io"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}
// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
// SchemeBuilder is the scheme builder with scheme init functions to run for this API package.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&StorageVersion{},
&StorageVersionList{},
)
return nil
}

View File

@ -0,0 +1,120 @@
/*
Copyright 2019 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 apiserverinternal
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Storage version of a specific resource.
type StorageVersion struct {
metav1.TypeMeta
// The name is <group>.<resource>.
metav1.ObjectMeta
// Spec is an empty spec. It is here to comply with Kubernetes API style.
Spec StorageVersionSpec
// API server instances report the version they can decode and the version they
// encode objects to when persisting objects in the backend.
Status StorageVersionStatus
}
// StorageVersionSpec is an empty spec.
type StorageVersionSpec struct{}
// API server instances report the versions they can decode and the version they
// encode objects to when persisting objects in the backend.
type StorageVersionStatus struct {
// The reported versions per API server instance.
// +optional
StorageVersions []ServerStorageVersion
// If all API server instances agree on the same encoding storage version,
// then this field is set to that version. Otherwise this field is left empty.
// API servers should finish updating its storageVersionStatus entry before
// serving write operations, so that this field will be in sync with the reality.
// +optional
CommonEncodingVersion *string
// The latest available observations of the storageVersion's state.
// +optional
Conditions []StorageVersionCondition
}
// An API server instance reports the version it can decode and the version it
// encodes objects to when persisting objects in the backend.
type ServerStorageVersion struct {
// The ID of the reporting API server.
APIServerID string
// The API server encodes the object to this version when persisting it in
// the backend (e.g., etcd).
EncodingVersion string
// The API server can decode objects encoded in these versions.
// The encodingVersion must be included in the decodableVersions.
DecodableVersions []string
}
type StorageVersionConditionType string
const (
// Indicates that encoding storage versions reported by all servers are equal.
AllEncodingVersionsEqual StorageVersionConditionType = "AllEncodingVersionsEqual"
)
type ConditionStatus string
const (
ConditionTrue ConditionStatus = "True"
ConditionFalse ConditionStatus = "False"
ConditionUnknown ConditionStatus = "Unknown"
)
// Describes the state of the storageVersion at a certain point.
type StorageVersionCondition struct {
// Type of the condition.
// +optional
Type StorageVersionConditionType
// Status of the condition, one of True, False, Unknown.
// +required
Status ConditionStatus
// If set, this represents the .metadata.generation that the condition was set based upon.
// +optional
ObservedGeneration int64
// Last time the condition transitioned from one status to another.
// +required
LastTransitionTime metav1.Time
// The reason for the condition's last transition.
// +required
Reason string
// A human readable message indicating details about the transition.
// +required
Message string
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// A list of StorageVersions.
type StorageVersionList struct {
metav1.TypeMeta
// +optional
metav1.ListMeta
Items []StorageVersion
}

View File

@ -0,0 +1,39 @@
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"zz_generated.conversion.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1",
importpath = "k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1",
deps = [
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

View File

@ -0,0 +1,27 @@
/*
Copyright 2019 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.
*/
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=package
// +k8s:conversion-gen=k8s.io/apiserver/pkg/apis/apiserverinternal
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +groupName=internal.apiserver.k8s.io
// Package v1alpha1 contains the v1alpha1 version of the API used by the
// apiservers themselves.
package v1alpha1 // import "k8s.io/apiserver/pkg/apis/apiserverinternal/v1alpha1"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,121 @@
/*
Copyright 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.
*/
// This file was autogenerated by go-to-protobuf. Do not edit it manually!
syntax = 'proto2';
package k8s.io.apiserver.pkg.apis.apiserverinternal.v1alpha1;
import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto";
// Package-wide variables from generator "generated".
option go_package = "v1alpha1";
// An API server instance reports the version it can decode and the version it
// encodes objects to when persisting objects in the backend.
message ServerStorageVersion {
// The ID of the reporting API server.
optional string apiServerID = 1;
// The API server encodes the object to this version when persisting it in
// the backend (e.g., etcd).
optional string encodingVersion = 2;
// The API server can decode objects encoded in these versions.
// The encodingVersion must be included in the decodableVersions.
// +listType=set
repeated string decodableVersions = 3;
}
// Storage version of a specific resource.
message StorageVersion {
// The name is <group>.<resource>.
optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
// Spec is an empty spec. It is here to comply with Kubernetes API style.
optional StorageVersionSpec spec = 2;
// API server instances report the version they can decode and the version they
// encode objects to when persisting objects in the backend.
optional StorageVersionStatus status = 3;
}
// Describes the state of the storageVersion at a certain point.
message StorageVersionCondition {
// Type of the condition.
// +required
optional string type = 1;
// Status of the condition, one of True, False, Unknown.
// +required
optional string status = 2;
// If set, this represents the .metadata.generation that the condition was set based upon.
// +optional
optional int64 observedGeneration = 3;
// Last time the condition transitioned from one status to another.
// +required
optional k8s.io.apimachinery.pkg.apis.meta.v1.Time lastTransitionTime = 4;
// The reason for the condition's last transition.
// +required
optional string reason = 5;
// A human readable message indicating details about the transition.
// +required
optional string message = 6;
}
// A list of StorageVersions.
message StorageVersionList {
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
repeated StorageVersion items = 2;
}
// StorageVersionSpec is an empty spec.
message StorageVersionSpec {
}
// API server instances report the versions they can decode and the version they
// encode objects to when persisting objects in the backend.
message StorageVersionStatus {
// The reported versions per API server instance.
// +optional
// +listType=map
// +listMapKey=apiserverID
repeated ServerStorageVersion storageVersions = 1;
// If all API server instances agree on the same encoding storage version,
// then this field is set to that version. Otherwise this field is left empty.
// API servers should finish updating its storageVersionStatus entry before
// serving write operations, so that this field will be in sync with the reality.
// +optional
optional string commonEncodingVersion = 2;
// The latest available observations of the storageVersion's state.
// +optional
// +listType=map
// +listMapKey=type
repeated StorageVersionCondition conditions = 3;
}

View File

@ -0,0 +1,56 @@
/*
Copyright 2019 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 v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name use in this package
const GroupName = "internal.apiserver.k8s.io"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)
func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&StorageVersion{},
&StorageVersionList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

View File

@ -0,0 +1,127 @@
/*
Copyright 2019 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 v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Storage version of a specific resource.
type StorageVersion struct {
metav1.TypeMeta `json:",inline"`
// The name is <group>.<resource>.
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Spec is an empty spec. It is here to comply with Kubernetes API style.
Spec StorageVersionSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
// API server instances report the version they can decode and the version they
// encode objects to when persisting objects in the backend.
Status StorageVersionStatus `json:"status" protobuf:"bytes,3,opt,name=status"`
}
// StorageVersionSpec is an empty spec.
type StorageVersionSpec struct{}
// API server instances report the versions they can decode and the version they
// encode objects to when persisting objects in the backend.
type StorageVersionStatus struct {
// The reported versions per API server instance.
// +optional
// +listType=map
// +listMapKey=apiserverID
StorageVersions []ServerStorageVersion `json:"storageVersions,omitempty" protobuf:"bytes,1,opt,name=storageVersions"`
// If all API server instances agree on the same encoding storage version,
// then this field is set to that version. Otherwise this field is left empty.
// API servers should finish updating its storageVersionStatus entry before
// serving write operations, so that this field will be in sync with the reality.
// +optional
CommonEncodingVersion *string `json:"commonEncodingVersion,omitempty" protobuf:"bytes,2,opt,name=commonEncodingVersion"`
// The latest available observations of the storageVersion's state.
// +optional
// +listType=map
// +listMapKey=type
Conditions []StorageVersionCondition `json:"conditions,omitempty" protobuf:"bytes,3,opt,name=conditions"`
}
// An API server instance reports the version it can decode and the version it
// encodes objects to when persisting objects in the backend.
type ServerStorageVersion struct {
// The ID of the reporting API server.
APIServerID string `json:"apiServerID,omitempty" protobuf:"bytes,1,opt,name=apiServerID"`
// The API server encodes the object to this version when persisting it in
// the backend (e.g., etcd).
EncodingVersion string `json:"encodingVersion,omitempty" protobuf:"bytes,2,opt,name=encodingVersion"`
// The API server can decode objects encoded in these versions.
// The encodingVersion must be included in the decodableVersions.
// +listType=set
DecodableVersions []string `json:"decodableVersions,omitempty" protobuf:"bytes,3,opt,name=decodableVersions"`
}
type StorageVersionConditionType string
const (
// Indicates that encoding storage versions reported by all servers are equal.
AllEncodingVersionsEqual StorageVersionConditionType = "AllEncodingVersionsEqual"
)
type ConditionStatus string
const (
ConditionTrue ConditionStatus = "True"
ConditionFalse ConditionStatus = "False"
ConditionUnknown ConditionStatus = "Unknown"
)
// Describes the state of the storageVersion at a certain point.
type StorageVersionCondition struct {
// Type of the condition.
// +required
Type StorageVersionConditionType `json:"type" protobuf:"bytes,1,opt,name=type"`
// Status of the condition, one of True, False, Unknown.
// +required
Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status"`
// If set, this represents the .metadata.generation that the condition was set based upon.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
// Last time the condition transitioned from one status to another.
// +required
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
// The reason for the condition's last transition.
// +required
Reason string `json:"reason" protobuf:"bytes,5,opt,name=reason"`
// A human readable message indicating details about the transition.
// +required
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// A list of StorageVersions.
type StorageVersionList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []StorageVersion `json:"items" protobuf:"bytes,2,rep,name=items"`
}

View File

@ -0,0 +1,249 @@
// +build !ignore_autogenerated
/*
Copyright 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.
*/
// Code generated by conversion-gen. DO NOT EDIT.
package v1alpha1
import (
unsafe "unsafe"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
apiserverinternal "k8s.io/apiserver/pkg/apis/apiserverinternal"
)
func init() {
localSchemeBuilder.Register(RegisterConversions)
}
// RegisterConversions adds conversion functions to the given scheme.
// Public to allow building arbitrary schemes.
func RegisterConversions(s *runtime.Scheme) error {
if err := s.AddGeneratedConversionFunc((*ServerStorageVersion)(nil), (*apiserverinternal.ServerStorageVersion)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_ServerStorageVersion_To_apiserverinternal_ServerStorageVersion(a.(*ServerStorageVersion), b.(*apiserverinternal.ServerStorageVersion), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*apiserverinternal.ServerStorageVersion)(nil), (*ServerStorageVersion)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_apiserverinternal_ServerStorageVersion_To_v1alpha1_ServerStorageVersion(a.(*apiserverinternal.ServerStorageVersion), b.(*ServerStorageVersion), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*StorageVersion)(nil), (*apiserverinternal.StorageVersion)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_StorageVersion_To_apiserverinternal_StorageVersion(a.(*StorageVersion), b.(*apiserverinternal.StorageVersion), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*apiserverinternal.StorageVersion)(nil), (*StorageVersion)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_apiserverinternal_StorageVersion_To_v1alpha1_StorageVersion(a.(*apiserverinternal.StorageVersion), b.(*StorageVersion), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*StorageVersionCondition)(nil), (*apiserverinternal.StorageVersionCondition)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_StorageVersionCondition_To_apiserverinternal_StorageVersionCondition(a.(*StorageVersionCondition), b.(*apiserverinternal.StorageVersionCondition), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*apiserverinternal.StorageVersionCondition)(nil), (*StorageVersionCondition)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_apiserverinternal_StorageVersionCondition_To_v1alpha1_StorageVersionCondition(a.(*apiserverinternal.StorageVersionCondition), b.(*StorageVersionCondition), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*StorageVersionList)(nil), (*apiserverinternal.StorageVersionList)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_StorageVersionList_To_apiserverinternal_StorageVersionList(a.(*StorageVersionList), b.(*apiserverinternal.StorageVersionList), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*apiserverinternal.StorageVersionList)(nil), (*StorageVersionList)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_apiserverinternal_StorageVersionList_To_v1alpha1_StorageVersionList(a.(*apiserverinternal.StorageVersionList), b.(*StorageVersionList), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*StorageVersionSpec)(nil), (*apiserverinternal.StorageVersionSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_StorageVersionSpec_To_apiserverinternal_StorageVersionSpec(a.(*StorageVersionSpec), b.(*apiserverinternal.StorageVersionSpec), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*apiserverinternal.StorageVersionSpec)(nil), (*StorageVersionSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_apiserverinternal_StorageVersionSpec_To_v1alpha1_StorageVersionSpec(a.(*apiserverinternal.StorageVersionSpec), b.(*StorageVersionSpec), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*StorageVersionStatus)(nil), (*apiserverinternal.StorageVersionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_StorageVersionStatus_To_apiserverinternal_StorageVersionStatus(a.(*StorageVersionStatus), b.(*apiserverinternal.StorageVersionStatus), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*apiserverinternal.StorageVersionStatus)(nil), (*StorageVersionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_apiserverinternal_StorageVersionStatus_To_v1alpha1_StorageVersionStatus(a.(*apiserverinternal.StorageVersionStatus), b.(*StorageVersionStatus), scope)
}); err != nil {
return err
}
return nil
}
func autoConvert_v1alpha1_ServerStorageVersion_To_apiserverinternal_ServerStorageVersion(in *ServerStorageVersion, out *apiserverinternal.ServerStorageVersion, s conversion.Scope) error {
out.APIServerID = in.APIServerID
out.EncodingVersion = in.EncodingVersion
out.DecodableVersions = *(*[]string)(unsafe.Pointer(&in.DecodableVersions))
return nil
}
// Convert_v1alpha1_ServerStorageVersion_To_apiserverinternal_ServerStorageVersion is an autogenerated conversion function.
func Convert_v1alpha1_ServerStorageVersion_To_apiserverinternal_ServerStorageVersion(in *ServerStorageVersion, out *apiserverinternal.ServerStorageVersion, s conversion.Scope) error {
return autoConvert_v1alpha1_ServerStorageVersion_To_apiserverinternal_ServerStorageVersion(in, out, s)
}
func autoConvert_apiserverinternal_ServerStorageVersion_To_v1alpha1_ServerStorageVersion(in *apiserverinternal.ServerStorageVersion, out *ServerStorageVersion, s conversion.Scope) error {
out.APIServerID = in.APIServerID
out.EncodingVersion = in.EncodingVersion
out.DecodableVersions = *(*[]string)(unsafe.Pointer(&in.DecodableVersions))
return nil
}
// Convert_apiserverinternal_ServerStorageVersion_To_v1alpha1_ServerStorageVersion is an autogenerated conversion function.
func Convert_apiserverinternal_ServerStorageVersion_To_v1alpha1_ServerStorageVersion(in *apiserverinternal.ServerStorageVersion, out *ServerStorageVersion, s conversion.Scope) error {
return autoConvert_apiserverinternal_ServerStorageVersion_To_v1alpha1_ServerStorageVersion(in, out, s)
}
func autoConvert_v1alpha1_StorageVersion_To_apiserverinternal_StorageVersion(in *StorageVersion, out *apiserverinternal.StorageVersion, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
if err := Convert_v1alpha1_StorageVersionSpec_To_apiserverinternal_StorageVersionSpec(&in.Spec, &out.Spec, s); err != nil {
return err
}
if err := Convert_v1alpha1_StorageVersionStatus_To_apiserverinternal_StorageVersionStatus(&in.Status, &out.Status, s); err != nil {
return err
}
return nil
}
// Convert_v1alpha1_StorageVersion_To_apiserverinternal_StorageVersion is an autogenerated conversion function.
func Convert_v1alpha1_StorageVersion_To_apiserverinternal_StorageVersion(in *StorageVersion, out *apiserverinternal.StorageVersion, s conversion.Scope) error {
return autoConvert_v1alpha1_StorageVersion_To_apiserverinternal_StorageVersion(in, out, s)
}
func autoConvert_apiserverinternal_StorageVersion_To_v1alpha1_StorageVersion(in *apiserverinternal.StorageVersion, out *StorageVersion, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
if err := Convert_apiserverinternal_StorageVersionSpec_To_v1alpha1_StorageVersionSpec(&in.Spec, &out.Spec, s); err != nil {
return err
}
if err := Convert_apiserverinternal_StorageVersionStatus_To_v1alpha1_StorageVersionStatus(&in.Status, &out.Status, s); err != nil {
return err
}
return nil
}
// Convert_apiserverinternal_StorageVersion_To_v1alpha1_StorageVersion is an autogenerated conversion function.
func Convert_apiserverinternal_StorageVersion_To_v1alpha1_StorageVersion(in *apiserverinternal.StorageVersion, out *StorageVersion, s conversion.Scope) error {
return autoConvert_apiserverinternal_StorageVersion_To_v1alpha1_StorageVersion(in, out, s)
}
func autoConvert_v1alpha1_StorageVersionCondition_To_apiserverinternal_StorageVersionCondition(in *StorageVersionCondition, out *apiserverinternal.StorageVersionCondition, s conversion.Scope) error {
out.Type = apiserverinternal.StorageVersionConditionType(in.Type)
out.Status = apiserverinternal.ConditionStatus(in.Status)
out.ObservedGeneration = in.ObservedGeneration
out.LastTransitionTime = in.LastTransitionTime
out.Reason = in.Reason
out.Message = in.Message
return nil
}
// Convert_v1alpha1_StorageVersionCondition_To_apiserverinternal_StorageVersionCondition is an autogenerated conversion function.
func Convert_v1alpha1_StorageVersionCondition_To_apiserverinternal_StorageVersionCondition(in *StorageVersionCondition, out *apiserverinternal.StorageVersionCondition, s conversion.Scope) error {
return autoConvert_v1alpha1_StorageVersionCondition_To_apiserverinternal_StorageVersionCondition(in, out, s)
}
func autoConvert_apiserverinternal_StorageVersionCondition_To_v1alpha1_StorageVersionCondition(in *apiserverinternal.StorageVersionCondition, out *StorageVersionCondition, s conversion.Scope) error {
out.Type = StorageVersionConditionType(in.Type)
out.Status = ConditionStatus(in.Status)
out.ObservedGeneration = in.ObservedGeneration
out.LastTransitionTime = in.LastTransitionTime
out.Reason = in.Reason
out.Message = in.Message
return nil
}
// Convert_apiserverinternal_StorageVersionCondition_To_v1alpha1_StorageVersionCondition is an autogenerated conversion function.
func Convert_apiserverinternal_StorageVersionCondition_To_v1alpha1_StorageVersionCondition(in *apiserverinternal.StorageVersionCondition, out *StorageVersionCondition, s conversion.Scope) error {
return autoConvert_apiserverinternal_StorageVersionCondition_To_v1alpha1_StorageVersionCondition(in, out, s)
}
func autoConvert_v1alpha1_StorageVersionList_To_apiserverinternal_StorageVersionList(in *StorageVersionList, out *apiserverinternal.StorageVersionList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]apiserverinternal.StorageVersion)(unsafe.Pointer(&in.Items))
return nil
}
// Convert_v1alpha1_StorageVersionList_To_apiserverinternal_StorageVersionList is an autogenerated conversion function.
func Convert_v1alpha1_StorageVersionList_To_apiserverinternal_StorageVersionList(in *StorageVersionList, out *apiserverinternal.StorageVersionList, s conversion.Scope) error {
return autoConvert_v1alpha1_StorageVersionList_To_apiserverinternal_StorageVersionList(in, out, s)
}
func autoConvert_apiserverinternal_StorageVersionList_To_v1alpha1_StorageVersionList(in *apiserverinternal.StorageVersionList, out *StorageVersionList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]StorageVersion)(unsafe.Pointer(&in.Items))
return nil
}
// Convert_apiserverinternal_StorageVersionList_To_v1alpha1_StorageVersionList is an autogenerated conversion function.
func Convert_apiserverinternal_StorageVersionList_To_v1alpha1_StorageVersionList(in *apiserverinternal.StorageVersionList, out *StorageVersionList, s conversion.Scope) error {
return autoConvert_apiserverinternal_StorageVersionList_To_v1alpha1_StorageVersionList(in, out, s)
}
func autoConvert_v1alpha1_StorageVersionSpec_To_apiserverinternal_StorageVersionSpec(in *StorageVersionSpec, out *apiserverinternal.StorageVersionSpec, s conversion.Scope) error {
return nil
}
// Convert_v1alpha1_StorageVersionSpec_To_apiserverinternal_StorageVersionSpec is an autogenerated conversion function.
func Convert_v1alpha1_StorageVersionSpec_To_apiserverinternal_StorageVersionSpec(in *StorageVersionSpec, out *apiserverinternal.StorageVersionSpec, s conversion.Scope) error {
return autoConvert_v1alpha1_StorageVersionSpec_To_apiserverinternal_StorageVersionSpec(in, out, s)
}
func autoConvert_apiserverinternal_StorageVersionSpec_To_v1alpha1_StorageVersionSpec(in *apiserverinternal.StorageVersionSpec, out *StorageVersionSpec, s conversion.Scope) error {
return nil
}
// Convert_apiserverinternal_StorageVersionSpec_To_v1alpha1_StorageVersionSpec is an autogenerated conversion function.
func Convert_apiserverinternal_StorageVersionSpec_To_v1alpha1_StorageVersionSpec(in *apiserverinternal.StorageVersionSpec, out *StorageVersionSpec, s conversion.Scope) error {
return autoConvert_apiserverinternal_StorageVersionSpec_To_v1alpha1_StorageVersionSpec(in, out, s)
}
func autoConvert_v1alpha1_StorageVersionStatus_To_apiserverinternal_StorageVersionStatus(in *StorageVersionStatus, out *apiserverinternal.StorageVersionStatus, s conversion.Scope) error {
out.StorageVersions = *(*[]apiserverinternal.ServerStorageVersion)(unsafe.Pointer(&in.StorageVersions))
out.CommonEncodingVersion = (*string)(unsafe.Pointer(in.CommonEncodingVersion))
out.Conditions = *(*[]apiserverinternal.StorageVersionCondition)(unsafe.Pointer(&in.Conditions))
return nil
}
// Convert_v1alpha1_StorageVersionStatus_To_apiserverinternal_StorageVersionStatus is an autogenerated conversion function.
func Convert_v1alpha1_StorageVersionStatus_To_apiserverinternal_StorageVersionStatus(in *StorageVersionStatus, out *apiserverinternal.StorageVersionStatus, s conversion.Scope) error {
return autoConvert_v1alpha1_StorageVersionStatus_To_apiserverinternal_StorageVersionStatus(in, out, s)
}
func autoConvert_apiserverinternal_StorageVersionStatus_To_v1alpha1_StorageVersionStatus(in *apiserverinternal.StorageVersionStatus, out *StorageVersionStatus, s conversion.Scope) error {
out.StorageVersions = *(*[]ServerStorageVersion)(unsafe.Pointer(&in.StorageVersions))
out.CommonEncodingVersion = (*string)(unsafe.Pointer(in.CommonEncodingVersion))
out.Conditions = *(*[]StorageVersionCondition)(unsafe.Pointer(&in.Conditions))
return nil
}
// Convert_apiserverinternal_StorageVersionStatus_To_v1alpha1_StorageVersionStatus is an autogenerated conversion function.
func Convert_apiserverinternal_StorageVersionStatus_To_v1alpha1_StorageVersionStatus(in *apiserverinternal.StorageVersionStatus, out *StorageVersionStatus, s conversion.Scope) error {
return autoConvert_apiserverinternal_StorageVersionStatus_To_v1alpha1_StorageVersionStatus(in, out, s)
}

View File

@ -0,0 +1,175 @@
// +build !ignore_autogenerated
/*
Copyright 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.
*/
// Code generated by deepcopy-gen. DO NOT EDIT.
package v1alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServerStorageVersion) DeepCopyInto(out *ServerStorageVersion) {
*out = *in
if in.DecodableVersions != nil {
in, out := &in.DecodableVersions, &out.DecodableVersions
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerStorageVersion.
func (in *ServerStorageVersion) DeepCopy() *ServerStorageVersion {
if in == nil {
return nil
}
out := new(ServerStorageVersion)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersion) DeepCopyInto(out *StorageVersion) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersion.
func (in *StorageVersion) DeepCopy() *StorageVersion {
if in == nil {
return nil
}
out := new(StorageVersion)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StorageVersion) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionCondition) DeepCopyInto(out *StorageVersionCondition) {
*out = *in
in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionCondition.
func (in *StorageVersionCondition) DeepCopy() *StorageVersionCondition {
if in == nil {
return nil
}
out := new(StorageVersionCondition)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionList) DeepCopyInto(out *StorageVersionList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]StorageVersion, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionList.
func (in *StorageVersionList) DeepCopy() *StorageVersionList {
if in == nil {
return nil
}
out := new(StorageVersionList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StorageVersionList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionSpec) DeepCopyInto(out *StorageVersionSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionSpec.
func (in *StorageVersionSpec) DeepCopy() *StorageVersionSpec {
if in == nil {
return nil
}
out := new(StorageVersionSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionStatus) DeepCopyInto(out *StorageVersionStatus) {
*out = *in
if in.StorageVersions != nil {
in, out := &in.StorageVersions, &out.StorageVersions
*out = make([]ServerStorageVersion, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.CommonEncodingVersion != nil {
in, out := &in.CommonEncodingVersion, &out.CommonEncodingVersion
*out = new(string)
**out = **in
}
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]StorageVersionCondition, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionStatus.
func (in *StorageVersionStatus) DeepCopy() *StorageVersionStatus {
if in == nil {
return nil
}
out := new(StorageVersionStatus)
in.DeepCopyInto(out)
return out
}

View File

@ -0,0 +1,32 @@
// +build !ignore_autogenerated
/*
Copyright 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.
*/
// Code generated by defaulter-gen. DO NOT EDIT.
package v1alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}

View File

@ -0,0 +1,39 @@
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["validation.go"],
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/apis/apiserverinternal/validation",
importpath = "k8s.io/apiserver/pkg/apis/apiserverinternal/validation",
deps = [
"//staging/src/k8s.io/apimachinery/pkg/api/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = ["validation_test.go"],
embed = [":go_default_library"],
deps = [
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/apiserverinternal:go_default_library",
],
)

View File

@ -0,0 +1,128 @@
/*
Copyright 2020 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 validation
import (
"fmt"
"strings"
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/apimachinery/pkg/util/validation"
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apiserver/pkg/apis/apiserverinternal"
)
// ValidateStorageVersion validate the storage version object.
func ValidateStorageVersion(sv *apiserverinternal.StorageVersion) field.ErrorList {
var allErrs field.ErrorList
allErrs = append(allErrs, validateStorageVersionStatus(sv.Status, field.NewPath("status"))...)
return allErrs
}
func validateStorageVersionStatus(ss apiserverinternal.StorageVersionStatus, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
for i, ssv := range ss.StorageVersions {
allErrs = append(allErrs, validateServerStorageVersion(ssv, fldPath.Child("storageVersions").Index(i))...)
}
if err := validateCommonVersion(ss, fldPath); err != nil {
allErrs = append(allErrs, err)
}
allErrs = append(allErrs, validateStorageVersionCondition(ss.Conditions, fldPath)...)
return allErrs
}
func validateServerStorageVersion(ssv apiserverinternal.ServerStorageVersion, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
for _, msg := range apimachineryvalidation.NameIsDNSSubdomain(ssv.APIServerID, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("apiServerID"), ssv.APIServerID, msg))
}
if errs := utilvalidation.IsDNS1035Label(ssv.EncodingVersion); len(errs) > 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("encodingVersion"), ssv.EncodingVersion, strings.Join(errs, ",")))
}
found := false
for i, dv := range ssv.DecodableVersions {
if errs := utilvalidation.IsDNS1035Label(dv); len(errs) > 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("decodableVersions").Index(i), dv, strings.Join(errs, ",")))
}
if dv == ssv.EncodingVersion {
found = true
}
}
if !found {
allErrs = append(allErrs, field.Invalid(fldPath.Child("decodableVersions"), ssv.DecodableVersions, fmt.Sprintf("decodableVersions must include encodingVersion %s", ssv.EncodingVersion)))
}
return allErrs
}
func commonVersion(ssv []apiserverinternal.ServerStorageVersion) *string {
if len(ssv) == 0 {
return nil
}
commonVersion := ssv[0].EncodingVersion
for _, v := range ssv[1:] {
if v.EncodingVersion != commonVersion {
return nil
}
}
return &commonVersion
}
func validateCommonVersion(svs apiserverinternal.StorageVersionStatus, fldPath *field.Path) *field.Error {
actualCommonVersion := commonVersion(svs.StorageVersions)
if actualCommonVersion == nil && svs.CommonEncodingVersion == nil {
return nil
}
if actualCommonVersion == nil && svs.CommonEncodingVersion != nil {
return field.Invalid(fldPath.Child("commonEncodingVersion"), *svs.CommonEncodingVersion, "should be nil if servers do not agree on the same encoding version, or if there is no server reporting the supported versions yet")
}
if actualCommonVersion != nil && svs.CommonEncodingVersion == nil {
return field.Invalid(fldPath.Child("commonEncodingVersion"), svs.CommonEncodingVersion, fmt.Sprintf("the common encoding version is %s", *actualCommonVersion))
}
if actualCommonVersion != nil && svs.CommonEncodingVersion != nil && *actualCommonVersion != *svs.CommonEncodingVersion {
return field.Invalid(fldPath.Child("commonEncodingVersion"), *svs.CommonEncodingVersion, fmt.Sprintf("the actual common encoding version is %s", *actualCommonVersion))
}
return nil
}
func validateStorageVersionCondition(conditions []apiserverinternal.StorageVersionCondition, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
// We do not verify that the condition type or the condition status is
// a predefined one because we might add more type or status later.
seenType := make(map[apiserverinternal.StorageVersionConditionType]int)
for i, condition := range conditions {
if ii, ok := seenType[condition.Type]; ok {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i).Child("type"), string(condition.Type),
fmt.Sprintf("the type of the condition is not unique, it also appears in conditions[%d]", ii)))
}
seenType[condition.Type] = i
for _, msg := range validation.IsQualifiedName(string(condition.Type)) {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i).Child("type"), string(condition.Type), msg))
}
for _, msg := range validation.IsQualifiedName(string(condition.Status)) {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i).Child("status"), string(condition.Type), msg))
}
if condition.Reason == "" {
allErrs = append(allErrs, field.Required(fldPath.Index(i).Child("reason"), "reason cannot be empty"))
}
if condition.Message == "" {
allErrs = append(allErrs, field.Required(fldPath.Index(i).Child("message"), "message cannot be empty"))
}
}
return allErrs
}

View File

@ -0,0 +1,286 @@
/*
Copyright 2020 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 validation
import (
"strings"
"testing"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apiserver/pkg/apis/apiserverinternal"
)
func TestValidateServerStorageVersion(t *testing.T) {
cases := []struct {
ssv apiserverinternal.ServerStorageVersion
expectedErr string
}{
{
ssv: apiserverinternal.ServerStorageVersion{
APIServerID: "-fea",
EncodingVersion: "v1alpha1",
DecodableVersions: []string{"v1alpha1", "v1"},
},
expectedErr: "apiServerID: Invalid value",
},
{
ssv: apiserverinternal.ServerStorageVersion{
APIServerID: "fea",
EncodingVersion: "v1alpha1",
DecodableVersions: []string{"v1beta1", "v1"},
},
expectedErr: "decodableVersions must include encodingVersion",
},
{
ssv: apiserverinternal.ServerStorageVersion{
APIServerID: "fea",
EncodingVersion: "v1alpha1",
DecodableVersions: []string{"v1alpha1", "v1", "-fea"},
},
expectedErr: "decodableVersions[2]: Invalid value",
},
{
ssv: apiserverinternal.ServerStorageVersion{
APIServerID: "fea",
EncodingVersion: "v1alpha1",
DecodableVersions: []string{"v1alpha1", "v1"},
},
expectedErr: "",
},
}
for _, tc := range cases {
err := validateServerStorageVersion(tc.ssv, field.NewPath("")).ToAggregate()
if err == nil && len(tc.expectedErr) == 0 {
continue
}
if err != nil && len(tc.expectedErr) == 0 {
t.Errorf("unexpected error %v", err)
continue
}
if err == nil && len(tc.expectedErr) != 0 {
t.Errorf("unexpected empty error")
continue
}
if !strings.Contains(err.Error(), tc.expectedErr) {
t.Errorf("expected error to contain %s, got %s", tc.expectedErr, err)
}
}
}
func TestValidateCommonVersion(t *testing.T) {
cases := []struct {
status apiserverinternal.StorageVersionStatus
expectedErr string
}{
{
status: apiserverinternal.StorageVersionStatus{
StorageVersions: []apiserverinternal.ServerStorageVersion{},
CommonEncodingVersion: func() *string { a := "v1alpha1"; return &a }(),
},
expectedErr: "should be nil if servers do not agree on the same encoding version, or if there is no server reporting the supported versions yet",
},
{
status: apiserverinternal.StorageVersionStatus{
StorageVersions: []apiserverinternal.ServerStorageVersion{
{
APIServerID: "1",
EncodingVersion: "v1alpha1",
},
{
APIServerID: "2",
EncodingVersion: "v1",
},
},
CommonEncodingVersion: func() *string { a := "v1alpha1"; return &a }(),
},
expectedErr: "should be nil if servers do not agree on the same encoding version, or if there is no server reporting the supported versions yet",
},
{
status: apiserverinternal.StorageVersionStatus{
StorageVersions: []apiserverinternal.ServerStorageVersion{
{
APIServerID: "1",
EncodingVersion: "v1alpha1",
},
{
APIServerID: "2",
EncodingVersion: "v1alpha1",
},
},
CommonEncodingVersion: nil,
},
expectedErr: "Invalid value: \"null\": the common encoding version is v1alpha1",
},
{
status: apiserverinternal.StorageVersionStatus{
StorageVersions: []apiserverinternal.ServerStorageVersion{
{
APIServerID: "1",
EncodingVersion: "v1alpha1",
},
{
APIServerID: "2",
EncodingVersion: "v1alpha1",
},
},
CommonEncodingVersion: func() *string { a := "v1"; return &a }(),
},
expectedErr: "Invalid value: \"v1\": the actual common encoding version is v1alpha1",
},
{
status: apiserverinternal.StorageVersionStatus{
StorageVersions: []apiserverinternal.ServerStorageVersion{
{
APIServerID: "1",
EncodingVersion: "v1alpha1",
},
{
APIServerID: "2",
EncodingVersion: "v1alpha1",
},
},
CommonEncodingVersion: func() *string { a := "v1alpha1"; return &a }(),
},
expectedErr: "",
},
{
status: apiserverinternal.StorageVersionStatus{
StorageVersions: []apiserverinternal.ServerStorageVersion{
{
APIServerID: "1",
EncodingVersion: "v1alpha1",
},
},
CommonEncodingVersion: func() *string { a := "v1alpha1"; return &a }(),
},
expectedErr: "",
},
}
for _, tc := range cases {
err := validateCommonVersion(tc.status, field.NewPath(""))
if err == nil && len(tc.expectedErr) == 0 {
continue
}
if err != nil && len(tc.expectedErr) == 0 {
t.Errorf("unexpected error %v", err)
continue
}
if err == nil && len(tc.expectedErr) != 0 {
t.Errorf("unexpected empty error")
continue
}
if !strings.Contains(err.Error(), tc.expectedErr) {
t.Errorf("expected error to contain %s, got %s", tc.expectedErr, err)
}
}
}
func TestValidateStorageVersionCondition(t *testing.T) {
cases := []struct {
conditions []apiserverinternal.StorageVersionCondition
expectedErr string
}{
{
conditions: []apiserverinternal.StorageVersionCondition{
{
Type: "-fea",
Status: "True",
Reason: "unknown",
Message: "unknown",
},
},
expectedErr: "type: Invalid value",
},
{
conditions: []apiserverinternal.StorageVersionCondition{
{
Type: "fea",
Status: "-True",
Reason: "unknown",
Message: "unknown",
},
},
expectedErr: "status: Invalid value",
},
{
conditions: []apiserverinternal.StorageVersionCondition{
{
Type: "fea",
Status: "True",
Message: "unknown",
},
},
expectedErr: "Required value: reason cannot be empty",
},
{
conditions: []apiserverinternal.StorageVersionCondition{
{
Type: "fea",
Status: "True",
Reason: "unknown",
},
},
expectedErr: "Required value: message cannot be empty",
},
{
conditions: []apiserverinternal.StorageVersionCondition{
{
Type: "fea",
Status: "True",
Reason: "unknown",
Message: "unknown",
},
{
Type: "fea",
Status: "True",
Reason: "unknown",
Message: "unknown",
},
},
expectedErr: `"fea": the type of the condition is not unique, it also appears in conditions[0]`,
},
{
conditions: []apiserverinternal.StorageVersionCondition{
{
Type: "fea",
Status: "True",
Reason: "unknown",
Message: "unknown",
},
},
expectedErr: "",
},
}
for _, tc := range cases {
err := validateStorageVersionCondition(tc.conditions, field.NewPath("")).ToAggregate()
if err == nil && len(tc.expectedErr) == 0 {
continue
}
if err != nil && len(tc.expectedErr) == 0 {
t.Errorf("unexpected error %v", err)
continue
}
if err == nil && len(tc.expectedErr) != 0 {
t.Errorf("unexpected empty error")
continue
}
if !strings.Contains(err.Error(), tc.expectedErr) {
t.Errorf("expected error to contain %s, got %s", tc.expectedErr, err)
}
}
}

View File

@ -0,0 +1,175 @@
// +build !ignore_autogenerated
/*
Copyright 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.
*/
// Code generated by deepcopy-gen. DO NOT EDIT.
package apiserverinternal
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServerStorageVersion) DeepCopyInto(out *ServerStorageVersion) {
*out = *in
if in.DecodableVersions != nil {
in, out := &in.DecodableVersions, &out.DecodableVersions
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerStorageVersion.
func (in *ServerStorageVersion) DeepCopy() *ServerStorageVersion {
if in == nil {
return nil
}
out := new(ServerStorageVersion)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersion) DeepCopyInto(out *StorageVersion) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersion.
func (in *StorageVersion) DeepCopy() *StorageVersion {
if in == nil {
return nil
}
out := new(StorageVersion)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StorageVersion) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionCondition) DeepCopyInto(out *StorageVersionCondition) {
*out = *in
in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionCondition.
func (in *StorageVersionCondition) DeepCopy() *StorageVersionCondition {
if in == nil {
return nil
}
out := new(StorageVersionCondition)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionList) DeepCopyInto(out *StorageVersionList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]StorageVersion, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionList.
func (in *StorageVersionList) DeepCopy() *StorageVersionList {
if in == nil {
return nil
}
out := new(StorageVersionList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StorageVersionList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionSpec) DeepCopyInto(out *StorageVersionSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionSpec.
func (in *StorageVersionSpec) DeepCopy() *StorageVersionSpec {
if in == nil {
return nil
}
out := new(StorageVersionSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StorageVersionStatus) DeepCopyInto(out *StorageVersionStatus) {
*out = *in
if in.StorageVersions != nil {
in, out := &in.StorageVersions, &out.StorageVersions
*out = make([]ServerStorageVersion, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.CommonEncodingVersion != nil {
in, out := &in.CommonEncodingVersion, &out.CommonEncodingVersion
*out = new(string)
**out = **in
}
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]StorageVersionCondition, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageVersionStatus.
func (in *StorageVersionStatus) DeepCopy() *StorageVersionStatus {
if in == nil {
return nil
}
out := new(StorageVersionStatus)
in.DeepCopyInto(out)
return out
}