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

Cannot generate protobuf for map[string][]string #46024

Closed
jianzhangbjz opened this issue May 18, 2017 · 1 comment
Closed

Cannot generate protobuf for map[string][]string #46024

jianzhangbjz opened this issue May 18, 2017 · 1 comment

Comments

@jianzhangbjz
Copy link
Contributor

Hey guys,

I added a new type(type TopologyMap map[ResourceName][]string) in pkg/api/v1/types.go file.
And execute ./hack/update-generated-protobuf.sh to update pkg/api/v1/generated.proto file, but I got map<string, string> gTopology = 11;, a bit confusing, details as the below:

pkg/api/v1/types.go

type TopologyMap map[ResourceName][]string

        // +optional
        GTopology TopologyMap `json:"gTopology,omitempty" protobuf:"bytes,11,opt,name=gTopology,casttype=TopologyMap,castkey=ResourceName"`

pkg/api/v1/generated.proto

// +optional
map<string, string> gTopology = 11;

Why the value of map is string? Or something else I missed?
And then execute make quick-release command, got errors as the below:

    plugin/cmd/kube-scheduler
# k8s.io/kubernetes/pkg/api/v1
pkg/api/v1/generated.pb.go:4734: arguments to copy have different element types: []byte and []string
pkg/api/v1/generated.pb.go:27251: cannot use mapvalue (type string) as type []string in assignment
!!! [0518 07:37:46] Call tree:
...
make: *** [quick-release] Error 1
@jianzhangbjz jianzhangbjz changed the title some problems about go-to-protobuf generated xxx.proto file Cannot generate protobuf for map[string][]string May 19, 2017
@jianzhangbjz
Copy link
Contributor Author

jianzhangbjz commented May 19, 2017

Refer to issue #27259 and PR #28788 fixed this problem. I have to define a new type for []string and add optional, like this:

type TopologyMap map[ResourceName]TopologyValue

// TopologyValue masks the value so protobuf can generate
// +protobuf.nullable=true
// +protobuf.options.(gogoproto.goproto_stringer)=false
type TopologyValue []string

func (t TopologyValue) String() string {
        return fmt.Sprintf("%v", []string(t))
}

So, close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant