Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added JobTemplate, a preliminary step for ScheduledJob and Workflow #21675

Merged
merged 4 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions api/swagger-spec/batch_v2alpha1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"swaggerVersion": "1.2",
"apiVersion": "batch/v2alpha1",
"basePath": "https://10.10.10.10:443",
"resourcePath": "/apis/batch/v2alpha1",
"apis": [
{
"path": "/apis/batch/v2alpha1",
"description": "API at /apis/batch/v2alpha1",
"operations": [
{
"type": "unversioned.APIResourceList",
"method": "GET",
"summary": "get available resources",
"nickname": "getAPIResources",
"parameters": [],
"produces": [
"application/json",
"application/yaml",
"application/vnd.kubernetes.protobuf"
],
"consumes": [
"application/json",
"application/yaml",
"application/vnd.kubernetes.protobuf"
]
}
]
}
],
"models": {
"unversioned.APIResourceList": {
"id": "unversioned.APIResourceList",
"description": "APIResourceList is a list of APIResource, it is used to expose the name of the resources supported in a specific group and version, and if the resource is namespaced.",
"required": [
"groupVersion",
"resources"
],
"properties": {
"kind": {
"type": "string",
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds"
},
"apiVersion": {
"type": "string",
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#resources"
},
"groupVersion": {
"type": "string",
"description": "groupVersion is the group and version this APIResourceList is for."
},
"resources": {
"type": "array",
"items": {
"$ref": "unversioned.APIResource"
},
"description": "resources contains the name of the resources and if they are namespaced."
}
}
},
"unversioned.APIResource": {
"id": "unversioned.APIResource",
"description": "APIResource specifies the name of a resource and whether it is namespaced.",
"required": [
"name",
"namespaced",
"kind"
],
"properties": {
"name": {
"type": "string",
"description": "name is the name of the resource."
},
"namespaced": {
"type": "boolean",
"description": "namespaced indicates if a resource is namespaced or not."
},
"kind": {
"type": "string",
"description": "kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')"
}
}
}
}
}
4 changes: 4 additions & 0 deletions api/swagger-spec/resourceListing.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"path": "/apis/batch/v1",
"description": "API at /apis/batch/v1"
},
{
"path": "/apis/batch/v2alpha1",
"description": "API at /apis/batch/v2alpha1"
},
{
"path": "/apis/batch",
"description": "get information of a group"
Expand Down
1 change: 1 addition & 0 deletions cmd/libs/go2idl/conversion-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
"k8s.io/kubernetes/pkg/apis/autoscaling/v1",
"k8s.io/kubernetes/pkg/apis/batch",
"k8s.io/kubernetes/pkg/apis/batch/v1",
"k8s.io/kubernetes/pkg/apis/batch/v2alpha1",
"k8s.io/kubernetes/pkg/apis/apps",
"k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
"k8s.io/kubernetes/pkg/apis/componentconfig",
Expand Down
1 change: 1 addition & 0 deletions cmd/libs/go2idl/deepcopy-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
"k8s.io/kubernetes/pkg/apis/autoscaling/v1",
"k8s.io/kubernetes/pkg/apis/batch",
"k8s.io/kubernetes/pkg/apis/batch/v1",
"k8s.io/kubernetes/pkg/apis/batch/v2alpha1",
"k8s.io/kubernetes/pkg/apis/apps",
"k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
"k8s.io/kubernetes/pkg/apis/componentconfig",
Expand Down
1 change: 1 addition & 0 deletions cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func New() *Generator {
`k8s.io/kubernetes/pkg/apis/extensions/v1beta1`,
`k8s.io/kubernetes/pkg/apis/autoscaling/v1`,
`k8s.io/kubernetes/pkg/apis/batch/v1`,
`k8s.io/kubernetes/pkg/apis/batch/v2alpha1`,
`k8s.io/kubernetes/pkg/apis/apps/v1alpha1`,
`k8s.io/kubernetes/federation/apis/federation/v1alpha1`,
}, ","),
Expand Down
2 changes: 1 addition & 1 deletion hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
# Lists of API Versions of each groups that should be tested, groups are
# separated by comma, lists are separated by semicolon. e.g.,
# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1,federation/v1alpha1;v1,autoscaling/v1,batch/v1,extensions/v1beta1,apps/v1alpha1,metrics/v1alpha1,federation/v1alpha1,policy/v1alpha1"}
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1,federation/v1alpha1;v1,autoscaling/v1,batch/v1,batch/v2alpha1,extensions/v1beta1,apps/v1alpha1,metrics/v1alpha1,federation/v1alpha1,policy/v1alpha1"}
# once we have multiple group supports
# Run tests with the standard (registry) and a custom etcd prefix
# (kubernetes.io/registry).
Expand Down
2 changes: 1 addition & 1 deletion hack/update-generated-swagger-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EOF
mv "$TMPFILE" "pkg/$(kube::util::group-version-to-pkg-path "${group_version}")/types_swagger_doc_generated.go"
}

GROUP_VERSIONS=(unversioned v1 authorization/v1beta1 autoscaling/v1 batch/v1 extensions/v1beta1 apps/v1alpha1)
GROUP_VERSIONS=(unversioned v1 authorization/v1beta1 autoscaling/v1 batch/v1 batch/v2alpha1 extensions/v1beta1 apps/v1alpha1)
# To avoid compile errors, remove the currently existing files.
for group_version in "${GROUP_VERSIONS[@]}"; do
rm -f "pkg/$(kube::util::group-version-to-pkg-path "${group_version}")/types_swagger_doc_generated.go"
Expand Down
2 changes: 1 addition & 1 deletion hack/update-swagger-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ APISERVER_PID=$!
kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver: "

SWAGGER_API_PATH="http://127.0.0.1:${API_PORT}/swaggerapi/"
DEFAULT_GROUP_VERSIONS="v1 autoscaling/v1 batch/v1 extensions/v1beta1 apps/v1alpha1"
DEFAULT_GROUP_VERSIONS="v1 autoscaling/v1 batch/v1 batch/v2alpha1 extensions/v1beta1 apps/v1alpha1"
VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS}

kube::log::status "Updating " ${SWAGGER_ROOT_DIR}
Expand Down
106 changes: 62 additions & 44 deletions pkg/api/testapi/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ var (
)

type TestGroup struct {
externalGroupVersion unversioned.GroupVersion
internalGroupVersion unversioned.GroupVersion
internalTypes map[string]reflect.Type
// the first element in the group is meant to be the preferred version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for dealing with this file. I think it needs some help in the future but I won't ask you do to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does :/. My work is just a tip of an iceberg we need to dig into to get multiple versions fully testable.

externalGroupVersions []unversioned.GroupVersion
internalGroupVersion unversioned.GroupVersion
internalTypes map[string]reflect.Type
}

func init() {
Expand Down Expand Up @@ -100,26 +101,31 @@ func init() {
}

internalGroupVersion := unversioned.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}
Groups[groupVersion.Group] = TestGroup{
externalGroupVersion: groupVersion,
internalGroupVersion: internalGroupVersion,
internalTypes: api.Scheme.KnownTypes(internalGroupVersion),
if group, ok := Groups[groupVersion.Group]; !ok {
Groups[groupVersion.Group] = TestGroup{
externalGroupVersions: []unversioned.GroupVersion{groupVersion},
internalGroupVersion: internalGroupVersion,
internalTypes: api.Scheme.KnownTypes(internalGroupVersion),
}
} else {
group.externalGroupVersions = append(group.externalGroupVersions, groupVersion)
Groups[groupVersion.Group] = group
}
}
}

if _, ok := Groups[api.GroupName]; !ok {
Groups[api.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: api.GroupName, Version: registered.GroupOrDie(api.GroupName).GroupVersion.Version},
internalGroupVersion: api.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(api.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: api.GroupName, Version: registered.GroupOrDie(api.GroupName).GroupVersion.Version}},
internalGroupVersion: api.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(api.SchemeGroupVersion),
}
}
if _, ok := Groups[extensions.GroupName]; !ok {
Groups[extensions.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: extensions.GroupName, Version: registered.GroupOrDie(extensions.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: extensions.GroupName, Version: registered.GroupOrDie(extensions.GroupName).GroupVersion.Version}},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
}
}
if _, ok := Groups[autoscaling.GroupName]; !ok {
Expand All @@ -131,9 +137,9 @@ func init() {
internalTypes[k] = t
}
Groups[autoscaling.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: internalTypes,
externalGroupVersions: []unversioned.GroupVersion{{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version}},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: internalTypes,
}
}
if _, ok := Groups[autoscaling.GroupName+"IntraGroup"]; !ok {
Expand All @@ -145,30 +151,34 @@ func init() {
}
}
Groups[autoscaling.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version},
internalGroupVersion: autoscaling.SchemeGroupVersion,
internalTypes: internalTypes,
externalGroupVersions: []unversioned.GroupVersion{{Group: autoscaling.GroupName, Version: registered.GroupOrDie(autoscaling.GroupName).GroupVersion.Version}},
internalGroupVersion: autoscaling.SchemeGroupVersion,
internalTypes: internalTypes,
}
}
if _, ok := Groups[batch.GroupName]; !ok {
var gvs []unversioned.GroupVersion
for _, gv := range registered.GroupOrDie(batch.GroupName).GroupVersions {
gvs = append(gvs, gv)
}
Groups[batch.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: batch.GroupName, Version: registered.GroupOrDie(batch.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
externalGroupVersions: gvs,
internalGroupVersion: batch.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(batch.SchemeGroupVersion),
}
}
if _, ok := Groups[apps.GroupName]; !ok {
Groups[apps.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: apps.GroupName, Version: registered.GroupOrDie(apps.GroupName).GroupVersion.Version},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: apps.GroupName, Version: registered.GroupOrDie(apps.GroupName).GroupVersion.Version}},
internalGroupVersion: extensions.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(extensions.SchemeGroupVersion),
}
}
if _, ok := Groups[federation.GroupName]; !ok {
Groups[federation.GroupName] = TestGroup{
externalGroupVersion: unversioned.GroupVersion{Group: federation.GroupName, Version: registered.GroupOrDie(federation.GroupName).GroupVersion.Version},
internalGroupVersion: federation.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(federation.SchemeGroupVersion),
externalGroupVersions: []unversioned.GroupVersion{{Group: federation.GroupName, Version: registered.GroupOrDie(federation.GroupName).GroupVersion.Version}},
internalGroupVersion: federation.SchemeGroupVersion,
internalTypes: api.Scheme.KnownTypes(federation.SchemeGroupVersion),
}
}

Expand All @@ -185,10 +195,14 @@ func (g TestGroup) ContentConfig() (string, *unversioned.GroupVersion, runtime.C
}

func (g TestGroup) GroupVersion() *unversioned.GroupVersion {
copyOfGroupVersion := g.externalGroupVersion
copyOfGroupVersion := g.externalGroupVersions[0]
return &copyOfGroupVersion
}

func (g TestGroup) GroupVersions() []unversioned.GroupVersion {
return append([]unversioned.GroupVersion{}, g.externalGroupVersions...)
}

// InternalGroupVersion returns the group,version used to identify the internal
// types for this API
func (g TestGroup) InternalGroupVersion() unversioned.GroupVersion {
Expand All @@ -204,9 +218,9 @@ func (g TestGroup) InternalTypes() map[string]reflect.Type {
// KUBE_TEST_API_TYPE env var.
func (g TestGroup) Codec() runtime.Codec {
if serializer.Serializer == nil {
return api.Codecs.LegacyCodec(g.externalGroupVersion)
return api.Codecs.LegacyCodec(g.externalGroupVersions[0])
}
return api.Codecs.CodecForVersions(serializer, api.Codecs.UniversalDeserializer(), []unversioned.GroupVersion{g.externalGroupVersion}, nil)
return api.Codecs.CodecForVersions(serializer, api.Codecs.UniversalDeserializer(), g.externalGroupVersions, nil)
}

// NegotiatedSerializer returns the negotiated serializer for the server.
Expand All @@ -224,7 +238,7 @@ func (g TestGroup) StorageCodec() runtime.Codec {
s := storageSerializer.Serializer

if s == nil {
return api.Codecs.LegacyCodec(g.externalGroupVersion)
return api.Codecs.LegacyCodec(g.externalGroupVersions[0])
}

// etcd2 only supports string data - we must wrap any result before returning
Expand All @@ -234,13 +248,13 @@ func (g TestGroup) StorageCodec() runtime.Codec {
}
ds := recognizer.NewDecoder(s, api.Codecs.UniversalDeserializer())

return api.Codecs.CodecForVersions(s, ds, []unversioned.GroupVersion{g.externalGroupVersion}, nil)
return api.Codecs.CodecForVersions(s, ds, g.externalGroupVersions, nil)
}

// Converter returns the api.Scheme for the API version to test against, as set by the
// KUBE_TEST_API env var.
func (g TestGroup) Converter() runtime.ObjectConvertor {
interfaces, err := registered.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion)
interfaces, err := registered.GroupOrDie(g.externalGroupVersions[0].Group).InterfacesFor(g.externalGroupVersions[0])
if err != nil {
panic(err)
}
Expand All @@ -250,7 +264,7 @@ func (g TestGroup) Converter() runtime.ObjectConvertor {
// MetadataAccessor returns the MetadataAccessor for the API version to test against,
// as set by the KUBE_TEST_API env var.
func (g TestGroup) MetadataAccessor() meta.MetadataAccessor {
interfaces, err := registered.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion)
interfaces, err := registered.GroupOrDie(g.externalGroupVersions[0].Group).InterfacesFor(g.externalGroupVersions[0])
if err != nil {
panic(err)
}
Expand All @@ -261,18 +275,18 @@ func (g TestGroup) MetadataAccessor() meta.MetadataAccessor {
// 'resource' should be the resource path, e.g. "pods" for the Pod type. 'name' should be
// empty for lists.
func (g TestGroup) SelfLink(resource, name string) string {
if g.externalGroupVersion.Group == api.GroupName {
if g.externalGroupVersions[0].Group == api.GroupName {
if name == "" {
return fmt.Sprintf("/api/%s/%s", g.externalGroupVersion.Version, resource)
return fmt.Sprintf("/api/%s/%s", g.externalGroupVersions[0].Version, resource)
}
return fmt.Sprintf("/api/%s/%s/%s", g.externalGroupVersion.Version, resource, name)
return fmt.Sprintf("/api/%s/%s/%s", g.externalGroupVersions[0].Version, resource, name)
} else {
// TODO: will need a /apis prefix once we have proper multi-group
// support
if name == "" {
return fmt.Sprintf("/apis/%s/%s/%s", g.externalGroupVersion.Group, g.externalGroupVersion.Version, resource)
return fmt.Sprintf("/apis/%s/%s/%s", g.externalGroupVersions[0].Group, g.externalGroupVersions[0].Version, resource)
}
return fmt.Sprintf("/apis/%s/%s/%s/%s", g.externalGroupVersion.Group, g.externalGroupVersion.Version, resource, name)
return fmt.Sprintf("/apis/%s/%s/%s/%s", g.externalGroupVersions[0].Group, g.externalGroupVersions[0].Version, resource, name)
}
}

Expand All @@ -281,12 +295,12 @@ func (g TestGroup) SelfLink(resource, name string) string {
// /api/v1/watch/namespaces/foo/pods/pod0 for v1.
func (g TestGroup) ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
var path string
if g.externalGroupVersion.Group == api.GroupName {
path = "/api/" + g.externalGroupVersion.Version
if g.externalGroupVersions[0].Group == api.GroupName {
path = "/api/" + g.externalGroupVersions[0].Version
} else {
// TODO: switch back once we have proper multiple group support
// path = "/apis/" + g.Group + "/" + Version(group...)
path = "/apis/" + g.externalGroupVersion.Group + "/" + g.externalGroupVersion.Version
path = "/apis/" + g.externalGroupVersions[0].Group + "/" + g.externalGroupVersions[0].Version
}

if prefix != "" {
Expand Down Expand Up @@ -355,5 +369,9 @@ func GetCodecForObject(obj runtime.Object) (runtime.Codec, error) {
}

func NewTestGroup(external, internal unversioned.GroupVersion, internalTypes map[string]reflect.Type) TestGroup {
return TestGroup{external, internal, internalTypes}
return TestGroup{
externalGroupVersions: []unversioned.GroupVersion{external},
internalGroupVersion: internal,
internalTypes: internalTypes,
}
}
Loading