Skip to content

Commit

Permalink
Merge pull request kubernetes#9971 from smarterclayton/make_conversio…
Browse files Browse the repository at this point in the history
…n_more_flexible

Improve conversion to support multiple packages
  • Loading branch information
mikedanese committed Jul 30, 2015
2 parents 1d9a062 + 1d41f5a commit 1a613c4
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 139 deletions.
13 changes: 11 additions & 2 deletions cmd/genconversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ limitations under the License.
package main

import (
"fmt"
"io"
"os"
"path"
"runtime"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
pkg_runtime "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

"github.com/golang/glog"
flag "github.com/spf13/pflag"
Expand All @@ -50,18 +53,24 @@ func main() {
funcOut = file
}

generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw())
generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw(), path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", *version))
apiShort := generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api")
generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource")
// TODO(wojtek-t): Change the overwrites to a flag.
generator.OverwritePackage(*version, "")
for _, knownType := range api.Scheme.KnownTypes(*version) {
if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
}
}
generator.RepackImports(util.NewStringSet())
if err := generator.WriteImports(funcOut); err != nil {
glog.Fatalf("error while writing imports: %v", err)
}
if err := generator.WriteConversionFunctions(funcOut); err != nil {
glog.Fatalf("Error while writing conversion functions: %v", err)
}
if err := generator.RegisterConversionFunctions(funcOut); err != nil {
if err := generator.RegisterConversionFunctions(funcOut, fmt.Sprintf("%s.Scheme", apiShort)); err != nil {
glog.Fatalf("Error while writing conversion functions: %v", err)
}
}
13 changes: 10 additions & 3 deletions cmd/gendeepcopy/deep_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package main
import (
"io"
"os"
"path"
"runtime"
"strings"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
pkg_runtime "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

"github.com/golang/glog"
flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -53,10 +55,14 @@ func main() {
}

knownVersion := *version
registerTo := "api.Scheme"
if knownVersion == "api" {
knownVersion = api.Scheme.Raw().InternalVersion
registerTo = "Scheme"
}
generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw())
pkgPath := path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", knownVersion)
generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw(), pkgPath, util.NewStringSet("github.com/GoogleCloudPlatform/kubernetes"))
generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api")

for _, overwrite := range strings.Split(*overwrites, ",") {
vals := strings.Split(overwrite, "=")
Expand All @@ -67,13 +73,14 @@ func main() {
glog.Errorf("error while generating deep copy functions for %v: %v", knownType, err)
}
}
if err := generator.WriteImports(funcOut, *version); err != nil {
generator.RepackImports()
if err := generator.WriteImports(funcOut); err != nil {
glog.Fatalf("error while writing imports: %v", err)
}
if err := generator.WriteDeepCopyFunctions(funcOut); err != nil {
glog.Fatalf("error while writing deep copy functions: %v", err)
}
if err := generator.RegisterDeepCopyFunctions(funcOut, *version); err != nil {
if err := generator.RegisterDeepCopyFunctions(funcOut, registerTo); err != nil {
glog.Fatalf("error while registering deep copy functions: %v", err)
}
}
8 changes: 0 additions & 8 deletions hack/update-generated-conversions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ function generate_version() {
cat >> $TMPFILE <<EOF
package ${version}
import (
"reflect"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
)
// AUTO-GENERATED FUNCTIONS START HERE
EOF

Expand Down
38 changes: 19 additions & 19 deletions pkg/api/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package api

// AUTO-GENERATED FUNCTIONS START HERE
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"speter.net/go/exp/math/dec/inf"
"time"
resource "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
conversion "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
fields "github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
labels "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
runtime "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
util "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
inf "speter.net/go/exp/math/dec/inf"
time "time"
)

func deepCopy_api_AWSElasticBlockStoreVolumeSource(in AWSElasticBlockStoreVolumeSource, out *AWSElasticBlockStoreVolumeSource, c *conversion.Cloner) error {
Expand Down Expand Up @@ -587,7 +587,7 @@ func deepCopy_api_LimitRange(in LimitRange, out *LimitRange, c *conversion.Clone
func deepCopy_api_LimitRangeItem(in LimitRangeItem, out *LimitRangeItem, c *conversion.Cloner) error {
out.Type = in.Type
if in.Max != nil {
out.Max = make(map[ResourceName]resource.Quantity)
out.Max = make(ResourceList)
for key, val := range in.Max {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand All @@ -599,7 +599,7 @@ func deepCopy_api_LimitRangeItem(in LimitRangeItem, out *LimitRangeItem, c *conv
out.Max = nil
}
if in.Min != nil {
out.Min = make(map[ResourceName]resource.Quantity)
out.Min = make(ResourceList)
for key, val := range in.Min {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand All @@ -611,7 +611,7 @@ func deepCopy_api_LimitRangeItem(in LimitRangeItem, out *LimitRangeItem, c *conv
out.Min = nil
}
if in.Default != nil {
out.Default = make(map[ResourceName]resource.Quantity)
out.Default = make(ResourceList)
for key, val := range in.Default {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand Down Expand Up @@ -857,7 +857,7 @@ func deepCopy_api_NodeSpec(in NodeSpec, out *NodeSpec, c *conversion.Cloner) err

func deepCopy_api_NodeStatus(in NodeStatus, out *NodeStatus, c *conversion.Cloner) error {
if in.Capacity != nil {
out.Capacity = make(map[ResourceName]resource.Quantity)
out.Capacity = make(ResourceList)
for key, val := range in.Capacity {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand Down Expand Up @@ -1041,7 +1041,7 @@ func deepCopy_api_PersistentVolumeClaimStatus(in PersistentVolumeClaimStatus, ou
out.AccessModes = nil
}
if in.Capacity != nil {
out.Capacity = make(map[ResourceName]resource.Quantity)
out.Capacity = make(ResourceList)
for key, val := range in.Capacity {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand Down Expand Up @@ -1143,7 +1143,7 @@ func deepCopy_api_PersistentVolumeSource(in PersistentVolumeSource, out *Persist

func deepCopy_api_PersistentVolumeSpec(in PersistentVolumeSpec, out *PersistentVolumeSpec, c *conversion.Cloner) error {
if in.Capacity != nil {
out.Capacity = make(map[ResourceName]resource.Quantity)
out.Capacity = make(ResourceList)
for key, val := range in.Capacity {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand Down Expand Up @@ -1571,7 +1571,7 @@ func deepCopy_api_ResourceQuotaList(in ResourceQuotaList, out *ResourceQuotaList

func deepCopy_api_ResourceQuotaSpec(in ResourceQuotaSpec, out *ResourceQuotaSpec, c *conversion.Cloner) error {
if in.Hard != nil {
out.Hard = make(map[ResourceName]resource.Quantity)
out.Hard = make(ResourceList)
for key, val := range in.Hard {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand All @@ -1587,7 +1587,7 @@ func deepCopy_api_ResourceQuotaSpec(in ResourceQuotaSpec, out *ResourceQuotaSpec

func deepCopy_api_ResourceQuotaStatus(in ResourceQuotaStatus, out *ResourceQuotaStatus, c *conversion.Cloner) error {
if in.Hard != nil {
out.Hard = make(map[ResourceName]resource.Quantity)
out.Hard = make(ResourceList)
for key, val := range in.Hard {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand All @@ -1599,7 +1599,7 @@ func deepCopy_api_ResourceQuotaStatus(in ResourceQuotaStatus, out *ResourceQuota
out.Hard = nil
}
if in.Used != nil {
out.Used = make(map[ResourceName]resource.Quantity)
out.Used = make(ResourceList)
for key, val := range in.Used {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand All @@ -1615,7 +1615,7 @@ func deepCopy_api_ResourceQuotaStatus(in ResourceQuotaStatus, out *ResourceQuota

func deepCopy_api_ResourceRequirements(in ResourceRequirements, out *ResourceRequirements, c *conversion.Cloner) error {
if in.Limits != nil {
out.Limits = make(map[ResourceName]resource.Quantity)
out.Limits = make(ResourceList)
for key, val := range in.Limits {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand All @@ -1627,7 +1627,7 @@ func deepCopy_api_ResourceRequirements(in ResourceRequirements, out *ResourceReq
out.Limits = nil
}
if in.Requests != nil {
out.Requests = make(map[ResourceName]resource.Quantity)
out.Requests = make(ResourceList)
for key, val := range in.Requests {
newVal := new(resource.Quantity)
if err := deepCopy_resource_Quantity(val, newVal, c); err != nil {
Expand Down
Loading

0 comments on commit 1a613c4

Please sign in to comment.