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 25, 2024
1 parent a9e0a57 commit 92a76b8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
39 changes: 32 additions & 7 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 @@ -157,13 +157,13 @@ func runStorageCheck() {
// LabelSelector: defaultLabelKey + "=" + defaultLabelValueBase + strconv.Itoa(int(now.Unix())),
})
if err != nil {
log.Infoln("Error on getting nodes..not sure what to do", err)
log.Errorln("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,15 @@ 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 +406,23 @@ func formatTaints(taints []v1.Taint) string {

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

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 {
schedulable = true
break
}
}

return schedulable
}
6 changes: 3 additions & 3 deletions cmd/storage-check/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func createStorageConfig(pvcname string) *corev1.PersistentVolumeClaim {
// Add the storage spec to the storage.
pvc.Spec = pvcSpec

log.Infoln("PVC ", pvcname, " is", pvc, "namespace environment variables:chris", additionalEnvVars)
log.Debugln("PVC", pvcname, "is", pvc, "namespace environment variables:chris", additionalEnvVars)
return pvc
}

Expand Down 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 Down Expand Up @@ -214,7 +214,7 @@ func checkNodeConfig(jobName string, pvcName string, node 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 Down

0 comments on commit 92a76b8

Please sign in to comment.