google / safetext

Apache License 2.0
148 stars 7 forks source link

`reflect.Set: value of type string is not assignable to type types.UID` #3

Open howardjohn opened 1 year ago

howardjohn commented 1 year ago

Full error:

deploymentcontroller_test.go:249: failed to render template: template: inject:1:0: executing "inject" at <ApplyInjectionDetection>: error calling ApplyInjectionDetection: reflect.Set: value of type string is not assignable to type types.UID

We are passing a struct as args that is ~4 levels of embedding to k8s metav1.ObjectMeta which has a UID set. https://github.com/istio/istio/blob/e3bd7d40ae6fe376c69ee93662a17c717d6d534a/pilot/pkg/config/kube/gateway/deploymentcontroller.go#L368

Our template references this UID: https://github.com/istio/istio/blob/e3bd7d40ae6fe376c69ee93662a17c717d6d534a/manifests/charts/istio-control/istio-discovery/files/kube-gateway.yaml#L20. Even if I remove this reference, however, we get the same error.

Oddly, if I try to make a simpler reproducer I cannot.

I will try to get some more info/a simpler reproduction but thought I would open the issue with what I know for now.

howardjohn commented 1 year ago

Minimal reproducer:


func TestUID(t *testing.T) {
    yamlTemplate := `
type: {{ print .ObjectMeta "" }}
`
    tmpl := template.Must(template.New("test").Parse(yamlTemplate))

    type UID string

    type ObjectMeta struct {
        Name   string
        UID UID
    }

    type Outer struct {
        ObjectMeta
    }

    var buf bytes.Buffer
    err := tmpl.Execute(&buf, Outer{})
    if err != nil {
        t.Errorf("tmpl.Execute() error = %v", err)
    }
}