Refactor kubectl/cmd helpers into pkg/kubectl/cmd/util

Allows helpers to be used by config commands.
This commit is contained in:
Jeff Lowdermilk
2015-02-04 16:14:48 -08:00
parent afeaf8fc6f
commit d46ae5d841
20 changed files with 179 additions and 185 deletions

View File

@@ -21,6 +21,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
@@ -203,3 +204,43 @@ func TestClientVersions(t *testing.T) {
}
}
}
func ExamplePrintReplicationController() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false)
tf.Client = &client.FakeRESTClient{
Codec: codec,
Client: nil,
}
cmd := f.NewCmdRunContainer(os.Stdout)
ctrl := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Labels: map[string]string{"foo": "bar"},
},
Spec: api.ReplicationControllerSpec{
Replicas: 1,
Selector: map[string]string{"foo": "bar"},
Template: &api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"foo": "bar"},
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "foo",
Image: "someimage",
},
},
},
},
},
}
err := f.PrintObject(cmd, ctrl, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
}
// Output:
// CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
// foo foo someimage foo=bar 1
}