mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Merge pull request #115168 from HirazawaUi/delte-pkg-apis-other-unused-functions
remove unused not api functions in the pkg/apis directory
This commit is contained in:
commit
56e17d6d67
@ -54,12 +54,6 @@ func ValidateSelfSubjectAccessReviewSpec(spec authorizationapi.SelfSubjectAccess
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateSelfSubjectRulesReview validates a SelfSubjectRulesReview and returns an
|
|
||||||
// ErrorList with any errors.
|
|
||||||
func ValidateSelfSubjectRulesReview(review *authorizationapi.SelfSubjectRulesReview) field.ErrorList {
|
|
||||||
return field.ErrorList{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateSubjectAccessReview validates a SubjectAccessReview and returns an
|
// ValidateSubjectAccessReview validates a SubjectAccessReview and returns an
|
||||||
// ErrorList with any errors.
|
// ErrorList with any errors.
|
||||||
func ValidateSubjectAccessReview(sar *authorizationapi.SubjectAccessReview) field.ErrorList {
|
func ValidateSubjectAccessReview(sar *authorizationapi.SubjectAccessReview) field.ErrorList {
|
||||||
|
@ -68,16 +68,10 @@ func DefaultSignerNameFromSpec(obj *certificatesv1beta1.CertificateSigningReques
|
|||||||
func IsKubeletServingCSR(req *x509.CertificateRequest, usages []certificatesv1beta1.KeyUsage) bool {
|
func IsKubeletServingCSR(req *x509.CertificateRequest, usages []certificatesv1beta1.KeyUsage) bool {
|
||||||
return certificates.IsKubeletServingCSR(req, usagesToSet(usages))
|
return certificates.IsKubeletServingCSR(req, usagesToSet(usages))
|
||||||
}
|
}
|
||||||
func ValidateKubeletServingCSR(req *x509.CertificateRequest, usages []certificatesv1beta1.KeyUsage) error {
|
|
||||||
return certificates.ValidateKubeletServingCSR(req, usagesToSet(usages))
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsKubeletClientCSR(req *x509.CertificateRequest, usages []certificatesv1beta1.KeyUsage) bool {
|
func IsKubeletClientCSR(req *x509.CertificateRequest, usages []certificatesv1beta1.KeyUsage) bool {
|
||||||
return certificates.IsKubeletClientCSR(req, usagesToSet(usages))
|
return certificates.IsKubeletClientCSR(req, usagesToSet(usages))
|
||||||
}
|
}
|
||||||
func ValidateKubeletClientCSR(req *x509.CertificateRequest, usages []certificatesv1beta1.KeyUsage) error {
|
|
||||||
return certificates.ValidateKubeletClientCSR(req, usagesToSet(usages))
|
|
||||||
}
|
|
||||||
|
|
||||||
func usagesToSet(usages []certificatesv1beta1.KeyUsage) sets.String {
|
func usagesToSet(usages []certificatesv1beta1.KeyUsage) sets.String {
|
||||||
result := sets.NewString()
|
result := sets.NewString()
|
||||||
|
@ -453,41 +453,6 @@ func PersistentVolumeClaimHasClass(claim *core.PersistentVolumeClaim) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func toResourceNames(resources core.ResourceList) []core.ResourceName {
|
|
||||||
result := []core.ResourceName{}
|
|
||||||
for resourceName := range resources {
|
|
||||||
result = append(result, resourceName)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func toSet(resourceNames []core.ResourceName) sets.String {
|
|
||||||
result := sets.NewString()
|
|
||||||
for _, resourceName := range resourceNames {
|
|
||||||
result.Insert(string(resourceName))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// toContainerResourcesSet returns a set of resources names in container resource requirements
|
|
||||||
func toContainerResourcesSet(ctr *core.Container) sets.String {
|
|
||||||
resourceNames := toResourceNames(ctr.Resources.Requests)
|
|
||||||
resourceNames = append(resourceNames, toResourceNames(ctr.Resources.Limits)...)
|
|
||||||
return toSet(resourceNames)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToPodResourcesSet returns a set of resource names in all containers in a pod.
|
|
||||||
func ToPodResourcesSet(podSpec *core.PodSpec) sets.String {
|
|
||||||
result := sets.NewString()
|
|
||||||
for i := range podSpec.InitContainers {
|
|
||||||
result = result.Union(toContainerResourcesSet(&podSpec.InitContainers[i]))
|
|
||||||
}
|
|
||||||
for i := range podSpec.Containers {
|
|
||||||
result = result.Union(toContainerResourcesSet(&podSpec.Containers[i]))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDeletionCostFromPodAnnotations returns the integer value of pod-deletion-cost. Returns 0
|
// GetDeletionCostFromPodAnnotations returns the integer value of pod-deletion-cost. Returns 0
|
||||||
// if not set or the value is invalid.
|
// if not set or the value is invalid.
|
||||||
func GetDeletionCostFromPodAnnotations(annotations map[string]string) (int32, error) {
|
func GetDeletionCostFromPodAnnotations(annotations map[string]string) (int32, error) {
|
||||||
|
@ -315,12 +315,6 @@ func AddOrUpdateTolerationInPodSpec(spec *v1.PodSpec, toleration *v1.Toleration)
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
|
|
||||||
// Returns true if something was updated, false otherwise.
|
|
||||||
func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
|
|
||||||
return AddOrUpdateTolerationInPodSpec(&pod.Spec, toleration)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMatchingTolerations returns true and list of Tolerations matching all Taints if all are tolerated, or false otherwise.
|
// GetMatchingTolerations returns true and list of Tolerations matching all Taints if all are tolerated, or false otherwise.
|
||||||
func GetMatchingTolerations(taints []v1.Taint, tolerations []v1.Toleration) (bool, []v1.Toleration) {
|
func GetMatchingTolerations(taints []v1.Taint, tolerations []v1.Toleration) (bool, []v1.Toleration) {
|
||||||
if len(taints) == 0 {
|
if len(taints) == 0 {
|
||||||
|
@ -21,13 +21,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RoleRefGroupKind(roleRef rbacv1.RoleRef) schema.GroupKind {
|
|
||||||
return schema.GroupKind{Group: roleRef.APIGroup, Kind: roleRef.Kind}
|
|
||||||
}
|
|
||||||
|
|
||||||
func VerbMatches(rule *rbacv1.PolicyRule, requestedVerb string) bool {
|
func VerbMatches(rule *rbacv1.PolicyRule, requestedVerb string) bool {
|
||||||
for _, ruleVerb := range rule.Verbs {
|
for _, ruleVerb := range rule.Verbs {
|
||||||
if ruleVerb == rbacv1.VerbAll {
|
if ruleVerb == rbacv1.VerbAll {
|
||||||
@ -112,36 +107,6 @@ func NonResourceURLMatches(rule *rbacv1.PolicyRule, requestedURL string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// subjectsStrings returns users, groups, serviceaccounts, unknown for display purposes.
|
|
||||||
func SubjectsStrings(subjects []rbacv1.Subject) ([]string, []string, []string, []string) {
|
|
||||||
users := []string{}
|
|
||||||
groups := []string{}
|
|
||||||
sas := []string{}
|
|
||||||
others := []string{}
|
|
||||||
|
|
||||||
for _, subject := range subjects {
|
|
||||||
switch subject.Kind {
|
|
||||||
case rbacv1.ServiceAccountKind:
|
|
||||||
sas = append(sas, fmt.Sprintf("%s/%s", subject.Namespace, subject.Name))
|
|
||||||
|
|
||||||
case rbacv1.UserKind:
|
|
||||||
users = append(users, subject.Name)
|
|
||||||
|
|
||||||
case rbacv1.GroupKind:
|
|
||||||
groups = append(groups, subject.Name)
|
|
||||||
|
|
||||||
default:
|
|
||||||
others = append(others, fmt.Sprintf("%s/%s/%s", subject.Kind, subject.Namespace, subject.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return users, groups, sas, others
|
|
||||||
}
|
|
||||||
|
|
||||||
func String(r rbacv1.PolicyRule) string {
|
|
||||||
return "PolicyRule" + CompactString(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CompactString exposes a compact string representation for use in escalation error messages
|
// CompactString exposes a compact string representation for use in escalation error messages
|
||||||
func CompactString(r rbacv1.PolicyRule) string {
|
func CompactString(r rbacv1.PolicyRule) string {
|
||||||
formatStringParts := []string{}
|
formatStringParts := []string{}
|
||||||
|
@ -186,22 +186,6 @@ func NewRoleBinding(roleName, namespace string) *RoleBindingBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoleBindingForClusterRole(roleName, namespace string) *RoleBindingBuilder {
|
|
||||||
return &RoleBindingBuilder{
|
|
||||||
RoleBinding: rbacv1.RoleBinding{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: roleName,
|
|
||||||
Namespace: namespace,
|
|
||||||
},
|
|
||||||
RoleRef: rbacv1.RoleRef{
|
|
||||||
APIGroup: GroupName,
|
|
||||||
Kind: "ClusterRole",
|
|
||||||
Name: roleName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Groups adds the specified groups as the subjects of the RoleBinding.
|
// Groups adds the specified groups as the subjects of the RoleBinding.
|
||||||
func (r *RoleBindingBuilder) Groups(groups ...string) *RoleBindingBuilder {
|
func (r *RoleBindingBuilder) Groups(groups ...string) *RoleBindingBuilder {
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
|
@ -20,8 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
rbacv1alpha1 "k8s.io/api/rbac/v1alpha1"
|
rbacv1alpha1 "k8s.io/api/rbac/v1alpha1"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PolicyRuleBuilder let's us attach methods. A no-no for API types.
|
// PolicyRuleBuilder let's us attach methods. A no-no for API types.
|
||||||
@ -31,12 +29,6 @@ type PolicyRuleBuilder struct {
|
|||||||
PolicyRule rbacv1alpha1.PolicyRule `protobuf:"bytes,1,opt,name=policyRule"`
|
PolicyRule rbacv1alpha1.PolicyRule `protobuf:"bytes,1,opt,name=policyRule"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRule(verbs ...string) *PolicyRuleBuilder {
|
|
||||||
return &PolicyRuleBuilder{
|
|
||||||
PolicyRule: rbacv1alpha1.PolicyRule{Verbs: verbs},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PolicyRuleBuilder) Groups(groups ...string) *PolicyRuleBuilder {
|
func (r *PolicyRuleBuilder) Groups(groups ...string) *PolicyRuleBuilder {
|
||||||
r.PolicyRule.APIGroups = append(r.PolicyRule.APIGroups, groups...)
|
r.PolicyRule.APIGroups = append(r.PolicyRule.APIGroups, groups...)
|
||||||
return r
|
return r
|
||||||
@ -97,19 +89,6 @@ type ClusterRoleBindingBuilder struct {
|
|||||||
ClusterRoleBinding rbacv1alpha1.ClusterRoleBinding `protobuf:"bytes,1,opt,name=clusterRoleBinding"`
|
ClusterRoleBinding rbacv1alpha1.ClusterRoleBinding `protobuf:"bytes,1,opt,name=clusterRoleBinding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClusterBinding(clusterRoleName string) *ClusterRoleBindingBuilder {
|
|
||||||
return &ClusterRoleBindingBuilder{
|
|
||||||
ClusterRoleBinding: rbacv1alpha1.ClusterRoleBinding{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: clusterRoleName},
|
|
||||||
RoleRef: rbacv1alpha1.RoleRef{
|
|
||||||
APIGroup: GroupName,
|
|
||||||
Kind: "ClusterRole",
|
|
||||||
Name: clusterRoleName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ClusterRoleBindingBuilder) Groups(groups ...string) *ClusterRoleBindingBuilder {
|
func (r *ClusterRoleBindingBuilder) Groups(groups ...string) *ClusterRoleBindingBuilder {
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1alpha1.Subject{Kind: rbacv1alpha1.GroupKind, Name: group})
|
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1alpha1.Subject{Kind: rbacv1alpha1.GroupKind, Name: group})
|
||||||
|
@ -20,8 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
|
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PolicyRuleBuilder let's us attach methods. A no-no for API types.
|
// PolicyRuleBuilder let's us attach methods. A no-no for API types.
|
||||||
@ -31,12 +29,6 @@ type PolicyRuleBuilder struct {
|
|||||||
PolicyRule rbacv1beta1.PolicyRule `protobuf:"bytes,1,opt,name=policyRule"`
|
PolicyRule rbacv1beta1.PolicyRule `protobuf:"bytes,1,opt,name=policyRule"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRule(verbs ...string) *PolicyRuleBuilder {
|
|
||||||
return &PolicyRuleBuilder{
|
|
||||||
PolicyRule: rbacv1beta1.PolicyRule{Verbs: verbs},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *PolicyRuleBuilder) Groups(groups ...string) *PolicyRuleBuilder {
|
func (r *PolicyRuleBuilder) Groups(groups ...string) *PolicyRuleBuilder {
|
||||||
r.PolicyRule.APIGroups = append(r.PolicyRule.APIGroups, groups...)
|
r.PolicyRule.APIGroups = append(r.PolicyRule.APIGroups, groups...)
|
||||||
return r
|
return r
|
||||||
@ -97,19 +89,6 @@ type ClusterRoleBindingBuilder struct {
|
|||||||
ClusterRoleBinding rbacv1beta1.ClusterRoleBinding `protobuf:"bytes,1,opt,name=clusterRoleBinding"`
|
ClusterRoleBinding rbacv1beta1.ClusterRoleBinding `protobuf:"bytes,1,opt,name=clusterRoleBinding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClusterBinding(clusterRoleName string) *ClusterRoleBindingBuilder {
|
|
||||||
return &ClusterRoleBindingBuilder{
|
|
||||||
ClusterRoleBinding: rbacv1beta1.ClusterRoleBinding{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: clusterRoleName},
|
|
||||||
RoleRef: rbacv1beta1.RoleRef{
|
|
||||||
APIGroup: GroupName,
|
|
||||||
Kind: "ClusterRole",
|
|
||||||
Name: clusterRoleName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ClusterRoleBindingBuilder) Groups(groups ...string) *ClusterRoleBindingBuilder {
|
func (r *ClusterRoleBindingBuilder) Groups(groups ...string) *ClusterRoleBindingBuilder {
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1beta1.Subject{Kind: rbacv1beta1.GroupKind, Name: group})
|
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1beta1.Subject{Kind: rbacv1beta1.GroupKind, Name: group})
|
||||||
|
@ -26,20 +26,6 @@ const IsDefaultStorageClassAnnotation = "storageclass.kubernetes.io/is-default-c
|
|||||||
// TODO: remove Beta when no longer used
|
// TODO: remove Beta when no longer used
|
||||||
const BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class"
|
const BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class"
|
||||||
|
|
||||||
// IsDefaultAnnotationText returns a pretty Yes/No String if
|
|
||||||
// the annotation is set
|
|
||||||
// TODO: remove Beta when no longer needed
|
|
||||||
func IsDefaultAnnotationText(obj metav1.ObjectMeta) string {
|
|
||||||
if obj.Annotations[IsDefaultStorageClassAnnotation] == "true" {
|
|
||||||
return "Yes"
|
|
||||||
}
|
|
||||||
if obj.Annotations[BetaIsDefaultStorageClassAnnotation] == "true" {
|
|
||||||
return "Yes"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "No"
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsDefaultAnnotation returns a boolean if
|
// IsDefaultAnnotation returns a boolean if
|
||||||
// the annotation is set
|
// the annotation is set
|
||||||
// TODO: remove Beta when no longer needed
|
// TODO: remove Beta when no longer needed
|
||||||
|
@ -352,11 +352,6 @@ func validateCSINodeDriverNodeID(nodeID string, fldPath *field.Path, validationO
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSINodeLongerID will check if the nodeID is longer than csiNodeIDMaxLength
|
|
||||||
func CSINodeLongerID(nodeID string) bool {
|
|
||||||
return len(nodeID) > csiNodeIDMaxLength
|
|
||||||
}
|
|
||||||
|
|
||||||
// validateCSINodeDriverAllocatable tests if Allocatable in CSINodeDriver has valid volume limits.
|
// validateCSINodeDriverAllocatable tests if Allocatable in CSINodeDriver has valid volume limits.
|
||||||
func validateCSINodeDriverAllocatable(a *storage.VolumeNodeResources, fldPath *field.Path) field.ErrorList {
|
func validateCSINodeDriverAllocatable(a *storage.VolumeNodeResources, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
Loading…
Reference in New Issue
Block a user