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
ba9c3700
Commit
ba9c3700
authored
Jul 11, 2014
by
Claire Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/controller: cleanup replication_controller.go
parent
89655584
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
23 deletions
+21
-23
replication_controller.go
pkg/controller/replication_controller.go
+21
-23
No files found.
pkg/controller/replication_controller.go
View file @
ba9c3700
...
@@ -100,10 +100,9 @@ func (rm *ReplicationManager) Run(period time.Duration) {
...
@@ -100,10 +100,9 @@ func (rm *ReplicationManager) Run(period time.Duration) {
func
(
rm
*
ReplicationManager
)
watchControllers
()
{
func
(
rm
*
ReplicationManager
)
watchControllers
()
{
watchChannel
:=
make
(
chan
*
etcd
.
Response
)
watchChannel
:=
make
(
chan
*
etcd
.
Response
)
stop
:=
make
(
chan
bool
)
stop
:=
make
(
chan
bool
)
defer
func
()
{
// Ensure that the call to watch ends.
// Ensure that the call to watch ends.
defer
close
(
stop
)
close
(
stop
)
}()
go
func
()
{
go
func
()
{
defer
util
.
HandleCrash
()
defer
util
.
HandleCrash
()
_
,
err
:=
rm
.
etcdClient
.
Watch
(
"/registry/controllers"
,
0
,
true
,
watchChannel
,
stop
)
_
,
err
:=
rm
.
etcdClient
.
Watch
(
"/registry/controllers"
,
0
,
true
,
watchChannel
,
stop
)
...
@@ -137,30 +136,29 @@ func (rm *ReplicationManager) watchControllers() {
...
@@ -137,30 +136,29 @@ func (rm *ReplicationManager) watchControllers() {
}
}
func
(
rm
*
ReplicationManager
)
handleWatchResponse
(
response
*
etcd
.
Response
)
(
*
api
.
ReplicationController
,
error
)
{
func
(
rm
*
ReplicationManager
)
handleWatchResponse
(
response
*
etcd
.
Response
)
(
*
api
.
ReplicationController
,
error
)
{
if
response
.
Action
==
"set"
{
switch
response
.
Action
{
if
response
.
Node
!=
nil
{
case
"set"
:
var
controllerSpec
api
.
ReplicationController
if
response
.
Node
==
nil
{
err
:=
json
.
Unmarshal
([]
byte
(
response
.
Node
.
Value
),
&
controllerSpec
)
return
nil
,
fmt
.
Errorf
(
"response node is null %#v"
,
response
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
controllerSpec
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"response node is null %#v"
,
response
)
var
controllerSpec
api
.
ReplicationController
}
else
if
response
.
Action
==
"delete"
{
if
err
:=
json
.
Unmarshal
([]
byte
(
response
.
Node
.
Value
),
&
controllerSpec
);
err
!=
nil
{
return
nil
,
err
}
return
&
controllerSpec
,
nil
case
"delete"
:
// Ensure that the final state of a replication controller is applied before it is deleted.
// Ensure that the final state of a replication controller is applied before it is deleted.
// Otherwise, a replication controller could be modified and then deleted (for example, from 3 to 0
// Otherwise, a replication controller could be modified and then deleted (for example, from 3 to 0
// replicas), and it would be non-deterministic which of its pods continued to exist.
// replicas), and it would be non-deterministic which of its pods continued to exist.
if
response
.
PrevNode
!=
nil
{
if
response
.
PrevNode
==
nil
{
var
controllerSpec
api
.
ReplicationController
return
nil
,
fmt
.
Errorf
(
"previous node is null %#v"
,
response
)
if
err
:=
json
.
Unmarshal
([]
byte
(
response
.
PrevNode
.
Value
),
&
controllerSpec
);
err
!=
nil
{
return
nil
,
err
}
return
&
controllerSpec
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"previous node is null %#v"
,
response
)
var
controllerSpec
api
.
ReplicationController
if
err
:=
json
.
Unmarshal
([]
byte
(
response
.
PrevNode
.
Value
),
&
controllerSpec
);
err
!=
nil
{
return
nil
,
err
}
return
&
controllerSpec
,
nil
}
}
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -190,7 +188,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
...
@@ -190,7 +188,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli
rm
.
podControl
.
createReplica
(
controllerSpec
)
rm
.
podControl
.
createReplica
(
controllerSpec
)
}
}
}
else
if
diff
>
0
{
}
else
if
diff
>
0
{
glog
.
Info
(
"Too many replicas, deleting"
)
glog
.
Info
f
(
"Too many replicas, deleting %d
\n
"
,
diff
)
for
i
:=
0
;
i
<
diff
;
i
++
{
for
i
:=
0
;
i
<
diff
;
i
++
{
rm
.
podControl
.
deletePod
(
filteredList
[
i
]
.
ID
)
rm
.
podControl
.
deletePod
(
filteredList
[
i
]
.
ID
)
}
}
...
...
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