[CPDEV-101898] - do not create empty /etc/kubernetes/nodes-k8s-versions.txt file #663
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
During upgrade procedure we create special temporary file with node versions:
/etc/kubernetes/nodes-k8s-versions.txt
.This file is needed to continue from the same step after failed upgrade: https://github.com/Netcracker/KubeMarine/blob/main/documentation/Maintenance.md#nodes-saved-versions-before-upgrade
This file is created with such complex command: https://github.com/Netcracker/KubeMarine/blob/v0.30.0/kubemarine/kubernetes/__init__.py#L1002
But if something went wrong, when kubemarine calls
kubectl get nodes
command (e.g. etcd restarts for some reason), no exceptions will be called and empty/etc/kubernetes/nodes-k8s-versions.txt
will be created.After that the exception appears in the next parsing of this file:
The problem is complicated by the fact that as a result of such a shutdown, this file is not deleted, so if the upgrade procedure is restarted when the cluster will be OK, it'll continue failing because of empty
/etc/kubernetes/nodes-k8s-versions.txt
.To resolve this issue, this file should be removed manually, but it's not obvious for user: in fact, this file is absolutely empty without the first line comment about its purpose.
Solution
kubectl get nodes
command fails, kubemarine throws the exception, that is handled and empty file is not created;kubectl get nodes
result is moved to the kubemarine code instead of usingsed
command;Test Cases
TestCase 1
Test Configuration:
Steps:
kubemarine install
and wait the successful installation;kubemarine upgrade
;prepull_images
(the best way is using breakpoints to fail etcd right before autodetect_non_upgraded_nodes function;kubemarine upgrade
finishes (successfully or not);kubemarine upgrade
when the etcd will be restarted;Results:
/etc/kubernetes/nodes-k8s-versions.txt
is created on the first control-plane after step 4etc/kubernetes/nodes-k8s-versions.txt
after step 4kubemarine upgrade
on step 5 failskubemarine upgrade
on step 5 is successfulkubemarine upgrade
on step 2-4 always failskubemarine upgrade
on step 2-4 can be finished successful if failed etcd restarts quickly and does not affect other commandsChecklist
Unit tests
Indicate new or changed unit tests and what they do, if any.