mirror of
https://github.com/rancher/types.git
synced 2025-08-31 21:00:16 +00:00
Update schemas
This commit is contained in:
52
main.go
52
main.go
@@ -3,54 +3,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/rancher/norman/generator"
|
||||
"github.com/rancher/norman/types"
|
||||
"github.com/rancher/types/generator"
|
||||
authzSchema "github.com/rancher/types/io.cattle.authorization/v1/schema"
|
||||
clusterSchema "github.com/rancher/types/io.cattle.cluster/v1/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
basePackage = "github.com/rancher/types"
|
||||
baseCattle = "client"
|
||||
workloadSchema "github.com/rancher/types/io.cattle.workload/v1/schema"
|
||||
)
|
||||
|
||||
func main() {
|
||||
generate(clusterSchema.Schemas)
|
||||
}
|
||||
|
||||
func generate(schemas *types.Schemas) {
|
||||
version := getVersion(schemas)
|
||||
groupParts := strings.Split(version.Group, ".")
|
||||
|
||||
cattleOutputPackage := path.Join(basePackage, baseCattle, groupParts[len(groupParts)-1], version.Version)
|
||||
k8sOutputPackage := path.Join(basePackage, version.Group, version.Version)
|
||||
|
||||
if err := generator.Generate(schemas, cattleOutputPackage, k8sOutputPackage); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getVersion(schemas *types.Schemas) *types.APIVersion {
|
||||
var version types.APIVersion
|
||||
for _, schema := range schemas.Schemas() {
|
||||
if version.Group == "" {
|
||||
version = schema.Version
|
||||
continue
|
||||
}
|
||||
if version.Group != schema.Version.Group ||
|
||||
version.Version != schema.Version.Version {
|
||||
panic("schema set contains two APIVersions")
|
||||
}
|
||||
}
|
||||
|
||||
return &version
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
generator.Generate(clusterSchema.Schemas)
|
||||
generator.Generate(workloadSchema.Schemas)
|
||||
generator.Generate(authzSchema.Schemas)
|
||||
}
|
||||
|
Reference in New Issue
Block a user