climc: k8s options, code refactor

This commit is contained in:
Zexi Li
2018-09-13 15:04:39 +08:00
parent f15f944e04
commit f1fec1b49e
36 changed files with 1209 additions and 977 deletions
+19
View File
@@ -0,0 +1,19 @@
package k8s
import (
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
var CronJobs *CronJobManager
type CronJobManager struct {
*NamespaceResourceManager
}
func init() {
CronJobs = &CronJobManager{
NamespaceResourceManager: NewNamespaceResourceManager("cronjob", "cronjobs", NewNamespaceCols(), NewColumns()),
}
modules.Register(CronJobs)
}
+19
View File
@@ -0,0 +1,19 @@
package k8s
import (
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
var Jobs *JobManager
type JobManager struct {
*NamespaceResourceManager
}
func init() {
Jobs = &JobManager{
NamespaceResourceManager: NewNamespaceResourceManager("job", "jobs", NewNamespaceCols(), NewColumns()),
}
modules.Register(Jobs)
}
+38
View File
@@ -0,0 +1,38 @@
package k8s
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
var PersistentVolumes *PersistentVolumeManager
type PersistentVolumeManager struct {
*MetaResourceManager
}
func init() {
PersistentVolumes = &PersistentVolumeManager{
MetaResourceManager: NewMetaResourceManager("persistentvolume", "persistentvolumes",
NewColumns("StorageClass", "Claim", "AccessModes"),
NewColumns()),
}
modules.Register(PersistentVolumes)
}
func (m PersistentVolumeManager) GetStorageClass(obj jsonutils.JSONObject) interface{} {
sc, _ := obj.GetString("storageClass")
return sc
}
func (m PersistentVolumeManager) GetClaim(obj jsonutils.JSONObject) interface{} {
claim, _ := obj.GetString("claim")
return claim
}
func (m PersistentVolumeManager) GetAccessModes(obj jsonutils.JSONObject) interface{} {
modes, _ := obj.(*jsonutils.JSONDict).GetArray("accessModes")
return modes
}
+34
View File
@@ -0,0 +1,34 @@
package k8s
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
var PersistentVolumeClaims *PersistentVolumeClaimManager
type PersistentVolumeClaimManager struct {
*NamespaceResourceManager
statusGetter
}
func init() {
PersistentVolumeClaims = &PersistentVolumeClaimManager{
NamespaceResourceManager: NewNamespaceResourceManager(
"persistentvolumeclaim", "persistentvolumeclaims",
NewColumns("Status", "Volume", "StorageClass"), NewColumns()),
statusGetter: getStatus,
}
modules.Register(PersistentVolumeClaims)
}
func (m PersistentVolumeClaimManager) GetVolume(obj jsonutils.JSONObject) interface{} {
volume, _ := obj.GetString("volume")
return volume
}
func (m PersistentVolumeClaimManager) GetStorageClass(obj jsonutils.JSONObject) interface{} {
sc, _ := obj.GetString("storageClass")
return sc
}
+25
View File
@@ -0,0 +1,25 @@
package k8s
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
var Secrets *SecretManager
type SecretManager struct {
*NamespaceResourceManager
}
func init() {
Secrets = &SecretManager{
NewNamespaceResourceManager("secret", "secrets",
NewNamespaceCols("Type"), NewColumns())}
modules.Register(Secrets)
}
func (m SecretManager) GetType(obj jsonutils.JSONObject) interface{} {
typ, _ := obj.GetString("type")
return typ
}
+26
View File
@@ -0,0 +1,26 @@
package k8s
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
var Storageclass *StorageclassManager
type StorageclassManager struct {
*MetaResourceManager
}
func init() {
Storageclass = &StorageclassManager{
MetaResourceManager: NewMetaResourceManager("storageclass", "storageclasses", NewColumns("Provisioner"), NewColumns()),
}
modules.Register(Storageclass)
}
func (m StorageclassManager) GetProvisioner(obj jsonutils.JSONObject) interface{} {
provisioner, _ := obj.GetString("provisioner")
return provisioner
}
+104
View File
@@ -0,0 +1,104 @@
package k8s
import (
"yunion.io/x/jsonutils"
)
type ClusterBaseOptions struct {
Cluster string `default:"$K8S_CLUSTER|default" help:"Kubernetes cluster name"`
}
func (o ClusterBaseOptions) Params() *jsonutils.JSONDict {
ret := jsonutils.NewDict()
ret.Add(jsonutils.NewString(o.Cluster), "cluster")
return ret
}
type BaseListOptions struct {
Limit int `default:"20" help:"Page limit"`
Offset int `default:"0" help:"page offset"`
}
func (o BaseListOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.Limit > 0 {
params.Add(jsonutils.NewInt(int64(o.Limit)), "limit")
}
if o.Offset > 0 {
params.Add(jsonutils.NewInt(int64(o.Offset)), "offset")
}
return params
}
type ResourceListOptions struct {
ClusterBaseOptions
BaseListOptions
}
func (o ResourceListOptions) Params() *jsonutils.JSONDict {
params := o.BaseListOptions.Params()
params.Update(o.ClusterBaseOptions.Params())
return params
}
type ResourceGetOptions struct {
ClusterBaseOptions
NAME string `help:"Name ident of the resource"`
}
func (o ResourceGetOptions) Params() *jsonutils.JSONDict {
params := o.ClusterBaseOptions.Params()
return params
}
type NamespaceResourceListOptions struct {
ResourceListOptions
Namespace string `help:"Namespace of this resource"`
AllNamespace bool `help:"Show resource in all namespace"`
}
func (o NamespaceResourceListOptions) Params() *jsonutils.JSONDict {
params := o.ResourceListOptions.Params()
if o.AllNamespace {
params.Add(jsonutils.JSONTrue, "all_namespace")
return params
}
if o.Namespace != "" {
params.Add(jsonutils.NewString(o.Namespace), "namespace")
}
return params
}
type NamespaceOptions struct {
Namespace string `help:"Namespace of this resource"`
}
func (o NamespaceOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.Namespace != "" {
params.Add(jsonutils.NewString(o.Namespace), "namespace")
}
return params
}
type NamespaceResourceGetOptions struct {
ResourceGetOptions
NamespaceOptions
}
func (o NamespaceResourceGetOptions) Params() *jsonutils.JSONDict {
params := o.ResourceGetOptions.Params()
params.Update(o.NamespaceOptions.Params())
return params
}
type NamespaceWithClusterOptions struct {
NamespaceOptions
ClusterBaseOptions
}
func (o NamespaceWithClusterOptions) Params() *jsonutils.JSONDict {
params := o.ClusterBaseOptions.Params()
params.Update(o.NamespaceOptions.Params())
return params
}
+49
View File
@@ -0,0 +1,49 @@
package k8s
import (
"yunion.io/x/jsonutils"
)
type ChartListOptions struct {
BaseListOptions
Name string `help:"Chart name"`
Repo string `help:"Repository name"`
RepoUrl string `help:"Repository url"`
AllVersion bool `json:"Get Chart all history versions"`
Keyword string `json:"Chart keyword"`
}
func (o ChartListOptions) Params() *jsonutils.JSONDict {
params := o.BaseListOptions.Params()
if len(o.Name) != 0 {
params.Add(jsonutils.NewString(o.Name), "name")
}
if len(o.Repo) != 0 {
params.Add(jsonutils.NewString(o.Repo), "repo")
}
if len(o.RepoUrl) != 0 {
params.Add(jsonutils.NewString(o.RepoUrl), "repo_url")
}
if o.AllVersion {
params.Add(jsonutils.JSONTrue, "all_version")
}
if len(o.Keyword) != 0 {
params.Add(jsonutils.NewString(o.Keyword), "keyword")
}
return params
}
type ChartGetOptions struct {
REPO string `help:"Repo of the chart"`
NAME string `help:"Chart name"`
Version string `help:"Chart version"`
}
func (o ChartGetOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(o.REPO), "repo")
if o.Version != "" {
params.Add(jsonutils.NewString(o.Version), "version")
}
return params
}
+177
View File
@@ -0,0 +1,177 @@
package k8s
import (
"fmt"
"io/ioutil"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/util/sets"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type ClusterListOptions struct {
options.BaseListOptions
}
func (o ClusterListOptions) Params() *jsonutils.JSONDict {
o.Details = options.Bool(true)
params, err := o.BaseListOptions.Params()
if err != nil {
panic(err)
}
return params
}
type ClusterCreateOptions struct {
NAME string `help:"Name of cluster"`
Mode string `help:"Cluster mode" choices:"internal"`
K8sVersion string `help:"Cluster kubernetes components version" choices:"v1.8.10|v1.9.5|v1.10.0"`
InfraImage string `help:"Cluster kubelet infra container image"`
Cidr string `help:"Cluster service CIDR, e.g. 10.43.0.0/16"`
Domain string `help:"Cluster pod domain, e.g. cluster.local"`
}
func (o ClusterCreateOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(o.NAME), "name")
if o.Mode != "" {
params.Add(jsonutils.NewString(o.Mode), "mode")
}
if o.K8sVersion != "" {
params.Add(jsonutils.NewString(o.K8sVersion), "k8s_version")
}
if o.InfraImage != "" {
params.Add(jsonutils.NewString(o.InfraImage), "infra_container_image")
}
if o.Cidr != "" {
params.Add(jsonutils.NewString(o.Cidr), "cluster_cidr")
}
if o.Domain != "" {
params.Add(jsonutils.NewString(o.Domain), "cluster_domain")
}
return params
}
type ClusterImportOptions struct {
NAME string `help:"Name of cluster to import"`
KUBECONFIG string `help:"Kubernetes auth config"`
}
func (o ClusterImportOptions) Params() (*jsonutils.JSONDict, error) {
kubeconfig, err := ioutil.ReadFile(o.KUBECONFIG)
if err != nil {
return nil, fmt.Errorf("Read kube config %q error: %v", o.KUBECONFIG, err)
}
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(string(kubeconfig)), "kube_config")
return params, nil
}
type ClusterUpdateOptions struct {
NAME string `help:"Name of cluster"`
K8sVersion string `help:"Cluster kubernetes components version" choices:"v1.8.10|v1.9.5|v1.10.0"`
}
func (o ClusterUpdateOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.K8sVersion != "" {
params.Add(jsonutils.NewString(o.K8sVersion), "k8s_version")
}
return params
}
type IdentOptions struct {
ID string `help:"ID or name of the model"`
}
type IdentsOptions struct {
ID []string `help:"ID of models to operate"`
}
type ClusterDeployOptions struct {
IdentOptions
Force bool `help:"Force deploy"`
}
func (o ClusterDeployOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.Force {
params.Add(jsonutils.JSONTrue, "force")
}
return params
}
type ClusterDeleteOptions struct {
IdentsOptions
}
type ClusterKubeconfigOptions struct {
IdentOptions
Directly bool `help:"Get directly connect kubeconfig"`
}
func (o ClusterKubeconfigOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.Directly {
params.Add(jsonutils.JSONTrue, "directly")
}
return params
}
type ClusterAddNodesOptions struct {
IdentOptions
NodeConfig []string `help:"Node spec, 'host:[roles]' e.g: --node-config host01:controlplane,etcd,worker --node-config host02:worker"`
AutoDeploy bool `help:"Auto deploy"`
}
func (o ClusterAddNodesOptions) Params() (*jsonutils.JSONDict, error) {
params := jsonutils.NewDict()
if o.AutoDeploy {
params.Add(jsonutils.JSONTrue, "auto_deploy")
}
nodesArray := jsonutils.NewArray()
for _, config := range o.NodeConfig {
opt, err := parseNodeAddConfigStr(config)
if err != nil {
return nil, err
}
nodesArray.Add(jsonutils.Marshal(opt))
}
params.Add(nodesArray, "nodes")
return params, nil
}
type dockerConfig struct {
RegistryMirrors []string `json:"registry-mirrors"`
InsecureRegistries []string `json:"insecure-registries"`
}
type nodeAddConfig struct {
Host string `json:"host"`
Roles []string `json:"roles"`
Name string `json:"name"`
HostnameOverride string `json:"hostname_override"`
DockerdConfig dockerConfig `json:"dockerd_config"`
}
func parseNodeAddConfigStr(config string) (nodeAddConfig, error) {
ret := nodeAddConfig{}
parts := strings.Split(config, ":")
if len(parts) != 2 {
return ret, fmt.Errorf("Invalid config: %q", config)
}
host := parts[0]
roleStr := parts[1]
ret.Host = host
roles := []string{}
for _, role := range strings.Split(roleStr, ",") {
if !sets.NewString("etcd", "controlplane", "worker").Has(role) {
return ret, fmt.Errorf("Invalid role: %q", role)
}
roles = append(roles, role)
}
ret.Roles = roles
return ret, nil
}
+147
View File
@@ -0,0 +1,147 @@
package k8s
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/util/regutils"
"yunion.io/x/pkg/util/sets"
)
type DeploymentCreateOptions struct {
NamespaceWithClusterOptions
NAME string `help:"Name of deployment"`
Image string `help:"The image for the container to run"`
Replicas int64 `help:"Number of replicas for pods in this deployment"`
RunAsPrivileged bool `help:"Whether to run the container as privileged user"`
Labels string `help:"Comma separated labels to apply to the pod(s)"`
Env []string `help:"Environment variables to set in container"`
Port []string `help:"Port for the service that is created, format is <protocol>:<service_port>:<container_port> e.g. tcp:80:3000"`
Net string `help:"Network config, e.g. net1, net1:10.168.222.171"`
}
func (o DeploymentCreateOptions) Params() (*jsonutils.JSONDict, error) {
params := o.NamespaceWithClusterOptions.Params()
params.Add(jsonutils.NewString(o.NAME), "name")
if len(o.Image) == 0 {
return nil, fmt.Errorf("Image must provided")
}
params.Add(jsonutils.NewString(o.Image), "containerImage")
if o.Replicas > 1 {
params.Add(jsonutils.NewInt(o.Replicas), "replicas")
}
if o.RunAsPrivileged {
params.Add(jsonutils.JSONTrue, "runAsPrivileged")
}
if len(o.Port) != 0 {
portMappings, err := parsePortMappings(o.Port)
if err != nil {
return nil, err
}
params.Add(portMappings, "portMappings")
}
envList := jsonutils.NewArray()
for _, env := range o.Env {
parts := strings.Split(env, "=")
if len(parts) != 2 {
return nil, fmt.Errorf("Bad env value: %v", env)
}
envObj := jsonutils.NewDict()
envObj.Add(jsonutils.NewString(parts[0]), "name")
envObj.Add(jsonutils.NewString(parts[1]), "value")
envList.Add(envObj)
}
params.Add(envList, "variables")
if o.Net != "" {
net, err := parseNetConfig(o.Net)
if err != nil {
return nil, err
}
params.Add(net, "networkConfig")
}
return params, nil
}
type portMapping struct {
Port int32 `json:"port"`
TargetPort int32 `json:"targetPort"`
Protocol string `json:"protocol"`
}
func parsePortMapping(port string) (*portMapping, error) {
if len(port) == 0 {
return nil, fmt.Errorf("empty port mapping desc string")
}
parts := strings.Split(port, ":")
mapping := &portMapping{}
for _, part := range parts {
if sets.NewString("tcp", "udp").Has(strings.ToLower(part)) {
mapping.Protocol = strings.ToUpper(part)
}
if port, err := strconv.Atoi(part); err != nil {
continue
} else {
if mapping.Port == 0 {
mapping.Port = int32(port)
} else {
mapping.TargetPort = int32(port)
}
}
}
if mapping.Protocol == "" {
mapping.Protocol = "TCP"
}
if mapping.Port <= 0 {
return nil, fmt.Errorf("Service port not provided")
}
if mapping.TargetPort < 0 {
return nil, fmt.Errorf("Container invalid targetPort %d", mapping.TargetPort)
}
if mapping.TargetPort == 0 {
mapping.TargetPort = mapping.Port
}
return mapping, nil
}
func parsePortMappings(ports []string) (*jsonutils.JSONArray, error) {
ret := jsonutils.NewArray()
for _, port := range ports {
mapping, err := parsePortMapping(port)
if err != nil {
return nil, fmt.Errorf("Port %q error: %v", port, err)
}
ret.Add(jsonutils.Marshal(mapping))
}
return ret, nil
}
func parseNetConfig(net string) (*jsonutils.JSONDict, error) {
ret := jsonutils.NewDict()
for _, p := range strings.Split(net, ":") {
if regutils.MatchIP4Addr(p) {
ret.Add(jsonutils.NewString(p), "address")
} else {
ret.Add(jsonutils.NewString(p), "network")
}
}
return ret, nil
}
type DeploymentCreateFromFileOptions struct {
NamespaceResourceGetOptions
FILE string `help:"K8s resource YAML or JSON file"`
}
func (o DeploymentCreateFromFileOptions) Params() (*jsonutils.JSONDict, error) {
params := o.NamespaceResourceGetOptions.Params()
params.Add(jsonutils.NewString(o.NAME), "name")
content, err := ioutil.ReadFile(o.FILE)
if err != nil {
return nil, err
}
params.Add(jsonutils.NewString(string(content)), "content")
return params, nil
}
+69
View File
@@ -0,0 +1,69 @@
package k8s
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type NodeListOptions struct {
options.BaseListOptions
Cluster string `help:"Filter by cluster"`
}
func (o NodeListOptions) Params() (*jsonutils.JSONDict, error) {
return options.ListStructToParams(&o)
}
type NodeCreateOptions struct {
CLUSTER string `help:"Cluster id"`
Etcd bool `help:"Etcd role"`
Controlplane bool `help:"Controlplane role"`
Worker bool `help:"Worker role"`
AllRole bool `help:"All roles"`
HostnameOverride string `help:"Worker node overrided hostname"`
Host string `help:"Yunion host server name or id"`
Name string `help:"Name of node"`
RegistryMirror []string `help:"Docker registry mirrors, e.g. 'https://registry.docker-cn.com'"`
InsecureRegistry []string `help:"Docker insecure registry"`
}
func (o NodeCreateOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.Name != "" {
params.Add(jsonutils.NewString(o.Name), "name")
}
params.Add(jsonutils.NewString(o.CLUSTER), "cluster")
dockerConf := dockerConfig{}
for _, rm := range o.RegistryMirror {
dockerConf.RegistryMirrors = append(dockerConf.RegistryMirrors, rm)
}
for _, im := range o.InsecureRegistry {
dockerConf.InsecureRegistries = append(dockerConf.InsecureRegistries, im)
}
confObj := jsonutils.Marshal(dockerConf)
params.Add(confObj, "dockerd_config")
roles := jsonutils.NewArray()
if o.AllRole {
roles.Add(jsonutils.NewString("etcd"), jsonutils.NewString("controlplane"), jsonutils.NewString("worker"))
} else {
if o.Etcd {
roles.Add(jsonutils.NewString("etcd"))
}
if o.Controlplane {
roles.Add(jsonutils.NewString("controlplane"))
}
if o.Worker {
roles.Add(jsonutils.NewString("worker"))
}
}
params.Add(roles, "roles")
if o.HostnameOverride != "" {
params.Add(jsonutils.NewString(o.HostnameOverride), "hostname_override")
}
if o.Host != "" {
params.Add(jsonutils.NewString(o.Host), "host")
}
return params
}
+136
View File
@@ -0,0 +1,136 @@
package k8s
import (
"io/ioutil"
"yunion.io/x/jsonutils"
)
type ReleaseListOptions struct {
NamespaceResourceListOptions
Name string `help:"Search by name"`
Filter string `help:"Filter, split by space"`
Admin bool `help:"Admin to show all namespace releases"`
Deployed bool `help:"Show deployed status releases"`
Deleted bool `help:"Show deleted status releases"`
Deleting bool `help:"Show deleting status releases"`
Failed bool `help:"Show failed status releases"`
Superseded bool `help:"Show superseded status releases"`
Pending bool `help:"Show pending status releases"`
}
func (o ReleaseListOptions) Params() *jsonutils.JSONDict {
params := o.NamespaceResourceListOptions.Params()
if o.Filter != "" {
params.Add(jsonutils.NewString(o.Filter), "filter")
}
if o.Namespace != "" {
params.Add(jsonutils.NewString(o.Namespace), "namespace")
}
if o.Name != "" {
params.Add(jsonutils.NewString(o.Name), "name")
}
params.Add(jsonutils.JSONTrue, "all")
if o.Admin {
params.Add(jsonutils.JSONTrue, "admin")
}
if o.Deployed {
params.Add(jsonutils.JSONTrue, "deployed")
}
if o.Deleted {
params.Add(jsonutils.JSONTrue, "deleted")
}
if o.Deleting {
params.Add(jsonutils.JSONTrue, "deleting")
}
if o.Failed {
params.Add(jsonutils.JSONTrue, "failed")
}
if o.Superseded {
params.Add(jsonutils.JSONTrue, "superseded")
}
if o.Pending {
params.Add(jsonutils.JSONTrue, "pending")
}
return params
}
type ReleaseCreateUpdateOptions struct {
Values string `help:"Specify values in a YAML file (can specify multiple)" short-token:"f"`
Version string `help:"Specify the exact chart version to install. If not specified, latest version installed"`
//Set []string `help:"set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)"`
DryRun bool `help:"Simulate an install"`
Details bool `help:"Show release deploy details, include kubernetes created resources"`
Timeout int64 `help:"Time in seconds to wait for any individual kubernetes operation (like Jobs for hooks)" default:"600"`
}
func (o ReleaseCreateUpdateOptions) Params() (*jsonutils.JSONDict, error) {
params := jsonutils.NewDict()
if o.Version != "" {
params.Add(jsonutils.NewString(o.Version), "version")
}
if o.DryRun {
params.Add(jsonutils.JSONTrue, "dry_run")
}
params.Add(jsonutils.NewInt(o.Timeout), "timeout")
if o.Values != "" {
//vals, err := helm.MergeValuesF(args.Values, args.Set, []string{})
vals, err := ioutil.ReadFile(o.Values)
if err != nil {
return nil, err
}
params.Add(jsonutils.NewString(string(vals)), "values")
}
return params, nil
}
type ReleaseCreateOptions struct {
NamespaceWithClusterOptions
ReleaseCreateUpdateOptions
Name string `help:"Release name, If unspecified, it will autogenerate one for you"`
CHARTNAME string `help:"Helm chart name, e.g stable/etcd"`
}
func (o ReleaseCreateOptions) Params() (*jsonutils.JSONDict, error) {
params, err := o.ReleaseCreateUpdateOptions.Params()
if err != nil {
return nil, err
}
params.Update(o.NamespaceWithClusterOptions.Params())
params.Add(jsonutils.NewString(o.CHARTNAME), "chart_name")
if o.Name != "" {
params.Add(jsonutils.NewString(o.Name), "release_name")
}
return params, nil
}
type ReleaseUpgradeOptions struct {
ClusterBaseOptions
ReleaseCreateUpdateOptions
NAME string `help:"Release instance name"`
CHARTNAME string `help:"Helm chart name, e.g stable/etcd"`
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"`
ResetValues bool `help:"When upgrading, reset the values to the ones built into the chart"`
}
func (o ReleaseUpgradeOptions) Params() (*jsonutils.JSONDict, error) {
params, err := o.ReleaseCreateUpdateOptions.Params()
if err != nil {
return nil, err
}
params.Update(o.ClusterBaseOptions.Params())
params.Add(jsonutils.NewString(o.CHARTNAME), "chart_name")
params.Add(jsonutils.NewString(o.NAME), "release_name")
if o.ReuseValues {
params.Add(jsonutils.JSONTrue, "reuse_values")
}
if o.ResetValues {
params.Add(jsonutils.JSONTrue, "reset_values")
}
return params, nil
}
type ReleaseDeleteOptions struct {
ClusterBaseOptions
NAME string `help:"Release instance name"`
}
+44
View File
@@ -0,0 +1,44 @@
package k8s
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type RepoListOptions struct {
options.BaseListOptions
}
type RepoGetOptions struct {
NAME string `help:"ID or name of the repo"`
}
type RepoCreateOptions struct {
RepoGetOptions
URL string `help:"Repository url"`
}
func (o RepoCreateOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(o.NAME), "name")
params.Add(jsonutils.NewString(o.URL), "url")
return params
}
type RepoUpdateOptions struct {
RepoGetOptions
Name string `help:"Repository name to change"`
Url string `help:"Repository url to change"`
}
func (o RepoUpdateOptions) Params() *jsonutils.JSONDict {
params := jsonutils.NewDict()
if o.Name != "" {
params.Add(jsonutils.NewString(o.Name), "name")
}
if o.Url != "" {
params.Add(jsonutils.NewString(o.Url), "url")
}
return params
}
+44
View File
@@ -0,0 +1,44 @@
package k8s
import (
"yunion.io/x/jsonutils"
)
type TillerCreateOptions struct {
ClusterBaseOptions
KubeContext string `json:"kube_context"`
Namespace string `json:"namespace" default:"kube-system"`
// Upgrade if Tiller is already installed
Upgrade bool `json:"upgrade"`
// Name of service account
ServiceAccount string `json:"service_account" default:"tiller"`
// Use the canary Tiller image
Canary bool `json:"canary_image"`
// Override Tiller image
Image string `json:"tiller_image" default:"yunion/tiller:v2.9.0"`
// Limit the maximum number of revisions saved per release. Use 0 for no limit.
MaxHistory int `json:"history_max"`
}
func (o TillerCreateOptions) Params() *jsonutils.JSONDict {
params := o.ClusterBaseOptions.Params()
if len(o.KubeContext) > 0 {
params.Add(jsonutils.NewString(o.KubeContext), "kube_context")
}
params.Add(jsonutils.NewString(o.Namespace), "namespace")
params.Add(jsonutils.NewString(o.ServiceAccount), "service_account")
if o.Canary {
params.Add(jsonutils.JSONTrue, "canary_image")
}
if o.Upgrade {
params.Add(jsonutils.JSONTrue, "upgrade")
}
if len(o.Image) > 0 {
params.Add(jsonutils.NewString(o.Image), "tiller_image")
}
if o.MaxHistory > 0 {
params.Add(jsonutils.NewInt(int64(o.MaxHistory)), "history_max")
}
return params
}