Files
velero/test/util/k8s/node.go
Xun Jiang 2178d36d14
Some checks failed
Run the E2E test on kind / build (push) Failing after 9s
Run the E2E test on kind / setup-test-matrix (push) Successful in 2s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Change the CreateFileToPod function's OS parameter as the E2E pass-in value.
Fix GetResourceWithLabel's bug: labels were not applied.
Add workOS for deployment and pod creationg.
Add OS label for select node.
Enlarge the context timeout to 10 minutes. 5 min is not enough for Windows.
Enlarge the Kibishii test context to 15 minutes for Windows.

Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
2025-08-21 09:34:06 +08:00

54 lines
1.3 KiB
Go

package k8s
import (
"context"
"encoding/json"
"fmt"
"os/exec"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
common "github.com/vmware-tanzu/velero/test/util/common"
)
func GetWorkerNodes(ctx context.Context, workerOS string) ([]string, error) {
getCMD := exec.CommandContext(
ctx,
"kubectl", "get", "node", "-l",
fmt.Sprintf("kubernetes.io/os=%s", workerOS),
"-o", "json",
)
fmt.Printf("kubectl get node cmd =%v\n", getCMD)
jsonBuf, err := common.CMDExecWithOutput(getCMD)
if err != nil {
return nil, err
}
nodes := &unstructured.UnstructuredList{}
err = json.Unmarshal(*jsonBuf, &nodes)
if err != nil {
return nil, err
}
var nodeNameList []string
for nodeIndex, node := range nodes.Items {
fmt.Println(nodeIndex)
fmt.Println(node.GetName())
anns := node.GetAnnotations()
lbls := node.GetLabels()
fmt.Println(anns)
fmt.Println(lbls)
// For Kubeadm vanilla cluster control-plane node selection
if _, ok := lbls["node-role.kubernetes.io/control-plane"]; ok {
continue
}
// For public cloud provider cluster control-plane node selection
if anns["cluster.x-k8s.io/owner-kind"] == "KubeadmControlPlane" {
continue
}
nodeNameList = append(nodeNameList, node.GetName())
}
fmt.Println(nodeNameList)
return nodeNameList, nil
}