Commit c298a1bc authored by Alex Robinson's avatar Alex Robinson

Merge pull request #23408 from janetkuo/update-guestbook

Update guestbook examples; replace RC concepts with Deployment
parents 2ac788b4 c1596e67
...@@ -36,14 +36,14 @@ var exampleMungeTagRE = regexp.MustCompile(beginMungeTag(fmt.Sprintf("%s %s", ex ...@@ -36,14 +36,14 @@ var exampleMungeTagRE = regexp.MustCompile(beginMungeTag(fmt.Sprintf("%s %s", ex
// the content of the example, thereby syncing it. // the content of the example, thereby syncing it.
// //
// For example, // For example,
// <!-- BEGIN MUNGE: EXAMPLE ../../examples/guestbook/frontend-controller.yaml --> // <!-- BEGIN MUNGE: EXAMPLE ../../examples/guestbook/frontend-service.yaml -->
// //
// ```yaml // ```yaml
// foo: // foo:
// bar: // bar:
// ``` // ```
// //
// [Download example](../../examples/guestbook/frontend-controller.yaml?raw=true) // [Download example](../../examples/guestbook/frontend-service.yaml?raw=true)
// <!-- END MUNGE: EXAMPLE --> // <!-- END MUNGE: EXAMPLE -->
func syncExamples(filePath string, mlines mungeLines) (mungeLines, error) { func syncExamples(filePath string, mlines mungeLines) (mungeLines, error) {
var err error var err error
......
...@@ -172,13 +172,18 @@ func TestExampleObjectSchemas(t *testing.T) { ...@@ -172,13 +172,18 @@ func TestExampleObjectSchemas(t *testing.T) {
"v1-controller": &api.ReplicationController{}, "v1-controller": &api.ReplicationController{},
}, },
"../examples/guestbook": { "../examples/guestbook": {
"frontend-controller": &api.ReplicationController{}, "frontend-deployment": &extensions.Deployment{},
"redis-slave-controller": &api.ReplicationController{}, "redis-slave-deployment": &extensions.Deployment{},
"redis-master-controller": &api.ReplicationController{}, "redis-master-deployment": &extensions.Deployment{},
"frontend-service": &api.Service{}, "frontend-service": &api.Service{},
"redis-master-service": &api.Service{}, "redis-master-service": &api.Service{},
"redis-slave-service": &api.Service{}, "redis-slave-service": &api.Service{},
}, },
"../examples/guestbook/legacy": {
"frontend-controller": &api.ReplicationController{},
"redis-slave-controller": &api.ReplicationController{},
"redis-master-controller": &api.ReplicationController{},
},
"../examples/guestbook-go": { "../examples/guestbook-go": {
"guestbook-controller": &api.ReplicationController{}, "guestbook-controller": &api.ReplicationController{},
"redis-slave-controller": &api.ReplicationController{}, "redis-slave-controller": &api.ReplicationController{},
......
...@@ -16,15 +16,15 @@ spec: ...@@ -16,15 +16,15 @@ spec:
app: guestbook app: guestbook
tier: frontend tier: frontend
--- ---
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: frontend name: frontend
# these labels can be applied automatically # these labels can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
labels: # labels:
app: guestbook # app: guestbook
tier: frontend # tier: frontend
spec: spec:
# this replicas value is default # this replicas value is default
# modify it according to your case # modify it according to your case
...@@ -32,8 +32,9 @@ spec: ...@@ -32,8 +32,9 @@ spec:
# selector can be applied automatically # selector can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
# selector: # selector:
# app: guestbook # matchLabels:
# tier: frontend # app: guestbook
# tier: frontend
template: template:
metadata: metadata:
labels: labels:
......
...@@ -16,16 +16,16 @@ spec: ...@@ -16,16 +16,16 @@ spec:
tier: backend tier: backend
role: master role: master
--- ---
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: redis-master name: redis-master
# these labels can be applied automatically # these labels can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
labels: # labels:
app: redis # app: redis
role: master # role: master
tier: backend # tier: backend
spec: spec:
# this replicas value is default # this replicas value is default
# modify it according to your case # modify it according to your case
...@@ -33,9 +33,10 @@ spec: ...@@ -33,9 +33,10 @@ spec:
# selector can be applied automatically # selector can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
# selector: # selector:
# app: guestbook # matchLabels:
# role: master # app: guestbook
# tier: backend # role: master
# tier: backend
template: template:
metadata: metadata:
labels: labels:
...@@ -70,16 +71,16 @@ spec: ...@@ -70,16 +71,16 @@ spec:
tier: backend tier: backend
role: slave role: slave
--- ---
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: redis-slave name: redis-slave
# these labels can be applied automatically # these labels can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
labels: # labels:
app: redis # app: redis
role: slave # role: slave
tier: backend # tier: backend
spec: spec:
# this replicas value is default # this replicas value is default
# modify it according to your case # modify it according to your case
...@@ -87,9 +88,10 @@ spec: ...@@ -87,9 +88,10 @@ spec:
# selector can be applied automatically # selector can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
# selector: # selector:
# app: guestbook # matchLabels:
# role: slave # app: guestbook
# tier: backend # role: slave
# tier: backend
template: template:
metadata: metadata:
labels: labels:
...@@ -133,15 +135,15 @@ spec: ...@@ -133,15 +135,15 @@ spec:
app: guestbook app: guestbook
tier: frontend tier: frontend
--- ---
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: frontend name: frontend
# these labels can be applied automatically # these labels can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
labels: # labels:
app: guestbook # app: guestbook
tier: frontend # tier: frontend
spec: spec:
# this replicas value is default # this replicas value is default
# modify it according to your case # modify it according to your case
...@@ -149,8 +151,9 @@ spec: ...@@ -149,8 +151,9 @@ spec:
# selector can be applied automatically # selector can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
# selector: # selector:
# app: guestbook # matchLabels:
# tier: frontend # app: guestbook
# tier: frontend
template: template:
metadata: metadata:
labels: labels:
......
...@@ -15,16 +15,16 @@ spec: ...@@ -15,16 +15,16 @@ spec:
role: slave role: slave
tier: backend tier: backend
--- ---
apiVersion: v1 apiVersion: extensions/v1beta1
kind: ReplicationController kind: Deployment
metadata: metadata:
name: redis-slave name: redis-slave
# these labels can be applied automatically # these labels can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
labels: # labels:
app: redis # app: redis
role: slave # role: slave
tier: backend # tier: backend
spec: spec:
# this replicas value is default # this replicas value is default
# modify it according to your case # modify it according to your case
...@@ -32,9 +32,10 @@ spec: ...@@ -32,9 +32,10 @@ spec:
# selector can be applied automatically # selector can be applied automatically
# from the labels in the pod template if not set # from the labels in the pod template if not set
# selector: # selector:
# app: guestbook # matchLabels:
# role: slave # app: guestbook
# tier: backend # role: slave
# tier: backend
template: template:
metadata: metadata:
labels: labels:
......
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: frontend
# these labels can be applied automatically
# from the labels in the pod template if not set
# labels:
# app: guestbook
# tier: frontend
spec:
# this replicas value is default
# modify it according to your case
replicas: 3
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# matchLabels:
# app: guestbook
# tier: frontend
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
# If your cluster config does not include a dns service, then to
# instead access environment variables to find service host
# info, comment out the 'value: dns' line above, and uncomment the
# line below.
# value: env
ports:
- containerPort: 80
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: redis-master
# these labels can be applied automatically
# from the labels in the pod template if not set
# labels:
# app: redis
# role: master
# tier: backend
spec:
# this replicas value is default
# modify it according to your case
replicas: 1
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# matchLabels:
# app: guestbook
# role: master
# tier: backend
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: gcr.io/google_containers/redis:e2e # or just image: redis
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: redis-slave
# these labels can be applied automatically
# from the labels in the pod template if not set
# labels:
# app: redis
# role: slave
# tier: backend
spec:
# this replicas value is default
# modify it according to your case
replicas: 2
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# matchLabels:
# app: guestbook
# role: slave
# tier: backend
template:
metadata:
labels:
app: redis
role: slave
tier: backend
spec:
containers:
- name: slave
image: gcr.io/google_samples/gb-redisslave:v1
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
# If your cluster config does not include a dns service, then to
# instead access an environment variable to find the master
# service's host, comment out the 'value: dns' line above, and
# uncomment the line below.
# value: env
ports:
- containerPort: 6379
...@@ -1106,8 +1106,8 @@ __EOF__ ...@@ -1106,8 +1106,8 @@ __EOF__
kubectl delete rc frontend "${kube_flags[@]}" kubectl delete rc frontend "${kube_flags[@]}"
### Scale multiple replication controllers ### Scale multiple replication controllers
kubectl create -f examples/guestbook/redis-master-controller.yaml "${kube_flags[@]}" kubectl create -f examples/guestbook/legacy/redis-master-controller.yaml "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-slave-controller.yaml "${kube_flags[@]}" kubectl create -f examples/guestbook/legacy/redis-slave-controller.yaml "${kube_flags[@]}"
# Command # Command
kubectl scale rc/redis-master rc/redis-slave --replicas=4 "${kube_flags[@]}" kubectl scale rc/redis-master rc/redis-slave --replicas=4 "${kube_flags[@]}"
# Post-condition: 4 replicas each # Post-condition: 4 replicas each
...@@ -1217,7 +1217,7 @@ __EOF__ ...@@ -1217,7 +1217,7 @@ __EOF__
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" '' kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" ''
# Command # Command
kubectl create -f hack/testdata/frontend-controller.yaml "${kube_flags[@]}" kubectl create -f hack/testdata/frontend-controller.yaml "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-slave-controller.yaml "${kube_flags[@]}" kubectl create -f examples/guestbook/legacy/redis-slave-controller.yaml "${kube_flags[@]}"
# Post-condition: frontend and redis-slave # Post-condition: frontend and redis-slave
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:redis-slave:' kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:redis-slave:'
......
...@@ -60,7 +60,7 @@ func TestCreateObject(t *testing.T) { ...@@ -60,7 +60,7 @@ func TestCreateObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdCreate(f, buf) cmd := NewCmdCreate(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
...@@ -94,7 +94,7 @@ func TestCreateMultipleObject(t *testing.T) { ...@@ -94,7 +94,7 @@ func TestCreateMultipleObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdCreate(f, buf) cmd := NewCmdCreate(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
...@@ -107,7 +107,7 @@ func TestCreateMultipleObject(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestCreateMultipleObject(t *testing.T) {
func TestCreateDirectory(t *testing.T) { func TestCreateDirectory(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, rc := testData() _, _, rc := testData()
rc.Items[0].Name = "name" rc.Items[0].Name = "name"
f, tf, codec := NewAPIFactory() f, tf, codec := NewAPIFactory()
...@@ -116,8 +116,6 @@ func TestCreateDirectory(t *testing.T) { ...@@ -116,8 +116,6 @@ func TestCreateDirectory(t *testing.T) {
Codec: codec, Codec: codec,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/services" && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &svc.Items[0])}, nil
case p == "/namespaces/test/replicationcontrollers" && m == "POST": case p == "/namespaces/test/replicationcontrollers" && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &rc.Items[0])}, nil return &http.Response{StatusCode: 201, Body: objBody(codec, &rc.Items[0])}, nil
default: default:
...@@ -130,11 +128,11 @@ func TestCreateDirectory(t *testing.T) { ...@@ -130,11 +128,11 @@ func TestCreateDirectory(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdCreate(f, buf) cmd := NewCmdCreate(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/name\nservice/baz\nreplicationcontroller/name\nservice/baz\nreplicationcontroller/name\nservice/baz\n" { if buf.String() != "replicationcontroller/name\nreplicationcontroller/name\nreplicationcontroller/name\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
......
...@@ -114,7 +114,7 @@ func TestDeleteObject(t *testing.T) { ...@@ -114,7 +114,7 @@ func TestDeleteObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdDelete(f, buf) cmd := NewCmdDelete(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
...@@ -145,7 +145,7 @@ func TestDeleteObjectNotFound(t *testing.T) { ...@@ -145,7 +145,7 @@ func TestDeleteObjectNotFound(t *testing.T) {
cmd := NewCmdDelete(f, buf) cmd := NewCmdDelete(f, buf)
options := &DeleteOptions{ options := &DeleteOptions{
Filenames: []string{"../../../examples/guestbook/redis-master-controller.yaml"}, Filenames: []string{"../../../examples/guestbook/legacy/redis-master-controller.yaml"},
} }
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -174,7 +174,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) { ...@@ -174,7 +174,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdDelete(f, buf) cmd := NewCmdDelete(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("ignore-not-found", "true") cmd.Flags().Set("ignore-not-found", "true")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -290,7 +290,7 @@ func TestDeleteMultipleObject(t *testing.T) { ...@@ -290,7 +290,7 @@ func TestDeleteMultipleObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdDelete(f, buf) cmd := NewCmdDelete(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -325,7 +325,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { ...@@ -325,7 +325,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
cmd := NewCmdDelete(f, buf) cmd := NewCmdDelete(f, buf)
options := &DeleteOptions{ options := &DeleteOptions{
Filenames: []string{"../../../examples/guestbook/redis-master-controller.yaml", "../../../examples/guestbook/frontend-service.yaml"}, Filenames: []string{"../../../examples/guestbook/legacy/redis-master-controller.yaml", "../../../examples/guestbook/frontend-service.yaml"},
} }
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -375,7 +375,7 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) { ...@@ -375,7 +375,7 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
} }
func TestDeleteDirectory(t *testing.T) { func TestDeleteDirectory(t *testing.T) {
_, svc, rc := testData() _, _, rc := testData()
f, tf, codec := NewAPIFactory() f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{} tf.Printer = &testPrinter{}
...@@ -383,8 +383,6 @@ func TestDeleteDirectory(t *testing.T) { ...@@ -383,8 +383,6 @@ func TestDeleteDirectory(t *testing.T) {
Codec: codec, Codec: codec,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case strings.HasPrefix(p, "/namespaces/test/services/") && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil
case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers/") && m == "DELETE": case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers/") && m == "DELETE":
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
default: default:
...@@ -397,12 +395,12 @@ func TestDeleteDirectory(t *testing.T) { ...@@ -397,12 +395,12 @@ func TestDeleteDirectory(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdDelete(f, buf) cmd := NewCmdDelete(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/frontend\nservice/frontend\nreplicationcontroller/redis-master\nservice/redis-master\nreplicationcontroller/redis-slave\nservice/redis-slave\n" { if buf.String() != "replicationcontroller/frontend\nreplicationcontroller/redis-master\nreplicationcontroller/redis-slave\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
......
...@@ -70,7 +70,7 @@ func TestDescribeObject(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestDescribeObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdDescribe(f, buf) cmd := NewCmdDescribe(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if d.Name != "redis-master" || d.Namespace != "test" { if d.Name != "redis-master" || d.Namespace != "test" {
......
...@@ -48,7 +48,7 @@ func TestReplaceObject(t *testing.T) { ...@@ -48,7 +48,7 @@ func TestReplaceObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdReplace(f, buf) cmd := NewCmdReplace(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
...@@ -95,7 +95,7 @@ func TestReplaceMultipleObject(t *testing.T) { ...@@ -95,7 +95,7 @@ func TestReplaceMultipleObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdReplace(f, buf) cmd := NewCmdReplace(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
...@@ -116,7 +116,7 @@ func TestReplaceMultipleObject(t *testing.T) { ...@@ -116,7 +116,7 @@ func TestReplaceMultipleObject(t *testing.T) {
} }
func TestReplaceDirectory(t *testing.T) { func TestReplaceDirectory(t *testing.T) {
_, svc, rc := testData() _, _, rc := testData()
f, tf, codec := NewAPIFactory() f, tf, codec := NewAPIFactory()
tf.Printer = &testPrinter{} tf.Printer = &testPrinter{}
...@@ -124,12 +124,8 @@ func TestReplaceDirectory(t *testing.T) { ...@@ -124,12 +124,8 @@ func TestReplaceDirectory(t *testing.T) {
Codec: codec, Codec: codec,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case strings.HasPrefix(p, "/namespaces/test/services/") && (m == "GET" || m == "PUT" || m == "DELETE"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &svc.Items[0])}, nil
case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers/") && (m == "GET" || m == "PUT" || m == "DELETE"): case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers/") && (m == "GET" || m == "PUT" || m == "DELETE"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
case strings.HasPrefix(p, "/namespaces/test/services") && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &svc.Items[0])}, nil
case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers") && m == "POST": case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers") && m == "POST":
return &http.Response{StatusCode: 201, Body: objBody(codec, &rc.Items[0])}, nil return &http.Response{StatusCode: 201, Body: objBody(codec, &rc.Items[0])}, nil
default: default:
...@@ -142,12 +138,12 @@ func TestReplaceDirectory(t *testing.T) { ...@@ -142,12 +138,12 @@ func TestReplaceDirectory(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdReplace(f, buf) cmd := NewCmdReplace(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy")
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/rc1\nservice/baz\nreplicationcontroller/rc1\nservice/baz\nreplicationcontroller/rc1\nservice/baz\n" { if buf.String() != "replicationcontroller/rc1\nreplicationcontroller/rc1\nreplicationcontroller/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
...@@ -156,8 +152,8 @@ func TestReplaceDirectory(t *testing.T) { ...@@ -156,8 +152,8 @@ func TestReplaceDirectory(t *testing.T) {
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
if buf.String() != "replicationcontroller/frontend\nservice/frontend\nreplicationcontroller/redis-master\nservice/redis-master\nreplicationcontroller/redis-slave\nservice/redis-slave\n"+ if buf.String() != "replicationcontroller/frontend\nreplicationcontroller/redis-master\nreplicationcontroller/redis-slave\n"+
"replicationcontroller/rc1\nservice/baz\nreplicationcontroller/rc1\nservice/baz\nreplicationcontroller/rc1\nservice/baz\n" { "replicationcontroller/rc1\nreplicationcontroller/rc1\nreplicationcontroller/rc1\n" {
t.Errorf("unexpected output: %s", buf.String()) t.Errorf("unexpected output: %s", buf.String())
} }
} }
...@@ -185,7 +181,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) { ...@@ -185,7 +181,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdReplace(f, buf) cmd := NewCmdReplace(f, buf)
cmd.Flags().Set("filename", "../../../examples/guestbook/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml")
cmd.Flags().Set("force", "true") cmd.Flags().Set("force", "true")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
......
...@@ -343,7 +343,7 @@ func TestPathBuilderWithMultiple(t *testing.T) { ...@@ -343,7 +343,7 @@ func TestPathBuilderWithMultiple(t *testing.T) {
}{ }{
{"pod", &api.Pod{}, false, "../../../examples/pod", []string{"nginx"}}, {"pod", &api.Pod{}, false, "../../../examples/pod", []string{"nginx"}},
{"recursive-pod", &api.Pod{}, true, fmt.Sprintf("%s/recursive/pod", tmpDir), []string{"busybox0", "busybox1"}}, {"recursive-pod", &api.Pod{}, true, fmt.Sprintf("%s/recursive/pod", tmpDir), []string{"busybox0", "busybox1"}},
{"rc", &api.ReplicationController{}, false, "../../../examples/guestbook/redis-master-controller.yaml", []string{"redis-master"}}, {"rc", &api.ReplicationController{}, false, "../../../examples/guestbook/legacy/redis-master-controller.yaml", []string{"redis-master"}},
{"recursive-rc", &api.ReplicationController{}, true, fmt.Sprintf("%s/recursive/rc", tmpDir), []string{"busybox0", "busybox1"}}, {"recursive-rc", &api.ReplicationController{}, true, fmt.Sprintf("%s/recursive/rc", tmpDir), []string{"busybox0", "busybox1"}},
{"hardlink", &api.Pod{}, false, fmt.Sprintf("%s/inode/hardlink/busybox-link.json", tmpDir), []string{"busybox0"}}, {"hardlink", &api.Pod{}, false, fmt.Sprintf("%s/inode/hardlink/busybox-link.json", tmpDir), []string{"busybox0"}},
{"hardlink", &api.Pod{}, true, fmt.Sprintf("%s/inode/hardlink/busybox-link.json", tmpDir), []string{"busybox0"}}, {"hardlink", &api.Pod{}, true, fmt.Sprintf("%s/inode/hardlink/busybox-link.json", tmpDir), []string{"busybox0"}},
...@@ -425,14 +425,14 @@ func TestPathBuilderWithMultipleInvalid(t *testing.T) { ...@@ -425,14 +425,14 @@ func TestPathBuilderWithMultipleInvalid(t *testing.T) {
func TestDirectoryBuilder(t *testing.T) { func TestDirectoryBuilder(t *testing.T) {
b := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClient(), testapi.Default.Codec()). b := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClient(), testapi.Default.Codec()).
FilenameParam(false, false, "../../../examples/guestbook"). FilenameParam(false, false, "../../../examples/guestbook/legacy").
NamespaceParam("test").DefaultNamespace() NamespaceParam("test").DefaultNamespace()
test := &testVisitor{} test := &testVisitor{}
singular := false singular := false
err := b.Do().IntoSingular(&singular).Visit(test.Handle) err := b.Do().IntoSingular(&singular).Visit(test.Handle)
if err != nil || singular || len(test.Infos) < 4 { if err != nil || singular || len(test.Infos) < 3 {
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos) t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
} }
...@@ -916,7 +916,7 @@ func TestContinueOnErrorVisitor(t *testing.T) { ...@@ -916,7 +916,7 @@ func TestContinueOnErrorVisitor(t *testing.T) {
func TestSingularObject(t *testing.T) { func TestSingularObject(t *testing.T) {
obj, err := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClient(), testapi.Default.Codec()). obj, err := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClient(), testapi.Default.Codec()).
NamespaceParam("test").DefaultNamespace(). NamespaceParam("test").DefaultNamespace().
FilenameParam(false, false, "../../../examples/guestbook/redis-master-controller.yaml"). FilenameParam(false, false, "../../../examples/guestbook/legacy/redis-master-controller.yaml").
Flatten(). Flatten().
Do().Object() Do().Object()
...@@ -1074,8 +1074,8 @@ func TestWatch(t *testing.T) { ...@@ -1074,8 +1074,8 @@ func TestWatch(t *testing.T) {
func TestWatchMultipleError(t *testing.T) { func TestWatchMultipleError(t *testing.T) {
_, err := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClient(), testapi.Default.Codec()). _, err := NewBuilder(testapi.Default.RESTMapper(), api.Scheme, fakeClient(), testapi.Default.Codec()).
NamespaceParam("test").DefaultNamespace(). NamespaceParam("test").DefaultNamespace().
FilenameParam(false, false, "../../../examples/guestbook/redis-master-controller.yaml").Flatten(). FilenameParam(false, false, "../../../examples/guestbook/legacy/redis-master-controller.yaml").Flatten().
FilenameParam(false, false, "../../../examples/guestbook/redis-master-controller.yaml").Flatten(). FilenameParam(false, false, "../../../examples/guestbook/legacy/redis-master-controller.yaml").Flatten().
Do().Watch("") Do().Watch("")
if err == nil { if err == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment