let client-gen understand vendor
This commit is contained in:
		@@ -29,6 +29,7 @@ import (
 | 
			
		||||
	clientgenargs "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/args"
 | 
			
		||||
	"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/fake"
 | 
			
		||||
	"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/scheme"
 | 
			
		||||
	"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/path"
 | 
			
		||||
	clientgentypes "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/types"
 | 
			
		||||
 | 
			
		||||
	"github.com/golang/glog"
 | 
			
		||||
@@ -221,7 +222,8 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
 | 
			
		||||
 | 
			
		||||
	gvToTypes := map[clientgentypes.GroupVersion][]*types.Type{}
 | 
			
		||||
	for gv, inputDir := range customArgs.GroupVersionToInputPath {
 | 
			
		||||
		p := context.Universe.Package(inputDir)
 | 
			
		||||
		// Package are indexed with the vendor prefix stripped
 | 
			
		||||
		p := context.Universe.Package(path.Vendorless(inputDir))
 | 
			
		||||
		for n, t := range p.Types {
 | 
			
		||||
			// filter out types which are not included in user specified overrides.
 | 
			
		||||
			typesOverride, ok := includedTypesOverrides[gv]
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ import (
 | 
			
		||||
	"k8s.io/gengo/generator"
 | 
			
		||||
	"k8s.io/gengo/namer"
 | 
			
		||||
	"k8s.io/gengo/types"
 | 
			
		||||
	"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/path"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// genFakeForType produces a file for each top-level type.
 | 
			
		||||
@@ -99,7 +100,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// allow user to define a group name that's different from the one parsed from the directory.
 | 
			
		||||
	p := c.Universe.Package(g.inputPackage)
 | 
			
		||||
	p := c.Universe.Package(path.Vendorless(g.inputPackage))
 | 
			
		||||
	if override := types.ExtractCommentTags("+", p.DocComments)["groupName"]; override != nil {
 | 
			
		||||
		groupName = override[0]
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@ import (
 | 
			
		||||
	"k8s.io/gengo/generator"
 | 
			
		||||
	"k8s.io/gengo/namer"
 | 
			
		||||
	"k8s.io/gengo/types"
 | 
			
		||||
	"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/path"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// genGroup produces a file for a group client, e.g. ExtensionsClient for the extension group.
 | 
			
		||||
@@ -76,7 +77,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
 | 
			
		||||
		groupName = ""
 | 
			
		||||
	}
 | 
			
		||||
	// allow user to define a group name that's different from the one parsed from the directory.
 | 
			
		||||
	p := c.Universe.Package(g.inputPackage)
 | 
			
		||||
	p := c.Universe.Package(path.Vendorless(g.inputPackage))
 | 
			
		||||
	if override := types.ExtractCommentTags("+", p.DocComments)["groupName"]; override != nil {
 | 
			
		||||
		groupName = override[0]
 | 
			
		||||
	}
 | 
			
		||||
@@ -95,7 +96,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
 | 
			
		||||
		"restDefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "DefaultKubernetesUserAgent"}),
 | 
			
		||||
		"restRESTClientInterface":        c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
 | 
			
		||||
		"restRESTClientFor":              c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClientFor"}),
 | 
			
		||||
		"SchemeGroupVersion":             c.Universe.Variable(types.Name{Package: g.inputPackage, Name: "SchemeGroupVersion"}),
 | 
			
		||||
		"SchemeGroupVersion":             c.Universe.Variable(types.Name{Package: path.Vendorless(g.inputPackage), Name: "SchemeGroupVersion"}),
 | 
			
		||||
	}
 | 
			
		||||
	sw.Do(groupInterfaceTemplate, m)
 | 
			
		||||
	sw.Do(groupClientTemplate, m)
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,7 @@ import (
 | 
			
		||||
	"k8s.io/gengo/generator"
 | 
			
		||||
	"k8s.io/gengo/namer"
 | 
			
		||||
	"k8s.io/gengo/types"
 | 
			
		||||
	"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/path"
 | 
			
		||||
	clientgentypes "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -66,10 +67,10 @@ func (g *GenScheme) Imports(c *generator.Context) (imports []string) {
 | 
			
		||||
					packagePath = filepath.Dir(packagePath)
 | 
			
		||||
				}
 | 
			
		||||
				packagePath = filepath.Join(packagePath, "install")
 | 
			
		||||
				imports = append(imports, strings.ToLower(fmt.Sprintf("%s \"%s\"", group.Group.NonEmpty(), packagePath)))
 | 
			
		||||
				imports = append(imports, strings.ToLower(fmt.Sprintf("%s \"%s\"", group.Group.NonEmpty(), path.Vendorless(packagePath))))
 | 
			
		||||
				break
 | 
			
		||||
			} else {
 | 
			
		||||
				imports = append(imports, strings.ToLower(fmt.Sprintf("%s%s \"%s\"", group.Group.NonEmpty(), version.NonEmpty(), packagePath)))
 | 
			
		||||
				imports = append(imports, strings.ToLower(fmt.Sprintf("%s%s \"%s\"", group.Group.NonEmpty(), version.NonEmpty(), path.Vendorless(packagePath))))
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										31
									
								
								cmd/libs/go2idl/client-gen/path/path.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								cmd/libs/go2idl/client-gen/path/path.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2017 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
    http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package path
 | 
			
		||||
 | 
			
		||||
import "strings"
 | 
			
		||||
 | 
			
		||||
// Vendorless removes the longest match of "*/vendor/" from the front of p.
 | 
			
		||||
// It is useful if a package locates in vendor/, e.g.,
 | 
			
		||||
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1, because gengo
 | 
			
		||||
// indexes the package with its import path, e.g.,
 | 
			
		||||
// k8s.io/apimachinery/pkg/apis/meta/v1,
 | 
			
		||||
func Vendorless(p string) string {
 | 
			
		||||
	if pos := strings.LastIndex(p, "/vendor/"); pos != -1 {
 | 
			
		||||
		return p[pos+len("/vendor/"):]
 | 
			
		||||
	}
 | 
			
		||||
	return p
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user