Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix SIGSERV when RawSpec is nil (due to anonymous struct) #892

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/crd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func structToSchema(ctx *schemaContext, structType *ast.StructType) *apiext.JSON
Properties: make(map[string]apiext.JSONSchemaProps),
}

if ctx.info.RawSpec.Type != structType {
if ctx.info.RawSpec != nil && ctx.info.RawSpec.Type != structType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add a test case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've managed to break the complex set of structs down to the following test case. controller-get crd paths="<path/to/testcase/below>/..." output:stdout currently fails on this one. With the fix it doesn't fail. It's due to the use of an anonymous struct.

// +groupName=test
package config

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type ExampleSpec struct {
	Service Service `json:"service"`
}

type Example struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec ExampleSpec `json:"spec,omitempty"`
}

type Service struct {

	// +optional
	Foobar struct {
		// placeholder
	} `yaml:"foobar" json:"foobar"`
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkettelerij please update pkg/crd/testdata/cronjob_types.go with an anonymous struct to test this

/ok-to-test

ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("encountered non-top-level struct (possibly embedded), those aren't allowed"), structType))
return props
}
Expand Down