kubernetes / code-generator

Generators for kube-like API types
Apache License 2.0
1.71k stars 411 forks source link

go-to-protobuf generated.proto reference k8s.* packages might clash with local package name #147

Closed tarvitz closed 1 year ago

tarvitz commented 1 year ago

I'm using API Aggregation over sample-apiserver extension with go.company.name.net/k8s/api-server package name. Running go-to-protobuf works well, but it creates the following generated.proto code:

package go.company.name.net.k8s.api_server.pkg.apis.ksm.v1alpha1;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/generated.proto";
import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto";

// Package-wide variables from generator "generated".
option (gogoproto.marshaler_all) = true;
option (gogoproto.stable_marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.stringer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_enum_prefix_all) = false;
option (gogoproto.goproto_getters_all) = false;
option go_package = "go.company.name.net/k8s/api-server/pkg/apis/ksm/v1alpha1";

// SecretReference is the Schema for the cloud fetch API objects
message SecretReference {
  optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1 [(gogoproto.customname) = "ObjectMeta", (gogoproto.nullable) = false];

  optional SecretReferenceSpec spec = 2 [(gogoproto.customname) = "Spec", (gogoproto.nullable) = false];

  optional SecretReferenceStatus status = 3 [(gogoproto.customname) = "Status", (gogoproto.nullable) = false];
}

I've managed a workaround way to fix it using one of the following ways:

  1. replace optional k8s.io... with optional .k8s.io...
  2. or replace package go.company.name.net.k8s.api_server.pkg.apis.ksm.v1alpha1; with package go.company.name.net._k8s.api_server.pkg.apis.ksm.v1alpha1;

Still those variants don't work well, because the following generation chain is broken (so I've just made a replacement for package in a generator code itself to enforce it generate _k8s for my package).

P.S. non k8s related packages which does not even use k8s dependencies works nicely with the tool ;)

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

tarvitz commented 1 year ago

Just in case very straightforward fix: https://github.com/tarvitz/code-generator/commit/55d383e79771c0cbe08257242c3d428528c2b59a (I have no doubts that it should not be done like this but at least it works).

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 1 year ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes/code-generator/issues/147#issuecomment-1493049944): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
muff1nman commented 1 year ago

/reopen

k8s-ci-robot commented 1 year ago

@muff1nman: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to [this](https://github.com/kubernetes/code-generator/issues/147#issuecomment-1567614319): >/reopen > Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
tarvitz commented 8 months ago

Well, I guess nothing have changed since the initial report message. The issue is still in there (tested over 1.28.5).

I'm still ok with using a dirty hack with package name replacing, it works :).