Merge pull request #82643 from ZP-AlwaysWin/dev02
Fix bug The statefulset have duplicate revision after resource was up… Kubernetes-commit: dd8a23ca2e366ccd247179f13da372762d81b33e
This commit is contained in:
commit
fc0c7def07
|
@ -596,15 +596,15 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
"Rev": "2bd34d193bac"
|
||||
"Rev": "61aeaa97a261"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/code-generator",
|
||||
"Rev": "6206bfaf5c98"
|
||||
"Rev": "32dfb485ddce"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/component-base",
|
||||
"Rev": "ef75bdfd7a61"
|
||||
"Rev": "7bf6ff4848c1"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo",
|
||||
|
|
10
go.mod
10
go.mod
|
@ -38,8 +38,8 @@ require (
|
|||
k8s.io/api v0.0.0-20190923155552-eac758366a00
|
||||
k8s.io/apimachinery v0.0.0-20190923155427-ec87dd743e08
|
||||
k8s.io/cli-runtime v0.0.0-20190923161306-5a96b90764c8
|
||||
k8s.io/client-go v0.0.0-20190923155754-2bd34d193bac
|
||||
k8s.io/component-base v0.0.0-20190923235848-ef75bdfd7a61
|
||||
k8s.io/client-go v0.0.0-20190925195753-61aeaa97a261
|
||||
k8s.io/component-base v0.0.0-20190924075842-7bf6ff4848c1
|
||||
k8s.io/klog v1.0.0
|
||||
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf
|
||||
k8s.io/metrics v0.0.0-20190923161207-de98b87c7fe1
|
||||
|
@ -59,8 +59,8 @@ replace (
|
|||
k8s.io/api => k8s.io/api v0.0.0-20190923155552-eac758366a00
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190923155427-ec87dd743e08
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190923161306-5a96b90764c8
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20190923155754-2bd34d193bac
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190923155300-6206bfaf5c98
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20190923235848-ef75bdfd7a61
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20190925195753-61aeaa97a261
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190925195306-32dfb485ddce
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20190924075842-7bf6ff4848c1
|
||||
k8s.io/metrics => k8s.io/metrics v0.0.0-20190923161207-de98b87c7fe1
|
||||
)
|
||||
|
|
6
go.sum
6
go.sum
|
@ -291,9 +291,9 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
|
|||
k8s.io/api v0.0.0-20190923155552-eac758366a00/go.mod h1:blPYY5r6fKug8SVOnjDtFAlzZzInCRL9NNls66SFhFI=
|
||||
k8s.io/apimachinery v0.0.0-20190923155427-ec87dd743e08/go.mod h1:grJJH0hgilA2pYoUiJcPu2EDUal95NTq1vpxxvMLSu8=
|
||||
k8s.io/cli-runtime v0.0.0-20190923161306-5a96b90764c8/go.mod h1:eF2knbzCHQ4V2lprgPOHejvS3d43jpDbNjN9cpqim98=
|
||||
k8s.io/client-go v0.0.0-20190923155754-2bd34d193bac/go.mod h1:D/1Tps6X8s8BMlqc5uhTjIUymrZ9AJqNc4nUpFrcf20=
|
||||
k8s.io/code-generator v0.0.0-20190923155300-6206bfaf5c98/go.mod h1:4MfOrxyyZxxCuenwsdaJRtoSnOP5T13jE2LRYPZ6KeY=
|
||||
k8s.io/component-base v0.0.0-20190923235848-ef75bdfd7a61/go.mod h1:zlnjiRdNFPvJLV16ktKZMcA+4qALVDa93nxbKBoZc5A=
|
||||
k8s.io/client-go v0.0.0-20190925195753-61aeaa97a261/go.mod h1:D/1Tps6X8s8BMlqc5uhTjIUymrZ9AJqNc4nUpFrcf20=
|
||||
k8s.io/code-generator v0.0.0-20190925195306-32dfb485ddce/go.mod h1:4MfOrxyyZxxCuenwsdaJRtoSnOP5T13jE2LRYPZ6KeY=
|
||||
k8s.io/component-base v0.0.0-20190924075842-7bf6ff4848c1/go.mod h1:zlnjiRdNFPvJLV16ktKZMcA+4qALVDa93nxbKBoZc5A=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/gengo v0.0.0-20190822140433-26a664648505/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
|
|
|
@ -242,7 +242,7 @@ func (h *StatefulSetHistoryViewer) ViewHistory(namespace, name string, revision
|
|||
if len(history) <= 0 {
|
||||
return "No rollout history found.", nil
|
||||
}
|
||||
revisions := make([]int64, len(history))
|
||||
revisions := make([]int64, 0, len(history))
|
||||
for _, revision := range history {
|
||||
revisions = append(revisions, revision.Revision)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ limitations under the License.
|
|||
package polymorphichelpers
|
||||
|
||||
import (
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -44,3 +47,61 @@ func TestHistoryViewerFor(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewHistory(t *testing.T) {
|
||||
|
||||
var (
|
||||
trueVar = true
|
||||
replicas = int32(1)
|
||||
|
||||
podStub = corev1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"foo": "bar"}},
|
||||
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "test", Image: "nginx"}}},
|
||||
}
|
||||
|
||||
ssStub = &appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "moons",
|
||||
Namespace: "default",
|
||||
UID: "1993",
|
||||
Labels: map[string]string{"foo": "bar"},
|
||||
},
|
||||
Spec: appsv1.StatefulSetSpec{Selector: &metav1.LabelSelector{MatchLabels: podStub.ObjectMeta.Labels}, Replicas: &replicas, Template: podStub},
|
||||
}
|
||||
|
||||
ssStub1 = &appsv1.ControllerRevision{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "moons",
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{"foo": "bar"},
|
||||
OwnerReferences: []metav1.OwnerReference{{"apps/v1", "StatefulSet", "moons", "1993", &trueVar, nil}},
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{Kind: "StatefulSet", APIVersion: "apps/v1"},
|
||||
Revision: 1,
|
||||
}
|
||||
)
|
||||
|
||||
fakeClientSet := fake.NewSimpleClientset(ssStub)
|
||||
_, err := fakeClientSet.AppsV1().ControllerRevisions("default").Create(ssStub1)
|
||||
if err != nil {
|
||||
t.Fatalf("create controllerRevisions error %v occurred ", err)
|
||||
}
|
||||
|
||||
var sts = &StatefulSetHistoryViewer{
|
||||
fakeClientSet,
|
||||
}
|
||||
|
||||
result, err := sts.ViewHistory("default", "moons", 1)
|
||||
if err != nil {
|
||||
t.Fatalf("error getting ViewHistory for a StatefulSets moons: %v", err)
|
||||
}
|
||||
|
||||
expected := `REVISION
|
||||
1
|
||||
`
|
||||
|
||||
if result != expected {
|
||||
t.Fatalf("unexpected output (%v was expected but got %v)", expected, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue