Skip to content

Commit

Permalink
fix label selector and deployment util
Browse files Browse the repository at this point in the history
  • Loading branch information
Song Gao committed Mar 27, 2020
1 parent 0fe67bf commit 727988d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 10 additions & 1 deletion pkg/controller/generic_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,26 @@ func (w *typedWrapper) CreateOrUpdateDeployment(controller runtime.Object, deplo
for k, v := range desiredDep.Annotations {
existingDep.Annotations[k] = v
}
for k, v := range desiredDep.Labels {
existingDep.Labels[k] = v
}
existingDep.Spec.Selector = desiredDep.Spec.Selector

// only override the default strategy if it is explicitly set in the desiredDep
if string(desiredDep.Spec.Strategy.Type) != "" {
existingDep.Spec.Strategy.Type = desiredDep.Spec.Strategy.Type
if existingDep.Spec.Strategy.RollingUpdate != nil {
existingDep.Spec.Strategy.RollingUpdate = desiredDep.Spec.Strategy.RollingUpdate
}
}
// pod selector of deployment is immutable, so we don't mutate the labels of pod

for k, v := range desiredDep.Spec.Template.Annotations {
existingDep.Spec.Template.Annotations[k] = v
}
for k, v := range desiredDep.Spec.Template.Labels {
desiredDep.Spec.Template.Labels[k] = v
}

// podSpec of deployment is hard to merge, use an annotation to assist
if DeploymentPodSpecChanged(desiredDep, existingDep) {
// Record last applied spec in favor of future equality check
Expand Down
14 changes: 4 additions & 10 deletions pkg/monitor/monitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,8 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
TargetPort: intstr.FromInt(9089),
},
},
Type: monitor.Spec.Reloader.Service.Type,
Selector: map[string]string{
label.InstanceLabelKey: monitor.Name,
label.ComponentLabelKey: label.TiDBMonitorVal,
},
Type: monitor.Spec.Reloader.Service.Type,
Selector: labels,
},
}

Expand Down Expand Up @@ -748,11 +745,8 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
TargetPort: intstr.FromInt(3000),
},
},
Type: monitor.Spec.Grafana.Service.Type,
Selector: map[string]string{
label.InstanceLabelKey: monitor.Name,
label.ComponentLabelKey: label.TiDBMonitorVal,
},
Type: monitor.Spec.Grafana.Service.Type,
Selector: labels,
},
}

Expand Down

0 comments on commit 727988d

Please sign in to comment.