提交 0ba3eb6f 编写于 作者: L Luiz Felipe G. Pereira

Adding old replica sets

上级 b2ebb59f
...@@ -4,9 +4,9 @@ import ( ...@@ -4,9 +4,9 @@ import (
"log" "log"
"github.com/kubernetes/dashboard/resource/common" "github.com/kubernetes/dashboard/resource/common"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
deploymentutil "k8s.io/kubernetes/pkg/util/deployment"
) )
type RollingUpdateStrategy struct { type RollingUpdateStrategy struct {
...@@ -31,15 +31,17 @@ type DeploymentDetail struct { ...@@ -31,15 +31,17 @@ type DeploymentDetail struct {
// Min ready seconds // Min ready seconds
MinReadySeconds int `json:"minReadySeconds"` MinReadySeconds int `json:"minReadySeconds"`
// Rolling update strategy // Rolling update strategy containing maxSurge and maxUnavailable
// 1 max unavailable, 1 max surge
RollingUpdateStrategy `json:"rollingUpdateStrategy,omitempty"` RollingUpdateStrategy `json:"rollingUpdateStrategy,omitempty"`
//OldReplicaSets // OldReplicaSets
OldReplicaSets []extensions.ReplicaSet `json:"oldReplicaSets"`
//NewReplicaSet // NewReplicaSet
NewReplicaSet extensions.ReplicaSet `json:"newReplicaSet"`
//Events // Events
// TODO
} }
func GetDeploymentDetail(client client.Interface, namespace string, name string) (*DeploymentDetail, error) { func GetDeploymentDetail(client client.Interface, namespace string, name string) (*DeploymentDetail, error) {
...@@ -51,10 +53,40 @@ func GetDeploymentDetail(client client.Interface, namespace string, name string) ...@@ -51,10 +53,40 @@ func GetDeploymentDetail(client client.Interface, namespace string, name string)
return nil, err return nil, err
} }
return getDeploymentDetail(deploymentData), nil channels := &common.ResourceChannels{
ReplicaSetList: common.GetReplicaSetListChannel(client.Extensions(), 1),
PodList: common.GetPodListChannel(client, 1),
}
replicaSetList := <-channels.ReplicaSetList.List
if err := <-channels.ReplicaSetList.Error; err != nil {
return nil, err
}
pods := <-channels.PodList.List
if err := <-channels.PodList.Error; err != nil {
return nil, err
}
oldReplicaSets, _, err := deploymentutil.FindOldReplicaSets(deploymentData, replicaSetList.Items, pods)
if err != nil {
return nil, err
}
//newReplicaSet, err := deploymentutil.FindNewReplicaSet(deploymentData, replicaSetList.Items)
//if err != nil {
//return nil, err
//}
return getDeploymentDetail(deploymentData, oldReplicaSets), nil
} }
func getDeploymentDetail(deployment *extensions.Deployment) *DeploymentDetail { func getDeploymentDetail(deployment *extensions.Deployment, old []*extensions.ReplicaSet) *DeploymentDetail {
oldReplicaSets := make([]extensions.ReplicaSet, len(old))
for i, replicaSet := range old {
oldReplicaSets[i] = *replicaSet
}
return &DeploymentDetail{ return &DeploymentDetail{
ObjectMeta: common.NewObjectMeta(deployment.ObjectMeta), ObjectMeta: common.NewObjectMeta(deployment.ObjectMeta),
...@@ -67,5 +99,7 @@ func getDeploymentDetail(deployment *extensions.Deployment) *DeploymentDetail { ...@@ -67,5 +99,7 @@ func getDeploymentDetail(deployment *extensions.Deployment) *DeploymentDetail {
MaxSurge: deployment.Spec.Strategy.RollingUpdate.MaxSurge.IntValue(), MaxSurge: deployment.Spec.Strategy.RollingUpdate.MaxSurge.IntValue(),
MaxUnavailable: deployment.Spec.Strategy.RollingUpdate.MaxUnavailable.IntValue(), MaxUnavailable: deployment.Spec.Strategy.RollingUpdate.MaxUnavailable.IntValue(),
}, },
OldReplicaSets: oldReplicaSets,
//NewReplicaSet: *newReplicaSet,
} }
} }
...@@ -8,12 +8,63 @@ import ( ...@@ -8,12 +8,63 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/unversioned/testclient" "k8s.io/kubernetes/pkg/client/unversioned/testclient"
deploymentutil "k8s.io/kubernetes/pkg/util/deployment"
"k8s.io/kubernetes/pkg/util/intstr" "k8s.io/kubernetes/pkg/util/intstr"
"github.com/kubernetes/dashboard/resource/common" "github.com/kubernetes/dashboard/resource/common"
) )
func TestGetDeploymentDetailFromChannels(t *testing.T) { func TestGetDeploymentDetail(t *testing.T) {
podList := &api.PodList{}
deployment := &extensions.Deployment{
ObjectMeta: api.ObjectMeta{
Name: "test-name",
Labels: map[string]string{"track": "beta"},
},
Spec: extensions.DeploymentSpec{
Selector: &unversioned.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
Replicas: 4,
MinReadySeconds: 5,
Strategy: extensions.DeploymentStrategy{
Type: extensions.RollingUpdateDeploymentStrategyType,
RollingUpdate: &extensions.RollingUpdateDeployment{
MaxSurge: intstr.FromInt(1),
MaxUnavailable: intstr.FromString("1"),
},
},
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Name: "test-pod-name",
Labels: map[string]string{"track": "beta"},
},
},
},
Status: extensions.DeploymentStatus{
Replicas: 4,
UpdatedReplicas: 2,
AvailableReplicas: 3,
UnavailableReplicas: 1,
},
}
podTemplateSpec := deploymentutil.GetNewReplicaSetTemplate(deployment)
newReplicaSet := extensions.ReplicaSet{
ObjectMeta: api.ObjectMeta{Name: "replica-set-1"},
Spec: extensions.ReplicaSetSpec{
Template: podTemplateSpec,
},
}
replicaSetList := &extensions.ReplicaSetList{
Items: []extensions.ReplicaSet{
newReplicaSet,
{
ObjectMeta: api.ObjectMeta{Name: "replica-set-2"},
},
},
}
cases := []struct { cases := []struct {
namespace, name string namespace, name string
...@@ -23,32 +74,15 @@ func TestGetDeploymentDetailFromChannels(t *testing.T) { ...@@ -23,32 +74,15 @@ func TestGetDeploymentDetailFromChannels(t *testing.T) {
}{ }{
{ {
"test-namespace", "test-name", "test-namespace", "test-name",
[]string{"get"}, []string{"get", "list", "list"},
&extensions.Deployment{ deployment,
ObjectMeta: api.ObjectMeta{Name: "test-name"},
Spec: extensions.DeploymentSpec{
Selector: &unversioned.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
Replicas: 4,
MinReadySeconds: 5,
Strategy: extensions.DeploymentStrategy{
Type: extensions.RollingUpdateDeploymentStrategyType,
RollingUpdate: &extensions.RollingUpdateDeployment{
MaxSurge: intstr.FromInt(1),
MaxUnavailable: intstr.FromString("1"),
},
},
},
Status: extensions.DeploymentStatus{
Replicas: 4,
UpdatedReplicas: 2,
AvailableReplicas: 3,
UnavailableReplicas: 1,
},
},
&DeploymentDetail{ &DeploymentDetail{
ObjectMeta: common.ObjectMeta{Name: "test-name"}, ObjectMeta: common.ObjectMeta{
TypeMeta: common.TypeMeta{Kind: common.ResourceKindDeployment}, Name: "test-name",
Selector: map[string]string{"foo": "bar"}, Labels: map[string]string{"track": "beta"},
},
TypeMeta: common.TypeMeta{Kind: common.ResourceKindDeployment},
Selector: map[string]string{"foo": "bar"},
Status: extensions.DeploymentStatus{ Status: extensions.DeploymentStatus{
Replicas: 4, Replicas: 4,
UpdatedReplicas: 2, UpdatedReplicas: 2,
...@@ -61,13 +95,15 @@ func TestGetDeploymentDetailFromChannels(t *testing.T) { ...@@ -61,13 +95,15 @@ func TestGetDeploymentDetailFromChannels(t *testing.T) {
MaxSurge: 1, MaxSurge: 1,
MaxUnavailable: 1, MaxUnavailable: 1,
}, },
OldReplicaSets: []extensions.ReplicaSet{},
//NewReplicaSet: newReplicaSet,
}, },
}, },
} }
for _, c := range cases { for _, c := range cases {
fakeClient := testclient.NewSimpleFake(c.deployment) fakeClient := testclient.NewSimpleFake(c.deployment, replicaSetList, podList)
actual, _ := GetDeploymentDetail(fakeClient, c.namespace, c.name) actual, _ := GetDeploymentDetail(fakeClient, c.namespace, c.name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册