Skip to content

Commit

Permalink
Fix wrong method to get tikv configmap in mutation webhook (#1871) (#…
Browse files Browse the repository at this point in the history
…1874)

* fix cmName

* Update pod_mutater.go

* Update pod_mutater.go

* Update pkg/webhook/pod/pod_mutater.go

Co-Authored-By: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com>

Co-authored-by: Song Gao <2695690803@qq.com>
Co-authored-by: Song Gao <disxiaofei@163.com>
Co-authored-by: DanielZhangQD <36026334+DanielZhangQD@users.noreply.github.com>
  • Loading branch information
4 people authored Mar 6, 2020
1 parent 5109ed5 commit a0785f7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/webhook/pod/pod_mutater.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/features"
"github.com/pingcap/tidb-operator/pkg/label"
operatorUtils "github.com/pingcap/tidb-operator/pkg/util"
Expand Down Expand Up @@ -82,10 +81,9 @@ func (pc *PodAdmissionControl) tikvHotRegionSchedule(tc *v1alpha1.TidbCluster, p
return nil
}

cmName := controller.TiKVMemberName(tc.Name)
cm, err := pc.kubeCli.CoreV1().ConfigMaps(tc.Namespace).Get(cmName, metav1.GetOptions{})
cm, err := pc.getTikvConfigMap(tc, pod)
if err != nil {
klog.Infof("cm[%s/%s] found error,err %v", tc.Namespace, cmName, err)
klog.Infof("tc[%s/%s]'s tikv %s configmap not found, error: %v", tc.Namespace, tc.Name, pod.Name, err)
return err
}
v, ok := cm.Data["config-file"]
Expand Down Expand Up @@ -114,3 +112,18 @@ func (pc *PodAdmissionControl) tikvHotRegionSchedule(tc *v1alpha1.TidbCluster, p
}
return nil
}

// Get tikv original configmap from the pod spec template volume
func (pc *PodAdmissionControl) getTikvConfigMap(tc *v1alpha1.TidbCluster, pod *corev1.Pod) (*corev1.ConfigMap, error) {
cnName := ""
for _, v := range pod.Spec.Volumes {
if (v.Name == "config" || v.Name == "startup-script") && v.ConfigMap != nil {
cnName = v.ConfigMap.Name
break
}
}
if cnName == "" {
return nil, fmt.Errorf("tc[%s/%s] 's tikv configmap can't find", tc.Namespace, tc.Name)
}
return pc.kubeCli.CoreV1().ConfigMaps(tc.Namespace).Get(cnName, metav1.GetOptions{})
}

0 comments on commit a0785f7

Please sign in to comment.