...

Source file src/k8s.io/kubernetes/pkg/kubelet/kubelet_network.go

Documentation: k8s.io/kubernetes/pkg/kubelet

     1  /*
     2  Copyright 2016 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 kubelet
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  
    23  	v1 "k8s.io/api/core/v1"
    24  	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
    25  	"k8s.io/klog/v2"
    26  )
    27  
    28  // providerRequiresNetworkingConfiguration returns whether the cloud provider
    29  // requires special networking configuration.
    30  func (kl *Kubelet) providerRequiresNetworkingConfiguration() bool {
    31  	// TODO: We should have a mechanism to say whether native cloud provider
    32  	// is used or whether we are using overlay networking. We should return
    33  	// true for cloud providers if they implement Routes() interface and
    34  	// we are not using overlay networking.
    35  	if kl.cloud == nil || kl.cloud.ProviderName() != "gce" {
    36  		return false
    37  	}
    38  	_, supported := kl.cloud.Routes()
    39  	return supported
    40  }
    41  
    42  // updatePodCIDR updates the pod CIDR in the runtime state if it is different
    43  // from the current CIDR. Return true if pod CIDR is actually changed.
    44  func (kl *Kubelet) updatePodCIDR(ctx context.Context, cidr string) (bool, error) {
    45  	kl.updatePodCIDRMux.Lock()
    46  	defer kl.updatePodCIDRMux.Unlock()
    47  
    48  	podCIDR := kl.runtimeState.podCIDR()
    49  
    50  	if podCIDR == cidr {
    51  		return false, nil
    52  	}
    53  
    54  	// kubelet -> generic runtime -> runtime shim -> network plugin
    55  	// docker/non-cri implementations have a passthrough UpdatePodCIDR
    56  	if err := kl.getRuntime().UpdatePodCIDR(ctx, cidr); err != nil {
    57  		// If updatePodCIDR would fail, theoretically pod CIDR could not change.
    58  		// But it is better to be on the safe side to still return true here.
    59  		return true, fmt.Errorf("failed to update pod CIDR: %v", err)
    60  	}
    61  	klog.InfoS("Updating Pod CIDR", "originalPodCIDR", podCIDR, "newPodCIDR", cidr)
    62  	kl.runtimeState.setPodCIDR(cidr)
    63  	return true, nil
    64  }
    65  
    66  // GetPodDNS returns DNS settings for the pod.
    67  // This function is defined in kubecontainer.RuntimeHelper interface so we
    68  // have to implement it.
    69  func (kl *Kubelet) GetPodDNS(pod *v1.Pod) (*runtimeapi.DNSConfig, error) {
    70  	return kl.dnsConfigurer.GetPodDNS(pod)
    71  }
    72  

View as plain text