Skip to content

Commit 0749c09

Browse files
committed
add constants file when grouping by kind
1 parent f17d493 commit 0749c09

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

codegen/cuekind/generators_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func TestResourceGenerator(t *testing.T) {
6060
files, err := ResourceGenerator("codegen-tests", "pkg/generated", false).Generate(kinds...)
6161
require.NoError(t, err)
6262
// Check number of files generated
63-
// 12 (7 -> object, spec, status, schema, codec, constants) * 2 versions
64-
assert.Len(t, files, 12, "should be 12 files generated, got %d", len(files))
63+
// 14 = 12 resource files across 2 versions plus 2 app package constants files for the gv client packages
64+
assert.Len(t, files, 14, "should be 14 files generated, got %d", len(files))
6565
// Check content against the golden files
6666
compareToGolden(t, files, "go/groupbykind")
6767
})

codegen/jennies/constants.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ func (c *Constants) Generate(appManifest codegen.AppManifest) (codejen.Files, er
3939
path: filepath.Join(path, "constants.go"),
4040
}
4141
}
42+
if !c.GroupByKind {
43+
continue
44+
}
45+
appPath := GetGeneratedGoTypePath(false, appManifest.Properties().Group, v.Name(), k.MachineName)
46+
if _, ok := m[appPath]; ok {
47+
continue
48+
}
49+
m[appPath] = constantsFileParams{
50+
group: appManifest.Properties().FullGroup,
51+
version: v.Name(),
52+
path: filepath.Join(appPath, "constants.go"),
53+
}
4254
}
4355
files := make(codejen.Files, 0)
4456
for _, v := range m {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package v0_0
2+
3+
import "k8s.io/apimachinery/pkg/runtime/schema"
4+
5+
const (
6+
// APIGroup is the API group used by all kinds in this package
7+
APIGroup = "customapp.ext.grafana.com"
8+
// APIVersion is the API version used by all kinds in this package
9+
APIVersion = "v0-0"
10+
)
11+
12+
var (
13+
// GroupVersion is a schema.GroupVersion consisting of the Group and Version constants for this package
14+
GroupVersion = schema.GroupVersion{
15+
Group: APIGroup,
16+
Version: APIVersion,
17+
}
18+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package v1_0
2+
3+
import "k8s.io/apimachinery/pkg/runtime/schema"
4+
5+
const (
6+
// APIGroup is the API group used by all kinds in this package
7+
APIGroup = "customapp.ext.grafana.com"
8+
// APIVersion is the API version used by all kinds in this package
9+
APIVersion = "v1-0"
10+
)
11+
12+
var (
13+
// GroupVersion is a schema.GroupVersion consisting of the Group and Version constants for this package
14+
GroupVersion = schema.GroupVersion{
15+
Group: APIGroup,
16+
Version: APIVersion,
17+
}
18+
)

0 commit comments

Comments
 (0)