Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c1596e67
Commit
c1596e67
authored
Mar 23, 2016
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update guestbook examples; replace RC concepts with Deployment
parent
2ac788b4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
211 additions
and
85 deletions
+211
-85
example_syncer.go
cmd/mungedocs/example_syncer.go
+2
-2
examples_test.go
examples/examples_test.go
+8
-3
README.md
examples/guestbook/README.md
+0
-0
frontend.yaml
examples/guestbook/all-in-one/frontend.yaml
+8
-7
guestbook-all-in-one.yaml
examples/guestbook/all-in-one/guestbook-all-in-one.yaml
+28
-25
redis-slave.yaml
examples/guestbook/all-in-one/redis-slave.yaml
+10
-9
frontend-deployment.yaml
examples/guestbook/frontend-deployment.yaml
+42
-0
frontend-controller.yaml
examples/guestbook/legacy/frontend-controller.yaml
+0
-0
redis-master-controller.yaml
examples/guestbook/legacy/redis-master-controller.yaml
+0
-0
redis-slave-controller.yaml
examples/guestbook/legacy/redis-slave-controller.yaml
+0
-0
redis-master-deployment.yaml
examples/guestbook/redis-master-deployment.yaml
+37
-0
redis-slave-deployment.yaml
examples/guestbook/redis-slave-deployment.yaml
+45
-0
test-cmd.sh
hack/test-cmd.sh
+3
-3
create_test.go
pkg/kubectl/cmd/create_test.go
+5
-7
delete_test.go
pkg/kubectl/cmd/delete_test.go
+8
-10
describe_test.go
pkg/kubectl/cmd/describe_test.go
+1
-1
replace_test.go
pkg/kubectl/cmd/replace_test.go
+8
-12
builder_test.go
pkg/kubectl/resource/builder_test.go
+6
-6
No files found.
cmd/mungedocs/example_syncer.go
View file @
c1596e67
...
...
@@ -36,14 +36,14 @@ var exampleMungeTagRE = regexp.MustCompile(beginMungeTag(fmt.Sprintf("%s %s", ex
// the content of the example, thereby syncing it.
//
// For example,
// <!-- BEGIN MUNGE: EXAMPLE ../../examples/guestbook/frontend-
controller
.yaml -->
// <!-- BEGIN MUNGE: EXAMPLE ../../examples/guestbook/frontend-
service
.yaml -->
//
// ```yaml
// foo:
// bar:
// ```
//
// [Download example](../../examples/guestbook/frontend-
controller
.yaml?raw=true)
// [Download example](../../examples/guestbook/frontend-
service
.yaml?raw=true)
// <!-- END MUNGE: EXAMPLE -->
func
syncExamples
(
filePath
string
,
mlines
mungeLines
)
(
mungeLines
,
error
)
{
var
err
error
...
...
examples/examples_test.go
View file @
c1596e67
...
...
@@ -172,13 +172,18 @@ func TestExampleObjectSchemas(t *testing.T) {
"v1-controller"
:
&
api
.
ReplicationController
{},
},
"../examples/guestbook"
:
{
"frontend-
controller"
:
&
api
.
ReplicationController
{},
"redis-slave-
controller"
:
&
api
.
ReplicationController
{},
"redis-master-
controller"
:
&
api
.
ReplicationController
{},
"frontend-
deployment"
:
&
extensions
.
Deployment
{},
"redis-slave-
deployment"
:
&
extensions
.
Deployment
{},
"redis-master-
deployment"
:
&
extensions
.
Deployment
{},
"frontend-service"
:
&
api
.
Service
{},
"redis-master-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"
:
{
"guestbook-controller"
:
&
api
.
ReplicationController
{},
"redis-slave-controller"
:
&
api
.
ReplicationController
{},
...
...
examples/guestbook/README.md
View file @
c1596e67
This diff is collapsed.
Click to expand it.
examples/guestbook/all-in-one/frontend.yaml
View file @
c1596e67
...
...
@@ -16,15 +16,15 @@ spec:
app
:
guestbook
tier
:
frontend
---
apiVersion
:
v
1
kind
:
ReplicationController
apiVersion
:
extensions/v1beta
1
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
#
labels:
#
app: guestbook
#
tier: frontend
spec
:
# this replicas value is default
# modify it according to your case
...
...
@@ -32,8 +32,9 @@ spec:
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# app: guestbook
# tier: frontend
# matchLabels:
# app: guestbook
# tier: frontend
template
:
metadata
:
labels
:
...
...
examples/guestbook/all-in-one/guestbook-all-in-one.yaml
View file @
c1596e67
...
...
@@ -16,16 +16,16 @@ spec:
tier
:
backend
role
:
master
---
apiVersion
:
v
1
kind
:
ReplicationController
apiVersion
:
extensions/v1beta
1
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
#
labels:
#
app: redis
#
role: master
#
tier: backend
spec
:
# this replicas value is default
# modify it according to your case
...
...
@@ -33,9 +33,10 @@ spec:
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# app: guestbook
# role: master
# tier: backend
# matchLabels:
# app: guestbook
# role: master
# tier: backend
template
:
metadata
:
labels
:
...
...
@@ -70,16 +71,16 @@ spec:
tier
:
backend
role
:
slave
---
apiVersion
:
v
1
kind
:
ReplicationController
apiVersion
:
extensions/v1beta
1
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
#
labels:
#
app: redis
#
role: slave
#
tier: backend
spec
:
# this replicas value is default
# modify it according to your case
...
...
@@ -87,9 +88,10 @@ spec:
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# app: guestbook
# role: slave
# tier: backend
# matchLabels:
# app: guestbook
# role: slave
# tier: backend
template
:
metadata
:
labels
:
...
...
@@ -133,15 +135,15 @@ spec:
app
:
guestbook
tier
:
frontend
---
apiVersion
:
v
1
kind
:
ReplicationController
apiVersion
:
extensions/v1beta
1
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
#
labels:
#
app: guestbook
#
tier: frontend
spec
:
# this replicas value is default
# modify it according to your case
...
...
@@ -149,8 +151,9 @@ spec:
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# app: guestbook
# tier: frontend
# matchLabels:
# app: guestbook
# tier: frontend
template
:
metadata
:
labels
:
...
...
examples/guestbook/all-in-one/redis-slave.yaml
View file @
c1596e67
...
...
@@ -15,16 +15,16 @@ spec:
role
:
slave
tier
:
backend
---
apiVersion
:
v
1
kind
:
ReplicationController
apiVersion
:
extensions/v1beta
1
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
#
labels:
#
app: redis
#
role: slave
#
tier: backend
spec
:
# this replicas value is default
# modify it according to your case
...
...
@@ -32,9 +32,10 @@ spec:
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# app: guestbook
# role: slave
# tier: backend
# matchLabels:
# app: guestbook
# role: slave
# tier: backend
template
:
metadata
:
labels
:
...
...
examples/guestbook/frontend-deployment.yaml
0 → 100644
View file @
c1596e67
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
examples/guestbook/frontend-controller.yaml
→
examples/guestbook/
legacy/
frontend-controller.yaml
View file @
c1596e67
File moved
examples/guestbook/redis-master-controller.yaml
→
examples/guestbook/
legacy/
redis-master-controller.yaml
View file @
c1596e67
File moved
examples/guestbook/redis-slave-controller.yaml
→
examples/guestbook/
legacy/
redis-slave-controller.yaml
View file @
c1596e67
File moved
examples/guestbook/redis-master-deployment.yaml
0 → 100644
View file @
c1596e67
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
examples/guestbook/redis-slave-deployment.yaml
0 → 100644
View file @
c1596e67
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
hack/test-cmd.sh
View file @
c1596e67
...
...
@@ -1106,8 +1106,8 @@ __EOF__
kubectl delete rc frontend
"
${
kube_flags
[@]
}
"
### Scale multiple replication controllers
kubectl create
-f
examples/guestbook/redis-master-controller.yaml
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/redis-slave-controller.yaml
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/
legacy/
redis-master-controller.yaml
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/
legacy/
redis-slave-controller.yaml
"
${
kube_flags
[@]
}
"
# Command
kubectl scale rc/redis-master rc/redis-slave
--replicas
=
4
"
${
kube_flags
[@]
}
"
# Post-condition: 4 replicas each
...
...
@@ -1217,7 +1217,7 @@ __EOF__
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
''
# Command
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
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
'frontend:redis-slave:'
...
...
pkg/kubectl/cmd/create_test.go
View file @
c1596e67
...
...
@@ -60,7 +60,7 @@ func TestCreateObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
.
Run
(
cmd
,
[]
string
{})
...
...
@@ -94,7 +94,7 @@ func TestCreateMultipleObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"output"
,
"name"
)
cmd
.
Run
(
cmd
,
[]
string
{})
...
...
@@ -107,7 +107,7 @@ func TestCreateMultipleObject(t *testing.T) {
func
TestCreateDirectory
(
t
*
testing
.
T
)
{
initTestErrorHandler
(
t
)
_
,
svc
,
rc
:=
testData
()
_
,
_
,
rc
:=
testData
()
rc
.
Items
[
0
]
.
Name
=
"name"
f
,
tf
,
codec
:=
NewAPIFactory
()
...
...
@@ -116,8 +116,6 @@ func TestCreateDirectory(t *testing.T) {
Codec
:
codec
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
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"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
...
...
@@ -130,11 +128,11 @@ func TestCreateDirectory(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdCreate
(
f
,
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook
/legacy
"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"name"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"replicationcontroller/name
\n
service/baz
\n
replicationcontroller/name
\n
service/baz
\n
replicationcontroller/name
\n
service/baz
\n
"
{
if
buf
.
String
()
!=
"replicationcontroller/name
\n
replicationcontroller/name
\n
replicationcontroller/name
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
...
...
pkg/kubectl/cmd/delete_test.go
View file @
c1596e67
...
...
@@ -114,7 +114,7 @@ func TestDeleteObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"output"
,
"name"
)
cmd
.
Run
(
cmd
,
[]
string
{})
...
...
@@ -145,7 +145,7 @@ func TestDeleteObjectNotFound(t *testing.T) {
cmd
:=
NewCmdDelete
(
f
,
buf
)
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
(
"output"
,
"name"
)
...
...
@@ -174,7 +174,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"ignore-not-found"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"name"
)
...
...
@@ -290,7 +290,7 @@ func TestDeleteMultipleObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"cascade"
,
"false"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"name"
)
...
...
@@ -325,7 +325,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
cmd
:=
NewCmdDelete
(
f
,
buf
)
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
(
"output"
,
"name"
)
...
...
@@ -375,7 +375,7 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
}
func
TestDeleteDirectory
(
t
*
testing
.
T
)
{
_
,
svc
,
rc
:=
testData
()
_
,
_
,
rc
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -383,8 +383,6 @@ func TestDeleteDirectory(t *testing.T) {
Codec
:
codec
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
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"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
...
...
@@ -397,12 +395,12 @@ func TestDeleteDirectory(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"output"
,
"name"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"replicationcontroller/frontend
\n
service/frontend
\n
replicationcontroller/redis-master
\n
service/redis-master
\n
replicationcontroller/redis-slave
\n
service
/redis-slave
\n
"
{
if
buf
.
String
()
!=
"replicationcontroller/frontend
\n
replicationcontroller/redis-master
\n
replicationcontroller
/redis-slave
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
...
...
pkg/kubectl/cmd/describe_test.go
View file @
c1596e67
...
...
@@ -70,7 +70,7 @@ func TestDescribeObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
{})
if
d
.
Name
!=
"redis-master"
||
d
.
Namespace
!=
"test"
{
...
...
pkg/kubectl/cmd/replace_test.go
View file @
c1596e67
...
...
@@ -48,7 +48,7 @@ func TestReplaceObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
.
Run
(
cmd
,
[]
string
{})
...
...
@@ -95,7 +95,7 @@ func TestReplaceMultipleObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"output"
,
"name"
)
cmd
.
Run
(
cmd
,
[]
string
{})
...
...
@@ -116,7 +116,7 @@ func TestReplaceMultipleObject(t *testing.T) {
}
func
TestReplaceDirectory
(
t
*
testing
.
T
)
{
_
,
svc
,
rc
:=
testData
()
_
,
_
,
rc
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -124,12 +124,8 @@ func TestReplaceDirectory(t *testing.T) {
Codec
:
codec
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
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"
)
:
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"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
...
...
@@ -142,12 +138,12 @@ func TestReplaceDirectory(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"output"
,
"name"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"replicationcontroller/rc1
\n
service/baz
\n
replicationcontroller/rc1
\n
service/baz
\n
replicationcontroller/rc1
\n
service/baz
\n
"
{
if
buf
.
String
()
!=
"replicationcontroller/rc1
\n
replicationcontroller/rc1
\n
replicationcontroller/rc1
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
...
...
@@ -156,8 +152,8 @@ func TestReplaceDirectory(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"cascade"
,
"false"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"replicationcontroller/frontend
\n
service/frontend
\n
replicationcontroller/redis-master
\n
service/redis-master
\n
replicationcontroller/redis-slave
\n
service
/redis-slave
\n
"
+
"replicationcontroller/rc1
\n
service/baz
\n
replicationcontroller/rc1
\n
service/baz
\n
replicationcontroller/rc1
\n
service/baz
\n
"
{
if
buf
.
String
()
!=
"replicationcontroller/frontend
\n
replicationcontroller/redis-master
\n
replicationcontroller
/redis-slave
\n
"
+
"replicationcontroller/rc1
\n
replicationcontroller/rc1
\n
replicationcontroller/rc1
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
...
...
@@ -185,7 +181,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
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
(
"cascade"
,
"false"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"name"
)
...
...
pkg/kubectl/resource/builder_test.go
View file @
c1596e67
...
...
@@ -343,7 +343,7 @@ func TestPathBuilderWithMultiple(t *testing.T) {
}{
{
"pod"
,
&
api
.
Pod
{},
false
,
"../../../examples/pod"
,
[]
string
{
"nginx"
}},
{
"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"
}},
{
"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"
}},
...
...
@@ -425,14 +425,14 @@ func TestPathBuilderWithMultipleInvalid(t *testing.T) {
func
TestDirectoryBuilder
(
t
*
testing
.
T
)
{
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
()
test
:=
&
testVisitor
{}
singular
:=
false
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
)
}
...
...
@@ -916,7 +916,7 @@ func TestContinueOnErrorVisitor(t *testing.T) {
func
TestSingularObject
(
t
*
testing
.
T
)
{
obj
,
err
:=
NewBuilder
(
testapi
.
Default
.
RESTMapper
(),
api
.
Scheme
,
fakeClient
(),
testapi
.
Default
.
Codec
())
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
.
FilenameParam
(
false
,
false
,
"../../../examples/guestbook/redis-master-controller.yaml"
)
.
FilenameParam
(
false
,
false
,
"../../../examples/guestbook/
legacy/
redis-master-controller.yaml"
)
.
Flatten
()
.
Do
()
.
Object
()
...
...
@@ -1074,8 +1074,8 @@ func TestWatch(t *testing.T) {
func
TestWatchMultipleError
(
t
*
testing
.
T
)
{
_
,
err
:=
NewBuilder
(
testapi
.
Default
.
RESTMapper
(),
api
.
Scheme
,
fakeClient
(),
testapi
.
Default
.
Codec
())
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
.
FilenameParam
(
false
,
false
,
"../../../examples/guestbook/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
()
.
FilenameParam
(
false
,
false
,
"../../../examples/guestbook/
legacy/
redis-master-controller.yaml"
)
.
Flatten
()
.
Do
()
.
Watch
(
""
)
if
err
==
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment