-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate CR/node name from the node names in the cluster
We want to validate that CR has been created correctly. Also UT functionality
- Loading branch information
Showing
3 changed files
with
68 additions
and
8 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
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
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,25 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// isNodeNameValid returns an error if nodeName doesn't match any node name int the cluster, otherwise a nil | ||
func IsNodeNameValid(r client.Reader, nodeName string) error { | ||
logger := ctrl.Log.WithName("utils-nodes") | ||
node := &corev1.Node{} | ||
objNodeName := types.NamespacedName{Name: nodeName} | ||
err := r.Get(context.TODO(), objNodeName, node) | ||
if err != nil { | ||
errMsg := fmt.Sprintf("node %s is not part of the cluster's node names", nodeName) | ||
logger.Error(err, errMsg) | ||
return err | ||
} | ||
return nil | ||
} |