Merge pull request #75615 from oomichi/golint-e2e-framework

Fix golint failures of e2e/framework/[a-c].go
This commit is contained in:
Kubernetes Prow Robot 2019-03-22 17:02:35 -07:00 committed by GitHub
commit 3dfe9072ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 19 deletions

View File

@ -42,7 +42,7 @@ func WaitForAuthorizationUpdate(c v1beta1authorization.SubjectAccessReviewsGette
return WaitForNamedAuthorizationUpdate(c, user, namespace, verb, "", resource, allowed) return WaitForNamedAuthorizationUpdate(c, user, namespace, verb, "", resource, allowed)
} }
// WaitForAuthorizationUpdate checks if the given user can perform the named verb and action on the named resource. // WaitForNamedAuthorizationUpdate checks if the given user can perform the named verb and action on the named resource.
// If policyCachePollTimeout is reached without the expected condition matching, an error is returned // If policyCachePollTimeout is reached without the expected condition matching, an error is returned
func WaitForNamedAuthorizationUpdate(c v1beta1authorization.SubjectAccessReviewsGetter, user, namespace, verb, resourceName string, resource schema.GroupResource, allowed bool) error { func WaitForNamedAuthorizationUpdate(c v1beta1authorization.SubjectAccessReviewsGetter, user, namespace, verb, resourceName string, resource schema.GroupResource, allowed bool) error {
review := &authorizationv1beta1.SubjectAccessReview{ review := &authorizationv1beta1.SubjectAccessReview{
@ -133,6 +133,7 @@ var (
isRBACEnabled bool isRBACEnabled bool
) )
// IsRBACEnabled returns true if RBAC is enabled. Otherwise false.
func IsRBACEnabled(f *Framework) bool { func IsRBACEnabled(f *Framework) bool {
isRBACEnabledOnce.Do(func() { isRBACEnabledOnce.Do(func() {
crs, err := f.ClientSet.RbacV1().ClusterRoles().List(metav1.ListOptions{}) crs, err := f.ClientSet.RbacV1().ClusterRoles().List(metav1.ListOptions{})

View File

@ -18,6 +18,7 @@ package framework
import "sync" import "sync"
// CleanupActionHandle is an integer pointer type for handling cleanup action
type CleanupActionHandle *int type CleanupActionHandle *int
var cleanupActionsLock sync.Mutex var cleanupActionsLock sync.Mutex

View File

@ -38,7 +38,7 @@ import (
// LoadFromManifests loads .yaml or .json manifest files and returns // LoadFromManifests loads .yaml or .json manifest files and returns
// all items that it finds in them. It supports all items for which // all items that it finds in them. It supports all items for which
// there is a factory registered in Factories and .yaml files with // there is a factory registered in factories and .yaml files with
// multiple items separated by "---". Files are accessed via the // multiple items separated by "---". Files are accessed via the
// "testfiles" package, which means they can come from a file system // "testfiles" package, which means they can come from a file system
// or be built into the binary. // or be built into the binary.
@ -58,7 +58,7 @@ func (f *Framework) LoadFromManifests(files ...string) ([]interface{}, error) {
return errors.Wrap(err, "decode TypeMeta") return errors.Wrap(err, "decode TypeMeta")
} }
factory := Factories[what] factory := factories[what]
if factory == nil { if factory == nil {
return errors.Errorf("item of type %+v not supported", what) return errors.Errorf("item of type %+v not supported", what)
} }
@ -167,7 +167,7 @@ func (f *Framework) CreateItems(items ...interface{}) (func(), error) {
// Uncomment this line to get a full dump of the entire item. // Uncomment this line to get a full dump of the entire item.
// description = fmt.Sprintf("%s:\n%s", description, PrettyPrint(item)) // description = fmt.Sprintf("%s:\n%s", description, PrettyPrint(item))
Logf("creating %s", description) Logf("creating %s", description)
for _, factory := range Factories { for _, factory := range factories {
destructor, err := factory.Create(f, item) destructor, err := factory.Create(f, item)
if destructor != nil { if destructor != nil {
destructors = append(destructors, func() error { destructors = append(destructors, func() error {
@ -178,7 +178,7 @@ func (f *Framework) CreateItems(items ...interface{}) (func(), error) {
if err == nil { if err == nil {
done = true done = true
break break
} else if errors.Cause(err) != ItemNotSupported { } else if errors.Cause(err) != errorItemNotSupported {
result = err result = err
break break
} }
@ -224,18 +224,22 @@ type What struct {
Kind string `json:"kind"` Kind string `json:"kind"`
} }
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new What.
func (in *What) DeepCopy() *What { func (in *What) DeepCopy() *What {
return &What{Kind: in.Kind} return &What{Kind: in.Kind}
} }
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out.
func (in *What) DeepCopyInto(out *What) { func (in *What) DeepCopyInto(out *What) {
out.Kind = in.Kind out.Kind = in.Kind
} }
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *What) DeepCopyObject() runtime.Object { func (in *What) DeepCopyObject() runtime.Object {
return &What{Kind: in.Kind} return &What{Kind: in.Kind}
} }
// GetObjectKind returns the ObjectKind schema
func (in *What) GetObjectKind() schema.ObjectKind { func (in *What) GetObjectKind() schema.ObjectKind {
return nil return nil
} }
@ -250,7 +254,7 @@ type ItemFactory interface {
// Create is responsible for creating the item. It returns an // Create is responsible for creating the item. It returns an
// error or a cleanup function for the created item. // error or a cleanup function for the created item.
// If the item is of an unsupported type, it must return // If the item is of an unsupported type, it must return
// an error that has ItemNotSupported as cause. // an error that has errorItemNotSupported as cause.
Create(f *Framework, item interface{}) (func() error, error) Create(f *Framework, item interface{}) (func() error, error)
} }
@ -266,11 +270,11 @@ func DescribeItem(item interface{}) string {
return fmt.Sprintf("%T: %s", item, item) return fmt.Sprintf("%T: %s", item, item)
} }
// ItemNotSupported is the error that Create methods // errorItemNotSupported is the error that Create methods
// must return or wrap when they don't support the given item. // must return or wrap when they don't support the given item.
var ItemNotSupported = errors.New("not supported") var errorItemNotSupported = errors.New("not supported")
var Factories = map[What]ItemFactory{ var factories = map[What]ItemFactory{
{"ClusterRole"}: &clusterRoleFactory{}, {"ClusterRole"}: &clusterRoleFactory{},
{"ClusterRoleBinding"}: &clusterRoleBindingFactory{}, {"ClusterRoleBinding"}: &clusterRoleBindingFactory{},
{"DaemonSet"}: &daemonSetFactory{}, {"DaemonSet"}: &daemonSetFactory{},
@ -372,7 +376,7 @@ func (f *serviceAccountFactory) New() runtime.Object {
func (*serviceAccountFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*serviceAccountFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*v1.ServiceAccount) item, ok := i.(*v1.ServiceAccount)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.CoreV1().ServiceAccounts(f.Namespace.GetName()) client := f.ClientSet.CoreV1().ServiceAccounts(f.Namespace.GetName())
if _, err := client.Create(item); err != nil { if _, err := client.Create(item); err != nil {
@ -392,7 +396,7 @@ func (f *clusterRoleFactory) New() runtime.Object {
func (*clusterRoleFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*clusterRoleFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.ClusterRole) item, ok := i.(*rbac.ClusterRole)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
Logf("Define cluster role %v", item.GetName()) Logf("Define cluster role %v", item.GetName())
@ -414,7 +418,7 @@ func (f *clusterRoleBindingFactory) New() runtime.Object {
func (*clusterRoleBindingFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*clusterRoleBindingFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.ClusterRoleBinding) item, ok := i.(*rbac.ClusterRoleBinding)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.RbacV1().ClusterRoleBindings() client := f.ClientSet.RbacV1().ClusterRoleBindings()
@ -435,7 +439,7 @@ func (f *roleFactory) New() runtime.Object {
func (*roleFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*roleFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.Role) item, ok := i.(*rbac.Role)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.RbacV1().Roles(f.Namespace.GetName()) client := f.ClientSet.RbacV1().Roles(f.Namespace.GetName())
@ -456,7 +460,7 @@ func (f *roleBindingFactory) New() runtime.Object {
func (*roleBindingFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*roleBindingFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.RoleBinding) item, ok := i.(*rbac.RoleBinding)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.RbacV1().RoleBindings(f.Namespace.GetName()) client := f.ClientSet.RbacV1().RoleBindings(f.Namespace.GetName())
@ -477,7 +481,7 @@ func (f *serviceFactory) New() runtime.Object {
func (*serviceFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*serviceFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*v1.Service) item, ok := i.(*v1.Service)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.CoreV1().Services(f.Namespace.GetName()) client := f.ClientSet.CoreV1().Services(f.Namespace.GetName())
@ -498,7 +502,7 @@ func (f *statefulSetFactory) New() runtime.Object {
func (*statefulSetFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*statefulSetFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*apps.StatefulSet) item, ok := i.(*apps.StatefulSet)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.AppsV1().StatefulSets(f.Namespace.GetName()) client := f.ClientSet.AppsV1().StatefulSets(f.Namespace.GetName())
@ -519,7 +523,7 @@ func (f *daemonSetFactory) New() runtime.Object {
func (*daemonSetFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*daemonSetFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*apps.DaemonSet) item, ok := i.(*apps.DaemonSet)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.AppsV1().DaemonSets(f.Namespace.GetName()) client := f.ClientSet.AppsV1().DaemonSets(f.Namespace.GetName())
@ -540,7 +544,7 @@ func (f *storageClassFactory) New() runtime.Object {
func (*storageClassFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*storageClassFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*storage.StorageClass) item, ok := i.(*storage.StorageClass)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.StorageV1().StorageClasses() client := f.ClientSet.StorageV1().StorageClasses()
@ -561,7 +565,7 @@ func (f *secretFactory) New() runtime.Object {
func (*secretFactory) Create(f *Framework, i interface{}) (func() error, error) { func (*secretFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*v1.Secret) item, ok := i.(*v1.Secret)
if !ok { if !ok {
return nil, ItemNotSupported return nil, errorItemNotSupported
} }
client := f.ClientSet.CoreV1().Secrets(f.Namespace.GetName()) client := f.ClientSet.CoreV1().Secrets(f.Namespace.GetName())