Merge pull request #48497 from shiywang/move

Automatic merge from submit-queue (batch tested with PRs 48497, 48604, 48599, 48560, 48546)

Move pkg/apimachinery/test to apimachinery

Fixes https://github.com/kubernetes/kubernetes/issues/48265

for circular dependency reason, all the test file contain both `"k8s.io/apimachinery/pkg/apis/meta/v1"` and `"k8s.io/apimachinery/pkg/runtime"` is hard to move to a ideal location, so I create a separated test package for those files

I also bump the example package :https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/apiserver/pkg/apis/example here for apimachinery, @sttts told me it's ok if to bump file if only for test   EDIT: seems it's no need to bump, will update soon
```
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-07-08 07:09:31 -07:00 committed by GitHub
commit af3dde34a6
35 changed files with 6927 additions and 131 deletions

View File

@ -69,6 +69,7 @@ pkg/api/service
pkg/api/v1
pkg/api/v1/node
pkg/api/v1/service
pkg/apimachinery/tests
pkg/apis/abac/v0
pkg/apis/abac/v1beta1
pkg/apis/admission/install
@ -329,6 +330,7 @@ staging/src/k8s.io/apimachinery/pkg/api/equality
staging/src/k8s.io/apimachinery/pkg/api/errors
staging/src/k8s.io/apimachinery/pkg/api/resource
staging/src/k8s.io/apimachinery/pkg/apimachinery
staging/src/k8s.io/apimachinery/pkg/apis/testapigroup/install
staging/src/k8s.io/apimachinery/pkg/conversion/queryparams
staging/src/k8s.io/apimachinery/pkg/fields
staging/src/k8s.io/apimachinery/pkg/labels

View File

@ -4,53 +4,20 @@ licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_test(
name = "go_default_test",
srcs = [
"api_meta_help_test.go",
"api_meta_meta_test.go",
"api_meta_scheme_test.go",
"apis_meta_v1_unstructed_unstructure_test.go",
"runtime_helper_test.go",
"runtime_serializer_protobuf_protobuf_test.go",
"runtime_unversioned_test.go",
"watch_until_test.go",
],
library = ":go_default_library",
srcs = ["api_meta_scheme_test.go"],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/api/validation:go_default_library",
"//pkg/apis/extensions:go_default_library",
"//vendor/github.com/google/gofuzz:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1: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",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["doc.go"],
tags = ["automanaged"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),

View File

@ -42,6 +42,7 @@ openapi_library(
"k8s.io/apimachinery/pkg/api/resource",
"k8s.io/apimachinery/pkg/apis/meta/v1",
"k8s.io/apimachinery/pkg/apis/meta/v1alpha1",
"k8s.io/apimachinery/pkg/apis/testapigroup/v1",
"k8s.io/apimachinery/pkg/runtime",
"k8s.io/apimachinery/pkg/util/intstr",
"k8s.io/apimachinery/pkg/version",

View File

@ -0,0 +1,25 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
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",
],
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)

View File

@ -0,0 +1,22 @@
/*
Copyright 2017 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,register
// +groupName=testapigroup.apimachinery.k8s.io
//
// package testapigroup contains an testapigroup API used to demonstrate how to create api groups. Moreover, this is
// used within tests.
package testapigroup // import "k8s.io/apimachinery/pkg/apis/testapigroup"

View File

@ -0,0 +1,22 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["fuzzer.go"],
tags = ["automanaged"],
deps = [
"//vendor/github.com/google/gofuzz:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/testing:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
],
)

View File

@ -0,0 +1,99 @@
/*
Copyright 2015 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 (
"github.com/google/gofuzz"
apitesting "k8s.io/apimachinery/pkg/api/testing"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"k8s.io/apimachinery/pkg/runtime"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
)
// overrideGenericFuncs override some generic fuzzer funcs from k8s.io/apimachinery in order to have more realistic
// values in a Kubernetes context.
func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
func(j *runtime.Object, c fuzz.Continue) {
// TODO: uncomment when round trip starts from a versioned object
if true { //c.RandBool() {
*j = &runtime.Unknown{
// We do not set TypeMeta here because it is not carried through a round trip
Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`),
ContentType: runtime.ContentTypeJSON,
}
} else {
types := []runtime.Object{&testapigroup.Carp{}}
t := types[c.Rand.Intn(len(types))]
c.Fuzz(t)
*j = t
}
},
func(r *runtime.RawExtension, c fuzz.Continue) {
// Pick an arbitrary type and fuzz it
types := []runtime.Object{&testapigroup.Carp{}}
obj := types[c.Rand.Intn(len(types))]
c.Fuzz(obj)
// Convert the object to raw bytes
bytes, err := runtime.Encode(apitesting.TestCodec(codecs, v1.SchemeGroupVersion), obj)
if err != nil {
t.Errorf("Failed to encode object: %v", err)
return
}
// Set the bytes field on the RawExtension
r.Raw = bytes
},
}
}
func testapigroupFuncs(t apitesting.TestingCommon) []interface{} {
return []interface{}{
func(s *testapigroup.CarpSpec, c fuzz.Continue) {
c.FuzzNoCustom(s)
// has a default value
ttl := int64(30)
if c.RandBool() {
ttl = int64(c.Uint32())
}
s.TerminationGracePeriodSeconds = &ttl
if s.SchedulerName == "" {
s.SchedulerName = "default-scheduler"
}
},
func(j *testapigroup.CarpPhase, c fuzz.Continue) {
statuses := []testapigroup.CarpPhase{"Pending", "Running", "Succeeded", "Failed", "Unknown"}
*j = statuses[c.Rand.Intn(len(statuses))]
},
func(rp *testapigroup.RestartPolicy, c fuzz.Continue) {
policies := []testapigroup.RestartPolicy{"Always", "Never", "OnFailure"}
*rp = policies[c.Rand.Intn(len(policies))]
},
}
}
func Funcs(t apitesting.TestingCommon, codecs runtimeserializer.CodecFactory) []interface{} {
return apitesting.MergeFuzzerFuncs(t,
apitesting.GenericFuzzerFuncs(t, codecs),
overrideGenericFuncs(t, codecs),
testapigroupFuncs(t),
)
}

View File

@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["install.go"],
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/apimachinery/announced:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apimachinery/registered:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
],
)

View File

@ -0,0 +1,44 @@
/*
Copyright 2016 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 certificates API group, making it available as
// an option to all of the API encoding/decoding machinery.
package install
import (
"k8s.io/apimachinery/pkg/apimachinery/announced"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// Install registers the API group and adds types to a scheme
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{
GroupName: testapigroup.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/apimachinery/pkg/apis/testapigroup",
AddInternalObjectsToScheme: testapigroup.AddToScheme,
},
announced.VersionToSchemeFunc{
v1.SchemeGroupVersion.Version: v1.AddToScheme,
},
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
panic(err)
}
}

View File

@ -0,0 +1,51 @@
/*
Copyright 2017 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 testapigroup
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)
// GroupName is the group name use in this package
const GroupName = "testapigroup.apimachinery.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()
}
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Carp{},
)
return nil
}

View File

@ -0,0 +1,134 @@
/*
Copyright 2017 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 testapigroup
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type (
ConditionStatus string
CarpConditionType string
CarpPhase string
RestartPolicy string
)
// Carp is a collection of containers, used as either input (create, update) or as output (list, get).
type Carp struct {
metav1.TypeMeta
// +optional
metav1.ObjectMeta
// Spec defines the behavior of a carp.
// +optional
Spec CarpSpec
// Status represents the current information about a carp. This data may not be up
// to date.
// +optional
Status CarpStatus
}
// CarpStatus represents information about the status of a carp. Status may trail the actual
// state of a system.
type CarpStatus struct {
// +optional
Phase CarpPhase
// +optional
Conditions []CarpCondition
// A human readable message indicating details about why the carp is in this state.
// +optional
Message string
// A brief CamelCase message indicating details about why the carp is in this state. e.g. 'OutOfDisk'
// +optional
Reason string
// +optional
HostIP string
// +optional
CarpIP string
// Date and time at which the object was acknowledged by the Kubelet.
// This is before the Kubelet pulled the container image(s) for the carp.
// +optional
StartTime *metav1.Time
}
type CarpCondition struct {
Type CarpConditionType
Status ConditionStatus
// +optional
LastProbeTime metav1.Time
// +optional
LastTransitionTime metav1.Time
// +optional
Reason string
// +optional
Message string
}
// CarpSpec is a description of a carp
type CarpSpec struct {
// +optional
RestartPolicy RestartPolicy
// Optional duration in seconds the carp needs to terminate gracefully. May be decreased in delete request.
// Value must be non-negative integer. The value zero indicates delete immediately.
// If this value is nil, the default grace period will be used instead.
// The grace period is the duration in seconds after the processes running in the carp are sent
// a termination signal and the time when the processes are forcibly halted with a kill signal.
// Set this value longer than the expected cleanup time for your process.
// +optional
TerminationGracePeriodSeconds *int64
// Optional duration in seconds relative to the StartTime that the carp may be active on a node
// before the system actively tries to terminate the carp; value must be positive integer
// +optional
ActiveDeadlineSeconds *int64
// NodeSelector is a selector which must be true for the carp to fit on a node
// +optional
NodeSelector map[string]string
// ServiceAccountName is the name of the ServiceAccount to use to run this carp
// The carp will be allowed to use secrets referenced by the ServiceAccount
ServiceAccountName string
// NodeName is a request to schedule this carp onto a specific node. If it is non-empty,
// the scheduler simply schedules this carp onto that node, assuming that it fits resource
// requirements.
// +optional
NodeName string
// Specifies the hostname of the Carp.
// If not specified, the carp's hostname will be set to a system-defined value.
// +optional
Hostname string
// If specified, the fully qualified Carp hostname will be "<hostname>.<subdomain>.<carp namespace>.svc.<cluster domain>".
// If not specified, the carp will not have a domainname at all.
// +optional
Subdomain string
// If specified, the carp will be dispatched by specified scheduler.
// If not specified, the carp will be dispatched by default scheduler.
// +optional
SchedulerName string
}
// CarpList is a list of Carps.
type CarpList struct {
metav1.TypeMeta
// +optional
metav1.ListMeta
Items []Carp
}

View File

@ -0,0 +1,37 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"conversion.go",
"defaults.go",
"doc.go",
"generated.pb.go",
"register.go",
"types.generated.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.conversion.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
tags = ["automanaged"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/sortkeys:go_default_library",
"//vendor/github.com/ugorji/go/codec:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
],
)

View File

@ -14,7 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// This package runs tests against the apimachinery which require a Scheme
// TODO Refactor the base types into the machinery and move these tests back.
// See https://github.com/kubernetes/kubernetes/issues/39611
package tests
package v1
import (
"k8s.io/apimachinery/pkg/runtime"
)
func addConversionFuncs(scheme *runtime.Scheme) error {
// Add non-generated conversion functions here. Currently there are none.
return nil
}

View File

@ -0,0 +1,26 @@
/*
Copyright 2017 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 v1
import (
"k8s.io/apimachinery/pkg/runtime"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
// return RegisterDefaults(scheme)
return nil
}

View File

@ -0,0 +1,23 @@
/*
Copyright 2017 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,register
// +k8s:conversion-gen=k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/testapigroup
// +k8s:openapi-gen=false
// +k8s:defaulter-gen=TypeMeta
// +groupName=testapigroup.apimachinery.k8s.io
package v1 // import "k8s.io/apimachinery/pkg/apis/testapigroup/v1"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,212 @@
/*
Copyright 2017 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.apimachinery.pkg.apis.testapigroup.v1;
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";
import "k8s.io/apimachinery/pkg/util/intstr/generated.proto";
// Package-wide variables from generator "generated".
option go_package = "v1";
// Carp is a collection of containers, used as either input (create, update) or as output (list, get).
message Carp {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
// Specification of the desired behavior of the carp.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
// +optional
optional CarpSpec spec = 2;
// Most recently observed status of the carp.
// This data may not be up to date.
// Populated by the system.
// Read-only.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
// +optional
optional CarpStatus status = 3;
}
message CarpCondition {
// Type is the type of the condition.
// Currently only Ready.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
optional string type = 1;
// Status is the status of the condition.
// Can be True, False, Unknown.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
optional string status = 2;
// Last time we probed the condition.
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.Time lastProbeTime = 3;
// Last time the condition transitioned from one status to another.
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.Time lastTransitionTime = 4;
// Unique, one-word, CamelCase reason for the condition's last transition.
// +optional
optional string reason = 5;
// Human-readable message indicating details about last transition.
// +optional
optional string message = 6;
}
// CarpList is a list of Carps.
message CarpList {
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
// List of carps.
// More info: http://kubernetes.io/docs/user-guide/carps
repeated Carp items = 2;
}
// CarpSpec is a description of a carp
message CarpSpec {
// Restart policy for all containers within the carp.
// One of Always, OnFailure, Never.
// Default to Always.
// More info: http://kubernetes.io/docs/user-guide/carp-states#restartpolicy
// +optional
optional string restartPolicy = 3;
// Optional duration in seconds the carp needs to terminate gracefully. May be decreased in delete request.
// Value must be non-negative integer. The value zero indicates delete immediately.
// If this value is nil, the default grace period will be used instead.
// The grace period is the duration in seconds after the processes running in the carp are sent
// a termination signal and the time when the processes are forcibly halted with a kill signal.
// Set this value longer than the expected cleanup time for your process.
// Defaults to 30 seconds.
// +optional
optional int64 terminationGracePeriodSeconds = 4;
// Optional duration in seconds the carp may be active on the node relative to
// StartTime before the system will actively try to mark it failed and kill associated containers.
// Value must be a positive integer.
// +optional
optional int64 activeDeadlineSeconds = 5;
// NodeSelector is a selector which must be true for the carp to fit on a node.
// Selector which must match a node's labels for the carp to be scheduled on that node.
// More info: http://kubernetes.io/docs/user-guide/node-selection/README
// +optional
map<string, string> nodeSelector = 7;
// ServiceAccountName is the name of the ServiceAccount to use to run this carp.
// More info: http://releases.k8s.io/HEAD/docs/design/service_accounts.md
// +optional
optional string serviceAccountName = 8;
// DeprecatedServiceAccount is a depreciated alias for ServiceAccountName.
// Deprecated: Use serviceAccountName instead.
// +k8s:conversion-gen=false
// +optional
optional string serviceAccount = 9;
// NodeName is a request to schedule this carp onto a specific node. If it is non-empty,
// the scheduler simply schedules this carp onto that node, assuming that it fits resource
// requirements.
// +optional
optional string nodeName = 10;
// Host networking requested for this carp. Use the host's network namespace.
// If this option is set, the ports that will be used must be specified.
// Default to false.
// +k8s:conversion-gen=false
// +optional
optional bool hostNetwork = 11;
// Use the host's pid namespace.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
optional bool hostPID = 12;
// Use the host's ipc namespace.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
optional bool hostIPC = 13;
// Specifies the hostname of the Carp
// If not specified, the carp's hostname will be set to a system-defined value.
// +optional
optional string hostname = 16;
// If specified, the fully qualified Carp hostname will be "<hostname>.<subdomain>.<carp namespace>.svc.<cluster domain>".
// If not specified, the carp will not have a domainname at all.
// +optional
optional string subdomain = 17;
// If specified, the carp will be dispatched by specified scheduler.
// If not specified, the carp will be dispatched by default scheduler.
// +optional
optional string schedulername = 19;
}
// CarpStatus represents information about the status of a carp. Status may trail the actual
// state of a system.
message CarpStatus {
// Current condition of the carp.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-phase
// +optional
optional string phase = 1;
// Current service state of carp.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
// +optional
repeated CarpCondition conditions = 2;
// A human readable message indicating details about why the carp is in this condition.
// +optional
optional string message = 3;
// A brief CamelCase message indicating details about why the carp is in this state.
// e.g. 'OutOfDisk'
// +optional
optional string reason = 4;
// IP address of the host to which the carp is assigned. Empty if not yet scheduled.
// +optional
optional string hostIP = 5;
// IP address allocated to the carp. Routable at least within the cluster.
// Empty if not yet allocated.
// +optional
optional string carpIP = 6;
// RFC 3339 date and time at which the object was acknowledged by the Kubelet.
// This is before the Kubelet pulled the container image(s) for the carp.
// +optional
optional k8s.io.apimachinery.pkg.apis.meta.v1.Time startTime = 7;
}

View File

@ -0,0 +1,63 @@
/*
Copyright 2017 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 v1
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 = "testapigroup.apimachinery.k8s.io"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
// 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 (
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
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, addConversionFuncs, addDefaultingFuncs)
}
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Carp{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,192 @@
/*
Copyright 2017 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 v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type (
ConditionStatus string
CarpConditionType string
CarpPhase string
RestartPolicy string
)
// Carp is a collection of containers, used as either input (create, update) or as output (list, get).
type Carp struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Specification of the desired behavior of the carp.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
// +optional
Spec CarpSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
// Most recently observed status of the carp.
// This data may not be up to date.
// Populated by the system.
// Read-only.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
// +optional
Status CarpStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// CarpStatus represents information about the status of a carp. Status may trail the actual
// state of a system.
type CarpStatus struct {
// Current condition of the carp.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-phase
// +optional
Phase CarpPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=CarpPhase"`
// Current service state of carp.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
// +optional
Conditions []CarpCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
// A human readable message indicating details about why the carp is in this condition.
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"`
// A brief CamelCase message indicating details about why the carp is in this state.
// e.g. 'OutOfDisk'
// +optional
Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
// IP address of the host to which the carp is assigned. Empty if not yet scheduled.
// +optional
HostIP string `json:"hostIP,omitempty" protobuf:"bytes,5,opt,name=hostIP"`
// IP address allocated to the carp. Routable at least within the cluster.
// Empty if not yet allocated.
// +optional
CarpIP string `json:"carpIP,omitempty" protobuf:"bytes,6,opt,name=carpIP"`
// RFC 3339 date and time at which the object was acknowledged by the Kubelet.
// This is before the Kubelet pulled the container image(s) for the carp.
// +optional
StartTime *metav1.Time `json:"startTime,omitempty" protobuf:"bytes,7,opt,name=startTime"`
}
type CarpCondition struct {
// Type is the type of the condition.
// Currently only Ready.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
Type CarpConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=CarpConditionType"`
// Status is the status of the condition.
// Can be True, False, Unknown.
// More info: http://kubernetes.io/docs/user-guide/carp-states#carp-conditions
Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
// Last time we probed the condition.
// +optional
LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,3,opt,name=lastProbeTime"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
// Unique, one-word, CamelCase reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
// Human-readable message indicating details about last transition.
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}
// CarpSpec is a description of a carp
type CarpSpec struct {
// Restart policy for all containers within the carp.
// One of Always, OnFailure, Never.
// Default to Always.
// More info: http://kubernetes.io/docs/user-guide/carp-states#restartpolicy
// +optional
RestartPolicy RestartPolicy `json:"restartPolicy,omitempty" protobuf:"bytes,3,opt,name=restartPolicy,casttype=RestartPolicy"`
// Optional duration in seconds the carp needs to terminate gracefully. May be decreased in delete request.
// Value must be non-negative integer. The value zero indicates delete immediately.
// If this value is nil, the default grace period will be used instead.
// The grace period is the duration in seconds after the processes running in the carp are sent
// a termination signal and the time when the processes are forcibly halted with a kill signal.
// Set this value longer than the expected cleanup time for your process.
// Defaults to 30 seconds.
// +optional
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
// Optional duration in seconds the carp may be active on the node relative to
// StartTime before the system will actively try to mark it failed and kill associated containers.
// Value must be a positive integer.
// +optional
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty" protobuf:"varint,5,opt,name=activeDeadlineSeconds"`
// NodeSelector is a selector which must be true for the carp to fit on a node.
// Selector which must match a node's labels for the carp to be scheduled on that node.
// More info: http://kubernetes.io/docs/user-guide/node-selection/README
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`
// ServiceAccountName is the name of the ServiceAccount to use to run this carp.
// More info: http://releases.k8s.io/HEAD/docs/design/service_accounts.md
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,8,opt,name=serviceAccountName"`
// DeprecatedServiceAccount is a depreciated alias for ServiceAccountName.
// Deprecated: Use serviceAccountName instead.
// +k8s:conversion-gen=false
// +optional
DeprecatedServiceAccount string `json:"serviceAccount,omitempty" protobuf:"bytes,9,opt,name=serviceAccount"`
// NodeName is a request to schedule this carp onto a specific node. If it is non-empty,
// the scheduler simply schedules this carp onto that node, assuming that it fits resource
// requirements.
// +optional
NodeName string `json:"nodeName,omitempty" protobuf:"bytes,10,opt,name=nodeName"`
// Host networking requested for this carp. Use the host's network namespace.
// If this option is set, the ports that will be used must be specified.
// Default to false.
// +k8s:conversion-gen=false
// +optional
HostNetwork bool `json:"hostNetwork,omitempty" protobuf:"varint,11,opt,name=hostNetwork"`
// Use the host's pid namespace.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
HostPID bool `json:"hostPID,omitempty" protobuf:"varint,12,opt,name=hostPID"`
// Use the host's ipc namespace.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
HostIPC bool `json:"hostIPC,omitempty" protobuf:"varint,13,opt,name=hostIPC"`
// Specifies the hostname of the Carp
// If not specified, the carp's hostname will be set to a system-defined value.
// +optional
Hostname string `json:"hostname,omitempty" protobuf:"bytes,16,opt,name=hostname"`
// If specified, the fully qualified Carp hostname will be "<hostname>.<subdomain>.<carp namespace>.svc.<cluster domain>".
// If not specified, the carp will not have a domainname at all.
// +optional
Subdomain string `json:"subdomain,omitempty" protobuf:"bytes,17,opt,name=subdomain"`
// If specified, the carp will be dispatched by specified scheduler.
// If not specified, the carp will be dispatched by default scheduler.
// +optional
SchedulerName string `json:"schedulername,omitempty" protobuf:"bytes,19,opt,name=schedulername"`
}
// CarpList is a list of Carps.
type CarpList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of carps.
// More info: http://kubernetes.io/docs/user-guide/carps
Items []Carp `json:"items" protobuf:"bytes,2,rep,name=items"`
}

View File

@ -0,0 +1,17 @@
/*
Copyright 2016 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 v1

View File

@ -0,0 +1,226 @@
// +build !ignore_autogenerated
/*
Copyright 2017 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 conversion-gen. Do not edit it manually!
package v1
import (
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testapigroup "k8s.io/apimachinery/pkg/apis/testapigroup"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
unsafe "unsafe"
)
func init() {
localSchemeBuilder.Register(RegisterConversions)
}
// RegisterConversions adds conversion functions to the given scheme.
// Public to allow building arbitrary schemes.
func RegisterConversions(scheme *runtime.Scheme) error {
return scheme.AddGeneratedConversionFuncs(
Convert_v1_Carp_To_testapigroup_Carp,
Convert_testapigroup_Carp_To_v1_Carp,
Convert_v1_CarpCondition_To_testapigroup_CarpCondition,
Convert_testapigroup_CarpCondition_To_v1_CarpCondition,
Convert_v1_CarpList_To_testapigroup_CarpList,
Convert_testapigroup_CarpList_To_v1_CarpList,
Convert_v1_CarpSpec_To_testapigroup_CarpSpec,
Convert_testapigroup_CarpSpec_To_v1_CarpSpec,
Convert_v1_CarpStatus_To_testapigroup_CarpStatus,
Convert_testapigroup_CarpStatus_To_v1_CarpStatus,
)
}
func autoConvert_v1_Carp_To_testapigroup_Carp(in *Carp, out *testapigroup.Carp, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
if err := Convert_v1_CarpSpec_To_testapigroup_CarpSpec(&in.Spec, &out.Spec, s); err != nil {
return err
}
if err := Convert_v1_CarpStatus_To_testapigroup_CarpStatus(&in.Status, &out.Status, s); err != nil {
return err
}
return nil
}
// Convert_v1_Carp_To_testapigroup_Carp is an autogenerated conversion function.
func Convert_v1_Carp_To_testapigroup_Carp(in *Carp, out *testapigroup.Carp, s conversion.Scope) error {
return autoConvert_v1_Carp_To_testapigroup_Carp(in, out, s)
}
func autoConvert_testapigroup_Carp_To_v1_Carp(in *testapigroup.Carp, out *Carp, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
if err := Convert_testapigroup_CarpSpec_To_v1_CarpSpec(&in.Spec, &out.Spec, s); err != nil {
return err
}
if err := Convert_testapigroup_CarpStatus_To_v1_CarpStatus(&in.Status, &out.Status, s); err != nil {
return err
}
return nil
}
// Convert_testapigroup_Carp_To_v1_Carp is an autogenerated conversion function.
func Convert_testapigroup_Carp_To_v1_Carp(in *testapigroup.Carp, out *Carp, s conversion.Scope) error {
return autoConvert_testapigroup_Carp_To_v1_Carp(in, out, s)
}
func autoConvert_v1_CarpCondition_To_testapigroup_CarpCondition(in *CarpCondition, out *testapigroup.CarpCondition, s conversion.Scope) error {
out.Type = testapigroup.CarpConditionType(in.Type)
out.Status = testapigroup.ConditionStatus(in.Status)
out.LastProbeTime = in.LastProbeTime
out.LastTransitionTime = in.LastTransitionTime
out.Reason = in.Reason
out.Message = in.Message
return nil
}
// Convert_v1_CarpCondition_To_testapigroup_CarpCondition is an autogenerated conversion function.
func Convert_v1_CarpCondition_To_testapigroup_CarpCondition(in *CarpCondition, out *testapigroup.CarpCondition, s conversion.Scope) error {
return autoConvert_v1_CarpCondition_To_testapigroup_CarpCondition(in, out, s)
}
func autoConvert_testapigroup_CarpCondition_To_v1_CarpCondition(in *testapigroup.CarpCondition, out *CarpCondition, s conversion.Scope) error {
out.Type = CarpConditionType(in.Type)
out.Status = ConditionStatus(in.Status)
out.LastProbeTime = in.LastProbeTime
out.LastTransitionTime = in.LastTransitionTime
out.Reason = in.Reason
out.Message = in.Message
return nil
}
// Convert_testapigroup_CarpCondition_To_v1_CarpCondition is an autogenerated conversion function.
func Convert_testapigroup_CarpCondition_To_v1_CarpCondition(in *testapigroup.CarpCondition, out *CarpCondition, s conversion.Scope) error {
return autoConvert_testapigroup_CarpCondition_To_v1_CarpCondition(in, out, s)
}
func autoConvert_v1_CarpList_To_testapigroup_CarpList(in *CarpList, out *testapigroup.CarpList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]testapigroup.Carp, len(*in))
for i := range *in {
if err := Convert_v1_Carp_To_testapigroup_Carp(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Items = nil
}
return nil
}
// Convert_v1_CarpList_To_testapigroup_CarpList is an autogenerated conversion function.
func Convert_v1_CarpList_To_testapigroup_CarpList(in *CarpList, out *testapigroup.CarpList, s conversion.Scope) error {
return autoConvert_v1_CarpList_To_testapigroup_CarpList(in, out, s)
}
func autoConvert_testapigroup_CarpList_To_v1_CarpList(in *testapigroup.CarpList, out *CarpList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Carp, len(*in))
for i := range *in {
if err := Convert_testapigroup_Carp_To_v1_Carp(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Items = make([]Carp, 0)
}
return nil
}
// Convert_testapigroup_CarpList_To_v1_CarpList is an autogenerated conversion function.
func Convert_testapigroup_CarpList_To_v1_CarpList(in *testapigroup.CarpList, out *CarpList, s conversion.Scope) error {
return autoConvert_testapigroup_CarpList_To_v1_CarpList(in, out, s)
}
func autoConvert_v1_CarpSpec_To_testapigroup_CarpSpec(in *CarpSpec, out *testapigroup.CarpSpec, s conversion.Scope) error {
out.RestartPolicy = testapigroup.RestartPolicy(in.RestartPolicy)
out.TerminationGracePeriodSeconds = (*int64)(unsafe.Pointer(in.TerminationGracePeriodSeconds))
out.ActiveDeadlineSeconds = (*int64)(unsafe.Pointer(in.ActiveDeadlineSeconds))
out.NodeSelector = *(*map[string]string)(unsafe.Pointer(&in.NodeSelector))
out.ServiceAccountName = in.ServiceAccountName
// INFO: in.DeprecatedServiceAccount opted out of conversion generation
out.NodeName = in.NodeName
// INFO: in.HostNetwork opted out of conversion generation
// INFO: in.HostPID opted out of conversion generation
// INFO: in.HostIPC opted out of conversion generation
out.Hostname = in.Hostname
out.Subdomain = in.Subdomain
out.SchedulerName = in.SchedulerName
return nil
}
// Convert_v1_CarpSpec_To_testapigroup_CarpSpec is an autogenerated conversion function.
func Convert_v1_CarpSpec_To_testapigroup_CarpSpec(in *CarpSpec, out *testapigroup.CarpSpec, s conversion.Scope) error {
return autoConvert_v1_CarpSpec_To_testapigroup_CarpSpec(in, out, s)
}
func autoConvert_testapigroup_CarpSpec_To_v1_CarpSpec(in *testapigroup.CarpSpec, out *CarpSpec, s conversion.Scope) error {
out.RestartPolicy = RestartPolicy(in.RestartPolicy)
out.TerminationGracePeriodSeconds = (*int64)(unsafe.Pointer(in.TerminationGracePeriodSeconds))
out.ActiveDeadlineSeconds = (*int64)(unsafe.Pointer(in.ActiveDeadlineSeconds))
out.NodeSelector = *(*map[string]string)(unsafe.Pointer(&in.NodeSelector))
out.ServiceAccountName = in.ServiceAccountName
out.NodeName = in.NodeName
out.Hostname = in.Hostname
out.Subdomain = in.Subdomain
out.SchedulerName = in.SchedulerName
return nil
}
// Convert_testapigroup_CarpSpec_To_v1_CarpSpec is an autogenerated conversion function.
func Convert_testapigroup_CarpSpec_To_v1_CarpSpec(in *testapigroup.CarpSpec, out *CarpSpec, s conversion.Scope) error {
return autoConvert_testapigroup_CarpSpec_To_v1_CarpSpec(in, out, s)
}
func autoConvert_v1_CarpStatus_To_testapigroup_CarpStatus(in *CarpStatus, out *testapigroup.CarpStatus, s conversion.Scope) error {
out.Phase = testapigroup.CarpPhase(in.Phase)
out.Conditions = *(*[]testapigroup.CarpCondition)(unsafe.Pointer(&in.Conditions))
out.Message = in.Message
out.Reason = in.Reason
out.HostIP = in.HostIP
out.CarpIP = in.CarpIP
out.StartTime = (*meta_v1.Time)(unsafe.Pointer(in.StartTime))
return nil
}
// Convert_v1_CarpStatus_To_testapigroup_CarpStatus is an autogenerated conversion function.
func Convert_v1_CarpStatus_To_testapigroup_CarpStatus(in *CarpStatus, out *testapigroup.CarpStatus, s conversion.Scope) error {
return autoConvert_v1_CarpStatus_To_testapigroup_CarpStatus(in, out, s)
}
func autoConvert_testapigroup_CarpStatus_To_v1_CarpStatus(in *testapigroup.CarpStatus, out *CarpStatus, s conversion.Scope) error {
out.Phase = CarpPhase(in.Phase)
out.Conditions = *(*[]CarpCondition)(unsafe.Pointer(&in.Conditions))
out.Message = in.Message
out.Reason = in.Reason
out.HostIP = in.HostIP
out.CarpIP = in.CarpIP
out.StartTime = (*meta_v1.Time)(unsafe.Pointer(in.StartTime))
return nil
}
// Convert_testapigroup_CarpStatus_To_v1_CarpStatus is an autogenerated conversion function.
func Convert_testapigroup_CarpStatus_To_v1_CarpStatus(in *testapigroup.CarpStatus, out *CarpStatus, s conversion.Scope) error {
return autoConvert_testapigroup_CarpStatus_To_v1_CarpStatus(in, out, s)
}

View File

@ -0,0 +1,155 @@
// +build !ignore_autogenerated
/*
Copyright 2017 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 deepcopy-gen. Do not edit it manually!
package v1
import (
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
reflect "reflect"
)
func init() {
SchemeBuilder.Register(RegisterDeepCopies)
}
// RegisterDeepCopies adds deep-copy functions to the given scheme. Public
// to allow building arbitrary schemes.
func RegisterDeepCopies(scheme *runtime.Scheme) error {
return scheme.AddGeneratedDeepCopyFuncs(
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1_Carp, InType: reflect.TypeOf(&Carp{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1_CarpCondition, InType: reflect.TypeOf(&CarpCondition{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1_CarpList, InType: reflect.TypeOf(&CarpList{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1_CarpSpec, InType: reflect.TypeOf(&CarpSpec{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1_CarpStatus, InType: reflect.TypeOf(&CarpStatus{})},
)
}
// DeepCopy_v1_Carp is an autogenerated deepcopy function.
func DeepCopy_v1_Carp(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Carp)
out := out.(*Carp)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*meta_v1.ObjectMeta)
}
if newVal, err := c.DeepCopy(&in.Spec); err != nil {
return err
} else {
out.Spec = *newVal.(*CarpSpec)
}
if newVal, err := c.DeepCopy(&in.Status); err != nil {
return err
} else {
out.Status = *newVal.(*CarpStatus)
}
return nil
}
}
// DeepCopy_v1_CarpCondition is an autogenerated deepcopy function.
func DeepCopy_v1_CarpCondition(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpCondition)
out := out.(*CarpCondition)
*out = *in
out.LastProbeTime = in.LastProbeTime.DeepCopy()
out.LastTransitionTime = in.LastTransitionTime.DeepCopy()
return nil
}
}
// DeepCopy_v1_CarpList is an autogenerated deepcopy function.
func DeepCopy_v1_CarpList(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpList)
out := out.(*CarpList)
*out = *in
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Carp, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*Carp)
}
}
}
return nil
}
}
// DeepCopy_v1_CarpSpec is an autogenerated deepcopy function.
func DeepCopy_v1_CarpSpec(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpSpec)
out := out.(*CarpSpec)
*out = *in
if in.TerminationGracePeriodSeconds != nil {
in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds
*out = new(int64)
**out = **in
}
if in.ActiveDeadlineSeconds != nil {
in, out := &in.ActiveDeadlineSeconds, &out.ActiveDeadlineSeconds
*out = new(int64)
**out = **in
}
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = make(map[string]string)
for key, val := range *in {
(*out)[key] = val
}
}
return nil
}
}
// DeepCopy_v1_CarpStatus is an autogenerated deepcopy function.
func DeepCopy_v1_CarpStatus(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpStatus)
out := out.(*CarpStatus)
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]CarpCondition, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*CarpCondition)
}
}
}
if in.StartTime != nil {
in, out := &in.StartTime, &out.StartTime
*out = new(meta_v1.Time)
**out = (*in).DeepCopy()
}
return nil
}
}

View File

@ -0,0 +1,32 @@
// +build !ignore_autogenerated
/*
Copyright 2017 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 defaulter-gen. Do not edit it manually!
package v1
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,155 @@
// +build !ignore_autogenerated
/*
Copyright 2017 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 deepcopy-gen. Do not edit it manually!
package testapigroup
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
reflect "reflect"
)
func init() {
SchemeBuilder.Register(RegisterDeepCopies)
}
// RegisterDeepCopies adds deep-copy functions to the given scheme. Public
// to allow building arbitrary schemes.
func RegisterDeepCopies(scheme *runtime.Scheme) error {
return scheme.AddGeneratedDeepCopyFuncs(
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_testapigroup_Carp, InType: reflect.TypeOf(&Carp{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_testapigroup_CarpCondition, InType: reflect.TypeOf(&CarpCondition{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_testapigroup_CarpList, InType: reflect.TypeOf(&CarpList{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_testapigroup_CarpSpec, InType: reflect.TypeOf(&CarpSpec{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_testapigroup_CarpStatus, InType: reflect.TypeOf(&CarpStatus{})},
)
}
// DeepCopy_testapigroup_Carp is an autogenerated deepcopy function.
func DeepCopy_testapigroup_Carp(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Carp)
out := out.(*Carp)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
if newVal, err := c.DeepCopy(&in.Spec); err != nil {
return err
} else {
out.Spec = *newVal.(*CarpSpec)
}
if newVal, err := c.DeepCopy(&in.Status); err != nil {
return err
} else {
out.Status = *newVal.(*CarpStatus)
}
return nil
}
}
// DeepCopy_testapigroup_CarpCondition is an autogenerated deepcopy function.
func DeepCopy_testapigroup_CarpCondition(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpCondition)
out := out.(*CarpCondition)
*out = *in
out.LastProbeTime = in.LastProbeTime.DeepCopy()
out.LastTransitionTime = in.LastTransitionTime.DeepCopy()
return nil
}
}
// DeepCopy_testapigroup_CarpList is an autogenerated deepcopy function.
func DeepCopy_testapigroup_CarpList(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpList)
out := out.(*CarpList)
*out = *in
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Carp, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*Carp)
}
}
}
return nil
}
}
// DeepCopy_testapigroup_CarpSpec is an autogenerated deepcopy function.
func DeepCopy_testapigroup_CarpSpec(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpSpec)
out := out.(*CarpSpec)
*out = *in
if in.TerminationGracePeriodSeconds != nil {
in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds
*out = new(int64)
**out = **in
}
if in.ActiveDeadlineSeconds != nil {
in, out := &in.ActiveDeadlineSeconds, &out.ActiveDeadlineSeconds
*out = new(int64)
**out = **in
}
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = make(map[string]string)
for key, val := range *in {
(*out)[key] = val
}
}
return nil
}
}
// DeepCopy_testapigroup_CarpStatus is an autogenerated deepcopy function.
func DeepCopy_testapigroup_CarpStatus(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*CarpStatus)
out := out.(*CarpStatus)
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]CarpCondition, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*CarpCondition)
}
}
}
if in.StartTime != nil {
in, out := &in.StartTime, &out.StartTime
*out = new(v1.Time)
**out = (*in).DeepCopy()
}
return nil
}
}

View File

@ -0,0 +1,52 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_test(
name = "go_default_test",
srcs = [
"api_meta_help_test.go",
"api_meta_meta_test.go",
"apis_meta_v1_unstructed_unstructure_test.go",
"runtime_helper_test.go",
"runtime_serializer_protobuf_protobuf_test.go",
"runtime_unversioned_test.go",
],
library = ":go_default_library",
tags = ["automanaged"],
deps = [
"//vendor/github.com/google/gofuzz:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/testing:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["util.go"],
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/testapigroup/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
],
)

View File

@ -14,22 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package test
import (
"reflect"
"testing"
"github.com/google/gofuzz"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api"
"github.com/google/gofuzz"
)
func TestIsList(t *testing.T) {
@ -37,8 +37,8 @@ func TestIsList(t *testing.T) {
obj runtime.Object
isList bool
}{
{&api.PodList{}, true},
{&api.Pod{}, false},
{&testapigroup.CarpList{}, true},
{&testapigroup.Carp{}, false},
}
for _, item := range tests {
if e, a := item.isList, meta.IsListType(item.obj); e != a {
@ -49,8 +49,8 @@ func TestIsList(t *testing.T) {
func TestExtractList(t *testing.T) {
list1 := []runtime.Object{
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&api.Service{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
}
list2 := &v1.List{
Items: []runtime.RawExtension{
@ -60,13 +60,13 @@ func TestExtractList(t *testing.T) {
},
}
list3 := &fakePtrValueList{
Items: []*api.Pod{
Items: []*testapigroup.Carp{
{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
},
}
list4 := &api.PodList{
Items: []api.Pod{
list4 := &testapigroup.CarpList{
Items: []testapigroup.Carp{
{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
@ -86,7 +86,7 @@ func TestExtractList(t *testing.T) {
equal bool
}{
{
in: &api.List{},
in: &List{},
out: []interface{}{},
},
{
@ -98,7 +98,7 @@ func TestExtractList(t *testing.T) {
out: []interface{}{},
},
{
in: &api.List{Items: list1},
in: &List{Items: list1},
out: []interface{}{list1[0], list1[1]},
},
{
@ -142,8 +142,8 @@ func TestExtractList(t *testing.T) {
func TestEachListItem(t *testing.T) {
list1 := []runtime.Object{
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&api.Service{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
}
list2 := &v1.List{
Items: []runtime.RawExtension{
@ -153,13 +153,13 @@ func TestEachListItem(t *testing.T) {
},
}
list3 := &fakePtrValueList{
Items: []*api.Pod{
Items: []*testapigroup.Carp{
{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
},
}
list4 := &api.PodList{
Items: []api.Pod{
list4 := &testapigroup.CarpList{
Items: []testapigroup.Carp{
{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
@ -178,7 +178,7 @@ func TestEachListItem(t *testing.T) {
out []interface{}
}{
{
in: &api.List{},
in: &List{},
out: []interface{}{},
},
{
@ -190,7 +190,7 @@ func TestEachListItem(t *testing.T) {
out: []interface{}{},
},
{
in: &api.List{Items: list1},
in: &List{Items: list1},
out: []interface{}{list1[0], list1[1]},
},
{
@ -252,7 +252,7 @@ func TestExtractListOfInterfacePtrs(t *testing.T) {
}
type fakePtrValueList struct {
Items []*api.Pod
Items []*testapigroup.Carp
}
func (obj fakePtrValueList) GetObjectKind() schema.ObjectKind {
@ -260,11 +260,11 @@ func (obj fakePtrValueList) GetObjectKind() schema.ObjectKind {
}
func TestSetList(t *testing.T) {
pl := &api.PodList{}
pl := &testapigroup.CarpList{}
list := []runtime.Object{
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
}
err := meta.SetList(pl, list)
if err != nil {
@ -274,18 +274,18 @@ func TestSetList(t *testing.T) {
t.Fatalf("Expected %v, got %v", e, a)
}
for i := range list {
if e, a := list[i].(*api.Pod).Name, pl.Items[i].Name; e != a {
if e, a := list[i].(*testapigroup.Carp).Name, pl.Items[i].Name; e != a {
t.Fatalf("Expected %v, got %v", e, a)
}
}
}
func TestSetListToRuntimeObjectArray(t *testing.T) {
pl := &api.List{}
pl := &List{}
list := []runtime.Object{
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "3"}},
}
err := meta.SetList(pl, list)
if err != nil {
@ -325,7 +325,7 @@ func TestSetListToMatchingType(t *testing.T) {
func TestSetExtractListRoundTrip(t *testing.T) {
fuzzer := fuzz.New().NilChance(0).NumElements(1, 5)
for i := 0; i < 5; i++ {
start := &api.PodList{}
start := &testapigroup.CarpList{}
fuzzer.Fuzz(&start.Items)
list, err := meta.ExtractList(start)
@ -333,7 +333,7 @@ func TestSetExtractListRoundTrip(t *testing.T) {
t.Errorf("Unexpected error %v", err)
continue
}
got := &api.PodList{}
got := &testapigroup.CarpList{}
err = meta.SetList(got, list)
if err != nil {
t.Errorf("Unexpected error %v", err)

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package test
import (
"reflect"
@ -24,14 +24,14 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api"
)
func TestAPIObjectMeta(t *testing.T) {
j := &api.Pod{
j := &testapigroup.Carp{
TypeMeta: metav1.TypeMeta{APIVersion: "/a", Kind: "b"},
ObjectMeta: metav1.ObjectMeta{
Namespace: "bar",
@ -394,7 +394,7 @@ func TestAccessOwnerReferences(t *testing.T) {
// BenchmarkAccessorSetFastPath shows the interface fast path
func BenchmarkAccessorSetFastPath(b *testing.B) {
obj := &api.Pod{
obj := &testapigroup.Carp{
TypeMeta: metav1.TypeMeta{APIVersion: "/a", Kind: "b"},
ObjectMeta: metav1.ObjectMeta{
Namespace: "bar",

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package test
import (
"fmt"
@ -24,21 +24,21 @@ import (
"testing"
"time"
apitesting "k8s.io/apimachinery/pkg/api/testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/validation"
)
func TestDecodeUnstructured(t *testing.T) {
groupVersionString := api.Registry.GroupOrDie(api.GroupName).GroupVersion.String()
groupVersionString := "v1"
rawJson := fmt.Sprintf(`{"kind":"Pod","apiVersion":"%s","metadata":{"name":"test"}}`, groupVersionString)
pl := &api.List{
pl := &List{
Items: []runtime.Object{
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&runtime.Unknown{
TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: groupVersionString},
Raw: []byte(rawJson),
@ -449,7 +449,7 @@ func TestDecodeNumbers(t *testing.T) {
// Start with a valid pod
originalJSON := []byte(`{
"kind":"Pod",
"kind":"Carp",
"apiVersion":"v1",
"metadata":{"name":"pod","namespace":"foo"},
"spec":{
@ -458,21 +458,15 @@ func TestDecodeNumbers(t *testing.T) {
}
}`)
pod := &api.Pod{}
pod := &testapigroup.Carp{}
// Decode with structured codec
codec, err := testapi.GetCodecForObject(pod)
_, codecs := TestScheme()
codec := apitesting.TestCodec(codecs, schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal})
err := runtime.DecodeInto(codec, originalJSON, pod)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
err = runtime.DecodeInto(codec, originalJSON, pod)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// ensure pod is valid
if errs := validation.ValidatePod(pod); len(errs) > 0 {
t.Fatalf("pod should be valid: %v", errs)
}
// Round-trip with unstructured codec
unstructuredObj, err := runtime.Decode(unstructured.UnstructuredJSONScheme, originalJSON)
@ -495,13 +489,11 @@ func TestDecodeNumbers(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
// ensure pod is still valid
pod2, ok := obj2.(*api.Pod)
pod2, ok := obj2.(*testapigroup.Carp)
if !ok {
t.Fatalf("expected an *api.Pod, got %#v", obj2)
}
if errs := validation.ValidatePod(pod2); len(errs) > 0 {
t.Fatalf("pod should be valid: %v", errs)
}
// ensure round-trip preserved large integers
if !reflect.DeepEqual(pod, pod2) {
t.Fatalf("Expected\n\t%#v, got \n\t%#v", pod, pod2)

View File

@ -14,32 +14,36 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package test
import (
"testing"
apitesting "k8s.io/apimachinery/pkg/api/testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
)
func TestDecodeList(t *testing.T) {
pl := &api.List{
pl := List{
Items: []runtime.Object{
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}},
&runtime.Unknown{
TypeMeta: runtime.TypeMeta{Kind: "Pod", APIVersion: api.Registry.GroupOrDie(api.GroupName).GroupVersion.String()},
Raw: []byte(`{"kind":"Pod","apiVersion":"` + api.Registry.GroupOrDie(api.GroupName).GroupVersion.String() + `","metadata":{"name":"test"}}`),
TypeMeta: runtime.TypeMeta{Kind: "Carp", APIVersion: "v1"},
Raw: []byte(`{"kind":"Carp","apiVersion":"` + "v1" + `","metadata":{"name":"test"}}`),
ContentType: runtime.ContentTypeJSON,
},
},
}
if errs := runtime.DecodeList(pl.Items, testapi.Default.Codec()); len(errs) != 0 {
_, codecs := TestScheme()
Codec := apitesting.TestCodec(codecs, testapigroup.SchemeGroupVersion)
if errs := runtime.DecodeList(pl.Items, Codec); len(errs) != 0 {
t.Fatalf("unexpected error %v", errs)
}
if pod, ok := pl.Items[1].(*api.Pod); !ok || pod.Name != "test" {
if pod, ok := pl.Items[1].(*testapigroup.Carp); !ok || pod.Name != "test" {
t.Errorf("object not converted: %#v", pl.Items[1])
}
}

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package test
import (
"bytes"
@ -31,8 +31,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api"
_ "k8s.io/kubernetes/pkg/api/install"
)
type testObject struct {
@ -323,9 +321,11 @@ func TestDecodeObjects(t *testing.T) {
data: wire1,
},
}
scheme := runtime.NewScheme()
for i, test := range testCases {
s := protobuf.NewSerializer(api.Scheme, api.Scheme, "application/protobuf")
scheme.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &v1.Pod{})
v1.AddToScheme(scheme)
s := protobuf.NewSerializer(scheme, scheme, "application/protobuf")
obj, err := runtime.Decode(s, test.data)
switch {

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package test
import (
"encoding/json"
@ -23,11 +23,10 @@ import (
// TODO: Ideally we should create the necessary package structure in e.g.,
// pkg/conversion/test/... instead of importing pkg/api here.
apitesting "k8s.io/apimachinery/pkg/api/testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func TestV1EncodeDecodeStatus(t *testing.T) {
@ -38,9 +37,10 @@ func TestV1EncodeDecodeStatus(t *testing.T) {
Message: "",
}
v1Codec := testapi.Default.Codec()
_, codecs := TestScheme()
codec := apitesting.TestCodec(codecs, schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal})
encoded, err := runtime.Encode(v1Codec, status)
encoded, err := runtime.Encode(codec, status)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -54,7 +54,7 @@ func TestV1EncodeDecodeStatus(t *testing.T) {
if typeMeta.APIVersion != "v1" {
t.Errorf("APIVersion is not set to \"v1\". Got %v", string(encoded))
}
decoded, err := runtime.Decode(v1Codec, encoded)
decoded, err := runtime.Decode(codec, encoded)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -72,7 +72,9 @@ func TestExperimentalEncodeDecodeStatus(t *testing.T) {
}
// TODO: caesarxuchao: use the testapi.Extensions.Codec() once the PR that
// moves experimental from v1 to v1beta1 got merged.
expCodec := api.Codecs.LegacyCodec(extensions.SchemeGroupVersion)
_, codecs := TestScheme()
expCodec := apitesting.TestCodec(codecs, schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal})
encoded, err := runtime.Encode(expCodec, status)
if err != nil {
t.Errorf("unexpected error: %v", err)

View File

@ -0,0 +1,57 @@
/*
Copyright 2017 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 test
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/testapigroup"
"k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
apiserializer "k8s.io/apimachinery/pkg/runtime/serializer"
)
// List holds a list of objects, which may not be known by the server.
type List struct {
metav1.TypeMeta
// +optional
metav1.ListMeta
Items []runtime.Object
}
func TestScheme() (*runtime.Scheme, apiserializer.CodecFactory) {
internalGV := schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal}
externalGV := schema.GroupVersion{Group: "", Version: "v1"}
scheme := runtime.NewScheme()
scheme.AddKnownTypes(internalGV,
&testapigroup.Carp{},
&testapigroup.CarpList{},
&List{},
)
scheme.AddKnownTypes(externalGV,
&v1.Carp{},
&v1.CarpList{},
&List{},
)
testapigroup.AddToScheme(scheme)
v1.AddToScheme(scheme)
codecs := apiserializer.NewCodecFactory(scheme)
return scheme, codecs
}

View File

@ -45,3 +45,14 @@ go_test(
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["until_test.go"],
library = ":go_default_library",
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
)

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
package watch
import (
"errors"
@ -22,15 +22,20 @@ import (
"testing"
"time"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
. "k8s.io/apimachinery/pkg/watch"
"k8s.io/kubernetes/pkg/api"
)
type fakePod struct {
name string
}
func (obj *fakePod) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func TestUntil(t *testing.T) {
fw := NewFake()
go func() {
var obj *api.Pod
var obj *fakePod
fw.Add(obj)
fw.Modify(obj)
}()
@ -50,7 +55,7 @@ func TestUntil(t *testing.T) {
if lastEvent.Type != Modified {
t.Fatalf("expected MODIFIED event type, got %v", lastEvent.Type)
}
if got, isPod := lastEvent.Object.(*api.Pod); !isPod {
if got, isPod := lastEvent.Object.(*fakePod); !isPod {
t.Fatalf("expected a pod event, got %#v", got)
}
}
@ -58,7 +63,7 @@ func TestUntil(t *testing.T) {
func TestUntilMultipleConditions(t *testing.T) {
fw := NewFake()
go func() {
var obj *api.Pod
var obj *fakePod
fw.Add(obj)
}()
conditions := []ConditionFunc{
@ -77,7 +82,7 @@ func TestUntilMultipleConditions(t *testing.T) {
if lastEvent.Type != Added {
t.Fatalf("expected MODIFIED event type, got %v", lastEvent.Type)
}
if got, isPod := lastEvent.Object.(*api.Pod); !isPod {
if got, isPod := lastEvent.Object.(*fakePod); !isPod {
t.Fatalf("expected a pod event, got %#v", got)
}
}
@ -85,7 +90,7 @@ func TestUntilMultipleConditions(t *testing.T) {
func TestUntilMultipleConditionsFail(t *testing.T) {
fw := NewFake()
go func() {
var obj *api.Pod
var obj *fakePod
fw.Add(obj)
}()
conditions := []ConditionFunc{
@ -105,7 +110,7 @@ func TestUntilMultipleConditionsFail(t *testing.T) {
if lastEvent.Type != Added {
t.Fatalf("expected ADDED event type, got %v", lastEvent.Type)
}
if got, isPod := lastEvent.Object.(*api.Pod); !isPod {
if got, isPod := lastEvent.Object.(*fakePod); !isPod {
t.Fatalf("expected a pod event, got %#v", got)
}
}
@ -113,7 +118,7 @@ func TestUntilMultipleConditionsFail(t *testing.T) {
func TestUntilTimeout(t *testing.T) {
fw := NewFake()
go func() {
var obj *api.Pod
var obj *fakePod
fw.Add(obj)
fw.Modify(obj)
}()
@ -137,7 +142,7 @@ func TestUntilTimeout(t *testing.T) {
if lastEvent.Type != Modified {
t.Fatalf("expected MODIFIED event type, got %v", lastEvent.Type)
}
if got, isPod := lastEvent.Object.(*api.Pod); !isPod {
if got, isPod := lastEvent.Object.(*fakePod); !isPod {
t.Fatalf("expected a pod event, got %#v", got)
}
}
@ -145,7 +150,7 @@ func TestUntilTimeout(t *testing.T) {
func TestUntilErrorCondition(t *testing.T) {
fw := NewFake()
go func() {
var obj *api.Pod
var obj *fakePod
fw.Add(obj)
}()
expected := "something bad"