Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add controller-name label for Pod and service #1067

Merged
merged 2 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/tf-operator.v1/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"flag"
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

const DefaultResyncPeriod = 12 * time.Hour
Expand Down
2 changes: 1 addition & 1 deletion cmd/tf-operator.v1/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/kubeflow/tf-operator/cmd/tf-operator.v1/app/options"
"github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1"
v1 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1"
tfjobclientset "github.com/kubeflow/tf-operator/pkg/client/clientset/versioned"
"github.com/kubeflow/tf-operator/pkg/client/clientset/versioned/scheme"
tfjobinformers "github.com/kubeflow/tf-operator/pkg/client/informers/externalversions"
Expand Down
2 changes: 1 addition & 1 deletion cmd/tf-operator.v1beta2/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package options
import (
"flag"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

// ServerOption is the main context object for the controller manager.
Expand Down
2 changes: 1 addition & 1 deletion cmd/tf-operator.v1beta2/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/kubeflow/tf-operator/pkg/version"
kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeinformers "k8s.io/client-go/informers"
Expand Down
2 changes: 1 addition & 1 deletion dashboard/backend/handler/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (apiHandler *APIHandler) handleGetTFJobDetail(request *restful.Request, res

// Get associated pods
pods, err := apiHandler.cManager.ClientSet.CoreV1().Pods(namespace).List(metav1.ListOptions{
LabelSelector: fmt.Sprintf("group-name=kubeflow.org,job-name=%s", name),
LabelSelector: fmt.Sprintf("group-name=kubeflow.org,job-name=%s,controller-name=tf-operator", name),
})
if err != nil {
log.Warningf("failed to list pods for TFJob %v under namespace %v: %v", name, namespace, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/common/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package v1

import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/common/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package v1beta2

import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/tensorflow/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"strings"

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/tensorflow/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"reflect"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1"
"github.com/kubeflow/tf-operator/pkg/util"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/tensorflow/v1beta2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"strings"

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1beta2"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/tensorflow/v1beta2/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"reflect"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1beta2"
"github.com/kubeflow/tf-operator/pkg/util"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/tensorflow/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
tfv1 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1"
tfv1beta2 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1beta2"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

func TestValidateBetaTwoTFJobSpec(t *testing.T) {
Expand Down
10 changes: 8 additions & 2 deletions pkg/common/jobcontroller/jobcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1"
kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/api/policy/v1beta1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -142,6 +142,9 @@ const (

// JobRoleLabel represents the label key for the job role, e.g. the value is master
JobRoleLabel = "job-role"

// ControllerNameLabel represents the label key for the job controller name
ControllerNameLabel = "controller-name"
)

func NewJobController(
Expand Down Expand Up @@ -208,10 +211,12 @@ func (jc *JobController) GenLabels(jobName string) map[string]string {
// deprecatedLabel is kept for backward compatibility. Has to be removed later
deprecatedLabelJobName := jc.Controller.GetJobNameLabelKey()
groupName := jc.Controller.GetGroupNameLabelValue()
controllerName := jc.Controller.ControllerName()
return map[string]string{
labelGroupName: groupName,
JobNameLabel: strings.Replace(jobName, "/", "-", -1),
deprecatedLabelJobName: strings.Replace(jobName, "/", "-", -1),
ControllerNameLabel: controllerName,
}
}

Expand Down Expand Up @@ -265,7 +270,8 @@ func (jc *JobController) SyncPdb(job metav1.Object, minAvailableReplicas int32)
MinAvailable: &minAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
JobNameLabel: job.GetName(),
JobNameLabel: job.GetName(),
ControllerNameLabel: jc.Controller.ControllerName(),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/jobcontroller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/jobcontroller/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/kubernetes/pkg/controller"
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/util/v1/testutil/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

Expand Down
2 changes: 1 addition & 1 deletion pkg/common/util/v1/testutil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

Expand Down
2 changes: 1 addition & 1 deletion pkg/common/util/v1/testutil/tfjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package testutil
import (
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1"
Expand Down
13 changes: 8 additions & 5 deletions pkg/common/util/v1/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import (

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1"
tfv1 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/tools/cache"
)

const (
LabelGroupName = "group-name"
JobNameLabel = "job-name"
LabelGroupName = "group-name"
JobNameLabel = "job-name"
ControllerNameLabel = "controller-name"
// Deprecated label. Has to be removed later
DeprecatedLabelTFJobName = "tf-job-name"
)
Expand All @@ -38,15 +39,17 @@ var (
// KeyFunc is the short name to DeletionHandlingMetaNamespaceKeyFunc.
// IndexerInformer uses a delta queue, therefore for deletes we have to use this
// key function but it should be just fine for non delete events.
KeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
GroupName = tfv1.GroupName
KeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
GroupName = tfv1.GroupName
ControllerName = "tf-operator"
)

func GenLabels(jobName string) map[string]string {
return map[string]string{
LabelGroupName: GroupName,
JobNameLabel: strings.Replace(jobName, "/", "-", -1),
DeprecatedLabelTFJobName: strings.Replace(jobName, "/", "-", -1),
ControllerNameLabel: ControllerName,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/common/util/v1beta2/testutil/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

Expand Down
2 changes: 1 addition & 1 deletion pkg/common/util/v1beta2/testutil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"

Expand Down
2 changes: 1 addition & 1 deletion pkg/common/util/v1beta2/testutil/tfjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package testutil
import (
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1beta2"
Expand Down
9 changes: 6 additions & 3 deletions pkg/common/util/v1beta2/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

common "github.com/kubeflow/tf-operator/pkg/apis/common/v1beta2"
tfv1beta2 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1beta2"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/tools/cache"
Expand All @@ -31,21 +31,24 @@ const (
LabelGroupName = "group-name"
JobNameLabel = "job-name"
DeprecatedLabelTFJobName = "tf-job-name"
ControllerNameLabel = "controller-name"
)

var (
// KeyFunc is the short name to DeletionHandlingMetaNamespaceKeyFunc.
// IndexerInformer uses a delta queue, therefore for deletes we have to use this
// key function but it should be just fine for non delete events.
KeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
GroupName = tfv1beta2.GroupName
KeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
GroupName = tfv1beta2.GroupName
ControllerName = "tf-operator"
)

func GenLabels(jobName string) map[string]string {
return map[string]string{
LabelGroupName: GroupName,
JobNameLabel: strings.Replace(jobName, "/", "-", -1),
DeprecatedLabelTFJobName: strings.Replace(jobName, "/", "-", -1),
ControllerNameLabel: ControllerName,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/control/pod_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"fmt"

"github.com/golang/glog"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/pod_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/service_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"sync"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/service_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/service_ref_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

"github.com/golang/glog"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/service_ref_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"reflect"
"testing"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/tensorflow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller.v1/tensorflow/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
"k8s.io/api/core/v1"
kubeinformers "k8s.io/client-go/informers"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -35,6 +34,7 @@ import (
tfjobinformers "github.com/kubeflow/tf-operator/pkg/client/informers/externalversions"
"github.com/kubeflow/tf-operator/pkg/common/util/v1/testutil"
"github.com/kubeflow/tf-operator/pkg/control"
v1 "k8s.io/api/core/v1"
"k8s.io/api/policy/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -455,7 +455,8 @@ func TestSyncPdb(t *testing.T) {
MinAvailable: &minAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"job-name": "test-sync-pdb",
"job-name": "test-sync-pdb",
"controller-name": "tf-operator",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/tensorflow/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/kubernetes/scheme"
Expand Down
Loading