fake.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package testing
  14. import (
  15. "net"
  16. "k8s.io/kubernetes/pkg/util/netsh"
  17. )
  18. // no-op implementation of netsh Interface
  19. type FakeNetsh struct {
  20. }
  21. func NewFake() *FakeNetsh {
  22. return &FakeNetsh{}
  23. }
  24. func (*FakeNetsh) EnsurePortProxyRule(args []string) (bool, error) {
  25. return true, nil
  26. }
  27. // DeletePortProxyRule deletes the specified portproxy rule. If the rule did not exist, return error.
  28. func (*FakeNetsh) DeletePortProxyRule(args []string) error {
  29. // Do Nothing
  30. return nil
  31. }
  32. // EnsureIPAddress checks if the specified IP Address is added to vEthernet (HNSTransparent) interface, if not, add it. If the address existed, return true.
  33. func (*FakeNetsh) EnsureIPAddress(args []string, ip net.IP) (bool, error) {
  34. return true, nil
  35. }
  36. // DeleteIPAddress checks if the specified IP address is present and, if so, deletes it.
  37. func (*FakeNetsh) DeleteIPAddress(args []string) error {
  38. // Do Nothing
  39. return nil
  40. }
  41. // Restore runs `netsh exec` to restore portproxy or addresses using a file.
  42. // TODO Check if this is required, most likely not
  43. func (*FakeNetsh) Restore(args []string) error {
  44. // Do Nothing
  45. return nil
  46. }
  47. // GetInterfaceToAddIP returns the interface name where Service IP needs to be added
  48. // IP Address needs to be added for netsh portproxy to redirect traffic
  49. // Reads Environment variable INTERFACE_TO_ADD_SERVICE_IP, if it is not defined then "vEthernet (HNSTransparent)" is returned
  50. func (*FakeNetsh) GetInterfaceToAddIP() string {
  51. return "Interface 1"
  52. }
  53. var _ = netsh.Interface(&FakeNetsh{})