validation.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package componentconfigs
  14. import (
  15. "k8s.io/apimachinery/pkg/util/validation/field"
  16. kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
  17. kubeletvalidation "k8s.io/kubernetes/pkg/kubelet/apis/config/validation"
  18. proxyvalidation "k8s.io/kubernetes/pkg/proxy/apis/config/validation"
  19. )
  20. // ValidateKubeProxyConfiguration validates proxy configuration and collects all encountered errors
  21. func ValidateKubeProxyConfiguration(internalcfg *kubeadmapi.ClusterConfiguration, _ *field.Path) field.ErrorList {
  22. allErrs := field.ErrorList{}
  23. if internalcfg.ComponentConfigs.KubeProxy == nil {
  24. return allErrs
  25. }
  26. return proxyvalidation.Validate(internalcfg.ComponentConfigs.KubeProxy)
  27. }
  28. // ValidateKubeletConfiguration validates kubelet configuration and collects all encountered errors
  29. func ValidateKubeletConfiguration(internalcfg *kubeadmapi.ClusterConfiguration, fldPath *field.Path) field.ErrorList {
  30. allErrs := field.ErrorList{}
  31. if internalcfg.ComponentConfigs.Kubelet == nil {
  32. return allErrs
  33. }
  34. if err := kubeletvalidation.ValidateKubeletConfiguration(internalcfg.ComponentConfigs.Kubelet); err != nil {
  35. allErrs = append(allErrs, field.Invalid(fldPath, "", err.Error()))
  36. }
  37. return allErrs
  38. }