From 40abe94a402a460ce9fdf18039f13e1ea603806d Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Mon, 23 Apr 2018 13:16:46 +0800 Subject: [PATCH] Validate cgroups-per-qos for windows --- .../apis/kubeletconfig/validation/BUILD | 39 ++++++++++++++++- .../kubeletconfig/validation/validation.go | 4 ++ .../validation/validation_others.go | 28 +++++++++++++ .../validation/validation_windows.go | 42 +++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 pkg/kubelet/apis/kubeletconfig/validation/validation_others.go create mode 100644 pkg/kubelet/apis/kubeletconfig/validation/validation_windows.go diff --git a/pkg/kubelet/apis/kubeletconfig/validation/BUILD b/pkg/kubelet/apis/kubeletconfig/validation/BUILD index 7fd457643ea..071a4b16f2e 100644 --- a/pkg/kubelet/apis/kubeletconfig/validation/BUILD +++ b/pkg/kubelet/apis/kubeletconfig/validation/BUILD @@ -8,7 +8,44 @@ load( go_library( name = "go_default_library", - srcs = ["validation.go"], + srcs = [ + "validation.go", + ] + select({ + "@io_bazel_rules_go//go/platform:android": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:darwin": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:dragonfly": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:freebsd": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:linux": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:nacl": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:netbsd": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:openbsd": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:plan9": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:solaris": [ + "validation_others.go", + ], + "@io_bazel_rules_go//go/platform:windows": [ + "validation_windows.go", + ], + "//conditions:default": [], + }), importpath = "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/validation", deps = [ "//pkg/features:go_default_library", diff --git a/pkg/kubelet/apis/kubeletconfig/validation/validation.go b/pkg/kubelet/apis/kubeletconfig/validation/validation.go index ab3bc4e14b4..624abdba4e4 100644 --- a/pkg/kubelet/apis/kubeletconfig/validation/validation.go +++ b/pkg/kubelet/apis/kubeletconfig/validation/validation.go @@ -118,5 +118,9 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error allErrors = append(allErrors, fmt.Errorf("invalid configuration: option %q specified for HairpinMode (--hairpin-mode). Valid options are %q, %q or %q", kc.HairpinMode, kubeletconfig.HairpinNone, kubeletconfig.HairpinVeth, kubeletconfig.PromiscuousBridge)) } + + if err := validateKubeletOSConfiguration(kc); err != nil { + allErrors = append(allErrors, err) + } return utilerrors.NewAggregate(allErrors) } diff --git a/pkg/kubelet/apis/kubeletconfig/validation/validation_others.go b/pkg/kubelet/apis/kubeletconfig/validation/validation_others.go new file mode 100644 index 00000000000..4cad825825e --- /dev/null +++ b/pkg/kubelet/apis/kubeletconfig/validation/validation_others.go @@ -0,0 +1,28 @@ +// +build !windows + +/* +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 ( + "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig" +) + +// validateKubeletOSConfiguration validates os specific kubelet configuration and returns an error if it is invalid. +func validateKubeletOSConfiguration(kc *kubeletconfig.KubeletConfiguration) error { + return nil +} diff --git a/pkg/kubelet/apis/kubeletconfig/validation/validation_windows.go b/pkg/kubelet/apis/kubeletconfig/validation/validation_windows.go new file mode 100644 index 00000000000..d1a8ec1dd6f --- /dev/null +++ b/pkg/kubelet/apis/kubeletconfig/validation/validation_windows.go @@ -0,0 +1,42 @@ +// +build windows + +/* +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 ( + "fmt" + + utilerrors "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig" +) + +// validateKubeletOSConfiguration validates os specific kubelet configuration and returns an error if it is invalid. +func validateKubeletOSConfiguration(kc *kubeletconfig.KubeletConfiguration) error { + message := "invalid configuration: %v (%v) %v is not supported on Windows" + allErrors := []error{} + + if kc.CgroupsPerQOS { + allErrors = append(allErrors, fmt.Errorf(message, "CgroupsPerQOS", "--cgroups-per-qos", kc.CgroupsPerQOS)) + } + + if len(kc.EnforceNodeAllocatable) > 0 { + allErrors = append(allErrors, fmt.Errorf(message, "EnforceNodeAllocatable", "--enforce-node-allocatable", kc.EnforceNodeAllocatable)) + } + + return utilerrors.NewAggregate(allErrors) +}