From bc86b31a8baf5ec0fb87997c8915561d2ada6026 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sat, 3 Jan 2015 15:38:33 -0500 Subject: [PATCH] Remove createall now that create supports directories and sources --- contrib/flags2yaml/README.md | 2 +- contrib/simplegen/README.md | 4 +- contrib/simplegen/simplegen.go | 4 +- contrib/srvexpand/srvexpand.go | 4 +- pkg/kubectl/cmd/cmd.go | 1 - pkg/kubectl/cmd/cmd_test.go | 6 +- pkg/kubectl/cmd/create_test.go | 2 +- pkg/kubectl/cmd/createall.go | 121 --------------------------------- pkg/kubectl/cmd/get_test.go | 4 +- 9 files changed, 15 insertions(+), 133 deletions(-) delete mode 100644 pkg/kubectl/cmd/createall.go diff --git a/contrib/flags2yaml/README.md b/contrib/flags2yaml/README.md index 6eff0432d4e..147832a825e 100644 --- a/contrib/flags2yaml/README.md +++ b/contrib/flags2yaml/README.md @@ -4,5 +4,5 @@ ### Usage ``` -$ flags2yaml image=dockerfile/nginx | simplegen - | cluster/kubectl.sh createall -f - +$ flags2yaml image=dockerfile/nginx | simplegen - | cluster/kubectl.sh create -f - ``` diff --git a/contrib/simplegen/README.md b/contrib/simplegen/README.md index a06a5957b4f..ec64e1fad75 100644 --- a/contrib/simplegen/README.md +++ b/contrib/simplegen/README.md @@ -41,8 +41,8 @@ portSpec: 10001:6379 ``` Output: ``` -$ simplegen redismaster.yaml | cluster/kubectl.sh createall -f - -$ simplegen redisslave.yaml | cluster/kubectl.sh createall -f - +$ simplegen redismaster.yaml | cluster/kubectl.sh create -f - +$ simplegen redisslave.yaml | cluster/kubectl.sh create -f - $ cluster/kubectl.sh get services NAME LABELS SELECTOR IP PORT kubernetes-ro component=apiserver,provider=kubernetes 10.0.0.2 80 diff --git a/contrib/simplegen/simplegen.go b/contrib/simplegen/simplegen.go index d9d6d32c506..5faae984326 100644 --- a/contrib/simplegen/simplegen.go +++ b/contrib/simplegen/simplegen.go @@ -16,8 +16,8 @@ limitations under the License. // simplegen is a tool to generate simple services from a simple description // -// $ simplegen myservice.json | kubectl createall -f - -// $ simplegen myservice.yaml | kubectl createall -f - +// $ simplegen myservice.json | kubectl create -f - +// $ simplegen myservice.yaml | kubectl create -f - // // This is completely separate from kubectl at the moment, until we figure out // what the right integration approach is. diff --git a/contrib/srvexpand/srvexpand.go b/contrib/srvexpand/srvexpand.go index 073589ac7fc..512dbd815c3 100644 --- a/contrib/srvexpand/srvexpand.go +++ b/contrib/srvexpand/srvexpand.go @@ -17,8 +17,8 @@ limitations under the License. // srvexpand is a tool to generate non-trivial but regular services // from a description free of most boilerplate // -// $ srvexpand myservice.json | kubectl createall -f - -// $ srvexpand myservice.yaml | kubectl createall -f - +// $ srvexpand myservice.json | kubectl create -f - +// $ srvexpand myservice.yaml | kubectl create -f - // // This is completely separate from kubectl at the moment, until we figure out // what the right integration approach is. diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 9d8efe5a7b1..9ff3e8c0c56 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -165,7 +165,6 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`, cmds.AddCommand(f.NewCmdGet(out)) cmds.AddCommand(f.NewCmdDescribe(out)) cmds.AddCommand(f.NewCmdCreate(out)) - cmds.AddCommand(f.NewCmdCreateAll(out)) cmds.AddCommand(f.NewCmdUpdate(out)) cmds.AddCommand(f.NewCmdDelete(out)) diff --git a/pkg/kubectl/cmd/cmd_test.go b/pkg/kubectl/cmd/cmd_test.go index a28e099291d..5331ad06846 100644 --- a/pkg/kubectl/cmd/cmd_test.go +++ b/pkg/kubectl/cmd/cmd_test.go @@ -92,6 +92,8 @@ func (t *testDescriber) Describe(namespace, name string) (output string, err err } type testFactory struct { + Mapper meta.RESTMapper + Typer runtime.ObjectTyper Client kubectl.RESTClient Describer kubectl.Describer Printer kubectl.ResourcePrinter @@ -103,10 +105,12 @@ func NewTestFactory() (*Factory, *testFactory, runtime.Codec) { scheme, mapper, codec := newExternalScheme() t := &testFactory{ Validator: validation.NullSchema{}, + Mapper: mapper, + Typer: scheme, } return &Factory{ Object: func(*cobra.Command) (meta.RESTMapper, runtime.ObjectTyper) { - return mapper, scheme + return t.Mapper, t.Typer }, RESTClient: func(*cobra.Command, *meta.RESTMapping) (resource.RESTClient, error) { return t.Client, t.Err diff --git a/pkg/kubectl/cmd/create_test.go b/pkg/kubectl/cmd/create_test.go index 7658190ea6c..a8b6fa0289d 100644 --- a/pkg/kubectl/cmd/create_test.go +++ b/pkg/kubectl/cmd/create_test.go @@ -99,7 +99,7 @@ func TestCreateDirectory(t *testing.T) { return &http.Response{StatusCode: 201, Body: objBody(codec, &pods.Items[0])}, nil case p == "/ns/test/services" && m == "POST": return &http.Response{StatusCode: 201, Body: objBody(codec, &svc.Items[0])}, nil - case p == "/ns/test/replicationControllers" && m == "POST": + case p == "/ns/test/replicationcontrollers" && m == "POST": return &http.Response{StatusCode: 201, Body: objBody(codec, &svc.Items[0])}, nil default: t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) diff --git a/pkg/kubectl/cmd/createall.go b/pkg/kubectl/cmd/createall.go deleted file mode 100644 index 48b33dd3db3..00000000000 --- a/pkg/kubectl/cmd/createall.go +++ /dev/null @@ -1,121 +0,0 @@ -/* -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 cmd - -import ( - "fmt" - "io" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta" - "github.com/GoogleCloudPlatform/kubernetes/pkg/config" - "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" - "github.com/ghodss/yaml" - "github.com/golang/glog" - "github.com/spf13/cobra" -) - -// DataToObjects converts the raw JSON data into API objects -func DataToObjects(m meta.RESTMapper, t runtime.ObjectTyper, data []byte) (result []runtime.Object, errors []error) { - configObj := []runtime.RawExtension{} - - if err := yaml.Unmarshal(data, &configObj); err != nil { - errors = append(errors, fmt.Errorf("config unmarshal: %v", err)) - return result, errors - } - - for i, in := range configObj { - version, kind, err := t.DataVersionAndKind(in.RawJSON) - if err != nil { - errors = append(errors, fmt.Errorf("item[%d] kind: %v", i, err)) - continue - } - - mapping, err := m.RESTMapping(kind, version) - if err != nil { - errors = append(errors, fmt.Errorf("item[%d] mapping: %v", i, err)) - continue - } - - obj, err := mapping.Codec.Decode(in.RawJSON) - if err != nil { - errors = append(errors, fmt.Errorf("item[%d] decode: %v", i, err)) - continue - } - result = append(result, obj) - } - return -} - -func (f *Factory) NewCmdCreateAll(out io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "createall [-d directory] [-f filename]", - Short: "Create all resources specified in a directory, filename or stdin", - Long: `Create all resources contained in JSON file specified in a directory, filename or stdin - -JSON and YAML formats are accepted. - -Examples: - $ kubectl createall -d configs/ - - - $ kubectl createall -f config.json - - - $ cat config.json | kubectl apply -f - - `, - Run: func(cmd *cobra.Command, args []string) { - clientFunc := func(mapping *meta.RESTMapping) (config.RESTClientPoster, error) { - client, err := f.RESTClient(cmd, mapping) - checkErr(err) - return client, nil - } - - filename := GetFlagString(cmd, "filename") - directory := GetFlagString(cmd, "directory") - if (len(filename) == 0 && len(directory) == 0) || (len(filename) != 0 && len(directory) != 0) { - usageError(cmd, "Must pass a directory or filename to update") - } - - files := []string{} - if len(filename) != 0 { - files = append(files, filename) - - } else { - files = append(GetFilesFromDir(directory, ".json"), GetFilesFromDir(directory, ".yaml")...) - } - - mapper, typer := f.Object(cmd) - for _, filename := range files { - data, err := ReadConfigData(filename) - checkErr(err) - - items, errs := DataToObjects(mapper, typer, data) - applyErrs := config.CreateObjects(typer, mapper, clientFunc, items) - - errs = append(errs, applyErrs...) - if len(errs) > 0 { - for _, e := range errs { - glog.Error(e) - } - } - } - }, - } - cmd.Flags().StringP("directory", "d", "", "Directory of JSON or YAML files to use to update the resource") - cmd.Flags().StringP("filename", "f", "", "Filename or URL to file to use to update the resource") - return cmd -} diff --git a/pkg/kubectl/cmd/get_test.go b/pkg/kubectl/cmd/get_test.go index d0ea2f0920c..9ea81450883 100644 --- a/pkg/kubectl/cmd/get_test.go +++ b/pkg/kubectl/cmd/get_test.go @@ -90,8 +90,8 @@ func TestGetUnknownSchemaObject(t *testing.T) { // Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get. func TestGetSchemaObject(t *testing.T) { f, tf, _ := NewTestFactory() - f.Mapper = latest.RESTMapper - f.Typer = api.Scheme + tf.Mapper = latest.RESTMapper + tf.Typer = api.Scheme codec := latest.Codec tf.Printer = &testPrinter{} tf.Client = &client.FakeRESTClient{