Commit 2aaf8b47 authored by Bowei Du's avatar Bowei Du

Clean up documentation.

parent 9a708855
...@@ -60,6 +60,7 @@ limitations under the License. ...@@ -60,6 +60,7 @@ limitations under the License.
// &ServiceInfo{ // &ServiceInfo{
// Object: "InstanceGroup", // Name of the object type. // Object: "InstanceGroup", // Name of the object type.
// Service: "InstanceGroups", // Name of the service. // Service: "InstanceGroups", // Name of the service.
// Resource: "instanceGroups", // Lowercase resource name (as appears in the URL).
// version: meta.VersionAlpha, // API version (one entry per version is needed). // version: meta.VersionAlpha, // API version (one entry per version is needed).
// keyType: Zonal, // What kind of resource this is. // keyType: Zonal, // What kind of resource this is.
// serviceType: reflect.TypeOf(&alpha.InstanceGroupsService{}), // Associated golang type. // serviceType: reflect.TypeOf(&alpha.InstanceGroupsService{}), // Associated golang type.
......
...@@ -21,9 +21,9 @@ import ( ...@@ -21,9 +21,9 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
compute "google.golang.org/api/compute/v1" compute "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
) )
// ProjectsOps is the manually implemented methods for the Projects service. // ProjectsOps is the manually implemented methods for the Projects service.
...@@ -37,6 +37,7 @@ type MockProjectOpsState struct { ...@@ -37,6 +37,7 @@ type MockProjectOpsState struct {
metadata map[string]*compute.Metadata metadata map[string]*compute.Metadata
} }
// Get a project by projectID.
func (m *MockProjects) Get(ctx context.Context, projectID string) (*compute.Project, error) { func (m *MockProjects) Get(ctx context.Context, projectID string) (*compute.Project, error) {
m.Lock.Lock() m.Lock.Lock()
defer m.Lock.Unlock() defer m.Lock.Unlock()
...@@ -50,6 +51,7 @@ func (m *MockProjects) Get(ctx context.Context, projectID string) (*compute.Proj ...@@ -50,6 +51,7 @@ func (m *MockProjects) Get(ctx context.Context, projectID string) (*compute.Proj
} }
} }
// Get a project by projectID.
func (g *GCEProjects) Get(ctx context.Context, projectID string) (*compute.Project, error) { func (g *GCEProjects) Get(ctx context.Context, projectID string) (*compute.Project, error) {
rk := &RateLimitKey{ rk := &RateLimitKey{
ProjectID: projectID, ProjectID: projectID,
...@@ -65,6 +67,7 @@ func (g *GCEProjects) Get(ctx context.Context, projectID string) (*compute.Proje ...@@ -65,6 +67,7 @@ func (g *GCEProjects) Get(ctx context.Context, projectID string) (*compute.Proje
return call.Do() return call.Do()
} }
// SetCommonInstanceMetadata for a given project.
func (m *MockProjects) SetCommonInstanceMetadata(ctx context.Context, projectID string, meta *compute.Metadata) error { func (m *MockProjects) SetCommonInstanceMetadata(ctx context.Context, projectID string, meta *compute.Metadata) error {
if m.X == nil { if m.X == nil {
m.X = &MockProjectOpsState{metadata: map[string]*compute.Metadata{}} m.X = &MockProjectOpsState{metadata: map[string]*compute.Metadata{}}
...@@ -74,6 +77,7 @@ func (m *MockProjects) SetCommonInstanceMetadata(ctx context.Context, projectID ...@@ -74,6 +77,7 @@ func (m *MockProjects) SetCommonInstanceMetadata(ctx context.Context, projectID
return nil return nil
} }
// SetCommonInstanceMetadata for a given project.
func (g *GCEProjects) SetCommonInstanceMetadata(ctx context.Context, projectID string, m *compute.Metadata) error { func (g *GCEProjects) SetCommonInstanceMetadata(ctx context.Context, projectID string, m *compute.Metadata) error {
rk := &RateLimitKey{ rk := &RateLimitKey{
ProjectID: projectID, ProjectID: projectID,
......
...@@ -30,8 +30,8 @@ import ( ...@@ -30,8 +30,8 @@ import (
"text/template" "text/template"
"time" "time"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
) )
const ( const (
...@@ -167,6 +167,7 @@ type GCE struct { ...@@ -167,6 +167,7 @@ type GCE struct {
} }
{{range .All}} {{range .All}}
// {{.WrapType}} returns the interface for the {{.Version}} {{.Service}}.
func (gce *GCE) {{.WrapType}}() {{.WrapType}} { func (gce *GCE) {{.WrapType}}() {{.WrapType}} {
return gce.{{.Field}} return gce.{{.Field}}
} }
...@@ -196,6 +197,7 @@ type MockGCE struct { ...@@ -196,6 +197,7 @@ type MockGCE struct {
{{- end}} {{- end}}
} }
{{range .All}} {{range .All}}
// {{.WrapType}} returns the interface for the {{.Version}} {{.Service}}.
func (mock *MockGCE) {{.WrapType}}() {{.WrapType}} { func (mock *MockGCE) {{.WrapType}}() {{.WrapType}} {
return mock.{{.MockField}} return mock.{{.MockField}}
} }
......
...@@ -91,7 +91,7 @@ func newMethod(s *ServiceInfo, m reflect.Method) *Method { ...@@ -91,7 +91,7 @@ func newMethod(s *ServiceInfo, m reflect.Method) *Method {
return ret return ret
} }
// Method is used to generate the calling code non-standard methods. // Method is used to generate the calling code for non-standard methods.
type Method struct { type Method struct {
*ServiceInfo *ServiceInfo
m reflect.Method m reflect.Method
...@@ -135,6 +135,7 @@ func (mr *Method) args(skip int, nameArgs bool, prefix []string) []string { ...@@ -135,6 +135,7 @@ func (mr *Method) args(skip int, nameArgs bool, prefix []string) []string {
return append(prefix, a...) return append(prefix, a...)
} }
// init the method, preforming some rudimentary static checking.
func (mr *Method) init() { func (mr *Method) init() {
fType := mr.m.Func.Type() fType := mr.m.Func.Type()
if fType.NumIn() < mr.argsSkip() { if fType.NumIn() < mr.argsSkip() {
...@@ -189,10 +190,14 @@ func (mr *Method) init() { ...@@ -189,10 +190,14 @@ func (mr *Method) init() {
} }
} }
// Name is the name of the method.
func (mr *Method) Name() string { func (mr *Method) Name() string {
return mr.m.Name return mr.m.Name
} }
// CallArgs is a list of comma separated "argN" used for calling the method.
// For example, if the method has two additional arguments, this will return
// "arg0, arg1".
func (mr *Method) CallArgs() string { func (mr *Method) CallArgs() string {
var args []string var args []string
for i := mr.argsSkip(); i < mr.m.Func.Type().NumIn(); i++ { for i := mr.argsSkip(); i < mr.m.Func.Type().NumIn(); i++ {
...@@ -204,10 +209,12 @@ func (mr *Method) CallArgs() string { ...@@ -204,10 +209,12 @@ func (mr *Method) CallArgs() string {
return fmt.Sprintf(", %s", strings.Join(args, ", ")) return fmt.Sprintf(", %s", strings.Join(args, ", "))
} }
// MockHookName is the name of the hook function in the mock.
func (mr *Method) MockHookName() string { func (mr *Method) MockHookName() string {
return mr.m.Name + "Hook" return mr.m.Name + "Hook"
} }
// MockHook is the definition of the hook function.
func (mr *Method) MockHook() string { func (mr *Method) MockHook() string {
args := mr.args(mr.argsSkip(), false, []string{ args := mr.args(mr.argsSkip(), false, []string{
fmt.Sprintf("*%s", mr.MockWrapType()), fmt.Sprintf("*%s", mr.MockWrapType()),
...@@ -220,6 +227,7 @@ func (mr *Method) MockHook() string { ...@@ -220,6 +227,7 @@ func (mr *Method) MockHook() string {
return fmt.Sprintf("%v func(%v) (*%v.%v, error)", mr.MockHookName(), strings.Join(args, ", "), mr.Version(), mr.ReturnType) return fmt.Sprintf("%v func(%v) (*%v.%v, error)", mr.MockHookName(), strings.Join(args, ", "), mr.Version(), mr.ReturnType)
} }
// FcnArgs is the function signature for the definition of the method.
func (mr *Method) FcnArgs() string { func (mr *Method) FcnArgs() string {
args := mr.args(mr.argsSkip(), true, []string{ args := mr.args(mr.argsSkip(), true, []string{
"ctx context.Context", "ctx context.Context",
...@@ -232,6 +240,7 @@ func (mr *Method) FcnArgs() string { ...@@ -232,6 +240,7 @@ func (mr *Method) FcnArgs() string {
return fmt.Sprintf("%v(%v) (*%v.%v, error)", mr.m.Name, strings.Join(args, ", "), mr.Version(), mr.ReturnType) return fmt.Sprintf("%v(%v) (*%v.%v, error)", mr.m.Name, strings.Join(args, ", "), mr.Version(), mr.ReturnType)
} }
// InterfaceFunc is the function declaration of the method in the interface.
func (mr *Method) InterfaceFunc() string { func (mr *Method) InterfaceFunc() string {
args := mr.args(mr.argsSkip(), false, []string{"context.Context", "meta.Key"}) args := mr.args(mr.argsSkip(), false, []string{"context.Context", "meta.Key"})
if mr.ReturnType == "Operation" { if mr.ReturnType == "Operation" {
......
...@@ -220,6 +220,7 @@ type ServiceGroup struct { ...@@ -220,6 +220,7 @@ type ServiceGroup struct {
GA *ServiceInfo GA *ServiceInfo
} }
// Service returns any ServiceInfo object belonging to the ServiceGroup.
func (sg *ServiceGroup) Service() string { func (sg *ServiceGroup) Service() string {
switch { switch {
case sg.GA != nil: case sg.GA != nil:
...@@ -233,14 +234,17 @@ func (sg *ServiceGroup) Service() string { ...@@ -233,14 +234,17 @@ func (sg *ServiceGroup) Service() string {
} }
} }
// HasGA returns true if this object has a GA representation.
func (sg *ServiceGroup) HasGA() bool { func (sg *ServiceGroup) HasGA() bool {
return sg.GA != nil return sg.GA != nil
} }
// HasAlpha returns true if this object has a Alpha representation.
func (sg *ServiceGroup) HasAlpha() bool { func (sg *ServiceGroup) HasAlpha() bool {
return sg.Alpha != nil return sg.Alpha != nil
} }
// HasBeta returns true if this object has a Beta representation.
func (sg *ServiceGroup) HasBeta() bool { func (sg *ServiceGroup) HasBeta() bool {
return sg.Beta != nil return sg.Beta != nil
} }
......
...@@ -39,6 +39,7 @@ type SingleProjectRouter struct { ...@@ -39,6 +39,7 @@ type SingleProjectRouter struct {
ID string ID string
} }
// ProjectID returns the project ID to be used for a call to the API.
func (r *SingleProjectRouter) ProjectID(ctx context.Context, version meta.Version, service string) string { func (r *SingleProjectRouter) ProjectID(ctx context.Context, version meta.Version, service string) string {
return r.ID return r.ID
} }
...@@ -51,6 +51,7 @@ type RateLimiter interface { ...@@ -51,6 +51,7 @@ type RateLimiter interface {
type NopRateLimiter struct { type NopRateLimiter struct {
} }
// Accept the operation to be rate limited.
func (*NopRateLimiter) Accept(ctx context.Context, key *RateLimitKey) error { func (*NopRateLimiter) Accept(ctx context.Context, key *RateLimitKey) error {
// Rate limit polling of the Operation status to avoid hammering GCE // Rate limit polling of the Operation status to avoid hammering GCE
// for the status of an operation. // for the status of an operation.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment