k8s.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2019 Yunion
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package k8s
  15. import (
  16. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/util/printutils"
  19. "yunion.io/x/onecloud/cmd/climc/shell"
  20. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  21. "yunion.io/x/onecloud/pkg/mcclient/modules/k8s"
  22. o "yunion.io/x/onecloud/pkg/mcclient/options/k8s"
  23. )
  24. func init() {
  25. // cluster resources
  26. initKubeCluster()
  27. initKubeMachine()
  28. initKubeCerts()
  29. // helm resources
  30. initTiller()
  31. initRepo()
  32. initChart()
  33. initRelease()
  34. // kubernetes original resources
  35. initRaw()
  36. initConfigMap()
  37. initDeployment()
  38. initStatefulset()
  39. initDaemonSet()
  40. initPod()
  41. initService()
  42. initIngress()
  43. initNamespace()
  44. initK8sNode()
  45. initSecret()
  46. initStorageClass()
  47. initPV()
  48. initPVC()
  49. initJob()
  50. initCronJob()
  51. initEvent()
  52. initRbac()
  53. initApp()
  54. // container registry
  55. initContainerRegistry()
  56. }
  57. var (
  58. R = shell.R
  59. printList = printutils.PrintJSONList
  60. printObject = printutils.PrintJSONObject
  61. printBatchResults = printutils.PrintJSONBatchResults
  62. )
  63. func resourceCmdN(prefix, suffix string) string {
  64. return fmt.Sprintf("k8s-%s-%s", prefix, suffix)
  65. }
  66. func clusterContext(clusterId string) modulebase.ManagerContext {
  67. return modulebase.ManagerContext{
  68. InstanceManager: k8s.KubeClusters,
  69. InstanceId: clusterId,
  70. }
  71. }
  72. func printObjectYAML(obj jsonutils.JSONObject) {
  73. fmt.Println(obj.YAMLString())
  74. }
  75. func initK8sClusterResource(kind string, manager modulebase.Manager) *K8sResourceCmd {
  76. cmd := NewK8sResourceCmd(manager)
  77. cmd.SetKeyword(kind)
  78. cmd.List(new(o.ResourceListOptions))
  79. cmd.Show(new(o.ResourceGetOptions))
  80. cmd.BatchDeleteWithParam(new(o.ResourceDeleteOptions))
  81. cmd.ShowEvent()
  82. return cmd
  83. }
  84. func initK8sNamespaceResource(kind string, manager k8s.IClusterResourceManager) *K8sResourceCmd {
  85. cmd := NewK8sResourceCmd(manager)
  86. cmd.SetKeyword(kind)
  87. cmd.List(new(o.NamespaceResourceListOptions))
  88. cmd.Show(new(o.NamespaceResourceGetOptions))
  89. cmd.BatchDeleteWithParam(new(o.NamespaceResourceDeleteOptions))
  90. cmd.ShowRaw(new(o.NamespaceResourceGetOptions))
  91. cmd.EditRaw(new(o.NamespaceResourceGetOptions))
  92. cmd.ShowEvent()
  93. return cmd
  94. }