Skip to content

Commit

Permalink
Fix potential nil dereference
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit authored and David Ko committed Dec 23, 2023
1 parent 9231284 commit 03eccc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
5 changes: 2 additions & 3 deletions controller/volume_attachment_controller.go
Expand Up @@ -313,7 +313,6 @@ func (vac *VolumeAttachmentController) reconcile(vaName string) (err error) {
return
}
}
return
}()

// Note that in this controller the desire state is recorded in VA.Spec
Expand Down Expand Up @@ -843,9 +842,9 @@ func (vac *VolumeAttachmentController) updateStatusForDesiredAttachingAttachment
func verifyAttachmentParameters(parameters map[string]string, vol *longhorn.Volume) bool {
disableFrontendString, ok := parameters["disableFrontend"]
if !ok || disableFrontendString == longhorn.FalseValue {
return vol.Spec.DisableFrontend == false
return !vol.Spec.DisableFrontend
} else if disableFrontendString == longhorn.TrueValue {
return vol.Spec.DisableFrontend == true
return vol.Spec.DisableFrontend
}
return true
}
Expand Down
31 changes: 19 additions & 12 deletions scheduler/replica_scheduler.go
Expand Up @@ -401,22 +401,29 @@ func (rcs *ReplicaScheduler) getNodeInfo() (map[string]*longhorn.Node, error) {
if err != nil {
return nil, err
}

scheduledNode := map[string]*longhorn.Node{}

for _, node := range nodeInfo {
// First check node ready condition
if node == nil || node.DeletionTimestamp != nil {
continue
}

nodeReadyCondition := types.GetCondition(node.Status.Conditions, longhorn.NodeConditionTypeReady)
// Get Schedulable condition
nodeSchedulableCondition :=
types.GetCondition(node.Status.Conditions,
longhorn.NodeConditionTypeSchedulable)
if node != nil && node.DeletionTimestamp == nil &&
nodeReadyCondition.Status == longhorn.ConditionStatusTrue &&
nodeSchedulableCondition.Status == longhorn.ConditionStatusTrue &&
node.Spec.AllowScheduling {
scheduledNode[node.Name] = node
nodeSchedulableCondition := types.GetCondition(node.Status.Conditions, longhorn.NodeConditionTypeSchedulable)

if nodeReadyCondition.Status != longhorn.ConditionStatusTrue {
continue
}
if nodeSchedulableCondition.Status != longhorn.ConditionStatusTrue {
continue
}
if !node.Spec.AllowScheduling {
continue
}
scheduledNode[node.Name] = node
}

return scheduledNode, nil
}

Expand Down Expand Up @@ -493,8 +500,8 @@ func (rcs *ReplicaScheduler) CheckAndReuseFailedReplica(replicas map[string]*lon
availableNodesInfo[r.Spec.NodeID] = allNodesInfo[r.Spec.NodeID]
availableNodeDisksMap[r.Spec.NodeID] = disks

if _, exists := reusableNodeReplicasMap[r.Spec.NodeID]; exists {
reusableNodeReplicasMap[r.Spec.NodeID] = append(reusableNodeReplicasMap[r.Spec.NodeID], r)
if replicas, exists := reusableNodeReplicasMap[r.Spec.NodeID]; exists {
reusableNodeReplicasMap[r.Spec.NodeID] = append(replicas, r)
} else {
reusableNodeReplicasMap[r.Spec.NodeID] = []*longhorn.Replica{r}
}
Expand Down

0 comments on commit 03eccc9

Please sign in to comment.