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
6f61326c
Commit
6f61326c
authored
Oct 07, 2015
by
nikhiljindal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing the selector for new RC created by deployment
parent
0737e108
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+4
-1
deployment.go
pkg/util/deployment/deployment.go
+20
-9
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
6f61326c
...
...
@@ -140,6 +140,9 @@ func (d *DeploymentController) getNewRC(deployment extensions.Deployment) (*api.
podTemplateSpecHash
:=
deploymentUtil
.
GetPodTemplateSpecHash
(
deployment
.
Spec
.
Template
)
rcName
:=
fmt
.
Sprintf
(
"deploymentrc-%d"
,
podTemplateSpecHash
)
newRCTemplate
:=
deploymentUtil
.
GetNewRCTemplate
(
deployment
)
// Add podTemplateHash label to selector.
newRCSelector
:=
deploymentUtil
.
CloneAndAddLabel
(
deployment
.
Spec
.
Selector
,
deployment
.
Spec
.
UniqueLabelKey
,
podTemplateSpecHash
)
newRC
:=
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
rcName
,
...
...
@@ -147,7 +150,7 @@ func (d *DeploymentController) getNewRC(deployment extensions.Deployment) (*api.
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
Selector
:
newRC
Template
.
ObjectMeta
.
Labels
,
Selector
:
newRC
Selector
,
Template
:
newRCTemplate
,
},
}
...
...
pkg/util/deployment/deployment.go
View file @
6f61326c
...
...
@@ -90,18 +90,29 @@ func GetNewRCTemplate(deployment extensions.Deployment) *api.PodTemplateSpec {
ObjectMeta
:
deployment
.
Spec
.
Template
.
ObjectMeta
,
Spec
:
deployment
.
Spec
.
Template
.
Spec
,
}
podTemplateSpecHash
:=
GetPodTemplateSpecHash
(
newRCTemplate
)
if
deployment
.
Spec
.
UniqueLabelKey
!=
""
{
newLabels
:=
map
[
string
]
string
{}
for
key
,
value
:=
range
deployment
.
Spec
.
Template
.
ObjectMeta
.
Labels
{
newLabels
[
key
]
=
value
}
newLabels
[
deployment
.
Spec
.
UniqueLabelKey
]
=
fmt
.
Sprintf
(
"%d"
,
podTemplateSpecHash
)
newRCTemplate
.
ObjectMeta
.
Labels
=
newLabels
}
newRCTemplate
.
ObjectMeta
.
Labels
=
CloneAndAddLabel
(
deployment
.
Spec
.
Template
.
ObjectMeta
.
Labels
,
deployment
.
Spec
.
UniqueLabelKey
,
GetPodTemplateSpecHash
(
newRCTemplate
))
return
newRCTemplate
}
// Clones the given map and returns a new map with the given key and value added.
// Returns the given map, if labelKey is empty.
func
CloneAndAddLabel
(
labels
map
[
string
]
string
,
labelKey
string
,
labelValue
uint32
)
map
[
string
]
string
{
if
labelKey
==
""
{
// Dont need to add a label.
return
labels
}
// Clone.
newLabels
:=
map
[
string
]
string
{}
for
key
,
value
:=
range
labels
{
newLabels
[
key
]
=
value
}
newLabels
[
labelKey
]
=
fmt
.
Sprintf
(
"%d"
,
labelValue
)
return
newLabels
}
func
GetPodTemplateSpecHash
(
template
*
api
.
PodTemplateSpec
)
uint32
{
podTemplateSpecHasher
:=
adler32
.
New
()
util
.
DeepHashObject
(
podTemplateSpecHasher
,
template
)
...
...
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