actions.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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 testing
  14. import (
  15. "fmt"
  16. "path"
  17. "strings"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. "k8s.io/apimachinery/pkg/fields"
  20. "k8s.io/apimachinery/pkg/labels"
  21. "k8s.io/apimachinery/pkg/runtime"
  22. "k8s.io/apimachinery/pkg/runtime/schema"
  23. "k8s.io/apimachinery/pkg/types"
  24. )
  25. // All NewRoot... functions return non-namespaced actions, and are equivalent to
  26. // calling the corresponding New... function with an empty namespace.
  27. // This is assumed by the fake client generator.
  28. func NewRootGetAction(resource schema.GroupVersionResource, name string) GetActionImpl {
  29. return NewRootGetActionWithOptions(resource, name, metav1.GetOptions{})
  30. }
  31. func NewRootGetActionWithOptions(resource schema.GroupVersionResource, name string, opts metav1.GetOptions) GetActionImpl {
  32. action := GetActionImpl{}
  33. action.Verb = "get"
  34. action.Resource = resource
  35. action.Name = name
  36. action.GetOptions = opts
  37. return action
  38. }
  39. func NewGetAction(resource schema.GroupVersionResource, namespace, name string) GetActionImpl {
  40. return NewGetActionWithOptions(resource, namespace, name, metav1.GetOptions{})
  41. }
  42. func NewGetActionWithOptions(resource schema.GroupVersionResource, namespace, name string, opts metav1.GetOptions) GetActionImpl {
  43. action := GetActionImpl{}
  44. action.Verb = "get"
  45. action.Resource = resource
  46. action.Namespace = namespace
  47. action.Name = name
  48. action.GetOptions = opts
  49. return action
  50. }
  51. func NewGetSubresourceAction(resource schema.GroupVersionResource, namespace, subresource, name string) GetActionImpl {
  52. return NewGetSubresourceActionWithOptions(resource, namespace, subresource, name, metav1.GetOptions{})
  53. }
  54. func NewGetSubresourceActionWithOptions(resource schema.GroupVersionResource, namespace, subresource, name string, opts metav1.GetOptions) GetActionImpl {
  55. action := GetActionImpl{}
  56. action.Verb = "get"
  57. action.Resource = resource
  58. action.Subresource = subresource
  59. action.Namespace = namespace
  60. action.Name = name
  61. action.GetOptions = opts
  62. return action
  63. }
  64. func NewRootGetSubresourceAction(resource schema.GroupVersionResource, subresource, name string) GetActionImpl {
  65. return NewRootGetSubresourceActionWithOptions(resource, subresource, name, metav1.GetOptions{})
  66. }
  67. func NewRootGetSubresourceActionWithOptions(resource schema.GroupVersionResource, subresource, name string, opts metav1.GetOptions) GetActionImpl {
  68. action := GetActionImpl{}
  69. action.Verb = "get"
  70. action.Resource = resource
  71. action.Subresource = subresource
  72. action.Name = name
  73. action.GetOptions = opts
  74. return action
  75. }
  76. func NewRootListAction(resource schema.GroupVersionResource, kind schema.GroupVersionKind, opts interface{}) ListActionImpl {
  77. action := ListActionImpl{}
  78. action.Verb = "list"
  79. action.Resource = resource
  80. action.Kind = kind
  81. labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
  82. action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
  83. action.ListOptions = metav1.ListOptions{LabelSelector: labelSelector.String(), FieldSelector: fieldSelector.String()}
  84. return action
  85. }
  86. func NewRootListActionWithOptions(resource schema.GroupVersionResource, kind schema.GroupVersionKind, opts metav1.ListOptions) ListActionImpl {
  87. action := ListActionImpl{}
  88. action.Verb = "list"
  89. action.Resource = resource
  90. action.Kind = kind
  91. action.ListOptions = opts
  92. labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
  93. action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
  94. action.ListOptions = metav1.ListOptions{LabelSelector: labelSelector.String(), FieldSelector: fieldSelector.String()}
  95. return action
  96. }
  97. func NewListAction(resource schema.GroupVersionResource, kind schema.GroupVersionKind, namespace string, opts interface{}) ListActionImpl {
  98. action := ListActionImpl{}
  99. action.Verb = "list"
  100. action.Resource = resource
  101. action.Kind = kind
  102. action.Namespace = namespace
  103. labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
  104. action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
  105. action.ListOptions = metav1.ListOptions{LabelSelector: labelSelector.String(), FieldSelector: fieldSelector.String()}
  106. return action
  107. }
  108. func NewListActionWithOptions(resource schema.GroupVersionResource, kind schema.GroupVersionKind, namespace string, opts metav1.ListOptions) ListActionImpl {
  109. action := ListActionImpl{}
  110. action.Verb = "list"
  111. action.Resource = resource
  112. action.Kind = kind
  113. action.Namespace = namespace
  114. action.ListOptions = opts
  115. labelSelector, fieldSelector, _ := ExtractFromListOptions(opts)
  116. action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
  117. return action
  118. }
  119. func NewRootCreateAction(resource schema.GroupVersionResource, object runtime.Object) CreateActionImpl {
  120. return NewRootCreateActionWithOptions(resource, object, metav1.CreateOptions{})
  121. }
  122. func NewRootCreateActionWithOptions(resource schema.GroupVersionResource, object runtime.Object, opts metav1.CreateOptions) CreateActionImpl {
  123. action := CreateActionImpl{}
  124. action.Verb = "create"
  125. action.Resource = resource
  126. action.Object = object
  127. action.CreateOptions = opts
  128. return action
  129. }
  130. func NewCreateAction(resource schema.GroupVersionResource, namespace string, object runtime.Object) CreateActionImpl {
  131. return NewCreateActionWithOptions(resource, namespace, object, metav1.CreateOptions{})
  132. }
  133. func NewCreateActionWithOptions(resource schema.GroupVersionResource, namespace string, object runtime.Object, opts metav1.CreateOptions) CreateActionImpl {
  134. action := CreateActionImpl{}
  135. action.Verb = "create"
  136. action.Resource = resource
  137. action.Namespace = namespace
  138. action.Object = object
  139. action.CreateOptions = opts
  140. return action
  141. }
  142. func NewRootCreateSubresourceAction(resource schema.GroupVersionResource, name, subresource string, object runtime.Object) CreateActionImpl {
  143. return NewRootCreateSubresourceActionWithOptions(resource, name, subresource, object, metav1.CreateOptions{})
  144. }
  145. func NewRootCreateSubresourceActionWithOptions(resource schema.GroupVersionResource, name, subresource string, object runtime.Object, opts metav1.CreateOptions) CreateActionImpl {
  146. action := CreateActionImpl{}
  147. action.Verb = "create"
  148. action.Resource = resource
  149. action.Subresource = subresource
  150. action.Name = name
  151. action.Object = object
  152. action.CreateOptions = opts
  153. return action
  154. }
  155. func NewCreateSubresourceAction(resource schema.GroupVersionResource, name, subresource, namespace string, object runtime.Object) CreateActionImpl {
  156. return NewCreateSubresourceActionWithOptions(resource, name, subresource, namespace, object, metav1.CreateOptions{})
  157. }
  158. func NewCreateSubresourceActionWithOptions(resource schema.GroupVersionResource, name, subresource, namespace string, object runtime.Object, opts metav1.CreateOptions) CreateActionImpl {
  159. action := CreateActionImpl{}
  160. action.Verb = "create"
  161. action.Resource = resource
  162. action.Namespace = namespace
  163. action.Subresource = subresource
  164. action.Name = name
  165. action.Object = object
  166. action.CreateOptions = opts
  167. return action
  168. }
  169. func NewRootUpdateAction(resource schema.GroupVersionResource, object runtime.Object) UpdateActionImpl {
  170. return NewRootUpdateActionWithOptions(resource, object, metav1.UpdateOptions{})
  171. }
  172. func NewRootUpdateActionWithOptions(resource schema.GroupVersionResource, object runtime.Object, opts metav1.UpdateOptions) UpdateActionImpl {
  173. action := UpdateActionImpl{}
  174. action.Verb = "update"
  175. action.Resource = resource
  176. action.Object = object
  177. action.UpdateOptions = opts
  178. return action
  179. }
  180. func NewUpdateAction(resource schema.GroupVersionResource, namespace string, object runtime.Object) UpdateActionImpl {
  181. return NewUpdateActionWithOptions(resource, namespace, object, metav1.UpdateOptions{})
  182. }
  183. func NewUpdateActionWithOptions(resource schema.GroupVersionResource, namespace string, object runtime.Object, opts metav1.UpdateOptions) UpdateActionImpl {
  184. action := UpdateActionImpl{}
  185. action.Verb = "update"
  186. action.Resource = resource
  187. action.Namespace = namespace
  188. action.Object = object
  189. action.UpdateOptions = opts
  190. return action
  191. }
  192. func NewRootPatchAction(resource schema.GroupVersionResource, name string, pt types.PatchType, patch []byte) PatchActionImpl {
  193. return NewRootPatchActionWithOptions(resource, name, pt, patch, metav1.PatchOptions{})
  194. }
  195. func NewRootPatchActionWithOptions(resource schema.GroupVersionResource, name string, pt types.PatchType, patch []byte, opts metav1.PatchOptions) PatchActionImpl {
  196. action := PatchActionImpl{}
  197. action.Verb = "patch"
  198. action.Resource = resource
  199. action.Name = name
  200. action.PatchType = pt
  201. action.Patch = patch
  202. action.PatchOptions = opts
  203. return action
  204. }
  205. func NewPatchAction(resource schema.GroupVersionResource, namespace string, name string, pt types.PatchType, patch []byte) PatchActionImpl {
  206. return NewPatchActionWithOptions(resource, namespace, name, pt, patch, metav1.PatchOptions{})
  207. }
  208. func NewPatchActionWithOptions(resource schema.GroupVersionResource, namespace string, name string, pt types.PatchType, patch []byte, opts metav1.PatchOptions) PatchActionImpl {
  209. action := PatchActionImpl{}
  210. action.Verb = "patch"
  211. action.Resource = resource
  212. action.Namespace = namespace
  213. action.Name = name
  214. action.PatchType = pt
  215. action.Patch = patch
  216. action.PatchOptions = opts
  217. return action
  218. }
  219. func NewRootPatchSubresourceAction(resource schema.GroupVersionResource, name string, pt types.PatchType, patch []byte, subresources ...string) PatchActionImpl {
  220. return NewRootPatchSubresourceActionWithOptions(resource, name, pt, patch, metav1.PatchOptions{}, subresources...)
  221. }
  222. func NewRootPatchSubresourceActionWithOptions(resource schema.GroupVersionResource, name string, pt types.PatchType, patch []byte, opts metav1.PatchOptions, subresources ...string) PatchActionImpl {
  223. action := PatchActionImpl{}
  224. action.Verb = "patch"
  225. action.Resource = resource
  226. action.Subresource = path.Join(subresources...)
  227. action.Name = name
  228. action.PatchType = pt
  229. action.Patch = patch
  230. action.PatchOptions = opts
  231. return action
  232. }
  233. func NewPatchSubresourceAction(resource schema.GroupVersionResource, namespace, name string, pt types.PatchType, patch []byte, subresources ...string) PatchActionImpl {
  234. return NewPatchSubresourceActionWithOptions(resource, namespace, name, pt, patch, metav1.PatchOptions{}, subresources...)
  235. }
  236. func NewPatchSubresourceActionWithOptions(resource schema.GroupVersionResource, namespace, name string, pt types.PatchType, patch []byte, opts metav1.PatchOptions, subresources ...string) PatchActionImpl {
  237. action := PatchActionImpl{}
  238. action.Verb = "patch"
  239. action.Resource = resource
  240. action.Subresource = path.Join(subresources...)
  241. action.Namespace = namespace
  242. action.Name = name
  243. action.PatchType = pt
  244. action.Patch = patch
  245. action.PatchOptions = opts
  246. return action
  247. }
  248. func NewRootUpdateSubresourceAction(resource schema.GroupVersionResource, subresource string, object runtime.Object) UpdateActionImpl {
  249. return NewRootUpdateSubresourceActionWithOptions(resource, subresource, object, metav1.UpdateOptions{})
  250. }
  251. func NewRootUpdateSubresourceActionWithOptions(resource schema.GroupVersionResource, subresource string, object runtime.Object, opts metav1.UpdateOptions) UpdateActionImpl {
  252. action := UpdateActionImpl{}
  253. action.Verb = "update"
  254. action.Resource = resource
  255. action.Subresource = subresource
  256. action.Object = object
  257. action.UpdateOptions = opts
  258. return action
  259. }
  260. func NewUpdateSubresourceAction(resource schema.GroupVersionResource, subresource string, namespace string, object runtime.Object) UpdateActionImpl {
  261. return NewUpdateSubresourceActionWithOptions(resource, subresource, namespace, object, metav1.UpdateOptions{})
  262. }
  263. func NewUpdateSubresourceActionWithOptions(resource schema.GroupVersionResource, subresource string, namespace string, object runtime.Object, opts metav1.UpdateOptions) UpdateActionImpl {
  264. action := UpdateActionImpl{}
  265. action.Verb = "update"
  266. action.Resource = resource
  267. action.Subresource = subresource
  268. action.Namespace = namespace
  269. action.Object = object
  270. action.UpdateOptions = opts
  271. return action
  272. }
  273. func NewRootDeleteAction(resource schema.GroupVersionResource, name string) DeleteActionImpl {
  274. return NewRootDeleteActionWithOptions(resource, name, metav1.DeleteOptions{})
  275. }
  276. func NewRootDeleteActionWithOptions(resource schema.GroupVersionResource, name string, opts metav1.DeleteOptions) DeleteActionImpl {
  277. action := DeleteActionImpl{}
  278. action.Verb = "delete"
  279. action.Resource = resource
  280. action.Name = name
  281. action.DeleteOptions = opts
  282. return action
  283. }
  284. func NewRootDeleteSubresourceAction(resource schema.GroupVersionResource, subresource string, name string) DeleteActionImpl {
  285. return NewRootDeleteSubresourceActionWithOptions(resource, subresource, name, metav1.DeleteOptions{})
  286. }
  287. func NewRootDeleteSubresourceActionWithOptions(resource schema.GroupVersionResource, subresource string, name string, opts metav1.DeleteOptions) DeleteActionImpl {
  288. action := DeleteActionImpl{}
  289. action.Verb = "delete"
  290. action.Resource = resource
  291. action.Subresource = subresource
  292. action.Name = name
  293. action.DeleteOptions = opts
  294. return action
  295. }
  296. func NewDeleteAction(resource schema.GroupVersionResource, namespace, name string) DeleteActionImpl {
  297. return NewDeleteActionWithOptions(resource, namespace, name, metav1.DeleteOptions{})
  298. }
  299. func NewDeleteActionWithOptions(resource schema.GroupVersionResource, namespace, name string, opts metav1.DeleteOptions) DeleteActionImpl {
  300. action := DeleteActionImpl{}
  301. action.Verb = "delete"
  302. action.Resource = resource
  303. action.Namespace = namespace
  304. action.Name = name
  305. action.DeleteOptions = opts
  306. return action
  307. }
  308. func NewDeleteSubresourceAction(resource schema.GroupVersionResource, subresource, namespace, name string) DeleteActionImpl {
  309. return NewDeleteSubresourceActionWithOptions(resource, subresource, namespace, name, metav1.DeleteOptions{})
  310. }
  311. func NewDeleteSubresourceActionWithOptions(resource schema.GroupVersionResource, subresource, namespace, name string, opts metav1.DeleteOptions) DeleteActionImpl {
  312. action := DeleteActionImpl{}
  313. action.Verb = "delete"
  314. action.Resource = resource
  315. action.Subresource = subresource
  316. action.Namespace = namespace
  317. action.Name = name
  318. action.DeleteOptions = opts
  319. return action
  320. }
  321. func NewRootDeleteCollectionAction(resource schema.GroupVersionResource, opts interface{}) DeleteCollectionActionImpl {
  322. listOpts, _ := opts.(metav1.ListOptions)
  323. return NewRootDeleteCollectionActionWithOptions(resource, metav1.DeleteOptions{}, listOpts)
  324. }
  325. func NewRootDeleteCollectionActionWithOptions(resource schema.GroupVersionResource, deleteOpts metav1.DeleteOptions, listOpts metav1.ListOptions) DeleteCollectionActionImpl {
  326. action := DeleteCollectionActionImpl{}
  327. action.Verb = "delete-collection"
  328. action.Resource = resource
  329. action.DeleteOptions = deleteOpts
  330. action.ListOptions = listOpts
  331. labelSelector, fieldSelector, _ := ExtractFromListOptions(listOpts)
  332. action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
  333. return action
  334. }
  335. func NewDeleteCollectionAction(resource schema.GroupVersionResource, namespace string, opts interface{}) DeleteCollectionActionImpl {
  336. listOpts, _ := opts.(metav1.ListOptions)
  337. return NewDeleteCollectionActionWithOptions(resource, namespace, metav1.DeleteOptions{}, listOpts)
  338. }
  339. func NewDeleteCollectionActionWithOptions(resource schema.GroupVersionResource, namespace string, deleteOpts metav1.DeleteOptions, listOpts metav1.ListOptions) DeleteCollectionActionImpl {
  340. action := DeleteCollectionActionImpl{}
  341. action.Verb = "delete-collection"
  342. action.Resource = resource
  343. action.Namespace = namespace
  344. action.DeleteOptions = deleteOpts
  345. action.ListOptions = listOpts
  346. labelSelector, fieldSelector, _ := ExtractFromListOptions(listOpts)
  347. action.ListRestrictions = ListRestrictions{labelSelector, fieldSelector}
  348. return action
  349. }
  350. func NewRootWatchAction(resource schema.GroupVersionResource, opts interface{}) WatchActionImpl {
  351. listOpts, _ := opts.(metav1.ListOptions)
  352. return NewRootWatchActionWithOptions(resource, listOpts)
  353. }
  354. func NewRootWatchActionWithOptions(resource schema.GroupVersionResource, opts metav1.ListOptions) WatchActionImpl {
  355. action := WatchActionImpl{}
  356. action.Verb = "watch"
  357. action.Resource = resource
  358. action.ListOptions = opts
  359. labelSelector, fieldSelector, resourceVersion := ExtractFromListOptions(opts)
  360. action.WatchRestrictions = WatchRestrictions{labelSelector, fieldSelector, resourceVersion}
  361. return action
  362. }
  363. func ExtractFromListOptions(opts interface{}) (labelSelector labels.Selector, fieldSelector fields.Selector, resourceVersion string) {
  364. var err error
  365. switch t := opts.(type) {
  366. case metav1.ListOptions:
  367. labelSelector, err = labels.Parse(t.LabelSelector)
  368. if err != nil {
  369. panic(fmt.Errorf("invalid selector %q: %v", t.LabelSelector, err))
  370. }
  371. fieldSelector, err = fields.ParseSelector(t.FieldSelector)
  372. if err != nil {
  373. panic(fmt.Errorf("invalid selector %q: %v", t.FieldSelector, err))
  374. }
  375. resourceVersion = t.ResourceVersion
  376. default:
  377. panic(fmt.Errorf("expect a ListOptions %T", opts))
  378. }
  379. if labelSelector == nil {
  380. labelSelector = labels.Everything()
  381. }
  382. if fieldSelector == nil {
  383. fieldSelector = fields.Everything()
  384. }
  385. return labelSelector, fieldSelector, resourceVersion
  386. }
  387. func NewWatchAction(resource schema.GroupVersionResource, namespace string, opts interface{}) WatchActionImpl {
  388. listOpts, _ := opts.(metav1.ListOptions)
  389. return NewWatchActionWithOptions(resource, namespace, listOpts)
  390. }
  391. func NewWatchActionWithOptions(resource schema.GroupVersionResource, namespace string, opts metav1.ListOptions) WatchActionImpl {
  392. action := WatchActionImpl{}
  393. action.Verb = "watch"
  394. action.Resource = resource
  395. action.Namespace = namespace
  396. action.ListOptions = opts
  397. labelSelector, fieldSelector, resourceVersion := ExtractFromListOptions(opts)
  398. action.WatchRestrictions = WatchRestrictions{labelSelector, fieldSelector, resourceVersion}
  399. return action
  400. }
  401. func NewProxyGetAction(resource schema.GroupVersionResource, namespace, scheme, name, port, path string, params map[string]string) ProxyGetActionImpl {
  402. action := ProxyGetActionImpl{}
  403. action.Verb = "get"
  404. action.Resource = resource
  405. action.Namespace = namespace
  406. action.Scheme = scheme
  407. action.Name = name
  408. action.Port = port
  409. action.Path = path
  410. action.Params = params
  411. return action
  412. }
  413. type ListRestrictions struct {
  414. Labels labels.Selector
  415. Fields fields.Selector
  416. }
  417. type WatchRestrictions struct {
  418. Labels labels.Selector
  419. Fields fields.Selector
  420. ResourceVersion string
  421. }
  422. type Action interface {
  423. GetNamespace() string
  424. GetVerb() string
  425. GetResource() schema.GroupVersionResource
  426. GetSubresource() string
  427. Matches(verb, resource string) bool
  428. // DeepCopy is used to copy an action to avoid any risk of accidental mutation. Most people never need to call this
  429. // because the invocation logic deep copies before calls to storage and reactors.
  430. DeepCopy() Action
  431. }
  432. type GenericAction interface {
  433. Action
  434. GetValue() interface{}
  435. }
  436. type GetAction interface {
  437. Action
  438. GetName() string
  439. }
  440. type ListAction interface {
  441. Action
  442. GetListRestrictions() ListRestrictions
  443. }
  444. type CreateAction interface {
  445. Action
  446. GetObject() runtime.Object
  447. }
  448. type UpdateAction interface {
  449. Action
  450. GetObject() runtime.Object
  451. }
  452. type DeleteAction interface {
  453. Action
  454. GetName() string
  455. GetDeleteOptions() metav1.DeleteOptions
  456. }
  457. type DeleteCollectionAction interface {
  458. Action
  459. GetListRestrictions() ListRestrictions
  460. }
  461. type PatchAction interface {
  462. Action
  463. GetName() string
  464. GetPatchType() types.PatchType
  465. GetPatch() []byte
  466. }
  467. type WatchAction interface {
  468. Action
  469. GetWatchRestrictions() WatchRestrictions
  470. }
  471. type ProxyGetAction interface {
  472. Action
  473. GetScheme() string
  474. GetName() string
  475. GetPort() string
  476. GetPath() string
  477. GetParams() map[string]string
  478. }
  479. type ActionImpl struct {
  480. Namespace string
  481. Verb string
  482. Resource schema.GroupVersionResource
  483. Subresource string
  484. }
  485. func (a ActionImpl) GetNamespace() string {
  486. return a.Namespace
  487. }
  488. func (a ActionImpl) GetVerb() string {
  489. return a.Verb
  490. }
  491. func (a ActionImpl) GetResource() schema.GroupVersionResource {
  492. return a.Resource
  493. }
  494. func (a ActionImpl) GetSubresource() string {
  495. return a.Subresource
  496. }
  497. func (a ActionImpl) Matches(verb, resource string) bool {
  498. // Stay backwards compatible.
  499. if !strings.Contains(resource, "/") {
  500. return strings.EqualFold(verb, a.Verb) &&
  501. strings.EqualFold(resource, a.Resource.Resource)
  502. }
  503. parts := strings.SplitN(resource, "/", 2)
  504. topresource, subresource := parts[0], parts[1]
  505. return strings.EqualFold(verb, a.Verb) &&
  506. strings.EqualFold(topresource, a.Resource.Resource) &&
  507. strings.EqualFold(subresource, a.Subresource)
  508. }
  509. func (a ActionImpl) DeepCopy() Action {
  510. ret := a
  511. return ret
  512. }
  513. type GenericActionImpl struct {
  514. ActionImpl
  515. Value interface{}
  516. }
  517. func (a GenericActionImpl) GetValue() interface{} {
  518. return a.Value
  519. }
  520. func (a GenericActionImpl) DeepCopy() Action {
  521. return GenericActionImpl{
  522. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  523. // TODO this is wrong, but no worse than before
  524. Value: a.Value,
  525. }
  526. }
  527. type GetActionImpl struct {
  528. ActionImpl
  529. Name string
  530. GetOptions metav1.GetOptions
  531. }
  532. func (a GetActionImpl) GetName() string {
  533. return a.Name
  534. }
  535. func (a GetActionImpl) GetGetOptions() metav1.GetOptions {
  536. return a.GetOptions
  537. }
  538. func (a GetActionImpl) DeepCopy() Action {
  539. return GetActionImpl{
  540. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  541. Name: a.Name,
  542. GetOptions: *a.GetOptions.DeepCopy(),
  543. }
  544. }
  545. type ListActionImpl struct {
  546. ActionImpl
  547. Kind schema.GroupVersionKind
  548. Name string
  549. ListRestrictions ListRestrictions
  550. ListOptions metav1.ListOptions
  551. }
  552. func (a ListActionImpl) GetKind() schema.GroupVersionKind {
  553. return a.Kind
  554. }
  555. func (a ListActionImpl) GetListRestrictions() ListRestrictions {
  556. return a.ListRestrictions
  557. }
  558. func (a ListActionImpl) GetListOptions() metav1.ListOptions {
  559. return a.ListOptions
  560. }
  561. func (a ListActionImpl) DeepCopy() Action {
  562. return ListActionImpl{
  563. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  564. Kind: a.Kind,
  565. Name: a.Name,
  566. ListRestrictions: ListRestrictions{
  567. Labels: a.ListRestrictions.Labels.DeepCopySelector(),
  568. Fields: a.ListRestrictions.Fields.DeepCopySelector(),
  569. },
  570. ListOptions: *a.ListOptions.DeepCopy(),
  571. }
  572. }
  573. type CreateActionImpl struct {
  574. ActionImpl
  575. Name string
  576. Object runtime.Object
  577. CreateOptions metav1.CreateOptions
  578. }
  579. func (a CreateActionImpl) GetObject() runtime.Object {
  580. return a.Object
  581. }
  582. func (a CreateActionImpl) GetCreateOptions() metav1.CreateOptions {
  583. return a.CreateOptions
  584. }
  585. func (a CreateActionImpl) DeepCopy() Action {
  586. return CreateActionImpl{
  587. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  588. Name: a.Name,
  589. Object: a.Object.DeepCopyObject(),
  590. CreateOptions: *a.CreateOptions.DeepCopy(),
  591. }
  592. }
  593. type UpdateActionImpl struct {
  594. ActionImpl
  595. Object runtime.Object
  596. UpdateOptions metav1.UpdateOptions
  597. }
  598. func (a UpdateActionImpl) GetObject() runtime.Object {
  599. return a.Object
  600. }
  601. func (a UpdateActionImpl) GetUpdateOptions() metav1.UpdateOptions {
  602. return a.UpdateOptions
  603. }
  604. func (a UpdateActionImpl) DeepCopy() Action {
  605. return UpdateActionImpl{
  606. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  607. Object: a.Object.DeepCopyObject(),
  608. UpdateOptions: *a.UpdateOptions.DeepCopy(),
  609. }
  610. }
  611. type PatchActionImpl struct {
  612. ActionImpl
  613. Name string
  614. PatchType types.PatchType
  615. Patch []byte
  616. PatchOptions metav1.PatchOptions
  617. }
  618. func (a PatchActionImpl) GetName() string {
  619. return a.Name
  620. }
  621. func (a PatchActionImpl) GetPatch() []byte {
  622. return a.Patch
  623. }
  624. func (a PatchActionImpl) GetPatchType() types.PatchType {
  625. return a.PatchType
  626. }
  627. func (a PatchActionImpl) GetPatchOptions() metav1.PatchOptions {
  628. return a.PatchOptions
  629. }
  630. func (a PatchActionImpl) DeepCopy() Action {
  631. patch := make([]byte, len(a.Patch))
  632. copy(patch, a.Patch)
  633. return PatchActionImpl{
  634. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  635. Name: a.Name,
  636. PatchType: a.PatchType,
  637. Patch: patch,
  638. PatchOptions: *a.PatchOptions.DeepCopy(),
  639. }
  640. }
  641. type DeleteActionImpl struct {
  642. ActionImpl
  643. Name string
  644. DeleteOptions metav1.DeleteOptions
  645. }
  646. func (a DeleteActionImpl) GetName() string {
  647. return a.Name
  648. }
  649. func (a DeleteActionImpl) GetDeleteOptions() metav1.DeleteOptions {
  650. return a.DeleteOptions
  651. }
  652. func (a DeleteActionImpl) DeepCopy() Action {
  653. return DeleteActionImpl{
  654. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  655. Name: a.Name,
  656. DeleteOptions: *a.DeleteOptions.DeepCopy(),
  657. }
  658. }
  659. type DeleteCollectionActionImpl struct {
  660. ActionImpl
  661. ListRestrictions ListRestrictions
  662. DeleteOptions metav1.DeleteOptions
  663. ListOptions metav1.ListOptions
  664. }
  665. func (a DeleteCollectionActionImpl) GetListRestrictions() ListRestrictions {
  666. return a.ListRestrictions
  667. }
  668. func (a DeleteCollectionActionImpl) GetDeleteOptions() metav1.DeleteOptions {
  669. return a.DeleteOptions
  670. }
  671. func (a DeleteCollectionActionImpl) GetListOptions() metav1.ListOptions {
  672. return a.ListOptions
  673. }
  674. func (a DeleteCollectionActionImpl) DeepCopy() Action {
  675. return DeleteCollectionActionImpl{
  676. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  677. ListRestrictions: ListRestrictions{
  678. Labels: a.ListRestrictions.Labels.DeepCopySelector(),
  679. Fields: a.ListRestrictions.Fields.DeepCopySelector(),
  680. },
  681. DeleteOptions: *a.DeleteOptions.DeepCopy(),
  682. ListOptions: *a.ListOptions.DeepCopy(),
  683. }
  684. }
  685. type WatchActionImpl struct {
  686. ActionImpl
  687. WatchRestrictions WatchRestrictions
  688. ListOptions metav1.ListOptions
  689. }
  690. func (a WatchActionImpl) GetWatchRestrictions() WatchRestrictions {
  691. return a.WatchRestrictions
  692. }
  693. func (a WatchActionImpl) GetListOptions() metav1.ListOptions {
  694. return a.ListOptions
  695. }
  696. func (a WatchActionImpl) DeepCopy() Action {
  697. return WatchActionImpl{
  698. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  699. WatchRestrictions: WatchRestrictions{
  700. Labels: a.WatchRestrictions.Labels.DeepCopySelector(),
  701. Fields: a.WatchRestrictions.Fields.DeepCopySelector(),
  702. ResourceVersion: a.WatchRestrictions.ResourceVersion,
  703. },
  704. ListOptions: *a.ListOptions.DeepCopy(),
  705. }
  706. }
  707. type ProxyGetActionImpl struct {
  708. ActionImpl
  709. Scheme string
  710. Name string
  711. Port string
  712. Path string
  713. Params map[string]string
  714. }
  715. func (a ProxyGetActionImpl) GetScheme() string {
  716. return a.Scheme
  717. }
  718. func (a ProxyGetActionImpl) GetName() string {
  719. return a.Name
  720. }
  721. func (a ProxyGetActionImpl) GetPort() string {
  722. return a.Port
  723. }
  724. func (a ProxyGetActionImpl) GetPath() string {
  725. return a.Path
  726. }
  727. func (a ProxyGetActionImpl) GetParams() map[string]string {
  728. return a.Params
  729. }
  730. func (a ProxyGetActionImpl) DeepCopy() Action {
  731. params := map[string]string{}
  732. for k, v := range a.Params {
  733. params[k] = v
  734. }
  735. return ProxyGetActionImpl{
  736. ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
  737. Scheme: a.Scheme,
  738. Name: a.Name,
  739. Port: a.Port,
  740. Path: a.Path,
  741. Params: params,
  742. }
  743. }