/* Copyright 2014 Google Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "flag" "fmt" "io/ioutil" "net/http" "os" "reflect" "sort" "strconv" "strings" "text/template" "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version" "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/golang/glog" ) var ( serverVersion = verflag.Version("server_version", verflag.VersionFalse, "Print the server's version information and quit") preventSkew = flag.Bool("expect_version_match", false, "Fail if server's version doesn't match own version.") config = flag.String("c", "", "Path or URL to the config file, or '-' to read from STDIN") selector = flag.String("l", "", "Selector (label query) to use for listing") updatePeriod = flag.Duration("u", 60*time.Second, "Update interval period") portSpec = flag.String("p", "", "The port spec, comma-separated list of :,...") servicePort = flag.Int("s", -1, "If positive, create and run a corresponding service on this port, only used with 'run'") authConfig = flag.String("auth", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file. If missing, prompt the user. Only used if doing https.") json = flag.Bool("json", false, "If true, print raw JSON for responses") yaml = flag.Bool("yaml", false, "If true, print raw YAML for responses") verbose = flag.Bool("verbose", false, "If true, print extra information") proxy = flag.Bool("proxy", false, "If true, run a proxy to the api server") www = flag.String("www", "", "If -proxy is true, use this directory to serve static files") templateFile = flag.String("template_file", "", "If present, load this file as a golang template and use it for output printing") templateStr = flag.String("template", "", "If present, parse this string as a golang template and use it for output printing") imageName = flag.String("image", "", "Image used when updating a replicationController. Will apply to the first container in the pod template.") clientConfig = &client.Config{} ) func init() { flag.StringVar(&clientConfig.Host, "h", "", "The host to connect to.") flag.StringVar(&clientConfig.Version, "api_version", latest.Version, "The version of the API to use against this server.") flag.StringVar(&clientConfig.CAFile, "certificate_authority", "", "Path to a cert. file for the certificate authority") flag.StringVar(&clientConfig.CertFile, "client_certificate", "", "Path to a client certificate for TLS.") flag.StringVar(&clientConfig.KeyFile, "client_key", "", "Path to a client key file for TLS.") flag.BoolVar(&clientConfig.Insecure, "insecure_skip_tls_verify", clientConfig.Insecure, "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.") } var parser = kubecfg.NewParser(map[string]runtime.Object{ "pods": &api.Pod{}, "services": &api.Service{}, "replicationControllers": &api.ReplicationController{}, "minions": &api.Minion{}, }) func usage() { fmt.Fprintf(os.Stderr, `Usage: kubecfg -h [-c config/file.json|url|-] Kubernetes REST API: kubecfg [OPTIONS] get|list|create|delete|update <%s>[/] Manage replication controllers: kubecfg [OPTIONS] stop|rm kubecfg [OPTIONS] [-u