@@ -33,6 +33,8 @@ import (
33
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
34
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
35
35
"k8s.io/apimachinery/pkg/runtime"
36
+ "k8s.io/apimachinery/pkg/util/wait"
37
+ "k8s.io/klog/v2"
36
38
"sigs.k8s.io/controller-runtime/pkg/client"
37
39
"sigs.k8s.io/yaml"
38
40
@@ -77,34 +79,6 @@ func GetCAPIResources(ctx context.Context, input GetCAPIResourcesInput) []*unstr
77
79
return objList
78
80
}
79
81
80
- // GetKubeSystemPodsInput is the input for GetKubeSystemPods.
81
- type GetKubeSystemPodsInput struct {
82
- Lister Lister
83
- }
84
-
85
- // GetKubeSystemPods reads all pods in the kube-system namespace.
86
- // Note: This function intentionally retrieves Pods as Unstructured, because we need the Pods
87
- // as Unstructured eventually.
88
- func GetKubeSystemPods (ctx context.Context , input GetKubeSystemPodsInput ) []* unstructured.Unstructured {
89
- Expect (ctx ).NotTo (BeNil (), "ctx is required for GetKubeSystemPods" )
90
- Expect (input .Lister ).NotTo (BeNil (), "input.Lister is required for GetKubeSystemPods" )
91
-
92
- podList := new (unstructured.UnstructuredList )
93
- podList .SetAPIVersion (corev1 .SchemeGroupVersion .String ())
94
- podList .SetKind ("Pod" )
95
- if err := input .Lister .List (ctx , podList , client .InNamespace (metav1 .NamespaceSystem )); err != nil {
96
- Fail (fmt .Sprintf ("failed to list Pods in kube-system: %v" , err ))
97
- }
98
-
99
- objList := []* unstructured.Unstructured {}
100
- for i := range podList .Items {
101
- obj := podList .Items [i ]
102
- objList = append (objList , & obj )
103
- }
104
-
105
- return objList
106
- }
107
-
108
82
// getClusterAPITypes returns the list of TypeMeta to be considered for the move discovery phase.
109
83
// This list includes all the types belonging to CAPI providers.
110
84
func getClusterAPITypes (ctx context.Context , lister Lister ) []metav1.TypeMeta {
@@ -158,24 +132,38 @@ func DumpAllResources(ctx context.Context, input DumpAllResourcesInput) {
158
132
}
159
133
}
160
134
161
- // DumpKubeSystemPodsInput is the input for DumpKubeSystemPods .
162
- type DumpKubeSystemPodsInput struct {
135
+ // DumpKubeSystemPodsForClusterInput is the input for DumpKubeSystemPodsForCluster .
136
+ type DumpKubeSystemPodsForClusterInput struct {
163
137
Lister Lister
164
138
LogPath string
139
+ Cluster * clusterv1.Cluster
165
140
}
166
141
167
- // DumpKubeSystemPods dumps kube-system Pods to YAML.
168
- func DumpKubeSystemPods (ctx context.Context , input DumpKubeSystemPodsInput ) {
142
+ // DumpKubeSystemPodsForCluster dumps kube-system Pods to YAML.
143
+ func DumpKubeSystemPodsForCluster (ctx context.Context , input DumpKubeSystemPodsForClusterInput ) {
169
144
Expect (ctx ).NotTo (BeNil (), "ctx is required for DumpAllResources" )
170
145
Expect (input .Lister ).NotTo (BeNil (), "input.Lister is required for DumpAllResources" )
146
+ Expect (input .Cluster ).NotTo (BeNil (), "input.Cluster is required for DumpAllResources" )
171
147
172
- resources := GetKubeSystemPods (ctx , GetKubeSystemPodsInput {
173
- Lister : input .Lister ,
148
+ // Note: We intentionally retrieve Pods as Unstructured because we need the Pods as Unstructured for dumpObject.
149
+ podList := new (unstructured.UnstructuredList )
150
+ podList .SetAPIVersion (corev1 .SchemeGroupVersion .String ())
151
+ podList .SetKind ("Pod" )
152
+ var listErr error
153
+ _ = wait .PollUntilContextTimeout (ctx , retryableOperationInterval , retryableOperationTimeout , true , func (ctx context.Context ) (bool , error ) {
154
+ if listErr = input .Lister .List (ctx , podList , client .InNamespace (metav1 .NamespaceSystem )); listErr != nil {
155
+ return false , nil //nolint:nilerr
156
+ }
157
+ return true , nil
174
158
})
159
+ if listErr != nil {
160
+ // NB. we are treating failures in collecting kube-system pods as a non-blocking operation (best effort)
161
+ fmt .Printf ("Failed to list Pods in kube-system for Cluster %s: %v\n " , klog .KObj (input .Cluster ), listErr )
162
+ return
163
+ }
175
164
176
- for i := range resources {
177
- r := resources [i ]
178
- dumpObject (r , input .LogPath )
165
+ for i := range podList .Items {
166
+ dumpObject (& podList .Items [i ], input .LogPath )
179
167
}
180
168
}
181
169
0 commit comments