-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go-native code-gen entrypoint structure
- Loading branch information
Showing
20 changed files
with
1,001 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
staging/src/k8s.io/code-generator/build/kn-event-e2e.junit.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites tests="6" failures="0" errors="0" time="1.157295"> | ||
<testsuite tests="2" failures="0" time="1.008000" name="k8s.io/code-generator/internal/codegen" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
<testcase classname="k8s.io/code-generator/internal/codegen" name="TestRun" time="0.000000"></testcase> | ||
<testcase classname="k8s.io/code-generator/internal/codegen" name="TestInvalid" time="0.000000"></testcase> | ||
</testsuite> | ||
<testsuite tests="0" failures="0" time="0.000000" name="k8s.io/code-generator/internal/codegen/command" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
</testsuite> | ||
<testsuite tests="0" failures="0" time="0.000000" name="k8s.io/code-generator/internal/codegen/command/genclient" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
</testsuite> | ||
<testsuite tests="0" failures="0" time="0.000000" name="k8s.io/code-generator/internal/codegen/command/genhelpers" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
</testsuite> | ||
<testsuite tests="0" failures="0" time="0.000000" name="k8s.io/code-generator/internal/codegen/command/genopenapi" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
</testsuite> | ||
<testsuite tests="2" failures="0" time="1.008000" name="k8s.io/code-generator/internal/codegen/command/help" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
<testcase classname="k8s.io/code-generator/internal/codegen/command/help" name="TestHelpCommand" time="0.000000"></testcase> | ||
<testcase classname="k8s.io/code-generator/internal/codegen/command/help" name="TestInvalidCommand" time="0.000000"></testcase> | ||
</testsuite> | ||
<testsuite tests="2" failures="0" time="1.008000" name="k8s.io/code-generator/internal/codegen/execution" timestamp="2023-12-01T16:55:30+01:00"> | ||
<properties> | ||
<property name="go.version" value="go1.21.4 linux/amd64"></property> | ||
</properties> | ||
<testcase classname="k8s.io/code-generator/internal/codegen/execution" name="TestPrint" time="0.000000"></testcase> | ||
<testcase classname="k8s.io/code-generator/internal/codegen/execution" name="TestPrintErr" time="0.000000"></testcase> | ||
</testsuite> | ||
</testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2023 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 main | ||
|
||
import ( | ||
"k8s.io/code-generator/internal/codegen" | ||
"k8s.io/code-generator/internal/codegen/execution" | ||
) | ||
|
||
var options []execution.Option | ||
|
||
func main() { | ||
codegen.Run(options...) | ||
} | ||
|
||
// RunMain is a wrapper for main() to allow for testing. | ||
func RunMain(opts ...execution.Option) { | ||
old := options | ||
defer func() { options = old }() | ||
options = append(make([]execution.Option, 0, len(opts)), opts...) | ||
main() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main_test | ||
|
||
import ( | ||
"bytes" | ||
"k8s.io/code-generator" | ||
"k8s.io/code-generator/internal/codegen/execution" | ||
"testing" | ||
) | ||
|
||
func TestMainFn(t *testing.T) { | ||
var out, err bytes.Buffer | ||
var retcode *int | ||
main.RunMain(func(ex *execution.Vars) { | ||
ex.Args = []string{"--help"} | ||
ex.Out = &out | ||
ex.Err = &err | ||
ex.Exit = func(code int) { | ||
retcode = &code | ||
} | ||
}) | ||
|
||
if retcode != nil { | ||
t.Errorf("expected exit func will not be called, but was with %d", *retcode) | ||
} | ||
if out.Len() != 0 { | ||
t.Errorf("expected no output, got %#v", out.String()) | ||
} | ||
if !bytes.Contains(err.Bytes(), []byte("Command:")) { | ||
t.Errorf("expected usage output, got %#v", err.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
staging/src/k8s.io/code-generator/internal/codegen/command.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2023 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 codegen | ||
|
||
import ( | ||
"k8s.io/code-generator/internal/codegen/command" | ||
"k8s.io/code-generator/internal/codegen/execution" | ||
) | ||
|
||
// Command is a command that can be run by code-gen. | ||
type Command interface { | ||
// Matches returns true if the command matches the execution context. | ||
Matches(ex *execution.Vars) bool | ||
// Run runs the command. | ||
Run(ex *execution.Vars) | ||
command.Usage | ||
} |
86 changes: 86 additions & 0 deletions
86
staging/src/k8s.io/code-generator/internal/codegen/command/genclient/cmd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2023 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 genclient | ||
|
||
import ( | ||
"k8s.io/code-generator/internal/codegen/execution" | ||
) | ||
|
||
type Command struct{} | ||
|
||
func (c Command) Matches(ex *execution.Vars) bool { | ||
return len(ex.Args) >= 1 && ex.Args[0] == c.Name() | ||
} | ||
|
||
func (c Command) Run(ex *execution.Vars) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c Command) Name() string { | ||
return "gen-client" | ||
} | ||
|
||
func (c Command) OneLine() string { | ||
return "Generate client code" | ||
} | ||
|
||
func (c Command) Help() string { | ||
return `Usage: code-generator gen-client [options] | ||
Generate client code | ||
Options: | ||
--input-pkg-root <string> | ||
The root package under which to search for types.go files which request | ||
clients to be generated. This must be Go package syntax, e.g. | ||
"k8s.io/foo/bar". | ||
--output-pkg-root <string> | ||
The root package into which generated directories and files will be | ||
placed. This must be Go package syntax, e.g. "k8s.io/foo/bar". | ||
--output-base <string> | ||
The root directory under which to emit code. The concatenation of | ||
<output-base> + <output-pkg-root> must be valid. | ||
--boilerplate <string = path_to_kube_codegen_boilerplate> | ||
An optional override for the header file to insert into generated files. | ||
--clientset-name <string = "clientset"> | ||
An optional override for the leaf name of the generated "clientset" directory. | ||
--versioned-name <string = "versioned"> | ||
An optional override for the leaf name of the generated | ||
"<clientset>/versioned" directory. | ||
--with-applyconfig | ||
Enables generation of applyconfiguration files. | ||
--applyconfig-name <string = "applyconfiguration"> | ||
An optional override for the leaf name of the generated "applyconfiguration" directory. | ||
--with-watch | ||
Enables generation of listers and informers for APIs which support WATCH. | ||
--listers-name <string = "listers"> | ||
An optional override for the leaf name of the generated "listers" directory. | ||
--informers-name <string = "informers"> | ||
An optional override for the leaf name of the generated "informers" directory. | ||
` | ||
} |
63 changes: 63 additions & 0 deletions
63
staging/src/k8s.io/code-generator/internal/codegen/command/genhelpers/cmd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2023 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 genhelpers | ||
|
||
import ( | ||
"k8s.io/code-generator/internal/codegen/execution" | ||
) | ||
|
||
type Command struct{} | ||
|
||
func (c Command) Name() string { | ||
return "gen-helpers" | ||
} | ||
|
||
func (c Command) OneLine() string { | ||
return "Generate tagged helper code: conversions, deepcopy, and defaults" | ||
} | ||
|
||
func (c Command) Help() string { | ||
return `Usage: code-generator gen-helpers [options] | ||
Generate tagged helper code: conversions, deepcopy, and defaults | ||
Options: | ||
--input-pkg-root <string> | ||
The root package under which to search for files which request code to be | ||
generated. This must be Go package syntax, e.g. "k8s.io/foo/bar". | ||
--output-base <string> | ||
The root directory under which to emit code. The concatenation of | ||
<output-base> + <input-pkg-root> must be valid. | ||
--boilerplate <string = path_to_kube_codegen_boilerplate> | ||
An optional override for the header file to insert into generated files. | ||
--extra-peer-dir <string> | ||
An optional list (this flag may be specified multiple times) of "extra" | ||
directories to consider during conversion generation. | ||
` | ||
} | ||
|
||
func (c Command) Matches(ex *execution.Vars) bool { | ||
return len(ex.Args) >= 1 && ex.Args[0] == c.Name() | ||
} | ||
|
||
func (c Command) Run(ex *execution.Vars) { | ||
//TODO implement me | ||
panic("implement me") | ||
} |
79 changes: 79 additions & 0 deletions
79
staging/src/k8s.io/code-generator/internal/codegen/command/genopenapi/cmd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2023 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 genopenapi | ||
|
||
import ( | ||
"k8s.io/code-generator/internal/codegen/execution" | ||
) | ||
|
||
type Command struct{} | ||
|
||
func (c Command) Matches(ex *execution.Vars) bool { | ||
return len(ex.Args) >= 1 && ex.Args[0] == c.Name() | ||
} | ||
|
||
func (c Command) Run(ex *execution.Vars) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c Command) Name() string { | ||
return "gen-openapi" | ||
} | ||
|
||
func (c Command) OneLine() string { | ||
return "Generate openapi code" | ||
} | ||
|
||
func (c Command) Help() string { | ||
return `Usage: code-generator gen-openapi [options] | ||
Generate openapi code | ||
Options: | ||
--input-pkg-root <string> | ||
The root package under which to search for files which request openapi to | ||
be generated. This must be Go package syntax, e.g. "k8s.io/foo/bar". | ||
--output-pkg-root <string> | ||
The root package under which generated directories and files | ||
will be placed. This must be go package syntax, e.g. "k8s.io/foo/bar". | ||
--output-base <string> | ||
The root directory under which to emit code. The concatenation of | ||
<output-base> + <input-pkg-root> must be valid. | ||
--openapi-name <string = "openapi"> | ||
An optional override for the leaf name of the generated directory. | ||
--extra-pkgs <string> | ||
An optional list of additional packages to be imported during openapi | ||
generation. The argument must be Go package syntax, e.g. | ||
"k8s.io/foo/bar". It may be a single value or a comma-delimited list. | ||
This flag may be repeated. | ||
--report-filename <string = "/dev/null"> | ||
An optional path at which to write an API violations report. "-" means | ||
stdout. | ||
--update-report | ||
If specified, update the report file in place, rather than diffing it. | ||
--boilerplate <string = path_to_kube_codegen_boilerplate> | ||
An optional override for the header file to insert into generated files. | ||
` | ||
} |
Oops, something went wrong.