Skip to content

Commit

Permalink
Fix example so it can work with types from the type repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pwittrock committed Aug 26, 2017
1 parent 6255f67 commit 0fb1a30
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/apiserver-boot/boot/build/build_executables.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ apiserver-boot build --goos linux --goarch amd64 --output linux/`,
func AddBuildExecutables(cmd *cobra.Command) {
cmd.AddCommand(createBuildExecutablesCmd)

createBuildExecutablesCmd.Flags().StringVar(&vendorDir, "vendor-dir", "", "Location of directory containing vendor files.")
createBuildExecutablesCmd.Flags().BoolVar(&GenerateForBuild, "generate", true, "if true, generate code before building")
createBuildExecutablesCmd.Flags().StringVar(&goos, "goos", "", "if specified, set this GOOS")
createBuildExecutablesCmd.Flags().StringVar(&goarch, "goarch", "", "if specified, set this GOARCH")
Expand Down
9 changes: 9 additions & 0 deletions cmd/apiserver-boot/boot/build/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var unversionedAPIs []string
var codegenerators []string
var copyright string
var generators = sets.String{}
var vendorDir string

var generateCmd = &cobra.Command{
Use: "generated",
Expand All @@ -55,6 +56,7 @@ var extraAPI = strings.Join([]string{
func AddGenerate(cmd *cobra.Command) {
cmd.AddCommand(generateCmd)
generateCmd.Flags().StringVar(&copyright, "copyright", "boilerplate.go.txt", "Location of copyright boilerplate file.")
generateCmd.Flags().StringVar(&vendorDir, "vendor-dir", "", "Location of directory containing vendor files.")
generateCmd.Flags().StringArrayVar(&versionedAPIs, "api-versions", []string{}, "API version to generate code for. Can be specified multiple times. e.g. --api-versions foo/v1beta1 --api-versions bar/v1 defaults to all versions found under directories pkg/apis/<group>/<version>")
generateCmd.Flags().StringArrayVar(&codegenerators, "generator", []string{}, "list of generators to run. e.g. --generator apiregister --generator conversion Valid values: [apiregister,conversion,client,deepcopy,defaulter,openapi]")
generateCmd.AddCommand(generateCleanCmd)
Expand Down Expand Up @@ -174,6 +176,10 @@ func RunGenerate(cmd *cobra.Command, args []string) {
apis = append(apis, filepath.Join("k8s.io", "client-go", "pkg", "api", "v1"))
}

if _, err := os.Stat(filepath.Join("vendor", "k8s.io", "api", "core", "v1", "doc.go")); err == nil {
apis = append(apis, filepath.Join("k8s.io", "api", "core", "v1"))
}

c := exec.Command(filepath.Join(root, "openapi-gen"),
append(all,
"-o", util.GoSrc,
Expand Down Expand Up @@ -267,6 +273,9 @@ func RunGenerate(cmd *cobra.Command, args []string) {

func getVendorApis(pkg string) []string {
dir := filepath.Join("vendor", pkg)
if len(vendorDir) >= 0 {
dir = filepath.Join(vendorDir, dir)
}
apis := []string{}
if groups, err := ioutil.ReadDir(dir); err == nil {
for _, g := range groups {
Expand Down
2 changes: 1 addition & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test: build
bash -c "find pkg/apis/ -name apiserver.local.config | xargs rm -rf"

build: cmds
bin/apiserver-boot build executables
bin/apiserver-boot build executables --vendor-dir ../

# Build docs
docs: cleandocs build
Expand Down
9 changes: 0 additions & 9 deletions example/pkg/apis/miskatonic/v1beta1/university_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,10 @@ type UniversitySpec struct {
// The unversioned struct definition for this field is automatically generated in the group package
Automatic AutomaticCreateUnversionedType

// WARNING: Using types from client-go as fields does not work outside this example
// This example hacked the vendored client-go to add the openapi generation directives
// to make this work
Template *corev1.PodSpec `json:"template,omitempty"`

// WARNING: Using types from client-go as fields does not work outside this example
// This example hacked the vendored client-go to add the openapi generation directives
// to make this work
ServiceSpec corev1.ServiceSpec `json:"service_spec,omitempty"`

// WARNING: Using types from client-go as fields does not work outside this example
// This example hacked the vendored client-go to add the openapi generation directives
// to make this work
Rollout []extensionsv1beta1.Deployment `json:"rollout,omitempty"`
}

Expand Down

0 comments on commit 0fb1a30

Please sign in to comment.