Skip to content

Commit a2ffdbe

Browse files
Merge pull request #150 from vaspahomov/ft/namespaced-pod-names-status
NamespacedName in PendingPods status field
2 parents 0c14ae8 + 8363cca commit a2ffdbe

8 files changed

+78
-1
lines changed

api/v1beta1/nodemaintenance_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ type NodeMaintenanceSpec struct {
5353
Reason string `json:"reason,omitempty"`
5454
}
5555

56+
type PodReference struct {
57+
// Namespace of the referent pod.
58+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
59+
// +optional
60+
Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"`
61+
// Name of the referent pod.
62+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
63+
// +optional
64+
Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"`
65+
}
66+
5667
// NodeMaintenanceStatus defines the observed state of NodeMaintenance
5768
type NodeMaintenanceStatus struct {
5869
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
@@ -73,6 +84,9 @@ type NodeMaintenanceStatus struct {
7384
// PendingPods is a list of pending pods for eviction
7485
//+operator-sdk:csv:customresourcedefinitions:type=status
7586
PendingPods []string `json:"pendingPods,omitempty"`
87+
// PendingPodsRefs is a list of refs of pending pods for eviction
88+
//+operator-sdk:csv:customresourcedefinitions:type=status
89+
PendingPodsRefs []PodReference `json:"pendingPodsRefs,omitempty"`
7690
// TotalPods is the total number of all pods on the node from the start
7791
//+operator-sdk:csv:customresourcedefinitions:type=status
7892
TotalPods int `json:"totalpods,omitempty"`

bundle/manifests/node-maintenance-operator.clusterserviceversion.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ spec:
6969
- description: PendingPods is a list of pending pods for eviction
7070
displayName: Pending Pods
7171
path: pendingPods
72+
- description: PendingPodsRefs is a list of refs of pending pods for eviction
73+
displayName: Pending Pods Refs
74+
path: pendingPodsRefs
7275
- description: Phase is the represtation of the maintenance progress (Running,Succeeded,Failed)
7376
displayName: Phase
7477
path: phase

bundle/manifests/nodemaintenance.medik8s.io_nodemaintenances.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ spec:
7878
items:
7979
type: string
8080
type: array
81+
pendingPodsRefs:
82+
description: PendingPodsRefs is a list of refs of pending pods for
83+
eviction
84+
items:
85+
properties:
86+
name:
87+
description: |-
88+
Name of the referent pod.
89+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
90+
type: string
91+
namespace:
92+
description: |-
93+
Namespace of the referent pod.
94+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
95+
type: string
96+
type: object
97+
type: array
8198
phase:
8299
description: Phase is the represtation of the maintenance progress
83100
(Running,Succeeded,Failed)

config/crd/bases/nodemaintenance.medik8s.io_nodemaintenances.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ spec:
7676
items:
7777
type: string
7878
type: array
79+
pendingPodsRefs:
80+
description: PendingPodsRefs is a list of refs of pending pods for
81+
eviction
82+
items:
83+
properties:
84+
name:
85+
description: |-
86+
Name of the referent pod.
87+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
88+
type: string
89+
namespace:
90+
description: |-
91+
Namespace of the referent pod.
92+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
93+
type: string
94+
type: object
95+
type: array
7996
phase:
8097
description: Phase is the represtation of the maintenance progress
8198
(Running,Succeeded,Failed)

config/manifests/bases/node-maintenance-operator.clusterserviceversion.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ spec:
5454
- description: PendingPods is a list of pending pods for eviction
5555
displayName: Pending Pods
5656
path: pendingPods
57+
- description: PendingPodsRefs is a list of refs of pending pods for eviction
58+
displayName: Pending Pods Refs
59+
path: pendingPodsRefs
5760
- description: Phase is the represtation of the maintenance progress (Running,Succeeded,Failed)
5861
displayName: Phase
5962
path: phase

controllers/nodemaintenance_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func (r *NodeMaintenanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
245245
nm.Status.Phase = v1beta1.MaintenanceSucceeded
246246
nm.Status.DrainProgress = 100
247247
nm.Status.PendingPods = nil
248+
nm.Status.PendingPodsRefs = nil
248249
err = r.Client.Status().Update(ctx, nm)
249250
if err != nil {
250251
r.logger.Error(err, "Failed to update NodeMaintenance with \"Succeeded\" status")
@@ -432,6 +433,7 @@ func initMaintenanceStatus(ctx context.Context, nm *v1beta1.NodeMaintenance, dra
432433
}
433434
if pendingList != nil {
434435
nm.Status.PendingPods = GetPodNameList(pendingList.Pods())
436+
nm.Status.PendingPodsRefs = GetPodRefList(pendingList.Pods())
435437
}
436438
nm.Status.EvictionPods = len(nm.Status.PendingPods)
437439

@@ -457,6 +459,7 @@ func (r *NodeMaintenanceReconciler) onReconcileErrorWithRequeue(ctx context.Cont
457459
pendingList, _ := drainer.GetPodsForDeletion(nm.Spec.NodeName)
458460
if pendingList != nil {
459461
nm.Status.PendingPods = GetPodNameList(pendingList.Pods())
462+
nm.Status.PendingPodsRefs = GetPodRefList(pendingList.Pods())
460463
if nm.Status.EvictionPods != 0 {
461464
nm.Status.DrainProgress = (nm.Status.EvictionPods - len(nm.Status.PendingPods)) * 100 / nm.Status.EvictionPods
462465
}

controllers/nodemaintenance_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var _ = Describe("Node Maintenance", func() {
7272
Expect(err).NotTo(HaveOccurred())
7373
Expect(nm.Status.Phase).To(Equal(v1beta1.MaintenanceRunning))
7474
Expect(len(nm.Status.PendingPods)).To(Equal(2))
75+
Expect(len(nm.Status.PendingPodsRefs)).To(Equal(2))
7576
Expect(nm.Status.EvictionPods).To(Equal(2))
7677
Expect(nm.Status.TotalPods).To(Equal(2))
7778
Expect(nm.Status.DrainProgress).To(Equal(0))
@@ -109,6 +110,7 @@ var _ = Describe("Node Maintenance", func() {
109110
Expect(err).NotTo(HaveOccurred())
110111
Expect(nmCopy.Status.Phase).To(Equal(v1beta1.MaintenanceFailed))
111112
Expect(len(nmCopy.Status.PendingPods)).To(Equal(0))
113+
Expect(len(nmCopy.Status.PendingPodsRefs)).To(Equal(0))
112114
Expect(nmCopy.Status.EvictionPods).To(Equal(0))
113115
Expect(nmCopy.Status.TotalPods).To(Equal(0))
114116
Expect(nmCopy.Status.DrainProgress).To(Equal(0))
@@ -201,6 +203,7 @@ var _ = Describe("Node Maintenance", func() {
201203

202204
Expect(maintenance.Status.Phase).To(Equal(v1beta1.MaintenanceSucceeded))
203205
Expect(len(maintenance.Status.PendingPods)).To(Equal(0))
206+
Expect(len(maintenance.Status.PendingPodsRefs)).To(Equal(0))
204207
Expect(maintenance.Status.EvictionPods).To(Equal(2))
205208
Expect(maintenance.Status.TotalPods).To(Equal(2))
206209
Expect(maintenance.Status.DrainProgress).To(Equal(100))
@@ -244,6 +247,7 @@ var _ = Describe("Node Maintenance", func() {
244247
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(nm), maintenance)).To(Succeed())
245248

246249
Expect(len(maintenance.Status.PendingPods)).To(Equal(0))
250+
Expect(len(maintenance.Status.PendingPodsRefs)).To(Equal(0))
247251
Expect(maintenance.Status.EvictionPods).To(Equal(0))
248252
Expect(maintenance.Status.TotalPods).To(Equal(0))
249253
Expect(maintenance.Status.DrainProgress).To(Equal(0))

controllers/utils.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package controllers
22

3-
import corev1 "k8s.io/api/core/v1"
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
6+
"github.com/medik8s/node-maintenance-operator/api/v1beta1"
7+
)
48

59
// ContainsString checks if the string array contains the given string.
610
func ContainsString(slice []string, s string) bool {
@@ -30,3 +34,15 @@ func GetPodNameList(pods []corev1.Pod) (result []string) {
3034
}
3135
return result
3236
}
37+
38+
// GetPodRefList returns a list of pod references.
39+
func GetPodRefList(pods []corev1.Pod) (result []v1beta1.PodReference) {
40+
for _, pod := range pods {
41+
result = append(result, v1beta1.PodReference{
42+
Namespace: pod.Namespace,
43+
Name: pod.Name,
44+
})
45+
}
46+
return result
47+
48+
}

0 commit comments

Comments
 (0)