Skip to content

Commit

Permalink
fail fs-backup for windows nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
  • Loading branch information
Lyndon-Li committed Dec 24, 2024
1 parent 623e023 commit 4e0a0e0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions pkg/util/kube/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ func IsLinuxNode(ctx context.Context, nodeName string, client client.Client) err
return errors.Wrapf(err, "error getting node %s", nodeName)
}

if os, found := node.Labels["kubernetes.io/os"]; !found {
os, found := node.Labels["kubernetes.io/os"]

if !found {
return errors.Errorf("no os type label for node %s", nodeName)
} else if os != "linux" {
}

if os != "linux" {
return errors.Errorf("os type %s for node %s is not linux", os, nodeName)
} else {
return nil
}

return nil
}

func WithLinuxNode(ctx context.Context, client client.Client, log logrus.FieldLogger) bool {
Expand All @@ -51,16 +55,25 @@ func WithWindowsNode(ctx context.Context, client client.Client, log logrus.Field
func withOSNode(ctx context.Context, client client.Client, osType string, log logrus.FieldLogger) bool {
nodeList := new(corev1api.NodeList)
if err := client.List(ctx, nodeList); err != nil {
log.Warn("Failed to list nodes, cannot decide existence of windows nodes")
log.Warnf("Failed to list nodes, cannot decide existence of nodes of OS %s", osType)
return false
}

Check warning on line 60 in pkg/util/kube/node.go

View check run for this annotation

Codecov / codecov/patch

pkg/util/kube/node.go#L58-L60

Added lines #L58 - L60 were not covered by tests

allNodeLabeled := true
for _, node := range nodeList.Items {
if os, found := node.Labels["kubernetes.io/os"]; !found {
log.Warnf("Node %s doesn't have os type label, cannot decide existence of windows nodes")
} else if os == osType {
os, found := node.Labels["kubernetes.io/os"]

if os == osType {
return true
}

if !found {
allNodeLabeled = false
}

Check warning on line 72 in pkg/util/kube/node.go

View check run for this annotation

Codecov / codecov/patch

pkg/util/kube/node.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}

if !allNodeLabeled {
log.Warnf("Not all nodes have os type label, cannot decide existence of nodes of OS %s", osType)
}

Check warning on line 77 in pkg/util/kube/node.go

View check run for this annotation

Codecov / codecov/patch

pkg/util/kube/node.go#L76-L77

Added lines #L76 - L77 were not covered by tests

return false
Expand Down

0 comments on commit 4e0a0e0

Please sign in to comment.