Skip to content

Actually run metalinter and fix lint errors #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 10, 2018
23 changes: 0 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ install:
- go get -u gopkg.in/alecthomas/gometalinter.v2 && gometalinter.v2 --install

script:
- go vet ./pkg/...
- golint -set_exit_status ./pkg/...
- gometalinter.v2 --disable-all --enable=misspell \
--enable=misspell \
--enable=structcheck \
--enable=maligned \
--enable=nakedret \
--enable=deadcode \
--enable=gocyclo \
--enable=ineffassign \
--enable=dupl \
--enable=golint \
--enable=goimports \
--enable=errcheck \
--enable=varcheck \
--enable=interfacer \
--enable=goconst \
--enable=unparam \
--enable=misspell \
--enable=lll \
--enable=gas \
--enable=safesql \
--enable=megacheck ./pkg/...
- TRACE=1 ./test.sh


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func TestProvisionServingCert(t *testing.T) {
cn := "mysvc.myns.svc"
cp := SelfSignedCertProvisioner{CommonName: cn}
certs, err := cp.ProvisionServingCert()
certs, _ := cp.ProvisionServingCert()

// First, create the set of root certificates. For this example we only
// have one. It's also possible to omit this in order to use the
Expand Down
14 changes: 11 additions & 3 deletions pkg/client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,23 @@ func (c *singleObjectCache) List(ctx context.Context, opts *ListOptions, out run
labelSel = opts.LabelSelector
}

outItems, err := c.getListItems(objs, labelSel)
if err != nil {
return err
}
return apimeta.SetList(out, outItems)
}

func (c *singleObjectCache) getListItems(objs []interface{}, labelSel labels.Selector) ([]runtime.Object, error) {
outItems := make([]runtime.Object, 0, len(objs))
for _, item := range objs {
obj, isObj := item.(runtime.Object)
if !isObj {
return fmt.Errorf("cache contained %T, which is not an Object", obj)
return nil, fmt.Errorf("cache contained %T, which is not an Object", obj)
}
meta, err := apimeta.Accessor(obj)
if err != nil {
return err
return nil, err
}
if labelSel != nil {
lbls := labels.Set(meta.GetLabels())
Expand All @@ -207,7 +215,7 @@ func (c *singleObjectCache) List(ctx context.Context, opts *ListOptions, out run
}
outItems = append(outItems, obj.DeepCopyObject())
}
return apimeta.SetList(out, outItems)
return outItems, nil
}

// TODO: Make an interface with this function that has an Informers as an object on the struct
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"

"k8s.io/client-go/kubernetes/scheme"
"reflect"

"k8s.io/client-go/kubernetes/scheme"
)

var _ = Describe("Indexers", func() {
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ type controller struct {
// the queue for processing
queue workqueue.RateLimitingInterface

// once ensures unspecified fields get default values
once sync.Once

// inject is used to inject dependencies into other objects such as Sources, EventHandlers and Predicates
inject func(i interface{}) error

Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/controller_suite_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/kubernetes-sigs/controller-runtime/pkg/controller"
"github.com/kubernetes-sigs/controller-runtime/pkg/internal/informer"
logf "github.com/kubernetes-sigs/controller-runtime/pkg/runtime/log"
"github.com/kubernetes-sigs/controller-runtime/pkg/test"
. "github.com/onsi/ginkgo"
Expand All @@ -38,7 +37,6 @@ func TestSource(t *testing.T) {
var testenv *test.Environment
var cfg *rest.Config
var clientset *kubernetes.Clientset
var icache informer.Informers

var _ = BeforeSuite(func() {
logf.SetLogger(logf.ZapLogger(false))
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/eventhandler/enqueue_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ type EnqueueOwnerHandler struct {

// groupKind is the cached Group and Kind from OwnerType
groupKind schema.GroupKind

// kindOk is true if OwnerType was successfully parsed
kindOk bool
}

var _ inject.Scheme = &EnqueueOwnerHandler{}
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/kubernetes-sigs/controller-runtime/pkg/internal/apiutil"
"github.com/kubernetes-sigs/controller-runtime/pkg/internal/informer"
"github.com/kubernetes-sigs/controller-runtime/pkg/runtime/inject"
"k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -105,7 +104,9 @@ func (cm *controllerManager) NewController(ca Args, r reconcile.Reconcile) (Cont
}

// Inject dependencies into Reconcile
cm.injectInto(r)
if err := cm.injectInto(r); err != nil {
return nil, err
}

// Create controller with dependencies set
c := &controller{
Expand Down Expand Up @@ -165,7 +166,9 @@ func (cm *controllerManager) GetFieldIndexer() client.FieldIndexer {
func (cm *controllerManager) Start(stop <-chan struct{}) error {
// Start the Informers.
cm.stop = stop
cm.informers.Start(stop)
if err := cm.informers.Start(stop); err != nil {
return err
}

// Start the controllers after the promises
for _, c := range cm.controllers {
Expand Down Expand Up @@ -224,7 +227,6 @@ func NewManager(args ManagerArgs) (Manager, error) {
Scheme: cm.scheme,
}
cm.informers = spi
cm.informers.InformerFor(&v1.Deployment{})

// Inject a Read / Write client into all controllers
// TODO(directxman12): Figure out how to allow users to request a client without requesting a watch
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/kubernetes-sigs/controller-runtime/pkg/controller/predicate"
logf "github.com/kubernetes-sigs/controller-runtime/pkg/runtime/log"
)

// Source is a source of events (eh.g. Create, Update, Delete operations on Kubernetes Objects, Webhook callbacks, etc)
Expand Down Expand Up @@ -61,8 +60,6 @@ func (ks ChannelSource) Start(
return nil
}

var log = logf.KBLog.WithName("source").WithName("KindSource")

// KindSource is used to provide a source of events originating inside the cluster from Watches (eh.g. Pod Create)
type KindSource struct {
// Type is the type of object to watch. e.g. &v1.Pod{}
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/admission/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package admission

import (
"fmt"

"k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/admission/example_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package admission_test

import (
"fmt"

"github.com/kubernetes-sigs/controller-runtime/pkg/internal/admission"
"k8s.io/api/admission/v1beta1"
corev1 "k8s.io/api/core/v1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/internal/admission/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package admission

import (
"net/http"

"k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/http"
)

// Func implements an AdmissionReview operation for a GroupVersionResource
Expand Down
5 changes: 3 additions & 2 deletions pkg/internal/admission/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package admission

import (
"encoding/json"
"github.com/golang/glog"
"io/ioutil"
"net/http"

"github.com/golang/glog"
"k8s.io/api/admission/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"net/http"
)

func (h httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down
51 changes: 23 additions & 28 deletions pkg/internal/admission/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,27 @@ limitations under the License.

package admission

import (
"crypto/tls"
"crypto/x509"
)
//type certs struct {
// Cert []byte
// Key []byte
// CACert []byte
//}

type certs struct {
Cert []byte
Key []byte
CACert []byte
}

// MakeTLSConfig makes a TLS configuration suitable for use with the server
func makeTLSConfig(certs certs) (*tls.Config, error) {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(certs.CACert)
//cert, err := tls.X509KeyPair(certs.Cert, certs.Key)
//if err != nil {
// return nil, err
//}
return &tls.Config{
//Certificates: []tls.Certificate{cert},
ClientCAs: caCertPool,
ClientAuth: tls.NoClientCert,
// Note on GKE there apparently is no client cert sent, so this
// does not work on GKE.
// TODO: make this into a configuration option.
// ClientAuth: tls.RequireAndVerifyClientCert,
}, nil
}
//// MakeTLSConfig makes a TLS configuration suitable for use with the server
//func makeTLSConfig(certs certs) (*tls.Config, error) {
// caCertPool := x509.NewCertPool()
// caCertPool.AppendCertsFromPEM(certs.CACert)
// //cert, err := tls.X509KeyPair(certs.Cert, certs.Key)
// //if err != nil {
// // return nil, err
// //}
// return &tls.Config{
// //Certificates: []tls.Certificate{cert},
// ClientCAs: caCertPool,
// ClientAuth: tls.NoClientCert,
// // Note on GKE there apparently is no client cert sent, so this
// // does not work on GKE.
// // TODO: make this into a configuration option.
// // ClientAuth: tls.RequireAndVerifyClientCert,
// }, nil
//}
2 changes: 1 addition & 1 deletion pkg/internal/informer/informertest/fake_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *FakeInformers) FakeInformerFor(obj runtime.Object) (*controllertest.Fak
return i.(*controllertest.FakeInformer), nil
}

func (c *FakeInformers) informerFor(gvk schema.GroupVersionKind, obj runtime.Object) (cache.SharedIndexInformer, error) {
func (c *FakeInformers) informerFor(gvk schema.GroupVersionKind, _ runtime.Object) (cache.SharedIndexInformer, error) {
if c.Error != nil {
return nil, c.Error
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type Environment struct {
}

// Stop stops a running server
func (te *Environment) Stop() {
te.ControlPlane.Stop()
func (te *Environment) Stop() error {
return te.ControlPlane.Stop()
}

// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
Expand Down
45 changes: 43 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,46 @@ fetch_kb_tools
# setup testing env
setup_envs

go test github.com/kubernetes-sigs/controller-runtime/pkg/...
go install github.com/kubernetes-sigs/controller-runtime/example
header_text "running go vet"

go vet ./pkg/...

header_text "running golint"

golint -set_exit_status ./pkg/...

header_text "running gometalinter.v2"

gometalinter.v2 --disable-all \
--deadline 5m \
--enable=misspell \
--enable=structcheck \
--enable=golint \
--enable=deadcode \
--enable=goimports \
--enable=errcheck \
--enable=varcheck \
--enable=goconst \
--enable=gas \
--enable=unparam \
--enable=ineffassign \
--enable=nakedret \
--enable=interfacer \
--enable=misspell \
--enable=gocyclo \
--line-length=170 \
--enable=lll \
--dupl-threshold=400 \
--enable=dupl \
./pkg/...
# TODO: Enable these as we fix them to make them pass
# --enable=maligned \
# --enable=safesql \

header_text "running go test"

go test ./pkg/...

header_text "running go install"

go install ./example