github-vet / github-vet/rangeloop-pointer-findings
openshift/openshift-tests: test/extended/templates/template.go; 61 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [openshift/openshift-tests](https://www.github.com/openshift/openshift-tests) at [test/extended/templates/template.go](https://github.com/openshift/openshift-tests/blob/0364757b566e306f75033bb2da76ea558045e834/test/extended/templates/template.go#L34-L94)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> reference to version is reassigned at line 36
[Click here to see the code in its original context.](https://github.com/openshift/openshift-tests/blob/0364757b566e306f75033bb2da76ea558045e834/test/extended/templates/template.go#L34-L94)
Click here to show the 61 line(s) of Go which triggered the analyzer.
```go
for _, version := range []schema.GroupVersion{v1.SchemeGroupVersion} {
config := rest.CopyConfig(oc.AdminConfig())
config.GroupVersion = &version
template := &templateapi.Template{
Parameters: []templateapi.Parameter{
{
Name: "NAME",
Value: "test",
},
},
}
corev1Scheme := runtime.NewScheme()
utilruntime.Must(corev1.AddToScheme(corev1Scheme))
corev1Codec := serializer.NewCodecFactory(corev1Scheme).LegacyCodec(corev1.SchemeGroupVersion)
template.Objects = append(template.Objects, runtime.RawExtension{
Raw: []byte(runtime.EncodeOrDie(corev1Codec, &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "${NAME}-tester",
Namespace: "somevalue",
},
Spec: v1.ServiceSpec{
ClusterIP: "1.2.3.4",
SessionAffinity: "some-bad-${VALUE}",
},
})),
})
dynamicClient, err := dynamic.NewForConfig(config)
if err != nil {
t.Fatal(err)
}
obj, err := templateprocessingclient.NewDynamicTemplateProcessor(dynamicClient).ProcessToList(template)
if err != nil {
t.Fatal(err)
}
if len(obj.Items) != 1 {
t.Fatalf("unexpected object: %#v", obj)
}
svc := obj.Items[0].Object
spec := svc["spec"].(map[string]interface{})
meta := svc["metadata"].(map[string]interface{})
// keep existing values
if spec["clusterIP"] != "1.2.3.4" {
t.Fatalf("unexpected object: %#v", svc)
}
// replace a value
if meta["name"] != "test-tester" {
t.Fatalf("unexpected object: %#v", svc)
}
// clear namespace
if _, ok := meta["namespace"]; ok {
t.Fatalf("unexpected object: %#v", svc)
}
// preserve values exactly
if spec["sessionAffinity"] != "some-bad-${VALUE}" {
t.Fatalf("unexpected object: %#v", svc)
}
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 0364757b566e306f75033bb2da76ea558045e834
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.