diff --git a/build/kazel_generated.bzl b/build/kazel_generated.bzl index 5ff90b7f491..f1fc00ae6d5 100644 --- a/build/kazel_generated.bzl +++ b/build/kazel_generated.bzl @@ -63,6 +63,7 @@ tags_values_pkgs = {"openapi-gen": { "staging/src/k8s.io/api/imagepolicy/v1alpha1", "staging/src/k8s.io/api/networking/v1", "staging/src/k8s.io/api/networking/v1beta1", + "staging/src/k8s.io/api/node/v1alpha1", "staging/src/k8s.io/api/policy/v1beta1", "staging/src/k8s.io/api/rbac/v1", "staging/src/k8s.io/api/rbac/v1alpha1", @@ -138,6 +139,7 @@ tags_pkgs_values = {"openapi-gen": { "staging/src/k8s.io/api/imagepolicy/v1alpha1": ["true"], "staging/src/k8s.io/api/networking/v1": ["true"], "staging/src/k8s.io/api/networking/v1beta1": ["true"], + "staging/src/k8s.io/api/node/v1alpha1": ["true"], "staging/src/k8s.io/api/policy/v1beta1": ["true"], "staging/src/k8s.io/api/rbac/v1": ["true"], "staging/src/k8s.io/api/rbac/v1alpha1": ["true"], diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index d3ac8d26d1c..3c95c2afe80 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -773,6 +773,7 @@ function create-master-audit-policy { - group: "extensions" - group: "metrics.k8s.io" - group: "networking.k8s.io" + - group: "node.k8s.io" - group: "policy" - group: "rbac.authorization.k8s.io" - group: "scheduling.k8s.io" @@ -1747,6 +1748,9 @@ function start-kube-apiserver { if [[ -n "${FEATURE_GATES:-}" ]]; then params+=" --feature-gates=${FEATURE_GATES}" fi + if [[ "${FEATURE_GATES:-}" =~ "RuntimeClass=true" ]]; then + params+=" --runtime-config=node.k8s.io/v1alpha1=true" + fi if [[ -n "${MASTER_ADVERTISE_ADDRESS:-}" ]]; then params+=" --advertise-address=${MASTER_ADVERTISE_ADDRESS}" if [[ -n "${PROXY_SSH_USER:-}" ]]; then @@ -2690,9 +2694,6 @@ EOF setup-addon-manifests "addons" "istio/noauth" fi fi - if [[ "${FEATURE_GATES:-}" =~ "RuntimeClass=true" ]]; then - setup-addon-manifests "addons" "runtimeclass" - fi if [[ -n "${EXTRA_ADDONS_URL:-}" ]]; then download-extra-addons setup-addon-manifests "addons" "gce-extras" diff --git a/cmd/kube-apiserver/app/aggregator.go b/cmd/kube-apiserver/app/aggregator.go index a0686212feb..ad7a120b052 100644 --- a/cmd/kube-apiserver/app/aggregator.go +++ b/cmd/kube-apiserver/app/aggregator.go @@ -276,6 +276,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{ {Group: "coordination.k8s.io", Version: "v1"}: {group: 16500, version: 15}, {Group: "coordination.k8s.io", Version: "v1beta1"}: {group: 16500, version: 9}, {Group: "auditregistration.k8s.io", Version: "v1alpha1"}: {group: 16400, version: 1}, + {Group: "node.k8s.io", Version: "v1alpha1"}: {group: 16300, version: 9}, // Append a new group to the end of the list if unsure. // You can use min(existing group)-100 as the initial value for a group. // Version can be set to 9 (to have space around) for a new group. diff --git a/hack/.golint_failures b/hack/.golint_failures index 7d0db783d29..5959909a0b8 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -279,6 +279,7 @@ pkg/registry/extensions/controller/storage pkg/registry/extensions/rest pkg/registry/networking/networkpolicy/storage pkg/registry/networking/rest +pkg/registry/node/rest pkg/registry/policy/poddisruptionbudget/storage pkg/registry/policy/rest pkg/registry/rbac/clusterrole diff --git a/hack/lib/init.sh b/hack/lib/init.sh index cf0f1f6fe03..3f6fc04cdd2 100755 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -80,6 +80,7 @@ events.k8s.io/v1beta1 \ imagepolicy.k8s.io/v1alpha1 \ networking.k8s.io/v1 \ networking.k8s.io/v1beta1 \ +node.k8s.io/v1alpha1 \ policy/v1beta1 \ rbac.authorization.k8s.io/v1 \ rbac.authorization.k8s.io/v1beta1 \ diff --git a/pkg/BUILD b/pkg/BUILD index c05c2b23db1..976abb05652 100644 --- a/pkg/BUILD +++ b/pkg/BUILD @@ -44,6 +44,7 @@ filegroup( "//pkg/apis/extensions:all-srcs", "//pkg/apis/imagepolicy:all-srcs", "//pkg/apis/networking:all-srcs", + "//pkg/apis/node:all-srcs", "//pkg/apis/policy:all-srcs", "//pkg/apis/rbac:all-srcs", "//pkg/apis/scheduling:all-srcs", diff --git a/pkg/api/testapi/BUILD b/pkg/api/testapi/BUILD index 11eec53bef4..754914c0405 100644 --- a/pkg/api/testapi/BUILD +++ b/pkg/api/testapi/BUILD @@ -41,6 +41,8 @@ go_library( "//pkg/apis/imagepolicy/install:go_default_library", "//pkg/apis/networking:go_default_library", "//pkg/apis/networking/install:go_default_library", + "//pkg/apis/node:go_default_library", + "//pkg/apis/node/install:go_default_library", "//pkg/apis/policy:go_default_library", "//pkg/apis/policy/install:go_default_library", "//pkg/apis/rbac:go_default_library", diff --git a/pkg/api/testapi/testapi.go b/pkg/api/testapi/testapi.go index 32b81d29d0e..ac30f681d2d 100644 --- a/pkg/api/testapi/testapi.go +++ b/pkg/api/testapi/testapi.go @@ -48,6 +48,7 @@ import ( "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/imagepolicy" "k8s.io/kubernetes/pkg/apis/networking" + "k8s.io/kubernetes/pkg/apis/node" "k8s.io/kubernetes/pkg/apis/policy" "k8s.io/kubernetes/pkg/apis/rbac" "k8s.io/kubernetes/pkg/apis/scheduling" @@ -70,6 +71,7 @@ import ( _ "k8s.io/kubernetes/pkg/apis/extensions/install" _ "k8s.io/kubernetes/pkg/apis/imagepolicy/install" _ "k8s.io/kubernetes/pkg/apis/networking/install" + _ "k8s.io/kubernetes/pkg/apis/node/install" _ "k8s.io/kubernetes/pkg/apis/policy/install" _ "k8s.io/kubernetes/pkg/apis/rbac/install" _ "k8s.io/kubernetes/pkg/apis/scheduling/install" @@ -257,6 +259,12 @@ func init() { externalGroupVersion: externalGroupVersion, } } + if _, ok := Groups[node.GroupName]; !ok { + externalGroupVersion := schema.GroupVersion{Group: node.GroupName, Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(node.GroupName)[0].Version} + Groups[node.GroupName] = TestGroup{ + externalGroupVersion: externalGroupVersion, + } + } if _, ok := Groups[events.GroupName]; !ok { externalGroupVersion := schema.GroupVersion{Group: events.GroupName, Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(events.GroupName)[0].Version} Groups[events.GroupName] = TestGroup{ diff --git a/pkg/apis/node/BUILD b/pkg/apis/node/BUILD new file mode 100644 index 00000000000..b4a74b0d977 --- /dev/null +++ b/pkg/apis/node/BUILD @@ -0,0 +1,36 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "register.go", + "types.go", + ], + importpath = "k8s.io/kubernetes/pkg/apis/node", + visibility = ["//visibility:public"], + deps = [ + "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//pkg/apis/node/install:all-srcs", + "//pkg/apis/node/v1alpha1:all-srcs", + "//pkg/apis/node/validation:all-srcs", + ], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/apis/node/doc.go b/pkg/apis/node/doc.go new file mode 100644 index 00000000000..639d61262a6 --- /dev/null +++ b/pkg/apis/node/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package +// +groupName=node.k8s.io + +package node // import "k8s.io/kubernetes/pkg/apis/node" diff --git a/pkg/apis/node/install/BUILD b/pkg/apis/node/install/BUILD new file mode 100644 index 00000000000..769c90e9f16 --- /dev/null +++ b/pkg/apis/node/install/BUILD @@ -0,0 +1,29 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["install.go"], + importpath = "k8s.io/kubernetes/pkg/apis/node/install", + visibility = ["//visibility:public"], + deps = [ + "//pkg/api/legacyscheme:go_default_library", + "//pkg/apis/node:go_default_library", + "//pkg/apis/node/v1alpha1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/apis/node/install/install.go b/pkg/apis/node/install/install.go new file mode 100644 index 00000000000..3537915400c --- /dev/null +++ b/pkg/apis/node/install/install.go @@ -0,0 +1,38 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package install adds the node API group, making it available as +// an option to all of the API encoding/decoding machinery. +package install + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/kubernetes/pkg/api/legacyscheme" + "k8s.io/kubernetes/pkg/apis/node" + "k8s.io/kubernetes/pkg/apis/node/v1alpha1" +) + +func init() { + Install(legacyscheme.Scheme) +} + +// Install registers the API group and adds types to a scheme +func Install(scheme *runtime.Scheme) { + utilruntime.Must(node.AddToScheme(scheme)) + utilruntime.Must(v1alpha1.AddToScheme(scheme)) + utilruntime.Must(scheme.SetVersionPriority(v1alpha1.SchemeGroupVersion)) +} diff --git a/pkg/apis/node/register.go b/pkg/apis/node/register.go new file mode 100644 index 00000000000..062ad1e0e80 --- /dev/null +++ b/pkg/apis/node/register.go @@ -0,0 +1,54 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package node + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "node.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + +// Kind takes an unqualified kind and returns a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder for node api registration. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme for node api registration. + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &RuntimeClass{}, + &RuntimeClassList{}, + ) + return nil +} diff --git a/pkg/apis/node/types.go b/pkg/apis/node/types.go new file mode 100644 index 00000000000..a10648f384a --- /dev/null +++ b/pkg/apis/node/types.go @@ -0,0 +1,60 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package node + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RuntimeClass defines a class of container runtime supported in the cluster. +// The RuntimeClass is used to determine which container runtime is used to run +// all containers in a pod. RuntimeClasses are (currently) manually defined by a +// user or cluster provisioner, and referenced in the PodSpec. The Kubelet is +// responsible for resolving the RuntimeClassName reference before running the +// pod. For more details, see +// https://git.k8s.io/enhancements/keps/sig-node/runtime-class.md +type RuntimeClass struct { + metav1.TypeMeta + // +optional + metav1.ObjectMeta + + // Handler specifies the underlying runtime and configuration that the CRI + // implementation will use to handle pods of this class. The possible values + // are specific to the node & CRI configuration. It is assumed that all + // handlers are available on every node, and handlers of the same name are + // equivalent on every node. + // For example, a handler called "runc" might specify that the runc OCI + // runtime (using native Linux containers) will be used to run the containers + // in a pod. + // The Handler must conform to the DNS Label (RFC 1123) requirements, and is + // immutable. + Handler string +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RuntimeClassList is a list of RuntimeClass objects. +type RuntimeClassList struct { + metav1.TypeMeta + // +optional + metav1.ListMeta + + // Items is a list of schema objects. + Items []RuntimeClass +} diff --git a/pkg/apis/node/v1alpha1/BUILD b/pkg/apis/node/v1alpha1/BUILD new file mode 100644 index 00000000000..5a613238100 --- /dev/null +++ b/pkg/apis/node/v1alpha1/BUILD @@ -0,0 +1,46 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "go_default_library", + srcs = [ + "conversion.go", + "doc.go", + "register.go", + ], + importpath = "k8s.io/kubernetes/pkg/apis/node/v1alpha1", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/node:go_default_library", + "//staging/src/k8s.io/api/node/v1alpha1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) + +go_test( + name = "go_default_test", + srcs = ["conversion_test.go"], + embed = [":go_default_library"], + deps = [ + "//pkg/apis/node:go_default_library", + "//staging/src/k8s.io/api/node/v1alpha1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/github.com/stretchr/testify/assert:go_default_library", + "//vendor/github.com/stretchr/testify/require:go_default_library", + ], +) diff --git a/pkg/apis/node/v1alpha1/conversion.go b/pkg/apis/node/v1alpha1/conversion.go new file mode 100644 index 00000000000..f1e96ea31ae --- /dev/null +++ b/pkg/apis/node/v1alpha1/conversion.go @@ -0,0 +1,43 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + v1alpha1 "k8s.io/api/node/v1alpha1" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + node "k8s.io/kubernetes/pkg/apis/node" +) + +func addConversionFuncs(s *runtime.Scheme) error { + return s.AddConversionFuncs( + Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass, + Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass, + ) +} + +func Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(in *v1alpha1.RuntimeClass, out *node.RuntimeClass, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.Handler = in.Spec.RuntimeHandler + return nil +} + +func Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(in *node.RuntimeClass, out *v1alpha1.RuntimeClass, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.Spec.RuntimeHandler = in.Handler + return nil +} diff --git a/pkg/apis/node/v1alpha1/conversion_test.go b/pkg/apis/node/v1alpha1/conversion_test.go new file mode 100644 index 00000000000..6c794ef6c78 --- /dev/null +++ b/pkg/apis/node/v1alpha1/conversion_test.go @@ -0,0 +1,54 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + v1alpha1 "k8s.io/api/node/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + node "k8s.io/kubernetes/pkg/apis/node" +) + +func TestRuntimeClassConversion(t *testing.T) { + const ( + name = "puppy" + handler = "heidi" + ) + internalRC := node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: name}, + Handler: handler, + } + v1alpha1RC := v1alpha1.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: name}, + Spec: v1alpha1.RuntimeClassSpec{ + RuntimeHandler: handler, + }, + } + + convertedInternal := node.RuntimeClass{} + require.NoError(t, + Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(&v1alpha1RC, &convertedInternal, nil)) + assert.Equal(t, internalRC, convertedInternal) + + convertedV1alpha1 := v1alpha1.RuntimeClass{} + require.NoError(t, + Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(&internalRC, &convertedV1alpha1, nil)) + assert.Equal(t, v1alpha1RC, convertedV1alpha1) +} diff --git a/pkg/apis/node/v1alpha1/doc.go b/pkg/apis/node/v1alpha1/doc.go new file mode 100644 index 00000000000..1c2e1431952 --- /dev/null +++ b/pkg/apis/node/v1alpha1/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/node +// +k8s:conversion-gen-external-types=k8s.io/api/node/v1alpha1 + +// +groupName=node.k8s.io + +package v1alpha1 // import "k8s.io/kubernetes/pkg/apis/node/v1alpha1" diff --git a/pkg/apis/node/v1alpha1/register.go b/pkg/apis/node/v1alpha1/register.go new file mode 100644 index 00000000000..b48efda70ac --- /dev/null +++ b/pkg/apis/node/v1alpha1/register.go @@ -0,0 +1,46 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + nodev1alpha1 "k8s.io/api/node/v1alpha1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName for node API +const GroupName = "node.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + localSchemeBuilder = &nodev1alpha1.SchemeBuilder + // AddToScheme node API registration + 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(addConversionFuncs) +} diff --git a/pkg/apis/node/validation/BUILD b/pkg/apis/node/validation/BUILD new file mode 100644 index 00000000000..7d7345099df --- /dev/null +++ b/pkg/apis/node/validation/BUILD @@ -0,0 +1,38 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "go_default_library", + srcs = ["validation.go"], + importpath = "k8s.io/kubernetes/pkg/apis/node/validation", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/node:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/api/validation:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library", + ], +) + +go_test( + name = "go_default_test", + srcs = ["validation_test.go"], + embed = [":go_default_library"], + deps = [ + "//pkg/apis/node:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/github.com/stretchr/testify/assert:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/apis/node/validation/validation.go b/pkg/apis/node/validation/validation.go new file mode 100644 index 00000000000..b89a01ff58d --- /dev/null +++ b/pkg/apis/node/validation/validation.go @@ -0,0 +1,43 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package validation + +import ( + apivalidation "k8s.io/apimachinery/pkg/api/validation" + "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/kubernetes/pkg/apis/node" +) + +// ValidateRuntimeClass validates the RuntimeClass +func ValidateRuntimeClass(rc *node.RuntimeClass) field.ErrorList { + allErrs := apivalidation.ValidateObjectMeta(&rc.ObjectMeta, false, apivalidation.NameIsDNSSubdomain, field.NewPath("metadata")) + + for _, msg := range apivalidation.NameIsDNSLabel(rc.Handler, false) { + allErrs = append(allErrs, field.Invalid(field.NewPath("handler"), rc.Handler, msg)) + } + + return allErrs +} + +// ValidateRuntimeClassUpdate validates an update to the object +func ValidateRuntimeClassUpdate(new, old *node.RuntimeClass) field.ErrorList { + allErrs := apivalidation.ValidateObjectMetaUpdate(&new.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata")) + + allErrs = append(allErrs, apivalidation.ValidateImmutableField(new.Handler, old.Handler, field.NewPath("handler"))...) + + return allErrs +} diff --git a/pkg/apis/node/validation/validation_test.go b/pkg/apis/node/validation/validation_test.go new file mode 100644 index 00000000000..fcbdc0e9a1d --- /dev/null +++ b/pkg/apis/node/validation/validation_test.go @@ -0,0 +1,128 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package validation + +import ( + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/apis/node" + + "github.com/stretchr/testify/assert" +) + +func TestValidateRuntimeClass(t *testing.T) { + tests := []struct { + name string + rc node.RuntimeClass + expectError bool + }{{ + name: "invalid name", + expectError: true, + rc: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: "&!@#"}, + Handler: "foo", + }, + }, { + name: "invalid Handler name", + expectError: true, + rc: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Handler: "&@#$", + }, + }, { + name: "invalid empty RuntimeClass", + expectError: true, + rc: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: "empty"}, + }, + }, { + name: "valid Handler", + expectError: false, + rc: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Handler: "bar-baz", + }, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + errs := ValidateRuntimeClass(&test.rc) + if test.expectError { + assert.NotEmpty(t, errs) + } else { + assert.Empty(t, errs) + } + }) + } +} + +func TestValidateRuntimeUpdate(t *testing.T) { + old := node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Handler: "bar", + } + tests := []struct { + name string + expectError bool + old, new node.RuntimeClass + }{{ + name: "valid metadata update", + old: old, + new: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Labels: map[string]string{"foo": "bar"}, + }, + Handler: "bar", + }, + }, { + name: "invalid metadata update", + expectError: true, + old: old, + new: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{ + Name: "empty", + ClusterName: "somethingelse", // immutable + }, + Handler: "bar", + }, + }, { + name: "invalid Handler update", + expectError: true, + old: old, + new: node.RuntimeClass{ + ObjectMeta: metav1.ObjectMeta{Name: "foo"}, + Handler: "somethingelse", + }, + }} + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + // So we don't need to write it in every test case... + test.old.ObjectMeta.ResourceVersion = "1" + test.new.ObjectMeta.ResourceVersion = "1" + + errs := ValidateRuntimeClassUpdate(&test.new, &test.old) + if test.expectError { + assert.NotEmpty(t, errs) + } else { + assert.Empty(t, errs) + } + }) + } +} diff --git a/pkg/master/BUILD b/pkg/master/BUILD index 0ba09673109..5388d161a4c 100644 --- a/pkg/master/BUILD +++ b/pkg/master/BUILD @@ -30,6 +30,7 @@ go_library( "//pkg/apis/extensions/install:go_default_library", "//pkg/apis/imagepolicy/install:go_default_library", "//pkg/apis/networking/install:go_default_library", + "//pkg/apis/node/install:go_default_library", "//pkg/apis/policy/install:go_default_library", "//pkg/apis/rbac/install:go_default_library", "//pkg/apis/scheduling/install:go_default_library", @@ -57,6 +58,7 @@ go_library( "//pkg/registry/events/rest:go_default_library", "//pkg/registry/extensions/rest:go_default_library", "//pkg/registry/networking/rest:go_default_library", + "//pkg/registry/node/rest:go_default_library", "//pkg/registry/policy/rest:go_default_library", "//pkg/registry/rbac/rest:go_default_library", "//pkg/registry/scheduling/rest:go_default_library", @@ -89,6 +91,7 @@ go_library( "//staging/src/k8s.io/api/extensions/v1beta1:go_default_library", "//staging/src/k8s.io/api/networking/v1:go_default_library", "//staging/src/k8s.io/api/networking/v1beta1:go_default_library", + "//staging/src/k8s.io/api/node/v1alpha1:go_default_library", "//staging/src/k8s.io/api/policy/v1beta1:go_default_library", "//staging/src/k8s.io/api/rbac/v1:go_default_library", "//staging/src/k8s.io/api/rbac/v1alpha1:go_default_library", diff --git a/pkg/master/import_known_versions.go b/pkg/master/import_known_versions.go index 46e9a33d0d8..1c5947e1f9c 100644 --- a/pkg/master/import_known_versions.go +++ b/pkg/master/import_known_versions.go @@ -33,6 +33,7 @@ import ( _ "k8s.io/kubernetes/pkg/apis/extensions/install" _ "k8s.io/kubernetes/pkg/apis/imagepolicy/install" _ "k8s.io/kubernetes/pkg/apis/networking/install" + _ "k8s.io/kubernetes/pkg/apis/node/install" _ "k8s.io/kubernetes/pkg/apis/policy/install" _ "k8s.io/kubernetes/pkg/apis/rbac/install" _ "k8s.io/kubernetes/pkg/apis/scheduling/install" diff --git a/pkg/master/master.go b/pkg/master/master.go index 64e81ed9b95..effc19b6df1 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -47,6 +47,7 @@ import ( extensionsapiv1beta1 "k8s.io/api/extensions/v1beta1" networkingapiv1 "k8s.io/api/networking/v1" networkingapiv1beta1 "k8s.io/api/networking/v1beta1" + nodev1alpha1 "k8s.io/api/node/v1alpha1" policyapiv1beta1 "k8s.io/api/policy/v1beta1" rbacv1 "k8s.io/api/rbac/v1" rbacv1alpha1 "k8s.io/api/rbac/v1alpha1" @@ -94,6 +95,7 @@ import ( eventsrest "k8s.io/kubernetes/pkg/registry/events/rest" extensionsrest "k8s.io/kubernetes/pkg/registry/extensions/rest" networkingrest "k8s.io/kubernetes/pkg/registry/networking/rest" + noderest "k8s.io/kubernetes/pkg/registry/node/rest" policyrest "k8s.io/kubernetes/pkg/registry/policy/rest" rbacrest "k8s.io/kubernetes/pkg/registry/rbac/rest" schedulingrest "k8s.io/kubernetes/pkg/registry/scheduling/rest" @@ -345,6 +347,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget) coordinationrest.RESTStorageProvider{}, extensionsrest.RESTStorageProvider{}, networkingrest.RESTStorageProvider{}, + noderest.RESTStorageProvider{}, policyrest.RESTStorageProvider{}, rbacrest.RESTStorageProvider{Authorizer: c.GenericConfig.Authorization.Authorizer}, schedulingrest.RESTStorageProvider{}, @@ -524,6 +527,7 @@ func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig { ret.DisableVersions( auditregistrationv1alpha1.SchemeGroupVersion, batchapiv2alpha1.SchemeGroupVersion, + nodev1alpha1.SchemeGroupVersion, rbacv1alpha1.SchemeGroupVersion, schedulingv1alpha1.SchemeGroupVersion, settingsv1alpha1.SchemeGroupVersion, diff --git a/pkg/registry/BUILD b/pkg/registry/BUILD index 5d432d0aa73..fbca297a6c8 100644 --- a/pkg/registry/BUILD +++ b/pkg/registry/BUILD @@ -76,6 +76,8 @@ filegroup( "//pkg/registry/networking/ingress:all-srcs", "//pkg/registry/networking/networkpolicy:all-srcs", "//pkg/registry/networking/rest:all-srcs", + "//pkg/registry/node/rest:all-srcs", + "//pkg/registry/node/runtimeclass:all-srcs", "//pkg/registry/policy/poddisruptionbudget:all-srcs", "//pkg/registry/policy/podsecuritypolicy:all-srcs", "//pkg/registry/policy/rest:all-srcs", diff --git a/pkg/registry/node/rest/BUILD b/pkg/registry/node/rest/BUILD new file mode 100644 index 00000000000..ec87beeb65b --- /dev/null +++ b/pkg/registry/node/rest/BUILD @@ -0,0 +1,31 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["runtime_class.go"], + importpath = "k8s.io/kubernetes/pkg/registry/node/rest", + visibility = ["//visibility:public"], + deps = [ + "//pkg/api/legacyscheme:go_default_library", + "//pkg/registry/node/runtimeclass/storage:go_default_library", + "//staging/src/k8s.io/api/node/v1alpha1:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/server:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/server/storage:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/registry/node/rest/runtime_class.go b/pkg/registry/node/rest/runtime_class.go new file mode 100644 index 00000000000..761fb5362dc --- /dev/null +++ b/pkg/registry/node/rest/runtime_class.go @@ -0,0 +1,53 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package rest + +import ( + nodev1alpha1 "k8s.io/api/node/v1alpha1" + "k8s.io/apiserver/pkg/registry/generic" + "k8s.io/apiserver/pkg/registry/rest" + genericapiserver "k8s.io/apiserver/pkg/server" + serverstorage "k8s.io/apiserver/pkg/server/storage" + "k8s.io/kubernetes/pkg/api/legacyscheme" + runtimeclassstorage "k8s.io/kubernetes/pkg/registry/node/runtimeclass/storage" +) + +// RESTStorageProvider is a REST storage provider for node.k8s.io +type RESTStorageProvider struct{} + +// NewRESTStorage returns a RESTStorageProvider +func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool) { + apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(nodev1alpha1.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs) + + if apiResourceConfigSource.VersionEnabled(nodev1alpha1.SchemeGroupVersion) { + apiGroupInfo.VersionedResourcesStorageMap[nodev1alpha1.SchemeGroupVersion.Version] = p.v1alpha1Storage(apiResourceConfigSource, restOptionsGetter) + } + return apiGroupInfo, true +} + +func (p RESTStorageProvider) v1alpha1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage { + storage := map[string]rest.Storage{} + s := runtimeclassstorage.NewREST(restOptionsGetter) + storage["runtimeclasses"] = s + + return storage +} + +// GroupName is the group name for the storage provider +func (p RESTStorageProvider) GroupName() string { + return nodev1alpha1.GroupName +} diff --git a/pkg/registry/node/runtimeclass/BUILD b/pkg/registry/node/runtimeclass/BUILD new file mode 100644 index 00000000000..865b2d68ae0 --- /dev/null +++ b/pkg/registry/node/runtimeclass/BUILD @@ -0,0 +1,37 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "strategy.go", + ], + importpath = "k8s.io/kubernetes/pkg/registry/node/runtimeclass", + visibility = ["//visibility:public"], + deps = [ + "//pkg/api/legacyscheme:go_default_library", + "//pkg/apis/node:go_default_library", + "//pkg/apis/node/validation:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/registry/rest:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//pkg/registry/node/runtimeclass/storage:all-srcs", + ], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/registry/node/runtimeclass/doc.go b/pkg/registry/node/runtimeclass/doc.go new file mode 100644 index 00000000000..3540f2014b0 --- /dev/null +++ b/pkg/registry/node/runtimeclass/doc.go @@ -0,0 +1,17 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package runtimeclass // import "k8s.io/kubernetes/pkg/registry/node/runtimeclass" diff --git a/pkg/registry/node/runtimeclass/storage/BUILD b/pkg/registry/node/runtimeclass/storage/BUILD new file mode 100644 index 00000000000..0cfde7370b0 --- /dev/null +++ b/pkg/registry/node/runtimeclass/storage/BUILD @@ -0,0 +1,29 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["storage.go"], + importpath = "k8s.io/kubernetes/pkg/registry/node/runtimeclass/storage", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/node:go_default_library", + "//pkg/registry/node/runtimeclass:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/registry/generic:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/registry/node/runtimeclass/storage/storage.go b/pkg/registry/node/runtimeclass/storage/storage.go new file mode 100644 index 00000000000..75951c5367b --- /dev/null +++ b/pkg/registry/node/runtimeclass/storage/storage.go @@ -0,0 +1,51 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package storage + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apiserver/pkg/registry/generic" + genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" + "k8s.io/kubernetes/pkg/apis/node" + "k8s.io/kubernetes/pkg/registry/node/runtimeclass" +) + +// REST implements a RESTStorage for RuntimeClass against etcd +type REST struct { + *genericregistry.Store +} + +// NewREST returns a RESTStorage object that will work against runtime classes. +func NewREST(optsGetter generic.RESTOptionsGetter) *REST { + store := &genericregistry.Store{ + NewFunc: func() runtime.Object { return &node.RuntimeClass{} }, + NewListFunc: func() runtime.Object { return &node.RuntimeClassList{} }, + ObjectNameFunc: func(obj runtime.Object) (string, error) { + return obj.(*node.RuntimeClass).Name, nil + }, + DefaultQualifiedResource: node.Resource("runtimeclasses"), + + CreateStrategy: runtimeclass.Strategy, + UpdateStrategy: runtimeclass.Strategy, + DeleteStrategy: runtimeclass.Strategy, + } + options := &generic.StoreOptions{RESTOptions: optsGetter} + if err := store.CompleteWithOptions(options); err != nil { + panic(err) // TODO: Propagate error up + } + return &REST{store} +} diff --git a/pkg/registry/node/runtimeclass/strategy.go b/pkg/registry/node/runtimeclass/strategy.go new file mode 100644 index 00000000000..b68150964df --- /dev/null +++ b/pkg/registry/node/runtimeclass/strategy.go @@ -0,0 +1,95 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package runtimeclass + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/apiserver/pkg/registry/rest" + "k8s.io/apiserver/pkg/storage/names" + "k8s.io/kubernetes/pkg/api/legacyscheme" + "k8s.io/kubernetes/pkg/apis/node" + "k8s.io/kubernetes/pkg/apis/node/validation" +) + +// strategy implements verification logic for RuntimeClass. +type strategy struct { + runtime.ObjectTyper + names.NameGenerator +} + +// Strategy is the default logic that applies when creating and updating RuntimeClass objects. +var Strategy = strategy{legacyscheme.Scheme, names.SimpleNameGenerator} + +// Strategy should implement rest.RESTCreateStrategy +var _ rest.RESTCreateStrategy = Strategy + +// Strategy should implement rest.RESTUpdateStrategy +var _ rest.RESTUpdateStrategy = Strategy + +// NamespaceScoped is false for RuntimeClasses +func (strategy) NamespaceScoped() bool { + return false +} + +// AllowCreateOnUpdate is true for RuntimeClasses. +func (strategy) AllowCreateOnUpdate() bool { + return true +} + +// PrepareForCreate clears fields that are not allowed to be set by end users +// on creation. +func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { + _ = obj.(*node.RuntimeClass) +} + +// PrepareForUpdate clears fields that are not allowed to be set by end users on update. +func (strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { + newRuntimeClass := obj.(*node.RuntimeClass) + oldRuntimeClass := old.(*node.RuntimeClass) + + _, _ = newRuntimeClass, oldRuntimeClass +} + +// Validate validates a new RuntimeClass. Validation must check for a correct signature. +func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { + runtimeClass := obj.(*node.RuntimeClass) + return validation.ValidateRuntimeClass(runtimeClass) +} + +// Canonicalize normalizes the object after validation. +func (strategy) Canonicalize(obj runtime.Object) { + _ = obj.(*node.RuntimeClass) +} + +// ValidateUpdate is the default update validation for an end user. +func (strategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { + newObj := obj.(*node.RuntimeClass) + errorList := validation.ValidateRuntimeClass(newObj) + return append(errorList, validation.ValidateRuntimeClassUpdate(newObj, old.(*node.RuntimeClass))...) +} + +// If AllowUnconditionalUpdate() is true and the object specified by +// the user does not have a resource version, then generic Update() +// populates it with the latest version. Else, it checks that the +// version specified by the user matches the version of latest etcd +// object. +func (strategy) AllowUnconditionalUpdate() bool { + return false +} diff --git a/staging/src/k8s.io/api/BUILD b/staging/src/k8s.io/api/BUILD index f17c54d8add..275080d5fdf 100644 --- a/staging/src/k8s.io/api/BUILD +++ b/staging/src/k8s.io/api/BUILD @@ -82,6 +82,7 @@ filegroup( "//staging/src/k8s.io/api/imagepolicy/v1alpha1:all-srcs", "//staging/src/k8s.io/api/networking/v1:all-srcs", "//staging/src/k8s.io/api/networking/v1beta1:all-srcs", + "//staging/src/k8s.io/api/node/v1alpha1:all-srcs", "//staging/src/k8s.io/api/policy/v1beta1:all-srcs", "//staging/src/k8s.io/api/rbac/v1:all-srcs", "//staging/src/k8s.io/api/rbac/v1alpha1:all-srcs", diff --git a/staging/src/k8s.io/api/node/OWNERS b/staging/src/k8s.io/api/node/OWNERS new file mode 100644 index 00000000000..d871b2832ce --- /dev/null +++ b/staging/src/k8s.io/api/node/OWNERS @@ -0,0 +1,9 @@ +# See the OWNERS docs at https://go.k8s.io/owners + +# approval on api packages bubbles to api-approvers +reviewers: +- tallclair +- dchen1107 +- derekwaynecarr +labels: +- sig/node diff --git a/staging/src/k8s.io/api/node/v1alpha1/BUILD b/staging/src/k8s.io/api/node/v1alpha1/BUILD new file mode 100644 index 00000000000..b5fefeb7263 --- /dev/null +++ b/staging/src/k8s.io/api/node/v1alpha1/BUILD @@ -0,0 +1,32 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "register.go", + "types.go", + ], + importmap = "k8s.io/kubernetes/vendor/k8s.io/api/node/v1alpha1", + importpath = "k8s.io/api/node/v1alpha1", + visibility = ["//visibility:public"], + deps = [ + "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/staging/src/k8s.io/api/node/v1alpha1/doc.go b/staging/src/k8s.io/api/node/v1alpha1/doc.go new file mode 100644 index 00000000000..f7f8b78b42a --- /dev/null +++ b/staging/src/k8s.io/api/node/v1alpha1/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package +// +k8s:openapi-gen=true + +// +groupName=node.k8s.io + +package v1alpha1 // import "k8s.io/api/node/v1alpha1" diff --git a/staging/src/k8s.io/api/node/v1alpha1/register.go b/staging/src/k8s.io/api/node/v1alpha1/register.go new file mode 100644 index 00000000000..b6082142a2a --- /dev/null +++ b/staging/src/k8s.io/api/node/v1alpha1/register.go @@ -0,0 +1,52 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "node.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder is the scheme builder with scheme init functions to run for this API package + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme is a common registration function for mapping packaged scoped group & version keys to a scheme + AddToScheme = SchemeBuilder.AddToScheme +) + +// addKnownTypes adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &RuntimeClass{}, + &RuntimeClassList{}, + ) + + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/staging/src/k8s.io/api/node/v1alpha1/types.go b/staging/src/k8s.io/api/node/v1alpha1/types.go new file mode 100644 index 00000000000..2ce67c116fc --- /dev/null +++ b/staging/src/k8s.io/api/node/v1alpha1/types.go @@ -0,0 +1,75 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RuntimeClass defines a class of container runtime supported in the cluster. +// The RuntimeClass is used to determine which container runtime is used to run +// all containers in a pod. RuntimeClasses are (currently) manually defined by a +// user or cluster provisioner, and referenced in the PodSpec. The Kubelet is +// responsible for resolving the RuntimeClassName reference before running the +// pod. For more details, see +// https://git.k8s.io/enhancements/keps/sig-node/runtime-class.md +type RuntimeClass struct { + metav1.TypeMeta `json:",inline"` + // 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 RuntimeClass + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status + Spec RuntimeClassSpec `json:"spec" protobuf:"bytes,2,name=spec"` +} + +// RuntimeClassSpec is a specification of a RuntimeClass. It contains parameters +// that are required to describe the RuntimeClass to the Container Runtime +// Interface (CRI) implementation, as well as any other components that need to +// understand how the pod will be run. The RuntimeClassSpec is immutable. +type RuntimeClassSpec struct { + // RuntimeHandler specifies the underlying runtime and configuration that the + // CRI implementation will use to handle pods of this class. The possible + // values are specific to the node & CRI configuration. It is assumed that + // all handlers are available on every node, and handlers of the same name are + // equivalent on every node. + // For example, a handler called "runc" might specify that the runc OCI + // runtime (using native Linux containers) will be used to run the containers + // in a pod. + // The RuntimeHandler must conform to the DNS Label (RFC 1123) requirements + // and is immutable. + RuntimeHandler string `json:"runtimeHandler" protobuf:"bytes,1,opt,name=runtimeHandler"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RuntimeClassList is a list of RuntimeClass objects. +type RuntimeClassList struct { + metav1.TypeMeta `json:",inline"` + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata + // +optional + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // Items is a list of schema objects. + Items []RuntimeClass `json:"items" protobuf:"bytes,2,rep,name=items"` +} diff --git a/cluster/addons/runtimeclass/OWNERS b/staging/src/k8s.io/node-api/manifests/OWNERS similarity index 100% rename from cluster/addons/runtimeclass/OWNERS rename to staging/src/k8s.io/node-api/manifests/OWNERS diff --git a/cluster/addons/runtimeclass/README.md b/staging/src/k8s.io/node-api/manifests/README.md similarity index 100% rename from cluster/addons/runtimeclass/README.md rename to staging/src/k8s.io/node-api/manifests/README.md diff --git a/cluster/addons/runtimeclass/runtimeclass_crd.yaml b/staging/src/k8s.io/node-api/manifests/runtimeclass_crd.yaml similarity index 100% rename from cluster/addons/runtimeclass/runtimeclass_crd.yaml rename to staging/src/k8s.io/node-api/manifests/runtimeclass_crd.yaml