cni_windows.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // +build windows
  2. /*
  3. Copyright 2017 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package cni
  15. import (
  16. "context"
  17. "fmt"
  18. "time"
  19. cniTypes020 "github.com/containernetworking/cni/pkg/types/020"
  20. runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
  21. "k8s.io/klog"
  22. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  23. "k8s.io/kubernetes/pkg/kubelet/dockershim/network"
  24. )
  25. func getLoNetwork(binDirs []string) *cniNetwork {
  26. return nil
  27. }
  28. func (plugin *cniNetworkPlugin) platformInit() error {
  29. return nil
  30. }
  31. // GetPodNetworkStatus : Assuming addToNetwork is idempotent, we can call this API as many times as required to get the IPAddress
  32. func (plugin *cniNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
  33. netnsPath, err := plugin.host.GetNetNS(id.ID)
  34. if err != nil {
  35. return nil, fmt.Errorf("CNI failed to retrieve network namespace path: %v", err)
  36. }
  37. if plugin.getDefaultNetwork() == nil {
  38. return nil, fmt.Errorf("CNI network not yet initialized, skipping pod network status for container %q", id)
  39. }
  40. // Because the default remote runtime request timeout is 4 min,so set slightly less than 240 seconds
  41. // Todo get the timeout from parent ctx
  42. cniTimeoutCtx, cancelFunc := context.WithTimeout(context.Background(), network.CNITimeoutSec*time.Second)
  43. defer cancelFunc()
  44. result, err := plugin.addToNetwork(cniTimeoutCtx, plugin.getDefaultNetwork(), name, namespace, id, netnsPath, nil, nil)
  45. klog.V(5).Infof("GetPodNetworkStatus result %+v", result)
  46. if err != nil {
  47. klog.Errorf("error while adding to cni network: %s", err)
  48. return nil, err
  49. }
  50. // Parse the result and get the IPAddress
  51. var result020 *cniTypes020.Result
  52. result020, err = cniTypes020.GetResult(result)
  53. if err != nil {
  54. klog.Errorf("error while cni parsing result: %s", err)
  55. return nil, err
  56. }
  57. return &network.PodNetworkStatus{IP: result020.IP4.IP.IP}, nil
  58. }
  59. // buildDNSCapabilities builds cniDNSConfig from runtimeapi.DNSConfig.
  60. func buildDNSCapabilities(dnsConfig *runtimeapi.DNSConfig) *cniDNSConfig {
  61. if dnsConfig != nil {
  62. return &cniDNSConfig{
  63. Servers: dnsConfig.Servers,
  64. Searches: dnsConfig.Searches,
  65. Options: dnsConfig.Options,
  66. }
  67. }
  68. return nil
  69. }