...

Source file src/k8s.io/kubernetes/pkg/apis/policy/v1beta1/conversion.go

Documentation: k8s.io/kubernetes/pkg/apis/policy/v1beta1

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	"k8s.io/api/policy/v1beta1"
    21  	apiequality "k8s.io/apimachinery/pkg/api/equality"
    22  	"k8s.io/apimachinery/pkg/conversion"
    23  	"k8s.io/kubernetes/pkg/apis/policy"
    24  )
    25  
    26  func Convert_v1beta1_PodDisruptionBudget_To_policy_PodDisruptionBudget(in *v1beta1.PodDisruptionBudget, out *policy.PodDisruptionBudget, s conversion.Scope) error {
    27  	if err := autoConvert_v1beta1_PodDisruptionBudget_To_policy_PodDisruptionBudget(in, out, s); err != nil {
    28  		return err
    29  	}
    30  
    31  	switch {
    32  	case apiequality.Semantic.DeepEqual(in.Spec.Selector, policy.V1beta1MatchNoneSelector):
    33  		// If the v1beta1 version has a non-nil but empty selector, it should be
    34  		// selecting no pods, even when used with the internal or v1 api. We
    35  		// add a selector that is non-empty but will never match any pods.
    36  		out.Spec.Selector = policy.NonV1beta1MatchNoneSelector.DeepCopy()
    37  	case apiequality.Semantic.DeepEqual(in.Spec.Selector, policy.V1beta1MatchAllSelector):
    38  		// If the v1beta1 version has our v1beta1-specific "match-all" selector,
    39  		// swap that out for a simpler empty "match-all" selector for v1
    40  		out.Spec.Selector = policy.NonV1beta1MatchAllSelector.DeepCopy()
    41  	default:
    42  		// otherwise, make sure the label intended to be used in a match-all or match-none selector
    43  		// never gets combined with user-specified fields
    44  		policy.StripPDBV1beta1Label(out.Spec.Selector)
    45  	}
    46  	return nil
    47  }
    48  
    49  func Convert_policy_PodDisruptionBudget_To_v1beta1_PodDisruptionBudget(in *policy.PodDisruptionBudget, out *v1beta1.PodDisruptionBudget, s conversion.Scope) error {
    50  	if err := autoConvert_policy_PodDisruptionBudget_To_v1beta1_PodDisruptionBudget(in, out, s); err != nil {
    51  		return err
    52  	}
    53  
    54  	switch {
    55  	case apiequality.Semantic.DeepEqual(in.Spec.Selector, policy.NonV1beta1MatchNoneSelector):
    56  		// If the internal version has our v1beta1-specific "match-none" selector,
    57  		// swap that out for a simpler empty "match-none" selector for v1beta1
    58  		out.Spec.Selector = policy.V1beta1MatchNoneSelector.DeepCopy()
    59  	case apiequality.Semantic.DeepEqual(in.Spec.Selector, policy.NonV1beta1MatchAllSelector):
    60  		// If the internal version has a non-nil but empty selector, we want it to
    61  		// select all pods. We make sure this happens even with the v1beta1 api by
    62  		// adding a non-empty selector that selects all pods.
    63  		out.Spec.Selector = policy.V1beta1MatchAllSelector.DeepCopy()
    64  	}
    65  	return nil
    66  }
    67  

View as plain text