release.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. "io/ioutil"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. )
  20. type ReleaseListOptions struct {
  21. NamespaceResourceListOptions
  22. Deployed bool `help:"Show deployed status releases"`
  23. Deleted bool `help:"Show deleted status releases"`
  24. Deleting bool `help:"Show deleting status releases"`
  25. Failed bool `help:"Show failed status releases"`
  26. Superseded bool `help:"Show superseded status releases"`
  27. Pending bool `help:"Show pending status releases"`
  28. Type string `help:"Release type" choices:"internal|external"`
  29. }
  30. func (o ReleaseListOptions) Params() (jsonutils.JSONObject, error) {
  31. ret, err := o.NamespaceResourceListOptions.Params()
  32. if err != nil {
  33. return nil, err
  34. }
  35. params := ret.(*jsonutils.JSONDict)
  36. if o.Namespace != "" {
  37. params.Add(jsonutils.NewString(o.Namespace), "namespace")
  38. }
  39. if o.Name != "" {
  40. params.Add(jsonutils.NewString(o.Name), "name")
  41. }
  42. if o.Type != "" {
  43. params.Add(jsonutils.NewString(o.Type), "type")
  44. }
  45. params.Add(jsonutils.JSONTrue, "all")
  46. if o.Deployed {
  47. params.Add(jsonutils.JSONTrue, "deployed")
  48. }
  49. if o.Deleted {
  50. params.Add(jsonutils.JSONTrue, "deleted")
  51. }
  52. if o.Deleting {
  53. params.Add(jsonutils.JSONTrue, "deleting")
  54. }
  55. if o.Failed {
  56. params.Add(jsonutils.JSONTrue, "failed")
  57. }
  58. if o.Superseded {
  59. params.Add(jsonutils.JSONTrue, "superseded")
  60. }
  61. if o.Pending {
  62. params.Add(jsonutils.JSONTrue, "pending")
  63. }
  64. return params, nil
  65. }
  66. type ReleaseCreateUpdateOptions struct {
  67. Values string `help:"Specify values in a YAML file (can specify multiple)" short-token:"f"`
  68. Version string `help:"Specify the exact chart version to install. If not specified, latest version installed"`
  69. //Set []string `help:"set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)"`
  70. DryRun bool `help:"Simulate an install"`
  71. Details bool `help:"Show release deploy details, include kubernetes created resources"`
  72. Timeout int64 `help:"Time in seconds to wait for any individual kubernetes operation (like Jobs for hooks)" default:"600"`
  73. }
  74. func (o ReleaseCreateUpdateOptions) Params() (*jsonutils.JSONDict, error) {
  75. params := jsonutils.NewDict()
  76. if o.Version != "" {
  77. params.Add(jsonutils.NewString(o.Version), "version")
  78. }
  79. if o.DryRun {
  80. params.Add(jsonutils.JSONTrue, "dry_run")
  81. }
  82. params.Add(jsonutils.NewInt(o.Timeout), "timeout")
  83. if o.Values != "" {
  84. //vals, err := helm.MergeValuesF(args.Values, args.Set, []string{})
  85. vals, err := ioutil.ReadFile(o.Values)
  86. if err != nil {
  87. return nil, err
  88. }
  89. valsJson, err := jsonutils.ParseYAML(string(vals))
  90. if err != nil {
  91. return nil, errors.Wrap(err, "parse yaml values")
  92. }
  93. params.Add(valsJson, "values_json")
  94. }
  95. return params, nil
  96. }
  97. type ReleaseCreateOptions struct {
  98. AppBaseCreateOptions
  99. CHARTNAME string `help:"Helm chart name, e.g stable/etcd"`
  100. }
  101. func (o ReleaseCreateOptions) Params() (jsonutils.JSONObject, error) {
  102. params, err := o.AppBaseCreateOptions.Params()
  103. if err != nil {
  104. return nil, err
  105. }
  106. params.Add(jsonutils.NewString(o.CHARTNAME), "chart_name")
  107. return params, nil
  108. }
  109. type ReleaseUpgradeOptions struct {
  110. NamespaceWithClusterOptions
  111. ReleaseCreateUpdateOptions
  112. ReuseValues bool `help:"When upgrading, reuse the last release's values, and merge in any new values. If '--reset-values' is specified, this is ignored"`
  113. ResetValues bool `help:"When upgrading, reset the values to the ones built into the chart"`
  114. NAME string `help:"Release instance name"`
  115. }
  116. func (o ReleaseUpgradeOptions) Params() (*jsonutils.JSONDict, error) {
  117. params, err := o.ReleaseCreateUpdateOptions.Params()
  118. if err != nil {
  119. return nil, err
  120. }
  121. params.Update(o.NamespaceWithClusterOptions.Params())
  122. params.Add(jsonutils.NewString(o.NAME), "release_name")
  123. if o.ReuseValues {
  124. params.Add(jsonutils.JSONTrue, "reuse_values")
  125. }
  126. if o.ResetValues {
  127. params.Add(jsonutils.JSONTrue, "reset_values")
  128. }
  129. return params, nil
  130. }
  131. type ReleaseDeleteOptions struct {
  132. NamespaceWithClusterOptions
  133. NAME string `help:"Release instance name"`
  134. }
  135. func (o *ReleaseDeleteOptions) GetId() string {
  136. return o.NAME
  137. }
  138. func (o *ReleaseDeleteOptions) Params() (jsonutils.JSONObject, error) {
  139. return o.NamespaceWithClusterOptions.Params(), nil
  140. }
  141. type ReleaseHistoryOptions struct {
  142. NamespaceWithClusterOptions
  143. NAME string `help:"Release instance name"`
  144. Max int64 `help:"History limit size"`
  145. }
  146. func (o ReleaseHistoryOptions) Params() *jsonutils.JSONDict {
  147. params := o.NamespaceWithClusterOptions.Params()
  148. if o.Max >= 1 {
  149. params.Add(jsonutils.NewInt(o.Max), "max")
  150. }
  151. return params
  152. }
  153. type ReleaseRollbackOptions struct {
  154. NamespaceWithClusterOptions
  155. NAME string `help:"Release instance name"`
  156. REVISION int64 `help:"Release history revision number"`
  157. Description string `help:"Release rollback description string"`
  158. }
  159. func (o ReleaseRollbackOptions) Params() *jsonutils.JSONDict {
  160. params := o.NamespaceWithClusterOptions.Params()
  161. params.Add(jsonutils.NewInt(o.REVISION), "revision")
  162. if o.Description != "" {
  163. params.Add(jsonutils.NewString(o.Description), "description")
  164. }
  165. return params
  166. }