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

Adding old replica sets

上级 b2ebb59f
......@@ -4,9 +4,9 @@ import (
"log"
"github.com/kubernetes/dashboard/resource/common"
"k8s.io/kubernetes/pkg/apis/extensions"
client "k8s.io/kubernetes/pkg/client/unversioned"
deploymentutil "k8s.io/kubernetes/pkg/util/deployment"
)
type RollingUpdateStrategy struct {
......@@ -31,15 +31,17 @@ type DeploymentDetail struct {
// Min ready seconds
MinReadySeconds int `json:"minReadySeconds"`
// Rolling update strategy
// 1 max unavailable, 1 max surge
// Rolling update strategy containing maxSurge and maxUnavailable
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) {
......@@ -51,10 +53,40 @@ func GetDeploymentDetail(client client.Interface, namespace string, name string)
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{
ObjectMeta: common.NewObjectMeta(deployment.ObjectMeta),
......@@ -67,5 +99,7 @@ func getDeploymentDetail(deployment *extensions.Deployment) *DeploymentDetail {
MaxSurge: deployment.Spec.Strategy.RollingUpdate.MaxSurge.IntValue(),
MaxUnavailable: deployment.Spec.Strategy.RollingUpdate.MaxUnavailable.IntValue(),
},
OldReplicaSets: oldReplicaSets,
//NewReplicaSet: *newReplicaSet,
}
}
......@@ -8,12 +8,63 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
deploymentutil "k8s.io/kubernetes/pkg/util/deployment"
"k8s.io/kubernetes/pkg/util/intstr"
"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 {
namespace, name string
......@@ -23,32 +74,15 @@ func TestGetDeploymentDetailFromChannels(t *testing.T) {
}{
{
"test-namespace", "test-name",
[]string{"get"},
&extensions.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,
},
},
[]string{"get", "list", "list"},
deployment,
&DeploymentDetail{
ObjectMeta: common.ObjectMeta{Name: "test-name"},
TypeMeta: common.TypeMeta{Kind: common.ResourceKindDeployment},
Selector: map[string]string{"foo": "bar"},
ObjectMeta: common.ObjectMeta{
Name: "test-name",
Labels: map[string]string{"track": "beta"},
},
TypeMeta: common.TypeMeta{Kind: common.ResourceKindDeployment},
Selector: map[string]string{"foo": "bar"},
Status: extensions.DeploymentStatus{
Replicas: 4,
UpdatedReplicas: 2,
......@@ -61,13 +95,15 @@ func TestGetDeploymentDetailFromChannels(t *testing.T) {
MaxSurge: 1,
MaxUnavailable: 1,
},
OldReplicaSets: []extensions.ReplicaSet{},
//NewReplicaSet: newReplicaSet,
},
},
}
for _, c := range cases {
fakeClient := testclient.NewSimpleFake(c.deployment)
fakeClient := testclient.NewSimpleFake(c.deployment, replicaSetList, podList)
actual, _ := GetDeploymentDetail(fakeClient, c.namespace, c.name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册