configmap.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Copyright 2015 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 unversioned
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/watch"
  17. )
  18. const (
  19. ConfigMapResourceName string = "configmaps"
  20. )
  21. type ConfigMapsNamespacer interface {
  22. ConfigMaps(namespace string) ConfigMapsInterface
  23. }
  24. type ConfigMapsInterface interface {
  25. Get(string) (*api.ConfigMap, error)
  26. List(opts api.ListOptions) (*api.ConfigMapList, error)
  27. Create(*api.ConfigMap) (*api.ConfigMap, error)
  28. Delete(string) error
  29. Update(*api.ConfigMap) (*api.ConfigMap, error)
  30. Watch(api.ListOptions) (watch.Interface, error)
  31. }
  32. type ConfigMaps struct {
  33. client *Client
  34. namespace string
  35. }
  36. // ConfigMaps should implement ConfigMapsInterface
  37. var _ ConfigMapsInterface = &ConfigMaps{}
  38. func newConfigMaps(c *Client, ns string) *ConfigMaps {
  39. return &ConfigMaps{
  40. client: c,
  41. namespace: ns,
  42. }
  43. }
  44. func (c *ConfigMaps) Get(name string) (*api.ConfigMap, error) {
  45. result := &api.ConfigMap{}
  46. err := c.client.Get().
  47. Namespace(c.namespace).
  48. Resource(ConfigMapResourceName).
  49. Name(name).
  50. Do().
  51. Into(result)
  52. return result, err
  53. }
  54. func (c *ConfigMaps) List(opts api.ListOptions) (*api.ConfigMapList, error) {
  55. result := &api.ConfigMapList{}
  56. err := c.client.Get().
  57. Namespace(c.namespace).
  58. Resource(ConfigMapResourceName).
  59. VersionedParams(&opts, api.ParameterCodec).
  60. Do().
  61. Into(result)
  62. return result, err
  63. }
  64. func (c *ConfigMaps) Create(cfg *api.ConfigMap) (*api.ConfigMap, error) {
  65. result := &api.ConfigMap{}
  66. err := c.client.Post().
  67. Namespace(c.namespace).
  68. Resource(ConfigMapResourceName).
  69. Body(cfg).
  70. Do().
  71. Into(result)
  72. return result, err
  73. }
  74. func (c *ConfigMaps) Delete(name string) error {
  75. return c.client.Delete().
  76. Namespace(c.namespace).
  77. Resource(ConfigMapResourceName).
  78. Name(name).
  79. Do().
  80. Error()
  81. }
  82. func (c *ConfigMaps) Update(cfg *api.ConfigMap) (*api.ConfigMap, error) {
  83. result := &api.ConfigMap{}
  84. err := c.client.Put().
  85. Namespace(c.namespace).
  86. Resource(ConfigMapResourceName).
  87. Name(cfg.Name).
  88. Body(cfg).
  89. Do().
  90. Into(result)
  91. return result, err
  92. }
  93. func (c *ConfigMaps) Watch(opts api.ListOptions) (watch.Interface, error) {
  94. return c.client.Get().
  95. Prefix("watch").
  96. Namespace(c.namespace).
  97. Resource(ConfigMapResourceName).
  98. VersionedParams(&opts, api.ParameterCodec).
  99. Watch()
  100. }