Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Add PodControlInterface and PodControllerRefManager (#73)
Browse files Browse the repository at this point in the history
* Add PodControlInterface and FakePodControl

* Add comments for service event reasons

* Skip deleting pods/services already in termination

Kubernetes pkg/controller/controller_utils.go doesn’t have this logic. This is from kubeflow/training-operator/pull/998. I think it’s safe to keep the logic here.

* Remove Kubernetes controller dependency

Use `KeyFunc` instead of k8s.io/kubernetes/pkg/controller.KeyFunc

* Add Base and PodControllerRefManager

Current implementation use PodControllerRefManager from `k8s.io/kubernetes/pkg/controller` and self-implemented `ServiceControllerRefManager` which brings some problems.

1. Pod impl may change along with k8s upgrade, service impl doesn’t
2. It’s not helping us remove Kubernetes direct dependency.
3. It’s not that straighforward for maintainers and contributors.

This change make sure we folk everything we need and remove ref_manager dependency.

* Rename service_ref_manager to controller_ref_manager

Since this file contains both BaseControllerRefManager, PodControllerRefManager and ServiceControllerRefManager. It makes sense to rename it to controller_ref_manager.go

* Address code review feedbacks
  • Loading branch information
Jeffwan authored Apr 20, 2020
1 parent 2780782 commit 5f6f32b
Show file tree
Hide file tree
Showing 7 changed files with 697 additions and 172 deletions.
9 changes: 4 additions & 5 deletions pkg/controller.v1/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/pkg/controller"

apiv1 "github.com/kubeflow/common/pkg/apis/common/v1"
commonutil "github.com/kubeflow/common/pkg/util"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (jc *JobController) AddPod(obj interface{}) {
return
}

jobKey, err := controller.KeyFunc(job)
jobKey, err := KeyFunc(job)
if err != nil {
logger.Infof("Failed to get the jobkey: %v", err)
return
Expand Down Expand Up @@ -116,7 +115,7 @@ func (jc *JobController) UpdatePod(old, cur interface{}) {
// The ControllerRef was changed. Sync the old controller, if any.
if job := jc.resolveControllerRef(oldPod.Namespace, oldControllerRef); job != nil {
logger.Infof("pod ControllerRef updated: %v, %v", curPod, oldPod)
jobKey, err := controller.KeyFunc(job)
jobKey, err := KeyFunc(job)
if err != nil {
return
}
Expand All @@ -132,7 +131,7 @@ func (jc *JobController) UpdatePod(old, cur interface{}) {
return
}
logger.Debugf("pod has a ControllerRef: %v, %v", curPod, oldPod)
jobKey, err := controller.KeyFunc(job)
jobKey, err := KeyFunc(job)
if err != nil {
return
}
Expand Down Expand Up @@ -175,7 +174,7 @@ func (jc *JobController) DeletePod(obj interface{}) {
if job == nil {
return
}
jobKey, err := controller.KeyFunc(job)
jobKey, err := KeyFunc(job)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller.v1/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/pkg/controller"
)

var (
Expand Down Expand Up @@ -62,7 +61,7 @@ func (jc *JobController) AddService(obj interface{}) {
return
}

jobKey, err := controller.KeyFunc(job)
jobKey, err := KeyFunc(job)
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 5f6f32b

Please sign in to comment.