Merge pull request #113083 from llorllale/deploy-describe-oldreplicasets
fix OldReplicaSets in `kubectl describe deploy` Kubernetes-commit: d19aaa7c8551a249de942a70cb3000fcdd6ecb62
This commit is contained in:
commit
bece78d445
|
@ -4319,7 +4319,7 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldRSs, newRSs []*appsv1.ReplicaSet
|
var oldRSs, newRSs []*appsv1.ReplicaSet
|
||||||
if oldResult, _, newResult, err := deploymentutil.GetAllReplicaSetsInChunks(d, dd.client.AppsV1(), describerSettings.ChunkSize); err == nil {
|
if _, oldResult, newResult, err := deploymentutil.GetAllReplicaSetsInChunks(d, dd.client.AppsV1(), describerSettings.ChunkSize); err == nil {
|
||||||
oldRSs = oldResult
|
oldRSs = oldResult
|
||||||
if newResult != nil {
|
if newResult != nil {
|
||||||
newRSs = append(newRSs, newResult)
|
newRSs = append(newRSs, newResult)
|
||||||
|
|
|
@ -2372,6 +2372,302 @@ func TestDescribeDeployment(t *testing.T) {
|
||||||
"Normal ScalingReplicaSet 60s deployment-controller Scaled down replica set bar-002 to 1",
|
"Normal ScalingReplicaSet 60s deployment-controller Scaled down replica set bar-002 to 1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "deployment after successful rollout",
|
||||||
|
objects: []runtime.Object{
|
||||||
|
&appsv1.Deployment{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
Labels: labels,
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
CreationTimestamp: metav1.NewTime(time.Date(2021, time.Month(1), 1, 0, 0, 0, 0, time.UTC)),
|
||||||
|
},
|
||||||
|
Spec: appsv1.DeploymentSpec{
|
||||||
|
Replicas: utilpointer.Int32Ptr(2),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: labels,
|
||||||
|
},
|
||||||
|
Template: corev1.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
Labels: labels,
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Image: "mytest-image:v2.0",
|
||||||
|
VolumeMounts: []corev1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "vol-foo",
|
||||||
|
MountPath: "/tmp/vol-foo",
|
||||||
|
}, {
|
||||||
|
Name: "vol-bar",
|
||||||
|
MountPath: "/tmp/vol-bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Volumes: []corev1.Volume{
|
||||||
|
{
|
||||||
|
Name: "vol-foo",
|
||||||
|
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "vol-bar",
|
||||||
|
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Status: appsv1.DeploymentStatus{
|
||||||
|
Replicas: 2,
|
||||||
|
UpdatedReplicas: 2,
|
||||||
|
AvailableReplicas: 2,
|
||||||
|
UnavailableReplicas: 0,
|
||||||
|
},
|
||||||
|
}, &appsv1.ReplicaSet{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-001",
|
||||||
|
Namespace: "foo",
|
||||||
|
Labels: labels,
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
OwnerReferences: []metav1.OwnerReference{
|
||||||
|
{
|
||||||
|
Controller: utilpointer.BoolPtr(true),
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: appsv1.ReplicaSetSpec{
|
||||||
|
Replicas: utilpointer.Int32Ptr(0),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: labels,
|
||||||
|
},
|
||||||
|
Template: corev1.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
Labels: labels,
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Image: "mytest-image:v1.0",
|
||||||
|
VolumeMounts: []corev1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "vol-foo",
|
||||||
|
MountPath: "/tmp/vol-foo",
|
||||||
|
}, {
|
||||||
|
Name: "vol-bar",
|
||||||
|
MountPath: "/tmp/vol-bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Volumes: []corev1.Volume{
|
||||||
|
{
|
||||||
|
Name: "vol-foo",
|
||||||
|
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "vol-bar",
|
||||||
|
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Status: appsv1.ReplicaSetStatus{
|
||||||
|
Replicas: 0,
|
||||||
|
ReadyReplicas: 0,
|
||||||
|
AvailableReplicas: 0,
|
||||||
|
},
|
||||||
|
}, &appsv1.ReplicaSet{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-002",
|
||||||
|
Namespace: "foo",
|
||||||
|
Labels: labels,
|
||||||
|
UID: "00000000-0000-0000-0000-000000000002",
|
||||||
|
OwnerReferences: []metav1.OwnerReference{
|
||||||
|
{
|
||||||
|
Controller: utilpointer.BoolPtr(true),
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: appsv1.ReplicaSetSpec{
|
||||||
|
Replicas: utilpointer.Int32Ptr(2),
|
||||||
|
Selector: &metav1.LabelSelector{
|
||||||
|
MatchLabels: labels,
|
||||||
|
},
|
||||||
|
Template: corev1.PodTemplateSpec{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
Labels: labels,
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Image: "mytest-image:v2.0",
|
||||||
|
VolumeMounts: []corev1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "vol-foo",
|
||||||
|
MountPath: "/tmp/vol-foo",
|
||||||
|
}, {
|
||||||
|
Name: "vol-bar",
|
||||||
|
MountPath: "/tmp/vol-bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Volumes: []corev1.Volume{
|
||||||
|
{
|
||||||
|
Name: "vol-foo",
|
||||||
|
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "vol-bar",
|
||||||
|
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Status: appsv1.ReplicaSetStatus{
|
||||||
|
Replicas: 2,
|
||||||
|
ReadyReplicas: 2,
|
||||||
|
AvailableReplicas: 2,
|
||||||
|
},
|
||||||
|
}, &corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-000",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
Type: corev1.EventTypeNormal,
|
||||||
|
Reason: "ScalingReplicaSet",
|
||||||
|
Message: "Scaled up replica set bar-002 to 1",
|
||||||
|
ReportingController: "deployment-controller",
|
||||||
|
EventTime: metav1.NewMicroTime(time.Now().Add(-20 * time.Minute)),
|
||||||
|
Series: &corev1.EventSeries{
|
||||||
|
Count: 3,
|
||||||
|
LastObservedTime: metav1.NewMicroTime(time.Now().Add(-12 * time.Minute)),
|
||||||
|
},
|
||||||
|
}, &corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-001",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
Type: corev1.EventTypeNormal,
|
||||||
|
Reason: "ScalingReplicaSet",
|
||||||
|
Message: "Scaled up replica set bar-001 to 2",
|
||||||
|
Source: corev1.EventSource{
|
||||||
|
Component: "deployment-controller",
|
||||||
|
},
|
||||||
|
FirstTimestamp: metav1.NewTime(time.Now().Add(-10 * time.Minute)),
|
||||||
|
}, &corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-002",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
Type: corev1.EventTypeNormal,
|
||||||
|
Reason: "ScalingReplicaSet",
|
||||||
|
Message: "Scaled up replica set bar-002 to 1",
|
||||||
|
Source: corev1.EventSource{
|
||||||
|
Component: "deployment-controller",
|
||||||
|
},
|
||||||
|
FirstTimestamp: metav1.NewTime(time.Now().Add(-2 * time.Minute)),
|
||||||
|
}, &corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-003",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
Type: corev1.EventTypeNormal,
|
||||||
|
Reason: "ScalingReplicaSet",
|
||||||
|
Message: "Scaled down replica set bar-002 to 1",
|
||||||
|
ReportingController: "deployment-controller",
|
||||||
|
EventTime: metav1.NewMicroTime(time.Now().Add(-1 * time.Minute)),
|
||||||
|
}, &corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-004",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
Type: corev1.EventTypeNormal,
|
||||||
|
Reason: "ScalingReplicaSet",
|
||||||
|
Message: "Scaled up replica set bar-002 to 2",
|
||||||
|
ReportingController: "deployment-controller",
|
||||||
|
EventTime: metav1.NewMicroTime(time.Now().Add(-15 * time.Second)),
|
||||||
|
}, &corev1.Event{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "bar-005",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
InvolvedObject: corev1.ObjectReference{
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
Kind: "Deployment",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "foo",
|
||||||
|
UID: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
Type: corev1.EventTypeNormal,
|
||||||
|
Reason: "ScalingReplicaSet",
|
||||||
|
Message: "Scaled down replica set bar-001 to 0",
|
||||||
|
ReportingController: "deployment-controller",
|
||||||
|
EventTime: metav1.NewMicroTime(time.Now().Add(-3 * time.Second)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expects: []string{
|
||||||
|
"Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable",
|
||||||
|
"Image: mytest-image:v2.0",
|
||||||
|
"OldReplicaSets: bar-001 (0/0 replicas created)",
|
||||||
|
"NewReplicaSet: bar-002 (2/2 replicas created)",
|
||||||
|
"Events:\n",
|
||||||
|
"Normal ScalingReplicaSet 12m (x3 over 20m) deployment-controller Scaled up replica set bar-002 to 1",
|
||||||
|
"Normal ScalingReplicaSet 10m deployment-controller Scaled up replica set bar-001 to 2",
|
||||||
|
"Normal ScalingReplicaSet 2m deployment-controller Scaled up replica set bar-002 to 1",
|
||||||
|
"Normal ScalingReplicaSet 60s deployment-controller Scaled down replica set bar-002 to 1",
|
||||||
|
"Normal ScalingReplicaSet 15s deployment-controller Scaled up replica set bar-002 to 2",
|
||||||
|
"Normal ScalingReplicaSet 3s deployment-controller Scaled down replica set bar-001 to 0",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue