canbeexposed.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 polymorphichelpers
  14. import (
  15. "fmt"
  16. appsv1 "k8s.io/api/apps/v1"
  17. corev1 "k8s.io/api/core/v1"
  18. extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
  19. "k8s.io/apimachinery/pkg/runtime/schema"
  20. )
  21. // Check whether the kind of resources could be exposed
  22. func canBeExposed(kind schema.GroupKind) error {
  23. switch kind {
  24. case
  25. corev1.SchemeGroupVersion.WithKind("ReplicationController").GroupKind(),
  26. corev1.SchemeGroupVersion.WithKind("Service").GroupKind(),
  27. corev1.SchemeGroupVersion.WithKind("Pod").GroupKind(),
  28. appsv1.SchemeGroupVersion.WithKind("Deployment").GroupKind(),
  29. appsv1.SchemeGroupVersion.WithKind("ReplicaSet").GroupKind(),
  30. extensionsv1beta1.SchemeGroupVersion.WithKind("Deployment").GroupKind(),
  31. extensionsv1beta1.SchemeGroupVersion.WithKind("ReplicaSet").GroupKind():
  32. // nothing to do here
  33. default:
  34. return fmt.Errorf("cannot expose a %s", kind)
  35. }
  36. return nil
  37. }