fake.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // FakeNetsh is a no-op implementation of the netsh Interface
  19. type FakeNetsh struct {
  20. }
  21. // NewFake returns a fakenetsh no-op implementation of the netsh Interface
  22. func NewFake() *FakeNetsh {
  23. return &FakeNetsh{}
  24. }
  25. // EnsurePortProxyRule function implementing the netsh interface and always returns true and nil without any error
  26. func (*FakeNetsh) EnsurePortProxyRule(args []string) (bool, error) {
  27. // Do Nothing
  28. return true, nil
  29. }
  30. // DeletePortProxyRule deletes the specified portproxy rule. If the rule did not exist, return error.
  31. func (*FakeNetsh) DeletePortProxyRule(args []string) error {
  32. // Do Nothing
  33. return nil
  34. }
  35. // EnsureIPAddress checks if the specified IP Address is added to vEthernet (HNSTransparent) interface, if not, add it. If the address existed, return true.
  36. func (*FakeNetsh) EnsureIPAddress(args []string, ip net.IP) (bool, error) {
  37. return true, nil
  38. }
  39. // DeleteIPAddress checks if the specified IP address is present and, if so, deletes it.
  40. func (*FakeNetsh) DeleteIPAddress(args []string) error {
  41. // Do Nothing
  42. return nil
  43. }
  44. // Restore runs `netsh exec` to restore portproxy or addresses using a file.
  45. // TODO Check if this is required, most likely not
  46. func (*FakeNetsh) Restore(args []string) error {
  47. // Do Nothing
  48. return nil
  49. }
  50. // GetInterfaceToAddIP returns the interface name where Service IP needs to be added
  51. // IP Address needs to be added for netsh portproxy to redirect traffic
  52. // Reads Environment variable INTERFACE_TO_ADD_SERVICE_IP, if it is not defined then "vEthernet (HNSTransparent)" is returned
  53. func (*FakeNetsh) GetInterfaceToAddIP() string {
  54. return "Interface 1"
  55. }
  56. var _ = netsh.Interface(&FakeNetsh{})