statefulset.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "yunion.io/x/jsonutils"
  17. )
  18. type StatefulSetCreateOptions struct {
  19. NamespaceWithClusterOptions
  20. K8sLabelOptions
  21. K8sPodTemplateOptions
  22. ServiceSpecOptions
  23. NAME string `help:"Name of deployment"`
  24. Replicas int64 `help:"Number of replicas for pods in this deployment"`
  25. K8sPVCTemplateOptions
  26. }
  27. func (o StatefulSetCreateOptions) Params() (jsonutils.JSONObject, error) {
  28. params := o.NamespaceWithClusterOptions.Params()
  29. pvcs, err := o.K8sPVCTemplateOptions.Parse()
  30. if err != nil {
  31. return nil, err
  32. }
  33. o.K8sPVCTemplateOptions.Attach(params, pvcs, &o.K8sPodTemplateOptions)
  34. o.K8sPodTemplateOptions.setContainerName(o.NAME)
  35. if err := o.K8sPodTemplateOptions.Attach(params); err != nil {
  36. return nil, err
  37. }
  38. if err := o.K8sLabelOptions.Attach(params); err != nil {
  39. return nil, err
  40. }
  41. if err := o.ServiceSpecOptions.Attach(params); err != nil {
  42. return nil, err
  43. }
  44. params.Add(jsonutils.NewString(o.NAME), "name")
  45. if o.Replicas > 1 {
  46. params.Add(jsonutils.NewInt(o.Replicas), "replicas")
  47. }
  48. return params, nil
  49. }