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

Clean up documentation.

parent 9a708855
......@@ -60,6 +60,7 @@ limitations under the License.
// &ServiceInfo{
// Object: "InstanceGroup", // Name of the object type.
// 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).
// keyType: Zonal, // What kind of resource this is.
// serviceType: reflect.TypeOf(&alpha.InstanceGroupsService{}), // Associated golang type.
......
......@@ -21,9 +21,9 @@ import (
"fmt"
"net/http"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
compute "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
// ProjectsOps is the manually implemented methods for the Projects service.
......@@ -37,6 +37,7 @@ type MockProjectOpsState struct {
metadata map[string]*compute.Metadata
}
// Get a project by projectID.
func (m *MockProjects) Get(ctx context.Context, projectID string) (*compute.Project, error) {
m.Lock.Lock()
defer m.Lock.Unlock()
......@@ -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) {
rk := &RateLimitKey{
ProjectID: projectID,
......@@ -65,6 +67,7 @@ func (g *GCEProjects) Get(ctx context.Context, projectID string) (*compute.Proje
return call.Do()
}
// SetCommonInstanceMetadata for a given project.
func (m *MockProjects) SetCommonInstanceMetadata(ctx context.Context, projectID string, meta *compute.Metadata) error {
if m.X == nil {
m.X = &MockProjectOpsState{metadata: map[string]*compute.Metadata{}}
......@@ -74,6 +77,7 @@ func (m *MockProjects) SetCommonInstanceMetadata(ctx context.Context, projectID
return nil
}
// SetCommonInstanceMetadata for a given project.
func (g *GCEProjects) SetCommonInstanceMetadata(ctx context.Context, projectID string, m *compute.Metadata) error {
rk := &RateLimitKey{
ProjectID: projectID,
......
......@@ -30,8 +30,8 @@ import (
"text/template"
"time"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
)
const (
......@@ -167,6 +167,7 @@ type GCE struct {
}
{{range .All}}
// {{.WrapType}} returns the interface for the {{.Version}} {{.Service}}.
func (gce *GCE) {{.WrapType}}() {{.WrapType}} {
return gce.{{.Field}}
}
......@@ -196,6 +197,7 @@ type MockGCE struct {
{{- end}}
}
{{range .All}}
// {{.WrapType}} returns the interface for the {{.Version}} {{.Service}}.
func (mock *MockGCE) {{.WrapType}}() {{.WrapType}} {
return mock.{{.MockField}}
}
......
......@@ -91,7 +91,7 @@ func newMethod(s *ServiceInfo, m reflect.Method) *Method {
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 {
*ServiceInfo
m reflect.Method
......@@ -135,6 +135,7 @@ func (mr *Method) args(skip int, nameArgs bool, prefix []string) []string {
return append(prefix, a...)
}
// init the method, preforming some rudimentary static checking.
func (mr *Method) init() {
fType := mr.m.Func.Type()
if fType.NumIn() < mr.argsSkip() {
......@@ -189,10 +190,14 @@ func (mr *Method) init() {
}
}
// Name is the name of the method.
func (mr *Method) Name() string {
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 {
var args []string
for i := mr.argsSkip(); i < mr.m.Func.Type().NumIn(); i++ {
......@@ -204,10 +209,12 @@ func (mr *Method) CallArgs() string {
return fmt.Sprintf(", %s", strings.Join(args, ", "))
}
// MockHookName is the name of the hook function in the mock.
func (mr *Method) MockHookName() string {
return mr.m.Name + "Hook"
}
// MockHook is the definition of the hook function.
func (mr *Method) MockHook() string {
args := mr.args(mr.argsSkip(), false, []string{
fmt.Sprintf("*%s", mr.MockWrapType()),
......@@ -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)
}
// FcnArgs is the function signature for the definition of the method.
func (mr *Method) FcnArgs() string {
args := mr.args(mr.argsSkip(), true, []string{
"ctx context.Context",
......@@ -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)
}
// InterfaceFunc is the function declaration of the method in the interface.
func (mr *Method) InterfaceFunc() string {
args := mr.args(mr.argsSkip(), false, []string{"context.Context", "meta.Key"})
if mr.ReturnType == "Operation" {
......
......@@ -220,6 +220,7 @@ type ServiceGroup struct {
GA *ServiceInfo
}
// Service returns any ServiceInfo object belonging to the ServiceGroup.
func (sg *ServiceGroup) Service() string {
switch {
case sg.GA != nil:
......@@ -233,14 +234,17 @@ func (sg *ServiceGroup) Service() string {
}
}
// HasGA returns true if this object has a GA representation.
func (sg *ServiceGroup) HasGA() bool {
return sg.GA != nil
}
// HasAlpha returns true if this object has a Alpha representation.
func (sg *ServiceGroup) HasAlpha() bool {
return sg.Alpha != nil
}
// HasBeta returns true if this object has a Beta representation.
func (sg *ServiceGroup) HasBeta() bool {
return sg.Beta != nil
}
......
......@@ -39,6 +39,7 @@ type SingleProjectRouter struct {
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 {
return r.ID
}
......@@ -51,6 +51,7 @@ type RateLimiter interface {
type NopRateLimiter struct {
}
// Accept the operation to be rate limited.
func (*NopRateLimiter) Accept(ctx context.Context, key *RateLimitKey) error {
// Rate limit polling of the Operation status to avoid hammering GCE
// 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