Skip to content

Commit

Permalink
label: Remove namespace from labels
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege committed Jun 15, 2018
1 parent ee95e54 commit 8bdd2e6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/control/pod_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestCreatePods(t *testing.T) {
testName := "pod-name"
podTemplate := testutil.NewTFReplicaSpecTemplate()
podTemplate.Name = testName
podTemplate.Labels = generator.GenLabels(testutil.GetKey(tfJob, t))
podTemplate.Labels = generator.GenLabels(tfJob.Name)
podTemplate.SetOwnerReferences([]metav1.OwnerReference{})

// Make sure createReplica sends a POST to the apiserver with a pod from the controllers pod template
Expand All @@ -67,7 +67,7 @@ func TestCreatePods(t *testing.T) {

expectedPod := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: generator.GenLabels(testutil.GetKey(tfJob, t)),
Labels: generator.GenLabels(tfJob.Name),
Name: testName,
},
Spec: podTemplate.Spec,
Expand Down
4 changes: 2 additions & 2 deletions pkg/control/service_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestCreateService(t *testing.T) {

expectedService := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: generator.GenLabels(testutil.GetKey(tfJob, t)),
Labels: generator.GenLabels(tfJob.Name),
Name: testName,
Namespace: ns,
},
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestCreateServicesWithControllerRef(t *testing.T) {

expectedService := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: generator.GenLabels(testutil.GetKey(tfJob, t)),
Labels: generator.GenLabels(tfJob.Name),
Name: testName,
Namespace: ns,
OwnerReferences: []metav1.OwnerReference{*ownerRef},
Expand Down
12 changes: 6 additions & 6 deletions pkg/control/service_ref_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestClaimServices(t *testing.T) {
func() test {
tfJob := testutil.NewTFJob(1, 0)
tfJobLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(testutil.GetKey(tfJob, t)),
MatchLabels: generator.GenLabels(tfJob.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -64,7 +64,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(testutil.GetKey(controller, t)),
MatchLabels: generator.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -90,7 +90,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(testutil.GetKey(controller, t)),
MatchLabels: generator.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -114,7 +114,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(testutil.GetKey(controller, t)),
MatchLabels: generator.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -136,7 +136,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(testutil.GetKey(controller, t)),
MatchLabels: generator.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -158,7 +158,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(testutil.GetKey(controller, t)),
MatchLabels: generator.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand Down
10 changes: 2 additions & 8 deletions pkg/controller.v2/controller_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (tc *TFJobController) createNewPod(tfjob *tfv1alpha2.TFJob, rt, index strin
controllerRef := generator.GenOwnerReference(tfjob)

// Set type and index for the worker.
labels := generator.GenLabels(tfjobKey)
labels := generator.GenLabels(tfjob.Name)
labels[tfReplicaTypeLabel] = rt
labels[tfReplicaIndexLabel] = index

Expand Down Expand Up @@ -221,15 +221,9 @@ func setRestartPolicy(podTemplateSpec *v1.PodTemplateSpec, spec *tfv1alpha2.TFRe
// It also reconciles ControllerRef by adopting/orphaning.
// Note that the returned Pods are pointers into the cache.
func (tc *TFJobController) getPodsForTFJob(tfjob *tfv1alpha2.TFJob) ([]*v1.Pod, error) {
tfjobKey, err := KeyFunc(tfjob)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for tfjob object %#v: %v", tfjob, err))
return nil, err
}

// Create selector.
selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(tfjobKey),
MatchLabels: generator.GenLabels(tfjob.Name),
})

if err != nil {
Expand Down
10 changes: 2 additions & 8 deletions pkg/controller.v2/controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (tc *TFJobController) createNewService(tfjob *tfv1alpha2.TFJob, rtype tfv1a
controllerRef := generator.GenOwnerReference(tfjob)

// Append tfReplicaTypeLabel and tfReplicaIndexLabel labels.
labels := generator.GenLabels(tfjobKey)
labels := generator.GenLabels(tfjob.Name)
labels[tfReplicaTypeLabel] = rt
labels[tfReplicaIndexLabel] = index

Expand Down Expand Up @@ -154,15 +154,9 @@ func (tc *TFJobController) createNewService(tfjob *tfv1alpha2.TFJob, rtype tfv1a
// It also reconciles ControllerRef by adopting/orphaning.
// Note that the returned services are pointers into the cache.
func (tc *TFJobController) getServicesForTFJob(tfjob *tfv1alpha2.TFJob) ([]*v1.Service, error) {
tfjobKey, err := KeyFunc(tfjob)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for tfjob object %#v: %v", tfjob, err))
return nil, err
}

// Create selector
selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(tfjobKey),
MatchLabels: generator.GenLabels(tfjob.Name),
})

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/testutil/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewBasePod(name string, tfJob *tfv1alpha2.TFJob, t *testing.T) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: generator.GenLabels(GetKey(tfJob, t)),
Labels: generator.GenLabels(tfJob.Name),
Namespace: tfJob.Namespace,
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(tfJob, controllerKind)},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/testutil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewBaseService(name string, tfJob *tfv1alpha2.TFJob, t *testing.T) *v1.Serv
return &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: generator.GenLabels(GetKey(tfJob, t)),
Labels: generator.GenLabels(tfJob.Name),
Namespace: tfJob.Namespace,
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(tfJob, controllerKind)},
},
Expand Down

0 comments on commit 8bdd2e6

Please sign in to comment.