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 bcedd4a * Parsing of gen-client flags 1160fc7 * Structure for all commands of the K8s code-gen db6a5d7 * Helpers-gen calls deepcopy-gen aaf0d26 * Remove unneeded Printer interface eb6748c * Setup a default boilerplate 67bcbb0 * Helper-gen calls defaulter-gen 5b524d1 * Streamline logging b596957 * Fixing tests 323501a * Helpers-gen calls the conversion-gen 2831fdd * Replace shell code with golang tooling 0615e85 * Fixing lint errors 30a4a7e * Auto-skip if git isn't available 79a1e6a * Add k8s.io/code-generator to examples go.mod b760ba5 * Printing stderr when exec.Command fails 7280dd2 * Update boilerplate 5c27b82 * Calculate sourcedir from regular sources, not test ones 8bfa3c5 * Migrate off using `git-*` shell outs to search Go files 7b61cf6 * Auto-skip failing test when executed in bad GOPATH 079f581 * Fix lint errors 41d722d * Use deepcopy gen fn for deepcopy-gen main 5be3f70 * Ensure to run codegen main with GO modules 1cd3950
- Loading branch information
Showing
61 changed files
with
2,965 additions
and
223 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
staging/src/k8s.io/code-generator/cmd/conversion-gen/generators/embed.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,51 @@ | ||
/* | ||
Copyright 2024 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 generators | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
generatorargs "k8s.io/code-generator/cmd/conversion-gen/args" | ||
"k8s.io/gengo/v2" | ||
"k8s.io/gengo/v2/generator" | ||
) | ||
|
||
// GenerateConversion runs the conversion-gen with given flagset and process args. | ||
func GenerateConversion(fs *pflag.FlagSet, processArgs []string) error { | ||
args := generatorargs.New() | ||
args.AddFlags(fs) | ||
|
||
if err := fs.Parse(processArgs); err != nil { | ||
return err | ||
} | ||
|
||
if err := args.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
myTargets := func(context *generator.Context) []generator.Target { | ||
return GetTargets(context, args) | ||
} | ||
|
||
// Run it. | ||
return gengo.Execute( | ||
NameSystems(), | ||
DefaultNameSystem(), | ||
myTargets, | ||
gengo.StdBuildTag, | ||
fs.Args(), | ||
) | ||
} |
43 changes: 43 additions & 0 deletions
43
staging/src/k8s.io/code-generator/cmd/conversion-gen/generators/embed_test.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,43 @@ | ||
/* | ||
Copyright 2024 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 generators_test | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
"github.com/spf13/pflag" | ||
"k8s.io/code-generator/cmd/conversion-gen/generators" | ||
|
||
"testing" | ||
) | ||
|
||
func TestConversion(t *testing.T) { | ||
t.Parallel() | ||
var out bytes.Buffer | ||
fs := pflag.NewFlagSet("test", pflag.ContinueOnError) | ||
fs.SetOutput(&out) | ||
args := []string{"--help"} | ||
|
||
err := generators.GenerateConversion(fs, args) | ||
if !errors.Is(err, pflag.ErrHelp) { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if out.Len() == 0 { | ||
t.Errorf("expected output, got none") | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
staging/src/k8s.io/code-generator/cmd/deepcopy-gen/generators/embed.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,51 @@ | ||
/* | ||
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 generators | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
generatorargs "k8s.io/code-generator/cmd/deepcopy-gen/args" | ||
"k8s.io/gengo/v2" | ||
"k8s.io/gengo/v2/generator" | ||
) | ||
|
||
// GenerateDeepCopy runs the deepcopy-gen with given flagset and process args. | ||
func GenerateDeepCopy(fs *pflag.FlagSet, processArgs []string) error { | ||
args := generatorargs.New() | ||
args.AddFlags(fs) | ||
|
||
if err := fs.Parse(processArgs); err != nil { | ||
return err | ||
} | ||
|
||
if err := args.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
myTargets := func(context *generator.Context) []generator.Target { | ||
return GetTargets(context, args) | ||
} | ||
|
||
// Run it. | ||
return gengo.Execute( | ||
NameSystems(), | ||
DefaultNameSystem(), | ||
myTargets, | ||
gengo.StdBuildTag, | ||
fs.Args(), | ||
) | ||
} |
42 changes: 42 additions & 0 deletions
42
staging/src/k8s.io/code-generator/cmd/deepcopy-gen/generators/embed_test.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,42 @@ | ||
/* | ||
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 generators_test | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/spf13/pflag" | ||
"k8s.io/code-generator/cmd/deepcopy-gen/generators" | ||
) | ||
|
||
func TestGenerateDeepCopy(t *testing.T) { | ||
t.Parallel() | ||
var out bytes.Buffer | ||
fs := pflag.NewFlagSet("test", pflag.ContinueOnError) | ||
fs.SetOutput(&out) | ||
args := []string{"--help"} | ||
|
||
err := generators.GenerateDeepCopy(fs, args) | ||
if !errors.Is(err, pflag.ErrHelp) { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if out.Len() == 0 { | ||
t.Errorf("expected output, got none") | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
staging/src/k8s.io/code-generator/cmd/defaulter-gen/generators/embed.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,51 @@ | ||
/* | ||
Copyright 2024 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 generators | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
generatorargs "k8s.io/code-generator/cmd/defaulter-gen/args" | ||
"k8s.io/gengo/v2" | ||
"k8s.io/gengo/v2/generator" | ||
) | ||
|
||
// GenerateDefaults runs the defaulter-gen with given flagset and process args. | ||
func GenerateDefaults(fs *pflag.FlagSet, processArgs []string) error { | ||
args := generatorargs.New() | ||
args.AddFlags(fs) | ||
|
||
if err := fs.Parse(processArgs); err != nil { | ||
return err | ||
} | ||
|
||
if err := args.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
myTargets := func(context *generator.Context) []generator.Target { | ||
return GetTargets(context, args) | ||
} | ||
|
||
// Run it. | ||
return gengo.Execute( | ||
NameSystems(), | ||
DefaultNameSystem(), | ||
myTargets, | ||
gengo.StdBuildTag, | ||
fs.Args(), | ||
) | ||
} |
43 changes: 43 additions & 0 deletions
43
staging/src/k8s.io/code-generator/cmd/defaulter-gen/generators/embed_test.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,43 @@ | ||
/* | ||
Copyright 2024 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 generators_test | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
"github.com/spf13/pflag" | ||
"k8s.io/code-generator/cmd/defaulter-gen/generators" | ||
|
||
"testing" | ||
) | ||
|
||
func TestDefaulter(t *testing.T) { | ||
t.Parallel() | ||
var out bytes.Buffer | ||
fs := pflag.NewFlagSet("test", pflag.ContinueOnError) | ||
fs.SetOutput(&out) | ||
args := []string{"--help"} | ||
|
||
err := generators.GenerateDefaults(fs, args) | ||
if !errors.Is(err, pflag.ErrHelp) { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if out.Len() == 0 { | ||
t.Errorf("expected output, got none") | ||
} | ||
} |
Oops, something went wrong.