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
63c85691
Commit
63c85691
authored
Feb 24, 2016
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21795 from janetkuo/deployment-e2e-flake-panic
Fix the nil pointer dereference in addHashKeyToRSAndPods
parents
9a4e3f84
3ed8426a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
deployment.go
pkg/util/deployment/deployment.go
+22
-13
util.go
test/e2e/util.go
+3
-3
No files found.
pkg/util/deployment/deployment.go
View file @
63c85691
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
"strconv"
"strconv"
"time"
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
...
@@ -172,33 +174,37 @@ func rsAndPodsWithHashKeySynced(deployment extensions.Deployment, c clientset.In
...
@@ -172,33 +174,37 @@ func rsAndPodsWithHashKeySynced(deployment extensions.Deployment, c clientset.In
// 2. Add hash label to all pods this rs owns
// 2. Add hash label to all pods this rs owns
// 3. Add hash label to the rs's label and selector
// 3. Add hash label to the rs's label and selector
func
addHashKeyToRSAndPods
(
deployment
extensions
.
Deployment
,
c
clientset
.
Interface
,
rs
extensions
.
ReplicaSet
,
getPodList
podListFunc
)
(
updatedRS
*
extensions
.
ReplicaSet
,
err
error
)
{
func
addHashKeyToRSAndPods
(
deployment
extensions
.
Deployment
,
c
clientset
.
Interface
,
rs
extensions
.
ReplicaSet
,
getPodList
podListFunc
)
(
updatedRS
*
extensions
.
ReplicaSet
,
err
error
)
{
updatedRS
=
&
rs
// If the rs already has the new hash label in its selector, it's done syncing
// If the rs already has the new hash label in its selector, it's done syncing
if
labelsutil
.
SelectorHasLabel
(
rs
.
Spec
.
Selector
,
extensions
.
DefaultDeploymentUniqueLabelKey
)
{
return
}
namespace
:=
deployment
.
Namespace
namespace
:=
deployment
.
Namespace
meta
:=
rs
.
Spec
.
Template
.
ObjectMeta
meta
.
Labels
=
labelsutil
.
CloneAndRemoveLabel
(
meta
.
Labels
,
extensions
.
DefaultDeploymentUniqueLabelKey
)
hash
:=
fmt
.
Sprintf
(
"%d"
,
podutil
.
GetPodTemplateSpecHash
(
api
.
PodTemplateSpec
{
hash
:=
fmt
.
Sprintf
(
"%d"
,
podutil
.
GetPodTemplateSpecHash
(
api
.
PodTemplateSpec
{
ObjectMeta
:
rs
.
Spec
.
Template
.
ObjectM
eta
,
ObjectMeta
:
m
eta
,
Spec
:
rs
.
Spec
.
Template
.
Spec
,
Spec
:
rs
.
Spec
.
Template
.
Spec
,
}))
}))
if
labelsutil
.
SelectorHasLabel
(
rs
.
Spec
.
Selector
,
extensions
.
DefaultDeploymentUniqueLabelKey
)
{
return
&
rs
,
nil
}
// 1. Add hash template label to the rs. This ensures that any newly created pods will have the new label.
// 1. Add hash template label to the rs. This ensures that any newly created pods will have the new label.
if
len
(
rs
.
Spec
.
Template
.
Labels
[
extensions
.
DefaultDeploymentUniqueLabelKey
])
==
0
{
if
len
(
updatedRS
.
Spec
.
Template
.
Labels
[
extensions
.
DefaultDeploymentUniqueLabelKey
])
==
0
{
updatedRS
,
err
=
updateRSWithRetries
(
c
.
Extensions
()
.
ReplicaSets
(
namespace
),
&
rs
,
func
(
updated
*
extensions
.
ReplicaSet
)
{
updatedRS
,
err
=
updateRSWithRetries
(
c
.
Extensions
()
.
ReplicaSets
(
namespace
),
updatedRS
,
func
(
updated
*
extensions
.
ReplicaSet
)
{
updated
.
Spec
.
Template
.
Labels
=
labelsutil
.
AddLabel
(
updated
.
Spec
.
Template
.
Labels
,
extensions
.
DefaultDeploymentUniqueLabelKey
,
hash
)
updated
.
Spec
.
Template
.
Labels
=
labelsutil
.
AddLabel
(
updated
.
Spec
.
Template
.
Labels
,
extensions
.
DefaultDeploymentUniqueLabelKey
,
hash
)
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error updating rs %s pod template label with template hash: %v"
,
updatedRS
.
Name
,
err
)
return
nil
,
fmt
.
Errorf
(
"error updating rs %s pod template label with template hash: %v"
,
updatedRS
.
Name
,
err
)
}
}
}
// Make sure rs pod template is updated so that it won't create pods without the new label (orphaned pods).
// Make sure rs pod template is updated so that it won't create pods without the new label (orphaned pods).
if
updatedRS
.
Generation
>
updatedRS
.
Status
.
ObservedGeneration
{
if
updatedRS
.
Generation
>
updatedRS
.
Status
.
ObservedGeneration
{
if
err
=
waitForReplicaSetUpdated
(
c
,
updatedRS
.
Generation
,
namespace
,
updatedRS
.
Name
);
err
!=
nil
{
if
err
=
waitForReplicaSetUpdated
(
c
,
updatedRS
.
Generation
,
namespace
,
rs
.
Name
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error waiting for rs %s generation %d observed by controller: %v"
,
updatedRS
.
Name
,
updatedRS
.
Generation
,
err
)
return
nil
,
fmt
.
Errorf
(
"error waiting for rs %s generation %d observed by controller: %v"
,
updatedRS
.
Name
,
updatedRS
.
Generation
,
err
)
}
}
}
glog
.
V
(
4
)
.
Infof
(
"Observed the update of rs %s's pod template with hash %s."
,
rs
.
Name
,
hash
)
}
}
// 2. Update all pods managed by the rs to have the new hash label, so they will be correctly adopted.
// 2. Update all pods managed by the rs to have the new hash label, so they will be correctly adopted.
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
rs
.
Spec
.
Selector
)
selector
,
err
:=
unversioned
.
LabelSelectorAsSelector
(
updatedRS
.
Spec
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -210,15 +216,17 @@ func addHashKeyToRSAndPods(deployment extensions.Deployment, c clientset.Interfa
...
@@ -210,15 +216,17 @@ func addHashKeyToRSAndPods(deployment extensions.Deployment, c clientset.Interfa
if
err
=
labelPodsWithHash
(
podList
,
c
,
namespace
,
hash
);
err
!=
nil
{
if
err
=
labelPodsWithHash
(
podList
,
c
,
namespace
,
hash
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
glog
.
V
(
4
)
.
Infof
(
"Labeled rs %s's pods with hash %s."
,
rs
.
Name
,
hash
)
// 3. Update rs label and selector to include the new hash label
// 3. Update rs label and selector to include the new hash label
// Copy the old selector, so that we can scrub out any orphaned pods
// Copy the old selector, so that we can scrub out any orphaned pods
if
updatedRS
,
err
=
updateRSWithRetries
(
c
.
Extensions
()
.
ReplicaSets
(
namespace
),
&
rs
,
func
(
updated
*
extensions
.
ReplicaSet
)
{
if
updatedRS
,
err
=
updateRSWithRetries
(
c
.
Extensions
()
.
ReplicaSets
(
namespace
),
updatedRS
,
func
(
updated
*
extensions
.
ReplicaSet
)
{
updated
.
Labels
=
labelsutil
.
AddLabel
(
updated
.
Labels
,
extensions
.
DefaultDeploymentUniqueLabelKey
,
hash
)
updated
.
Labels
=
labelsutil
.
AddLabel
(
updated
.
Labels
,
extensions
.
DefaultDeploymentUniqueLabelKey
,
hash
)
updated
.
Spec
.
Selector
=
labelsutil
.
AddLabelToSelector
(
updated
.
Spec
.
Selector
,
extensions
.
DefaultDeploymentUniqueLabelKey
,
hash
)
updated
.
Spec
.
Selector
=
labelsutil
.
AddLabelToSelector
(
updated
.
Spec
.
Selector
,
extensions
.
DefaultDeploymentUniqueLabelKey
,
hash
)
});
err
!=
nil
{
});
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error updating rs %s label and selector with template hash: %v"
,
updatedRS
.
Name
,
err
)
return
nil
,
fmt
.
Errorf
(
"error updating rs %s label and selector with template hash: %v"
,
updatedRS
.
Name
,
err
)
}
}
glog
.
V
(
4
)
.
Infof
(
"Updated rs %s's selector and label with hash %s."
,
rs
.
Name
,
hash
)
// TODO: look for orphaned pods and label them in the background somewhere else periodically
// TODO: look for orphaned pods and label them in the background somewhere else periodically
...
@@ -245,6 +253,7 @@ func labelPodsWithHash(podList *api.PodList, c clientset.Interface, namespace, h
...
@@ -245,6 +253,7 @@ func labelPodsWithHash(podList *api.PodList, c clientset.Interface, namespace, h
});
err
!=
nil
{
});
err
!=
nil
{
return
err
return
err
}
}
glog
.
V
(
4
)
.
Infof
(
"Labeled pod %s with hash %s."
,
pod
.
Name
,
hash
)
}
}
}
}
return
nil
return
nil
...
...
test/e2e/util.go
View file @
63c85691
...
@@ -2227,11 +2227,11 @@ func waitForDeploymentOldRSsNum(c *clientset.Clientset, ns, deploymentName strin
...
@@ -2227,11 +2227,11 @@ func waitForDeploymentOldRSsNum(c *clientset.Clientset, ns, deploymentName strin
}
}
func
logReplicaSetsOfDeployment
(
deployment
*
extensions
.
Deployment
,
allOldRSs
[]
*
extensions
.
ReplicaSet
,
newRS
*
extensions
.
ReplicaSet
)
{
func
logReplicaSetsOfDeployment
(
deployment
*
extensions
.
Deployment
,
allOldRSs
[]
*
extensions
.
ReplicaSet
,
newRS
*
extensions
.
ReplicaSet
)
{
Logf
(
"Deployment
= %+v"
,
deployment
)
Logf
(
"Deployment
: %+v. Selector = %+v"
,
deployment
,
deployment
.
Spec
.
Selector
)
for
i
:=
range
allOldRSs
{
for
i
:=
range
allOldRSs
{
Logf
(
"All old ReplicaSets (%d/%d) of deployment %s: %+v
"
,
i
+
1
,
len
(
allOldRSs
),
deployment
.
Name
,
allOldRSs
[
i
]
)
Logf
(
"All old ReplicaSets (%d/%d) of deployment %s: %+v
. Selector = %+v"
,
i
+
1
,
len
(
allOldRSs
),
deployment
.
Name
,
allOldRSs
[
i
],
allOldRSs
[
i
]
.
Spec
.
Selector
)
}
}
Logf
(
"New ReplicaSet of deployment %s: %+v
"
,
deployment
.
Name
,
newRS
)
Logf
(
"New ReplicaSet of deployment %s: %+v
. Selector = %+v"
,
deployment
.
Name
,
newRS
,
newRS
.
Spec
.
Selector
)
}
}
func
waitForObservedDeployment
(
c
*
clientset
.
Clientset
,
ns
,
deploymentName
string
,
desiredGeneration
int64
)
error
{
func
waitForObservedDeployment
(
c
*
clientset
.
Clientset
,
ns
,
deploymentName
string
,
desiredGeneration
int64
)
error
{
...
...
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