Sitelet https://github.com/kubernetes/kops/commit/80f3199d99559c4f1cf5392f62a86ad2d6b9c491
Skip to content

Commit 80f3199

Browse files
authored
Merge pull request #18072 from justinsb/avoid_npe_in_nil_cloud_dump
fix: don't panic when dumping nodes if we didn't capture cloud resources
2 parents c58890d + ea794e2 commit 80f3199

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎pkg/dump/dumper.go‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,20 @@ func NewLogDumper(bastionAddress string, sshConfig *ssh.ClientConfig, keyRing ag
104104
// if the IPs are not found from kubectl get nodes, then these will be dumped also.
105105
// This allows for dumping log on nodes even if they don't register as a kubernetes
106106
// node, or if a node fails to register, or if the whole cluster fails to start.
107-
func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, maxNodesToDump int, cloudResources *resources.Dump) error {
107+
func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, maxNodesToDump int, cloudDump *resources.Dump) error {
108108
var special, regular []*corev1.Node
109109
var missingK8sNodes []*resources.Instance
110110
var dumped []string
111111

112112
foundInstanceNames := make(map[string]struct{})
113-
for _, cloudNode := range cloudResources.Instances {
113+
114+
var cloudInstances []*resources.Instance
115+
116+
if cloudDump != nil {
117+
cloudInstances = cloudDump.Instances
118+
}
119+
120+
for _, cloudNode := range cloudInstances {
114121
for _, k8sNode := range nodes.Items {
115122
if k8sNode.Name == cloudNode.Name {
116123
foundInstanceNames[cloudNode.Name] = struct{}{}
@@ -131,14 +138,14 @@ func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, max
131138
}
132139
}
133140

134-
for _, cloudNode := range cloudResources.Instances {
141+
for _, cloudNode := range cloudInstances {
135142
if _, found := foundInstanceNames[cloudNode.Name]; !found {
136143
missingK8sNodes = append(missingK8sNodes, cloudNode)
137144
}
138145
}
139146

140147
if len(missingK8sNodes) > 0 {
141-
klog.V(2).Infof("number of nodes from kubernetes (%d) differs from number of instances from cloud resources (%d)", len(nodes.Items), len(cloudResources.Instances))
148+
klog.V(2).Infof("number of nodes from kubernetes (%d) differs from number of instances from cloud resources (%d)", len(nodes.Items), len(cloudInstances))
142149
}
143150

144151
// Dumping priority

0 commit comments

Comments
 (0)