client.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. Copyright 2014 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. "net"
  16. "net/url"
  17. "strings"
  18. "k8s.io/kubernetes/pkg/client/restclient"
  19. "k8s.io/kubernetes/pkg/client/typed/discovery"
  20. )
  21. // Interface holds the methods for clients of Kubernetes,
  22. // an interface to allow mock testing.
  23. type Interface interface {
  24. PodsNamespacer
  25. PodTemplatesNamespacer
  26. ReplicationControllersNamespacer
  27. ServicesNamespacer
  28. EndpointsNamespacer
  29. NodesInterface
  30. EventNamespacer
  31. LimitRangesNamespacer
  32. ResourceQuotasNamespacer
  33. ServiceAccountsNamespacer
  34. SecretsNamespacer
  35. NamespacesInterface
  36. PersistentVolumesInterface
  37. PersistentVolumeClaimsNamespacer
  38. ComponentStatusesInterface
  39. ConfigMapsNamespacer
  40. Apps() AppsInterface
  41. Authorization() AuthorizationInterface
  42. Autoscaling() AutoscalingInterface
  43. Authentication() AuthenticationInterface
  44. Batch() BatchInterface
  45. Extensions() ExtensionsInterface
  46. Rbac() RbacInterface
  47. Discovery() discovery.DiscoveryInterface
  48. Certificates() CertificatesInterface
  49. }
  50. func (c *Client) ReplicationControllers(namespace string) ReplicationControllerInterface {
  51. return newReplicationControllers(c, namespace)
  52. }
  53. func (c *Client) Nodes() NodeInterface {
  54. return newNodes(c)
  55. }
  56. func (c *Client) Events(namespace string) EventInterface {
  57. return newEvents(c, namespace)
  58. }
  59. func (c *Client) Endpoints(namespace string) EndpointsInterface {
  60. return newEndpoints(c, namespace)
  61. }
  62. func (c *Client) Pods(namespace string) PodInterface {
  63. return newPods(c, namespace)
  64. }
  65. func (c *Client) PodTemplates(namespace string) PodTemplateInterface {
  66. return newPodTemplates(c, namespace)
  67. }
  68. func (c *Client) Services(namespace string) ServiceInterface {
  69. return newServices(c, namespace)
  70. }
  71. func (c *Client) LimitRanges(namespace string) LimitRangeInterface {
  72. return newLimitRanges(c, namespace)
  73. }
  74. func (c *Client) ResourceQuotas(namespace string) ResourceQuotaInterface {
  75. return newResourceQuotas(c, namespace)
  76. }
  77. func (c *Client) ServiceAccounts(namespace string) ServiceAccountsInterface {
  78. return newServiceAccounts(c, namespace)
  79. }
  80. func (c *Client) Secrets(namespace string) SecretsInterface {
  81. return newSecrets(c, namespace)
  82. }
  83. func (c *Client) Namespaces() NamespaceInterface {
  84. return newNamespaces(c)
  85. }
  86. func (c *Client) PersistentVolumes() PersistentVolumeInterface {
  87. return newPersistentVolumes(c)
  88. }
  89. func (c *Client) PersistentVolumeClaims(namespace string) PersistentVolumeClaimInterface {
  90. return newPersistentVolumeClaims(c, namespace)
  91. }
  92. func (c *Client) ComponentStatuses() ComponentStatusInterface {
  93. return newComponentStatuses(c)
  94. }
  95. func (c *Client) ConfigMaps(namespace string) ConfigMapsInterface {
  96. return newConfigMaps(c, namespace)
  97. }
  98. // Client is the implementation of a Kubernetes client.
  99. type Client struct {
  100. *restclient.RESTClient
  101. *AuthorizationClient
  102. *AutoscalingClient
  103. *AuthenticationClient
  104. *BatchClient
  105. *ExtensionsClient
  106. *AppsClient
  107. *PolicyClient
  108. *RbacClient
  109. *discovery.DiscoveryClient
  110. *CertificatesClient
  111. }
  112. // IsTimeout tests if this is a timeout error in the underlying transport.
  113. // This is unbelievably ugly.
  114. // See: http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error for details
  115. func IsTimeout(err error) bool {
  116. if err == nil {
  117. return false
  118. }
  119. switch err := err.(type) {
  120. case *url.Error:
  121. if err, ok := err.Err.(net.Error); ok {
  122. return err.Timeout()
  123. }
  124. case net.Error:
  125. return err.Timeout()
  126. }
  127. if strings.Contains(err.Error(), "use of closed network connection") {
  128. return true
  129. }
  130. return false
  131. }
  132. func (c *Client) Authorization() AuthorizationInterface {
  133. return c.AuthorizationClient
  134. }
  135. func (c *Client) Autoscaling() AutoscalingInterface {
  136. return c.AutoscalingClient
  137. }
  138. func (c *Client) Authentication() AuthenticationInterface {
  139. return c.AuthenticationClient
  140. }
  141. func (c *Client) Batch() BatchInterface {
  142. return c.BatchClient
  143. }
  144. func (c *Client) Extensions() ExtensionsInterface {
  145. return c.ExtensionsClient
  146. }
  147. func (c *Client) Apps() AppsInterface {
  148. return c.AppsClient
  149. }
  150. func (c *Client) Rbac() RbacInterface {
  151. return c.RbacClient
  152. }
  153. func (c *Client) Policy() PolicyInterface {
  154. return c.PolicyClient
  155. }
  156. func (c *Client) Discovery() discovery.DiscoveryInterface {
  157. return c.DiscoveryClient
  158. }
  159. func (c *Client) Certificates() CertificatesInterface {
  160. return c.CertificatesClient
  161. }