mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 05:46:37 +00:00
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>
54 lines
1.3 KiB
Go
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
|
|
}
|