Skip to content

🌱 switch to logicalcluster.v3 #74

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

Merged
merged 5 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ $(GOLANGCI_LINT):
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --timeout=10m ./...
cd examples && $(GOLANGCI_LINT) run --timeout=10m ./...
# temporarily disable the linter in the example directory, see https://github.com/kcp-dev/code-generator/issues/75
# cd examples && $(GOLANGCI_LINT) run --timeout=10m ./...

.PHONY: test
test:
Expand Down
5 changes: 3 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.18
replace acme.corp/pkg => ./pkg

require (
github.com/kcp-dev/apimachinery v0.0.0-20221102195355-d65878bc16be
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0
github.com/kcp-dev/client-go v0.0.0-20221013125607-cac9fbfe7455
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.3
github.com/kcp-dev/logicalcluster/v3 v3.0.0
k8s.io/apimachinery v0.25.2
k8s.io/client-go v0.25.2
sigs.k8s.io/structured-merge-diff/v4 v4.2.3
Expand All @@ -30,6 +30,7 @@ require (
github.com/google/gofuzz v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
10 changes: 6 additions & 4 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kcp-dev/apimachinery v0.0.0-20221102195355-d65878bc16be h1:2uDzJ896+ojtzgr9HJL8+tZEoqhq8blwymGinWFrQ6E=
github.com/kcp-dev/apimachinery v0.0.0-20221102195355-d65878bc16be/go.mod h1:qnvUHkdxOrNzX17yX+z8r81CZEBuFdveNzWqFlwZ55w=
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0 h1:fb+3CdDlxvnK+o1wm3IcDbD+MJndMUa17EUGqYORsvg=
github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0/go.mod h1:dn1hXHMY9E6JbyOGa0qXt1Dq4akd/jHMZOpFhJoX7q4=
github.com/kcp-dev/client-go v0.0.0-20221013125607-cac9fbfe7455 h1:4tYJ1Pkjwsv9x+TKRyFizyUTJL4SfbNahPckRyIMD4A=
github.com/kcp-dev/client-go v0.0.0-20221013125607-cac9fbfe7455/go.mod h1:E/pWNs9gXdW4QbDJhDl6yVWv22AHU+EhSv54EagP96I=
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.3 h1:+DwIG/loh2nDB9c/FqNvLzFFq/YtBliLxAfw/uWNzyE=
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.3/go.mod h1:lfWJL764jKFJxZWOGuFuT3PCCLPo6lV5Cl8P7u9T05g=
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1 h1:6EMfOioekQNrpcHEK7k2ANBWogFMlf+3xTB3CC4k+2s=
github.com/kcp-dev/logicalcluster/v2 v2.0.0-alpha.1/go.mod h1:lfWJL764jKFJxZWOGuFuT3PCCLPo6lV5Cl8P7u9T05g=
github.com/kcp-dev/logicalcluster/v3 v3.0.0 h1:tH6M2NuA11eLMsxii9IDOGo64X8B+P3e3pC6W2oEsx8=
github.com/kcp-dev/logicalcluster/v3 v3.0.0/go.mod h1:6rb68Tntup98cRr9+50rvSDxUbfqrC1yQ/T6RiZcSgA=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module github.com/kcp-dev/code-generator
module github.com/kcp-dev/code-generator/v2

go 1.18

require (
github.com/kcp-dev/code-generator v0.0.0-20221103165105-2dc1248118a7
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.20.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
golang.org/x/tools v0.1.12
k8s.io/apimachinery v0.25.0
k8s.io/code-generator v0.24.3
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185
Expand All @@ -27,7 +29,6 @@ require (
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kcp-dev/code-generator v0.0.0-20221103165105-2dc1248118a7 h1:ZCdSsY/oF01fxLMajM867hJJINoB6DhuVf6j4O9S37Y=
github.com/kcp-dev/code-generator v0.0.0-20221103165105-2dc1248118a7/go.mod h1:QH3PS4O/Z3nyZzt5XLK8nqxwFnNEYo8ePkR8u+xj4ho=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
6 changes: 3 additions & 3 deletions pkg/generators/clientgen/clientgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"

"github.com/kcp-dev/code-generator/pkg/internal/clientgen"
"github.com/kcp-dev/code-generator/pkg/parser"
"github.com/kcp-dev/code-generator/pkg/util"
"github.com/kcp-dev/code-generator/v2/pkg/internal/clientgen"
"github.com/kcp-dev/code-generator/v2/pkg/parser"
"github.com/kcp-dev/code-generator/v2/pkg/util"
)

type Generator struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/generators/informergen/informergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"

"github.com/kcp-dev/code-generator/pkg/internal/informergen"
"github.com/kcp-dev/code-generator/pkg/parser"
"github.com/kcp-dev/code-generator/pkg/util"
"github.com/kcp-dev/code-generator/v2/pkg/internal/informergen"
"github.com/kcp-dev/code-generator/v2/pkg/parser"
"github.com/kcp-dev/code-generator/v2/pkg/util"
)

type Generator struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/generators/listergen/listergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/markers"

"github.com/kcp-dev/code-generator/pkg/internal/listergen"
"github.com/kcp-dev/code-generator/pkg/parser"
"github.com/kcp-dev/code-generator/pkg/util"
"github.com/kcp-dev/code-generator/v2/pkg/internal/listergen"
"github.com/kcp-dev/code-generator/v2/pkg/parser"
"github.com/kcp-dev/code-generator/v2/pkg/util"
)

type Generator struct {
Expand Down
16 changes: 8 additions & 8 deletions pkg/internal/clientgen/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"k8s.io/code-generator/cmd/client-gen/types"

"github.com/kcp-dev/code-generator/pkg/util"
"github.com/kcp-dev/code-generator/v2/pkg/util"
)

type ClientSet struct {
Expand Down Expand Up @@ -57,8 +57,8 @@ import (
"fmt"
"net/http"

kcpclient "github.com/kcp-dev/apimachinery/pkg/client"
"github.com/kcp-dev/logicalcluster/v2"
kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client"
"github.com/kcp-dev/logicalcluster/v3"

client "{{.singleClusterClientPackagePath}}"

Expand All @@ -71,7 +71,7 @@ import (
)

type ClusterInterface interface {
Cluster(logicalcluster.Name) client.Interface
Cluster(logicalcluster.Path) client.Interface
Discovery() discovery.DiscoveryInterface
{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface
{{end -}}
Expand Down Expand Up @@ -101,11 +101,11 @@ func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.G
{{end -}}

// Cluster scopes this clientset to one cluster.
func (c *ClusterClientset) Cluster(name logicalcluster.Name) client.Interface {
if name == logicalcluster.Wildcard {
func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface {
if clusterPath == logicalcluster.Wildcard {
panic("A specific cluster must be provided when scoping, not the wildcard.")
}
return c.clientCache.ClusterOrDie(name)
return c.clientCache.ClusterOrDie(clusterPath)
}

// NewForConfig creates a new ClusterClientset for the given config.
Expand Down Expand Up @@ -145,7 +145,7 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli
cache := kcpclient.NewCache(c, httpClient, &kcpclient.Constructor[*client.Clientset]{
NewForConfigAndClient: client.NewForConfigAndClient,
})
if _, err := cache.Cluster(logicalcluster.New("root")); err != nil {
if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil {
return nil, err
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/internal/clientgen/fake_clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"k8s.io/code-generator/cmd/client-gen/types"

"github.com/kcp-dev/code-generator/pkg/util"
"github.com/kcp-dev/code-generator/v2/pkg/util"
)

type FakeClientset struct {
Expand Down Expand Up @@ -56,7 +56,7 @@ package fake
import (
kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing"
kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake"
"github.com/kcp-dev/logicalcluster/v2"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/discovery"
Expand All @@ -82,7 +82,7 @@ func NewSimpleClientset(objects ...runtime.Object) *ClusterClientset {
o.AddAll(objects...)

cs := &ClusterClientset{Fake: &kcptesting.Fake{}, tracker: o}
cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, Cluster: logicalcluster.Wildcard}
cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, ClusterPath: logicalcluster.Wildcard}
cs.AddReactor("*", "*", kcptesting.ObjectReaction(o))
cs.AddWatchReactor("*", kcptesting.WatchReaction(o))

Expand Down Expand Up @@ -115,15 +115,15 @@ func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() kcp{{.PackageAlias}}.{
{{end -}}

// Cluster scopes this clientset to one cluster.
func (c *ClusterClientset) Cluster(cluster logicalcluster.Name) client.Interface {
if cluster == logicalcluster.Wildcard {
func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface {
if clusterPath == logicalcluster.Wildcard {
panic("A specific cluster must be provided when scoping, not the wildcard.")
}
return &Clientset{
Fake: c.Fake,
discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, Cluster: cluster},
tracker: c.tracker.Cluster(cluster),
cluster: cluster,
discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, ClusterPath: clusterPath},
tracker: c.tracker.Cluster(clusterPath),
clusterPath: clusterPath,
}
}

Expand All @@ -134,7 +134,7 @@ type Clientset struct {
*kcptesting.Fake
discovery *kcpfakediscovery.FakeDiscovery
tracker kcptesting.ScopedObjectTracker
cluster logicalcluster.Name
clusterPath logicalcluster.Path
}

// Discovery retrieves the DiscoveryClient
Expand All @@ -149,7 +149,7 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker {
{{range .groups}}
// {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}Client.
func (c *Clientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Interface {
return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, Cluster: c.cluster}
return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, ClusterPath: c.clusterPath}
}
{{end -}}
`
16 changes: 8 additions & 8 deletions pkg/internal/clientgen/fake_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"k8s.io/code-generator/cmd/client-gen/types"

"github.com/kcp-dev/code-generator/pkg/parser"
"github.com/kcp-dev/code-generator/pkg/util"
"github.com/kcp-dev/code-generator/v2/pkg/parser"
"github.com/kcp-dev/code-generator/v2/pkg/util"
)

type FakeGroup struct {
Expand Down Expand Up @@ -56,7 +56,7 @@ package {{.group.Version.PackageName}}

import (
kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing"
"github.com/kcp-dev/logicalcluster/v2"
"github.com/kcp-dev/logicalcluster/v3"

"k8s.io/client-go/rest"
kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}"
Expand All @@ -69,11 +69,11 @@ type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct {
*kcptesting.Fake
}

func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(cluster logicalcluster.Name) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface {
if cluster == logicalcluster.Wildcard {
func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface {
if clusterPath == logicalcluster.Wildcard {
panic("A specific cluster must be provided when scoping, not the wildcard.")
}
return &{{.group.GroupGoName}}{{.group.Version}}Client{Fake: c.Fake, Cluster: cluster}
return &{{.group.GroupGoName}}{{.group.Version}}Client{Fake: c.Fake, ClusterPath: clusterPath}
}

{{ range .kinds}}
Expand All @@ -86,7 +86,7 @@ var _ {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface

type {{.group.GroupGoName}}{{.group.Version}}Client struct {
*kcptesting.Fake
Cluster logicalcluster.Name
ClusterPath logicalcluster.Path
}

func (c *{{.group.GroupGoName}}{{.group.Version}}Client) RESTClient() rest.Interface {
Expand All @@ -96,7 +96,7 @@ func (c *{{.group.GroupGoName}}{{.group.Version}}Client) RESTClient() rest.Inter

{{ range .kinds}}
func (c *{{$.group.GroupGoName}}{{$.group.Version}}Client) {{.Plural}}({{if .IsNamespaced}}namespace string{{end}}) {{$.group.PackageAlias}}.{{.String}}Interface {
return &{{.Plural | lowerFirst}}Client{Fake: c.Fake, Cluster: c.Cluster{{if .IsNamespaced}}, Namespace: namespace{{end}}}
return &{{.Plural | lowerFirst}}Client{Fake: c.Fake, ClusterPath: c.ClusterPath{{if .IsNamespaced}}, Namespace: namespace{{end}}}
}
{{end -}}
`
Loading