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
bdfe18f6
Commit
bdfe18f6
authored
Feb 26, 2017
by
Anthony Yeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Job: Add ControllerRef on all created Pods.
parent
33d036a5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
jobcontroller.go
pkg/controller/job/jobcontroller.go
+4
-1
jobcontroller_test.go
pkg/controller/job/jobcontroller_test.go
+20
-3
utils.go
pkg/controller/job/utils.go
+12
-0
No files found.
pkg/controller/job/jobcontroller.go
View file @
bdfe18f6
...
...
@@ -46,6 +46,9 @@ import (
"github.com/golang/glog"
)
// controllerKind contains the schema.GroupVersionKind for this controller type.
var
controllerKind
=
batch
.
SchemeGroupVersion
.
WithKind
(
"Job"
)
type
JobController
struct
{
kubeClient
clientset
.
Interface
podControl
controller
.
PodControlInterface
...
...
@@ -507,7 +510,7 @@ func (jm *JobController) manageJob(activePods []*v1.Pod, succeeded int32, job *b
for
i
:=
int32
(
0
);
i
<
diff
;
i
++
{
go
func
()
{
defer
wait
.
Done
()
if
err
:=
jm
.
podControl
.
CreatePods
(
job
.
Namespace
,
&
job
.
Spec
.
Template
,
job
);
err
!=
nil
{
if
err
:=
jm
.
podControl
.
CreatePods
WithControllerRef
(
job
.
Namespace
,
&
job
.
Spec
.
Template
,
job
,
newControllerRef
(
job
)
);
err
!=
nil
{
defer
utilruntime
.
HandleError
(
err
)
// Decrement the expected number of creates because the informer won't observe this pod
jm
.
expectations
.
CreationObserved
(
jobKey
)
...
...
pkg/controller/job/jobcontroller_test.go
View file @
bdfe18f6
...
...
@@ -101,9 +101,10 @@ func newPodList(count int32, status v1.PodPhase, job *batch.Job) []v1.Pod {
for
i
:=
int32
(
0
);
i
<
count
;
i
++
{
newPod
:=
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
fmt
.
Sprintf
(
"pod-%v"
,
rand
.
String
(
10
)),
Labels
:
job
.
Spec
.
Selector
.
MatchLabels
,
Namespace
:
job
.
Namespace
,
Name
:
fmt
.
Sprintf
(
"pod-%v"
,
rand
.
String
(
10
)),
Labels
:
job
.
Spec
.
Selector
.
MatchLabels
,
Namespace
:
job
.
Namespace
,
OwnerReferences
:
[]
metav1
.
OwnerReference
{
*
newControllerRef
(
job
)},
},
Status
:
v1
.
PodStatus
{
Phase
:
status
},
}
...
...
@@ -274,6 +275,22 @@ func TestControllerSyncJob(t *testing.T) {
if
int32
(
len
(
fakePodControl
.
DeletePodName
))
!=
tc
.
expectedDeletions
{
t
.
Errorf
(
"%s: unexpected number of deletes. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedDeletions
,
len
(
fakePodControl
.
DeletePodName
))
}
// Each create should have an accompanying ControllerRef.
if
len
(
fakePodControl
.
ControllerRefs
)
!=
int
(
tc
.
expectedCreations
)
{
t
.
Errorf
(
"%s: unexpected number of ControllerRefs. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedCreations
,
len
(
fakePodControl
.
ControllerRefs
))
}
// Make sure the ControllerRefs are correct.
for
_
,
controllerRef
:=
range
fakePodControl
.
ControllerRefs
{
if
got
,
want
:=
controllerRef
.
APIVersion
,
"batch/v1"
;
got
!=
want
{
t
.
Errorf
(
"controllerRef.APIVersion = %q, want %q"
,
got
,
want
)
}
if
got
,
want
:=
controllerRef
.
Kind
,
"Job"
;
got
!=
want
{
t
.
Errorf
(
"controllerRef.Kind = %q, want %q"
,
got
,
want
)
}
if
controllerRef
.
Controller
==
nil
||
*
controllerRef
.
Controller
!=
true
{
t
.
Errorf
(
"controllerRef.Controller is not set to true"
)
}
}
// validate status
if
actual
.
Status
.
Active
!=
tc
.
expectedActive
{
t
.
Errorf
(
"%s: unexpected number of active pods. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedActive
,
actual
.
Status
.
Active
)
...
...
pkg/controller/job/utils.go
View file @
bdfe18f6
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
job
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/api/v1"
batch
"k8s.io/kubernetes/pkg/apis/batch/v1"
)
...
...
@@ -29,3 +30,14 @@ func IsJobFinished(j *batch.Job) bool {
}
return
false
}
func
newControllerRef
(
j
*
batch
.
Job
)
*
metav1
.
OwnerReference
{
isController
:=
true
return
&
metav1
.
OwnerReference
{
APIVersion
:
controllerKind
.
GroupVersion
()
.
String
(),
Kind
:
controllerKind
.
Kind
,
Name
:
j
.
Name
,
UID
:
j
.
UID
,
Controller
:
&
isController
,
}
}
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