add expansion interface

pull/6/head
Chao Xu 2016-01-07 14:01:02 -08:00
parent 9ac13f665d
commit a0489e8685
30 changed files with 212 additions and 3 deletions

View File

@ -18,6 +18,7 @@ limitations under the License.
package generators
import (
"os"
"path/filepath"
"strings"
@ -50,8 +51,8 @@ func DefaultNameSystem() string {
return "public"
}
func packageForGroup(group string, version string, typeList []*types.Type, basePath string, boilerplate []byte) generator.Package {
outputPackagePath := filepath.Join(basePath, group, version)
func packageForGroup(group string, version string, typeList []*types.Type, packageBasePath string, srcTreePath string, boilerplate []byte) generator.Package {
outputPackagePath := filepath.Join(packageBasePath, group, version)
return &generator.DefaultPackage{
PackageName: version,
PackagePath: outputPackagePath,
@ -89,6 +90,18 @@ func packageForGroup(group string, version string, typeList []*types.Type, baseP
types: typeList,
imports: generator.NewImportTracker(),
})
expansionFileName := "generated_expansion"
// To avoid overriding user's manual modification, only generate the expansion file if it doesn't exist.
if _, err := os.Stat(filepath.Join(srcTreePath, outputPackagePath, expansionFileName+".go")); os.IsNotExist(err) {
generators = append(generators, &genExpansion{
DefaultGen: generator.DefaultGen{
OptionalName: expansionFileName,
},
types: typeList,
})
}
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
@ -126,7 +139,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
var packageList []generator.Package
orderer := namer.Orderer{namer.NewPrivateNamer(0)}
for group, types := range groupToTypes {
packageList = append(packageList, packageForGroup(group, "unversioned", orderer.OrderTypes(types), arguments.OutputPackagePath, boilerplate))
packageList = append(packageList, packageForGroup(group, "unversioned", orderer.OrderTypes(types), arguments.OutputPackagePath, arguments.OutputBase, boilerplate))
}
return generator.Packages(packageList)

View File

@ -0,0 +1,48 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 (
"io"
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
"k8s.io/kubernetes/cmd/libs/go2idl/types"
)
// genExpansion produces a file for a group client, e.g. ExtensionsClient for the extension group.
type genExpansion struct {
generator.DefaultGen
// types in a group
types []*types.Type
}
// We only want to call GenerateType() once per group.
func (g *genExpansion) Filter(c *generator.Context, t *types.Type) bool {
return t == g.types[0]
}
func (g *genExpansion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
for _, t := range g.types {
sw.Do(expansionInterfaceTemplate, t)
}
return sw.Error()
}
var expansionInterfaceTemplate = `
type $.|public$Expansion interface {}
`

View File

@ -94,6 +94,7 @@ type $.type|public$Interface interface {
Get(name string) (*$.type|raw$, error)
List(opts $.apiListOptions|raw$) (*$.type|raw$List, error)
Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error)
$.type|public$Expansion
}
`

View File

@ -0,0 +1,17 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 unversioned

View File

@ -214,3 +214,10 @@ func TestListTestTypesLabels(t *testing.T) {
receivedTestTypeList, err := c.TestTypes(ns).List(options)
c.simpleClient.Validate(t, receivedTestTypeList, err)
}
func TestExpansionInterface(t *testing.T) {
c := New(nil)
if e, a := "hello!", c.TestTypes("").Hello(); e != a {
t.Errorf("expansion failed")
}
}

View File

@ -36,6 +36,7 @@ type TestTypeInterface interface {
Get(name string) (*testgroup.TestType, error)
List(opts api.ListOptions) (*testgroup.TestTypeList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
TestTypeExpansion
}
// testTypes implements TestTypeInterface

View File

@ -0,0 +1,25 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 unversioned
type TestTypeExpansion interface {
Hello() string
}
func (c *testTypes) Hello() string {
return "hello!"
}

View File

@ -36,6 +36,7 @@ type DaemonSetInterface interface {
Get(name string) (*extensions.DaemonSet, error)
List(opts api.ListOptions) (*extensions.DaemonSetList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
DaemonSetExpansion
}
// daemonSets implements DaemonSetInterface

View File

@ -36,6 +36,7 @@ type DeploymentInterface interface {
Get(name string) (*extensions.Deployment, error)
List(opts api.ListOptions) (*extensions.DeploymentList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
DeploymentExpansion
}
// deployments implements DeploymentInterface

View File

@ -0,0 +1,29 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 unversioned
type DaemonSetExpansion interface{}
type DeploymentExpansion interface{}
type HorizontalPodAutoscalerExpansion interface{}
type IngressExpansion interface{}
type JobExpansion interface{}
type ThirdPartyResourceExpansion interface{}

View File

@ -36,6 +36,7 @@ type HorizontalPodAutoscalerInterface interface {
Get(name string) (*extensions.HorizontalPodAutoscaler, error)
List(opts api.ListOptions) (*extensions.HorizontalPodAutoscalerList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
HorizontalPodAutoscalerExpansion
}
// horizontalPodAutoscalers implements HorizontalPodAutoscalerInterface

View File

@ -36,6 +36,7 @@ type IngressInterface interface {
Get(name string) (*extensions.Ingress, error)
List(opts api.ListOptions) (*extensions.IngressList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
IngressExpansion
}
// ingresses implements IngressInterface

View File

@ -36,6 +36,7 @@ type JobInterface interface {
Get(name string) (*extensions.Job, error)
List(opts api.ListOptions) (*extensions.JobList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
JobExpansion
}
// jobs implements JobInterface

View File

@ -36,6 +36,7 @@ type ThirdPartyResourceInterface interface {
Get(name string) (*extensions.ThirdPartyResource, error)
List(opts api.ListOptions) (*extensions.ThirdPartyResourceList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ThirdPartyResourceExpansion
}
// thirdPartyResources implements ThirdPartyResourceInterface

View File

@ -35,6 +35,7 @@ type ComponentStatusInterface interface {
Get(name string) (*api.ComponentStatus, error)
List(opts api.ListOptions) (*api.ComponentStatusList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ComponentStatusExpansion
}
// componentStatus implements ComponentStatusInterface

View File

@ -35,6 +35,7 @@ type EndpointsInterface interface {
Get(name string) (*api.Endpoints, error)
List(opts api.ListOptions) (*api.EndpointsList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
EndpointsExpansion
}
// endpoints implements EndpointsInterface

View File

@ -35,6 +35,7 @@ type EventInterface interface {
Get(name string) (*api.Event, error)
List(opts api.ListOptions) (*api.EventList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
EventExpansion
}
// events implements EventInterface

View File

@ -0,0 +1,47 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 unversioned
type ComponentStatusExpansion interface{}
type EndpointsExpansion interface{}
type EventExpansion interface{}
type LimitRangeExpansion interface{}
type NamespaceExpansion interface{}
type NodeExpansion interface{}
type PersistentVolumeExpansion interface{}
type PersistentVolumeClaimExpansion interface{}
type PodExpansion interface{}
type PodTemplateExpansion interface{}
type ReplicationControllerExpansion interface{}
type ResourceQuotaExpansion interface{}
type SecretExpansion interface{}
type ServiceExpansion interface{}
type ServiceAccountExpansion interface{}

View File

@ -35,6 +35,7 @@ type LimitRangeInterface interface {
Get(name string) (*api.LimitRange, error)
List(opts api.ListOptions) (*api.LimitRangeList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
LimitRangeExpansion
}
// limitRanges implements LimitRangeInterface

View File

@ -35,6 +35,7 @@ type NamespaceInterface interface {
Get(name string) (*api.Namespace, error)
List(opts api.ListOptions) (*api.NamespaceList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
NamespaceExpansion
}
// namespaces implements NamespaceInterface

View File

@ -35,6 +35,7 @@ type NodeInterface interface {
Get(name string) (*api.Node, error)
List(opts api.ListOptions) (*api.NodeList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
NodeExpansion
}
// nodes implements NodeInterface

View File

@ -35,6 +35,7 @@ type PersistentVolumeInterface interface {
Get(name string) (*api.PersistentVolume, error)
List(opts api.ListOptions) (*api.PersistentVolumeList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
PersistentVolumeExpansion
}
// persistentVolumes implements PersistentVolumeInterface

View File

@ -35,6 +35,7 @@ type PersistentVolumeClaimInterface interface {
Get(name string) (*api.PersistentVolumeClaim, error)
List(opts api.ListOptions) (*api.PersistentVolumeClaimList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
PersistentVolumeClaimExpansion
}
// persistentVolumeClaims implements PersistentVolumeClaimInterface

View File

@ -35,6 +35,7 @@ type PodInterface interface {
Get(name string) (*api.Pod, error)
List(opts api.ListOptions) (*api.PodList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
PodExpansion
}
// pods implements PodInterface

View File

@ -35,6 +35,7 @@ type PodTemplateInterface interface {
Get(name string) (*api.PodTemplate, error)
List(opts api.ListOptions) (*api.PodTemplateList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
PodTemplateExpansion
}
// podTemplates implements PodTemplateInterface

View File

@ -35,6 +35,7 @@ type ReplicationControllerInterface interface {
Get(name string) (*api.ReplicationController, error)
List(opts api.ListOptions) (*api.ReplicationControllerList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ReplicationControllerExpansion
}
// replicationControllers implements ReplicationControllerInterface

View File

@ -35,6 +35,7 @@ type ResourceQuotaInterface interface {
Get(name string) (*api.ResourceQuota, error)
List(opts api.ListOptions) (*api.ResourceQuotaList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ResourceQuotaExpansion
}
// resourceQuotas implements ResourceQuotaInterface

View File

@ -35,6 +35,7 @@ type SecretInterface interface {
Get(name string) (*api.Secret, error)
List(opts api.ListOptions) (*api.SecretList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
SecretExpansion
}
// secrets implements SecretInterface

View File

@ -35,6 +35,7 @@ type ServiceInterface interface {
Get(name string) (*api.Service, error)
List(opts api.ListOptions) (*api.ServiceList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ServiceExpansion
}
// services implements ServiceInterface

View File

@ -35,6 +35,7 @@ type ServiceAccountInterface interface {
Get(name string) (*api.ServiceAccount, error)
List(opts api.ListOptions) (*api.ServiceAccountList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ServiceAccountExpansion
}
// serviceAccounts implements ServiceAccountInterface