mirror of https://github.com/kubernetes/kops.git
Protokube should mount volumes in a consistent order
And always mounting the main volume first should be a little faster Fix #934
This commit is contained in:
parent
1e3e14add5
commit
911826e397
1
Makefile
1
Makefile
|
|
@ -78,6 +78,7 @@ codegen: kops-gobindata
|
||||||
test:
|
test:
|
||||||
go test k8s.io/kops/pkg/... -args -v=1 -logtostderr
|
go test k8s.io/kops/pkg/... -args -v=1 -logtostderr
|
||||||
go test k8s.io/kops/upup/pkg/... -args -v=1 -logtostderr
|
go test k8s.io/kops/upup/pkg/... -args -v=1 -logtostderr
|
||||||
|
go test k8s.io/kops/protokube/... -args -v=1 -logtostderr
|
||||||
go test k8s.io/kops/dns-controller/pkg/... -args -v=1 -logtostderr
|
go test k8s.io/kops/dns-controller/pkg/... -args -v=1 -logtostderr
|
||||||
go test k8s.io/kops/cmd/... -args -v=1 -logtostderr
|
go test k8s.io/kops/cmd/... -args -v=1 -logtostderr
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/util/exec"
|
"k8s.io/kubernetes/pkg/util/exec"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -193,6 +194,8 @@ func (k *VolumeMountController) attachMasterVolumes() ([]*Volume, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tryAttach) != 0 {
|
if len(tryAttach) != 0 {
|
||||||
|
sort.Stable(ByEtcdClusterName(tryAttach))
|
||||||
|
|
||||||
for _, v := range tryAttach {
|
for _, v := range tryAttach {
|
||||||
glog.V(2).Infof("Trying to mount master volume: %q", v.ID)
|
glog.V(2).Infof("Trying to mount master volume: %q", v.ID)
|
||||||
|
|
||||||
|
|
@ -210,3 +213,26 @@ func (k *VolumeMountController) attachMasterVolumes() ([]*Volume, error) {
|
||||||
|
|
||||||
return attached, nil
|
return attached, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByEtcdClusterName sorts volumes so that we mount in a consistent order,
|
||||||
|
// and in particular we try to mount the main etcd volume before the events etcd volume
|
||||||
|
type ByEtcdClusterName []*Volume
|
||||||
|
|
||||||
|
func (a ByEtcdClusterName) Len() int {
|
||||||
|
return len(a)
|
||||||
|
}
|
||||||
|
func (a ByEtcdClusterName) Swap(i, j int) {
|
||||||
|
a[i], a[j] = a[j], a[i]
|
||||||
|
}
|
||||||
|
func (a ByEtcdClusterName) Less(i, j int) bool {
|
||||||
|
nameI := ""
|
||||||
|
if len(a[i].Info.EtcdClusters) > 0 {
|
||||||
|
nameI = a[i].Info.EtcdClusters[0].ClusterKey
|
||||||
|
}
|
||||||
|
nameJ := ""
|
||||||
|
if len(a[j].Info.EtcdClusters) > 0 {
|
||||||
|
nameJ = a[j].Info.EtcdClusters[0].ClusterKey
|
||||||
|
}
|
||||||
|
// reverse so "main" comes before "events"
|
||||||
|
return nameI > nameJ
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package protokube
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getIDs(volumes []*Volume) string {
|
||||||
|
var ids []string
|
||||||
|
for _, v := range volumes {
|
||||||
|
ids = append(ids, v.ID)
|
||||||
|
}
|
||||||
|
return strings.Join(ids, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_VolumeSort_ByEtcdClusterName(t *testing.T) {
|
||||||
|
v1 := &Volume{}
|
||||||
|
v1.ID = "1"
|
||||||
|
v2 := &Volume{}
|
||||||
|
v2.ID = "2"
|
||||||
|
v3 := &Volume{}
|
||||||
|
v3.ID = "3"
|
||||||
|
|
||||||
|
volumes := []*Volume{v1, v2, v3}
|
||||||
|
sort.Stable(ByEtcdClusterName(volumes))
|
||||||
|
if getIDs(volumes) != "1,2,3" {
|
||||||
|
t.Fatalf("Fail at sort 1: %v", getIDs(volumes))
|
||||||
|
}
|
||||||
|
|
||||||
|
v2.Info.EtcdClusters = append(v2.Info.EtcdClusters, &EtcdClusterSpec{ClusterKey: "events"})
|
||||||
|
sort.Stable(ByEtcdClusterName(volumes))
|
||||||
|
if getIDs(volumes) != "2,1,3" {
|
||||||
|
t.Fatalf("Fail at sort 2: %v", getIDs(volumes))
|
||||||
|
}
|
||||||
|
|
||||||
|
v3.Info.EtcdClusters = append(v3.Info.EtcdClusters, &EtcdClusterSpec{ClusterKey: "main"})
|
||||||
|
sort.Stable(ByEtcdClusterName(volumes))
|
||||||
|
if getIDs(volumes) != "3,2,1" {
|
||||||
|
t.Fatalf("Fail at sort 3: %v", getIDs(volumes))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue