...

Source file src/k8s.io/kubernetes/pkg/apis/networking/v1/defaults.go

Documentation: k8s.io/kubernetes/pkg/apis/networking/v1

     1  /*
     2  Copyright 2017 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 v1
    18  
    19  import (
    20  	v1 "k8s.io/api/core/v1"
    21  	networkingv1 "k8s.io/api/networking/v1"
    22  	"k8s.io/apimachinery/pkg/runtime"
    23  	utilpointer "k8s.io/utils/pointer"
    24  )
    25  
    26  func addDefaultingFuncs(scheme *runtime.Scheme) error {
    27  	return RegisterDefaults(scheme)
    28  }
    29  
    30  func SetDefaults_NetworkPolicyPort(obj *networkingv1.NetworkPolicyPort) {
    31  	// Default any undefined Protocol fields to TCP.
    32  	if obj.Protocol == nil {
    33  		proto := v1.ProtocolTCP
    34  		obj.Protocol = &proto
    35  	}
    36  }
    37  
    38  func SetDefaults_NetworkPolicy(obj *networkingv1.NetworkPolicy) {
    39  	if len(obj.Spec.PolicyTypes) == 0 {
    40  		// Any policy that does not specify policyTypes implies at least "Ingress".
    41  		obj.Spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeIngress}
    42  		if len(obj.Spec.Egress) != 0 {
    43  			obj.Spec.PolicyTypes = append(obj.Spec.PolicyTypes, networkingv1.PolicyTypeEgress)
    44  		}
    45  	}
    46  }
    47  
    48  func SetDefaults_IngressClass(obj *networkingv1.IngressClass) {
    49  	if obj.Spec.Parameters != nil && obj.Spec.Parameters.Scope == nil {
    50  		obj.Spec.Parameters.Scope = utilpointer.String(networkingv1.IngressClassParametersReferenceScopeCluster)
    51  	}
    52  }
    53  

View as plain text