istio: Error "panic: runtime error: invalid memory address or nil pointer dereference" when using istio networking HTTPRoute struct

Bug description Hi, I’m creating a custom operator in Go (using Kubebuilder). So in my CR i want to include istio HTTPRoute type. Here my CR def :

package v1

import (
	networkingv1alpha3 "istio.io/api/networking/v1alpha3"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type VirtualServiceFragmentSpec struct {
	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
	// Important: Run "make" to regenerate code after modifying this file
	HandledRevision string `json:"handledRevision,omitempty"`

	// +kubebuilder:validation:Required
	Target string `json:"name"`

	// +kubebuilder:validation:Required
	Gateways []string `json:"gateways"`

	// +kubebuilder:validation:Required
	Hosts []string `json:"hosts"`

	// +kubebuilder:validation:Optional
	Http *networkingv1alpha3.HTTPRoute `json:"http,omitempty"`
}

When i’m generating ther CRD using istio.io/api v0.0.0-20221107183313-6f1164d46553 (with kubebuilder command “make manifest”) i have an error :

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10493ff5c]

goroutine 1 [running]:
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedPackage(0x1400033c840, 0x0)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/parser.go:237 +0x4c
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x1400033c840, {0x0?, {0x14000e87bc8?, 0x31?}})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/parser.go:170 +0x48
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0x14002d41050?, {0x14000236940?, 0x1049cfd18?}, {0x14000e87bc8?, 0x8?})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:107 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.namedToSchema(0x14002d41050, 0x140005b9ab8)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:254 +0x1b4
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14002d41050, {0x104c4f858?, 0x140005b9ab8})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:173 +0x68
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14002d41050, {0x104c4f8e8?, 0x140005b9cc8})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:179 +0xc8
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x14000a2ce48, 0x14000915188)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:401 +0x750
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14000a2ce48, {0x104c4f918?, 0x14000915188})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:181 +0x94
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0x14000a2ce48)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:124 +0x114
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x1400033c840, {0x14000c40220?, {0x14000138da0?, 0x20?}})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/parser.go:193 +0x204
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0x14001867b30?, {0x14000485220?, 0x1049cfd18?}, {0x14000138da0?, 0x9?})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:107 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.namedToSchema(0x14001867b30, 0x140002bf878)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:254 +0x1b4
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14001867b30, {0x104c4f858?, 0x140002bf878})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:173 +0x68
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14001867b30, {0x104c4f8e8?, 0x140002bf890})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:179 +0xc8
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x14000a2d908, 0x140002bf8a8)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:401 +0x750
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14000a2d908, {0x104c4f918?, 0x140002bf8a8})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:181 +0x94
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0x14000a2d908)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:124 +0x114
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x1400033c840, {0x14001313060?, {0x14000c0d1c0?, 0x0?}})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/parser.go:193 +0x204
sigs.k8s.io/controller-tools/pkg/crd.(*schemaContext).requestSchema(0x1400059f0e0?, {0x0?, 0x1049cfd18?}, {0x14000c0d1c0?, 0x0?})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:107 +0xd8
sigs.k8s.io/controller-tools/pkg/crd.localNamedToSchema(0x14001866d20, 0x14000cbb360)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:237 +0x1e4
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14001866d20, {0x104c4f5b8?, 0x14000cbb360})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:171 +0x120
sigs.k8s.io/controller-tools/pkg/crd.structToSchema(0x14000a2e368, 0x140002bfb60)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:401 +0x750
sigs.k8s.io/controller-tools/pkg/crd.typeToSchema(0x14000a2e368, {0x104c4f918?, 0x140002bfb60})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:181 +0x94
sigs.k8s.io/controller-tools/pkg/crd.infoToSchema(0x14000a2e368)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/schema.go:124 +0x114
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedSchemaFor(0x1400033c840, {0x14001313060?, {0x14000c02de0?, 0x8?}})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/parser.go:193 +0x204
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedFlattenedSchemaFor(0x1400033c840, {0x14001313060?, {0x14000c02de0?, 0x1049ce17a?}})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/parser.go:205 +0x88
sigs.k8s.io/controller-tools/pkg/crd.(*Parser).NeedCRDFor(0x1400033c840, {{0x14000d0604e?, 0x0?}, {0x14000c02de0?, 0x0?}}, 0x0)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/spec.go:85 +0x400
sigs.k8s.io/controller-tools/pkg/crd.Generator.Generate({0x0, 0x0, 0x0, {0x0, 0x0, 0x0}, 0x0}, 0x14000d12a50)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/crd/gen.go:132 +0x228
sigs.k8s.io/controller-tools/pkg/genall.(*Runtime).Run(0x140003afd40)
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/pkg/genall/genall.go:261 +0x234
main.main.func1(0x140002fec80?, {0x140000a1db0?, 0x5?, 0x5?})
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/cmd/controller-gen/main.go:176 +0x68
github.com/spf13/cobra.(*Command).execute(0x140002fec80, {0x140000321f0, 0x5, 0x5})
        xxxxxxxx/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:856 +0x4c4
github.com/spf13/cobra.(*Command).ExecuteC(0x140002fec80)
        xxxxxxxx/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x354
github.com/spf13/cobra.(*Command).Execute(...)
        xxxxxxxx/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
main.main()
        xxxxxxxx/go/pkg/mod/sigs.k8s.io/controller-tools@v0.9.2/cmd/controller-gen/main.go:200 +0x27c
make: *** [manifests] Error 2

But when i’m using an old version like istio.io/api v0.0.0-20211206163441-1a632586cbd4 i have no errors.

So is it a known issue ? is there a solution ?

Thanks for your help.

Affected product area (please put an X in all that apply)

[ ] Configuration Infrastructure [ ] Docs [ ] Installation [x] Networking [ ] Performance and Scalability [ ] Policies and Telemetry [ ] Security [ ] Test and Release [ ] User Experience

Version (include the output of istioctl version --remote and kubectl version)

istio.io/api v0.0.0-20221107183313-6f1164d46553

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 17 (4 by maintainers)

Most upvoted comments

hi @ArenaSu I think this issue was introduced by this commit , you can try using the version before this pr.

Can confirm, using v0.0.0-20220322234440-289bfe748e00 works (albeit has a bunch of warnings about certain structs not having JSON tags).

Using the version that’s built off of that commit (v0.0.0-20220323151137-9d336787a432) gives me the panic error.

FYI to get the api version for these commits you should look at the update_api_dep_client_go_api_postsubmit build logs in the status check.

hi @ArenaSu I think this issue was introduced by this commit , you can try using the version before this pr.