cni_windows.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. "fmt"
  17. cniTypes020 "github.com/containernetworking/cni/pkg/types/020"
  18. runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
  19. "k8s.io/klog"
  20. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  21. "k8s.io/kubernetes/pkg/kubelet/dockershim/network"
  22. )
  23. func getLoNetwork(binDirs []string) *cniNetwork {
  24. return nil
  25. }
  26. func (plugin *cniNetworkPlugin) platformInit() error {
  27. return nil
  28. }
  29. // GetPodNetworkStatus : Assuming addToNetwork is idempotent, we can call this API as many times as required to get the IPAddress
  30. func (plugin *cniNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
  31. netnsPath, err := plugin.host.GetNetNS(id.ID)
  32. if err != nil {
  33. return nil, fmt.Errorf("CNI failed to retrieve network namespace path: %v", err)
  34. }
  35. result, err := plugin.addToNetwork(plugin.getDefaultNetwork(), name, namespace, id, netnsPath, nil, nil)
  36. klog.V(5).Infof("GetPodNetworkStatus result %+v", result)
  37. if err != nil {
  38. klog.Errorf("error while adding to cni network: %s", err)
  39. return nil, err
  40. }
  41. // Parse the result and get the IPAddress
  42. var result020 *cniTypes020.Result
  43. result020, err = cniTypes020.GetResult(result)
  44. if err != nil {
  45. klog.Errorf("error while cni parsing result: %s", err)
  46. return nil, err
  47. }
  48. return &network.PodNetworkStatus{IP: result020.IP4.IP.IP}, nil
  49. }
  50. // buildDNSCapabilities builds cniDNSConfig from runtimeapi.DNSConfig.
  51. func buildDNSCapabilities(dnsConfig *runtimeapi.DNSConfig) *cniDNSConfig {
  52. if dnsConfig != nil {
  53. return &cniDNSConfig{
  54. Servers: dnsConfig.Servers,
  55. Searches: dnsConfig.Searches,
  56. Options: dnsConfig.Options,
  57. }
  58. }
  59. return nil
  60. }