This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a reboot test for FLUO, the test verifies if the FLUO can reboot a node running stateless applications. Signed-off-by: Suraj Deshmukh <[email protected]>
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
test/components/flatcar-linux-update-operator/fluo_reboot_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2020 The Lokomotive Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build packet_fluo | ||
// +build disruptivee2e | ||
|
||
package fluo_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
|
||
testutil "github.com/kinvolk/lokomotive/test/components/util" | ||
) | ||
|
||
//nolint:funlen | ||
func TestReboot(t *testing.T) { | ||
t.Parallel() | ||
|
||
client := testutil.CreateKubeClient(t) | ||
|
||
// Select a node from the general worker pool. | ||
nodesList, err := client.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{ | ||
LabelSelector: "fluo-test-pool=true", | ||
}) | ||
if err != nil { | ||
t.Fatalf("Listing nodes with label 'fluo-test-pool=true': %v", err) | ||
} | ||
|
||
nodes := nodesList.Items | ||
if len(nodes) < 1 { | ||
t.Fatalf("Wanted one or more nodes with label 'fluo-test-pool=true', found none.") | ||
} | ||
|
||
// Select a node to remove annotation | ||
chosenNode := nodes[0] | ||
t.Logf("Chosen node to reboot: %s", chosenNode.Name) | ||
|
||
// Remove annotation that disables node reboot by FLUO. This test assumes that the node has | ||
// annotation set. | ||
annotation := "flatcar-linux-update.v1.flatcar-linux.net/reboot-paused" | ||
|
||
// This annotation should be set on the node during the cluster creation, if it is not set then | ||
// something changed in the cluster setup process in the CI. | ||
if _, ok := chosenNode.Annotations[annotation]; !ok { | ||
t.Fatalf("Annotation %q not found on the node.", annotation) | ||
} | ||
|
||
// Remove the annotation that disables node reboot. | ||
delete(chosenNode.Annotations, annotation) | ||
|
||
if _, err := client.CoreV1().Nodes().Update(context.Background(), &chosenNode, metav1.UpdateOptions{}); err != nil { | ||
t.Fatalf("Removing node annotation %q: %v", annotation, err) | ||
} | ||
|
||
// Wait for the FLUO to add following annotation key value pair to the chosen node. This may | ||
// involve node reboot if the OS is outdated. | ||
// "flatcar-linux-update.v1.flatcar-linux.net/status": "UPDATE_STATUS_IDLE" | ||
statusAnnotationKey := "flatcar-linux-update.v1.flatcar-linux.net/status" | ||
statusAnnotationVal := "UPDATE_STATUS_IDLE" | ||
|
||
if err := wait.PollImmediate(testutil.RetryInterval, testutil.Timeout, func() (done bool, err error) { | ||
node, err := client.CoreV1().Nodes().Get(context.Background(), chosenNode.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
return false, fmt.Errorf("Getting node %q: %v", chosenNode.Name, err) | ||
} | ||
|
||
val, ok := node.Annotations[statusAnnotationKey] | ||
if !ok { | ||
return false, nil | ||
} | ||
|
||
// Test passed since the annotation is added by the FLUO to the nodes. | ||
if val == statusAnnotationVal { | ||
return true, nil | ||
} | ||
|
||
return false, nil | ||
}); err != nil { | ||
t.Fatalf("Waiting for the node to add annotation '%s:%s' %v", | ||
statusAnnotationKey, statusAnnotationVal, err) | ||
} | ||
} |