namespace_opts.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Copyright The containerd 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 cni
  14. type NamespaceOpts func(s *Namespace) error
  15. // WithCapabilityPortMap adds support for port mappings
  16. func WithCapabilityPortMap(portMapping []PortMapping) NamespaceOpts {
  17. return func(c *Namespace) error {
  18. c.capabilityArgs["portMappings"] = portMapping
  19. return nil
  20. }
  21. }
  22. // WithCapabilityIPRanges adds support for ip ranges
  23. func WithCapabilityIPRanges(ipRanges []IPRanges) NamespaceOpts {
  24. return func(c *Namespace) error {
  25. c.capabilityArgs["ipRanges"] = ipRanges
  26. return nil
  27. }
  28. }
  29. // WithCapabilityBandWitdh adds support for bandwidth limits
  30. func WithCapabilityBandWidth(bandWidth BandWidth) NamespaceOpts {
  31. return func(c *Namespace) error {
  32. c.capabilityArgs["bandwidth"] = bandWidth
  33. return nil
  34. }
  35. }
  36. // WithCapabilityDNS adds support for dns
  37. func WithCapabilityDNS(dns DNS) NamespaceOpts {
  38. return func(c *Namespace) error {
  39. c.capabilityArgs["dns"] = dns
  40. return nil
  41. }
  42. }
  43. // WithCapabilityCgroupPath passes in the cgroup path capability.
  44. func WithCapabilityCgroupPath(cgroupPath string) NamespaceOpts {
  45. return func(c *Namespace) error {
  46. c.capabilityArgs["cgroupPath"] = cgroupPath
  47. return nil
  48. }
  49. }
  50. // WithCapability support well-known capabilities
  51. // https://www.cni.dev/docs/conventions/#well-known-capabilities
  52. func WithCapability(name string, capability interface{}) NamespaceOpts {
  53. return func(c *Namespace) error {
  54. c.capabilityArgs[name] = capability
  55. return nil
  56. }
  57. }
  58. // Args
  59. func WithLabels(labels map[string]string) NamespaceOpts {
  60. return func(c *Namespace) error {
  61. for k, v := range labels {
  62. c.args[k] = v
  63. }
  64. return nil
  65. }
  66. }
  67. func WithArgs(k, v string) NamespaceOpts {
  68. return func(c *Namespace) error {
  69. c.args[k] = v
  70. return nil
  71. }
  72. }