Skip to content

Commit

Permalink
add extra check to verify node to test is still schedulable
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekm committed Apr 23, 2024
1 parent a9e0a57 commit d84b9e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
42 changes: 36 additions & 6 deletions cmd/storage-check/run_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func runStorageCheck() {
// Create a storage resource.
storageConfig := createStorageConfig(checkStorageName)
log.Infoln("Created Storage resource.")
log.Infof("It looks like: %v", storageConfig)
log.Debugf("It looks like: %v", storageConfig)

// Apply the storage struct manifest to the cluster.
var storageResult StorageResult
Expand Down Expand Up @@ -100,7 +100,7 @@ func runStorageCheck() {
//initStorageConfig := initializeStorageConfig(checkStorageName+"-init", checkStorageName)
initStorageConfig := initializeStorageConfig(checkStorageName+"-init-job", checkStorageName)
log.Infoln("Created Storage Initialiazer resource.")
log.Infof("It looks like: %v", initStorageConfig)
log.Debugf("It looks like: %v", initStorageConfig)

// Initialize the storage
var initStorageResult InitStorageResult
Expand Down Expand Up @@ -160,10 +160,10 @@ func runStorageCheck() {
log.Infoln("Error on getting nodes..not sure what to do", err)
}

log.Infoln("Nodes are ", nodes)
log.Debugln("Nodes are ", nodes)
for _, n := range nodes.Items {
log.Infoln("Node.name=", n.Name)
log.Infoln("Status=", n.Status)
log.Debugln("Status=", n.Status)

node := new(Node)
node.name = n.Name
Expand Down Expand Up @@ -221,10 +221,16 @@ func runStorageCheck() {

for nodeName, node := range checkNodes {
if node.schedulable == true {
log.Infof("Creating config for %s %+v", nodeName, node)

if !verifyStillSchedulable(nodeName) {
log.Infof("Node %s is no longer schedulable, skipping check", nodeName)
continue
}

log.Infof("Creating config for %s", nodeName)
config := checkNodeConfig(checkStorageName+"-check-job", checkStorageName, nodeName)
log.Infoln("Created config.")
log.Infof("It looks like: %+v", config)
log.Debugf("It looks like: %+v", config)

// Initialize the storage
var checkStorageResult CheckStorageResult
Expand Down Expand Up @@ -401,3 +407,27 @@ func formatTaints(taints []v1.Taint) string {

return strings.Join(taintStrings, ",")
}

// veriffyStillSchedulable checks if the node is still schedulable
func verifyStillSchedulable(nodeName string) bool {
log.Infof("Checking if %s is still schedulable", nodeName)

nodes, err := client.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
log.Errorln("Error on getting nodes... not sure what to do", err)
}

schedulable := false

for _, n := range nodes.Items {
if n.Name == nodeName {
if len(n.Spec.Taints) > 0 {
schedulable = toleratesAllTaints(tolerations, n.Spec.Taints)
} else {
schedulable = true
}
}
}

return schedulable
}
4 changes: 2 additions & 2 deletions cmd/storage-check/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func initializeStorageConfig(jobName string, pvcName string) *batchv1.Job {
// Add the storage spec to the storage.
job.Spec = jobSpec

log.Infoln("Job ", jobName, " is", job, "namespace environment variables:", additionalEnvVars)
log.Debugln("Job", jobName, "is", job, "namespace environment variables:", additionalEnvVars)
return job
}

Expand All @@ -164,7 +164,7 @@ func checkNodeConfig(jobName string, pvcName string, node string) *batchv1.Job {
// Make a Job
job := &batchv1.Job{}

log.Infoln("Creating a job", jobName, " in", checkNamespace, "namespace environment variables:", additionalEnvVars)
log.Infoln("Creating a job", jobName, "in", checkNamespace, "namespace environment variables:", additionalEnvVars)

// Make labels for Job
labels := make(map[string]string, 0)
Expand Down

0 comments on commit d84b9e7

Please sign in to comment.