deis / workflow-manager

Deis Workflow Manager: Cluster First Aid
MIT License
14 stars 15 forks source link

k8s.runningK8sData methods have shadowed variables. #91

Closed jackfrancis closed 8 years ago

jackfrancis commented 8 years ago

E.g.,

// Pods method for runningK8sData
func (rkd *runningK8sData) Pods() ([]*models.K8sResource, error) {
    pods, err := getPods(rkd.podLister)
    if err != nil {
        return nil, err
    }
    ret := make([]*models.K8sResource, len(pods))
    for i, p := range pods {
        pod := &models.K8sResource{
            Data: &p,
        }
        ret[i] = pod
    }
    return ret, nil
}

The usage of &p in the for i, p :- range pods iteration is being shadowed over each loop iteration, resulting in a ret slice where all items are duplicates pointing to the final member of the pods slice.

There are several instances of this, and each should be remediated. @arschles figured out that by making a copy of the enumeration variable, and then assigning a pointer to it, we'll solve this.