Update staticcheck version and fix all warnings (#1381)

This commit is contained in:
Ta-Ching Chen
2019-11-05 18:09:12 +08:00
committed by GitHub
parent 93d4b88d84
commit b9a5588ca9
43 changed files with 122 additions and 219 deletions
-1
View File
@@ -218,5 +218,4 @@ func (client *PreUpgradeTaskClient) SetupRoleBindings() {
client.logger.Info("created rolebindings in default namespace", client.logger.Info("created rolebindings in default namespace",
zap.Strings("role_bindings", []string{types.PackageGetterRB, types.SecretConfigMapGetterRB})) zap.Strings("role_bindings", []string{types.PackageGetterRB, types.SecretConfigMapGetterRB}))
return
} }
+2 -4
View File
@@ -38,10 +38,8 @@ func (e *Env) ToStringEnv() []string {
func NewEnv(stringEnv []string) *Env { func NewEnv(stringEnv []string) *Env {
env := &Env{} env := &Env{}
if stringEnv != nil { for _, rawEnvVar := range stringEnv {
for _, rawEnvVar := range stringEnv { env.SetEnv(FromString(rawEnvVar))
env.SetEnv(FromString(rawEnvVar))
}
} }
return env return env
} }
+5 -5
View File
@@ -14,12 +14,12 @@ then
fi fi
# Get staticcheck # Get staticcheck
STATICCHECK_VERSION=2019.1.1 STATICCHECK_VERSION=2019.2.3
if [ ! -f $TOOL_DIR/staticcheck ] if [ ! -f $TOOL_DIR/staticcheck ] || (staticcheck -version | grep -v $STATICCHECK_VERSION)
then then
curl -LO https://github.com/dominikh/go-tools/releases/download/${STATICCHECK_VERSION}/staticcheck_linux_amd64 curl -LO https://github.com/dominikh/go-tools/releases/download/${STATICCHECK_VERSION}/staticcheck_linux_amd64.tar.gz
chmod +x staticcheck_linux_amd64 tar xzvf staticcheck_linux_amd64.tar.gz
mv staticcheck_linux_amd64 $TOOL_DIR/staticcheck mv staticcheck/staticcheck $TOOL_DIR/staticcheck
fi fi
K8SCLI_DIR=$HOME/k8scli K8SCLI_DIR=$HOME/k8scli
+1 -9
View File
@@ -6,12 +6,4 @@ set -o pipefail
ROOT=`realpath $(dirname $0)/..` ROOT=`realpath $(dirname $0)/..`
# Currently here only lists the packages that already addressed all warnings for gradual code repair. go list ./...| grep -v vendor | grep -v "examples" | grep -v "demos" | xargs -I@ staticcheck @
# That means we don't allow adding new warnings to any of package in list. And eventually, the
# list will be replaced by find command.
declare -a pkgs=("pkg/builder" "pkg/builder" "pkg/crd" "pkg/logger" "pkg/buildermgr" "pkg/fission-cli" "cmd/fission-cli")
for pkg in "${pkgs[@]}"
do
find ${ROOT}/${pkg} -type d |grep -v influxdb | xargs -I@ staticcheck @
done
+1 -1
View File
@@ -37,7 +37,7 @@ const (
) )
var ( var (
validAzureQueueName = regexp.MustCompile("^[a-z0-9][a-z0-9\\-]*[a-z0-9]$") validAzureQueueName = regexp.MustCompile(`^[a-z0-9][a-z0-9\\-]*[a-z0-9]$`)
// Need to use raw string to support escape sequence for - & . chars // Need to use raw string to support escape sequence for - & . chars
validKafkaTopicName = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9\-\._]*[a-zA-Z0-9]$`) validKafkaTopicName = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9\-\._]*[a-zA-Z0-9]$`)
) )
+1 -1
View File
@@ -74,7 +74,7 @@ func MakeBuilder(logger *zap.Logger, sharedVolumePath string) *Builder {
func (builder *Builder) VersionHandler(w http.ResponseWriter, r *http.Request) { func (builder *Builder) VersionHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, info.BuildInfo().String()) w.Write([]byte(info.BuildInfo().String()))
} }
func (builder *Builder) Handler(w http.ResponseWriter, r *http.Request) { func (builder *Builder) Handler(w http.ResponseWriter, r *http.Request) {
+1 -1
View File
@@ -84,7 +84,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
// Ignore duplicate build requests // Ignore duplicate build requests
key := fmt.Sprintf("%v-%v", srcpkg.Metadata.Name, srcpkg.Metadata.ResourceVersion) key := fmt.Sprintf("%v-%v", srcpkg.Metadata.Name, srcpkg.Metadata.ResourceVersion)
err, _ := buildCache.Set(key, srcpkg) _, err := buildCache.Set(key, srcpkg)
if err != nil { if err != nil {
return return
} }
+2 -2
View File
@@ -159,7 +159,7 @@ func (c *Cache) Get(key interface{}) (interface{}, error) {
// if key exists in the cache, the new value is NOT set; instead an // if key exists in the cache, the new value is NOT set; instead an
// error and the old value are returned // error and the old value are returned
func (c *Cache) Set(key interface{}, value interface{}) (error, interface{}) { func (c *Cache) Set(key interface{}, value interface{}) (interface{}, error) {
respChannel := make(chan *response) respChannel := make(chan *response)
c.requestChannel <- &request{ c.requestChannel <- &request{
requestType: SET, requestType: SET,
@@ -168,7 +168,7 @@ func (c *Cache) Set(key interface{}, value interface{}) (error, interface{}) {
responseChannel: respChannel, responseChannel: respChannel,
} }
resp := <-respChannel resp := <-respChannel
return resp.error, resp.existingValue return resp.existingValue, resp.error
} }
func (c *Cache) Delete(key interface{}) error { func (c *Cache) Delete(key interface{}) error {
+3 -3
View File
@@ -31,9 +31,9 @@ func checkErr(err error) {
func TestCache(t *testing.T) { func TestCache(t *testing.T) {
c := MakeCache(100*time.Millisecond, 100*time.Millisecond) c := MakeCache(100*time.Millisecond, 100*time.Millisecond)
err, _ := c.Set("a", "b") _, err := c.Set("a", "b")
checkErr(err) checkErr(err)
err, _ = c.Set("p", "q") _, err = c.Set("p", "q")
checkErr(err) checkErr(err)
val, err := c.Get("a") val, err := c.Get("a")
@@ -55,7 +55,7 @@ func TestCache(t *testing.T) {
log.Panicf("found deleted element") log.Panicf("found deleted element")
} }
err, _ = c.Set("expires", "42") _, err = c.Set("expires", "42")
checkErr(err) checkErr(err)
time.Sleep(150 * time.Millisecond) time.Sleep(150 * time.Millisecond)
_, err = c.Get("expires") _, err = c.Get("expires")
+1 -1
View File
@@ -68,7 +68,7 @@ func (cancelFuncMap *canaryConfigCancelFuncMap) lookup(f *metav1.ObjectMeta) (*C
func (cancelFuncMap *canaryConfigCancelFuncMap) assign(f *metav1.ObjectMeta, value *CanaryProcessingInfo) error { func (cancelFuncMap *canaryConfigCancelFuncMap) assign(f *metav1.ObjectMeta, value *CanaryProcessingInfo) error {
mk := keyFromMetadata(f) mk := keyFromMetadata(f)
err, _ := cancelFuncMap.cache.Set(mk, value) _, err := cancelFuncMap.cache.Set(mk, value)
return err return err
} }
+3
View File
@@ -443,6 +443,9 @@ func (canaryCfgMgr *canaryConfigMgr) rollback(canaryConfig *fv1.CanaryConfig, tr
functionWeights[canaryConfig.Spec.OldFunction] = 100 functionWeights[canaryConfig.Spec.OldFunction] = 100
err := canaryCfgMgr.updateHttpTriggerWithRetries(trigger.Metadata.Name, trigger.Metadata.Namespace, functionWeights) err := canaryCfgMgr.updateHttpTriggerWithRetries(trigger.Metadata.Name, trigger.Metadata.Namespace, functionWeights)
if err != nil {
return err
}
err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.Metadata.Name, canaryConfig.Metadata.Namespace, err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.Metadata.Name, canaryConfig.Metadata.Namespace,
types.CanaryConfigStatusFailed) types.CanaryConfigStatusFailed)
+1 -2
View File
@@ -53,7 +53,6 @@ type (
builderManagerUrl string builderManagerUrl string
workflowApiUrl string workflowApiUrl string
functionNamespace string functionNamespace string
useIstio bool
featureStatus map[string]string featureStatus map[string]string
} }
@@ -167,7 +166,7 @@ func (api *API) getLogDBConfig(dbType string) logDBConfig {
func (api *API) HomeHandler(w http.ResponseWriter, r *http.Request) { func (api *API) HomeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, info.ApiInfo().String()) w.Write([]byte(info.ApiInfo().String()))
} }
func (api *API) ApiVersionMismatchHandler(w http.ResponseWriter, r *http.Request) { func (api *API) ApiVersionMismatchHandler(w http.ResponseWriter, r *http.Request) {
+3 -3
View File
@@ -20,13 +20,13 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
"golang.org/x/net/context/ctxhttp" "golang.org/x/net/context/ctxhttp"
ferror "github.com/fission/fission/pkg/error" ferror "github.com/fission/fission/pkg/error"
@@ -58,9 +58,9 @@ func (c *Client) delete(relativeUrl string) error {
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return errors.New("Delete failed") return errors.Wrap(err, "error deleting")
} else { } else {
return errors.New("Delete failed: " + string(body)) return errors.Errorf("failed to delete: %v", string(body))
} }
} }
+3 -1
View File
@@ -22,6 +22,8 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"github.com/pkg/errors"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@@ -84,7 +86,7 @@ func (c *Client) GetSvcURL(label string) (string, error) {
} }
if resp == nil { if resp == nil {
return "", fmt.Errorf("Failed to find service for given label: %v", label) return "", errors.Errorf("failed to find service for given label: %v", label)
} }
defer resp.Body.Close() defer resp.Body.Close()
+1 -8
View File
@@ -106,12 +106,6 @@ func RegisterFunctionRoute(ws *restful.WebService) {
Returns(http.StatusOK, "Only HTTP status returned", nil)) Returns(http.StatusOK, "Only HTTP status returned", nil))
} }
func (a *API) getIstioServiceLabels(fnName string) map[string]string {
return map[string]string{
"functionName": fnName,
}
}
func (a *API) FunctionApiList(w http.ResponseWriter, r *http.Request) { func (a *API) FunctionApiList(w http.ResponseWriter, r *http.Request) {
ns := a.extractQueryParamFromRequest(r, "namespace") ns := a.extractQueryParamFromRequest(r, "namespace")
if len(ns) == 0 { if len(ns) == 0 {
@@ -325,7 +319,7 @@ func (a *API) FunctionPodLogs(w http.ResponseWriter, r *http.Request) {
if len(pods) > 0 { if len(pods) > 0 {
podLogsReq = a.kubernetesClient.CoreV1().Pods(ns).GetLogs(pods[0].ObjectMeta.Name, &podLogOpts) podLogsReq = a.kubernetesClient.CoreV1().Pods(ns).GetLogs(pods[0].ObjectMeta.Name, &podLogOpts)
} else { } else {
a.respondWithError(w, errors.New("No active pods found")) a.respondWithError(w, errors.New("no active pods found"))
return return
} }
@@ -341,5 +335,4 @@ func (a *API) FunctionPodLogs(w http.ResponseWriter, r *http.Request) {
a.respondWithError(w, err) a.respondWithError(w, err)
return return
} }
return
} }
-15
View File
@@ -25,10 +25,8 @@ package executor
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"math/rand" "math/rand"
"net/http"
"os" "os"
"testing" "testing"
"time" "time"
@@ -99,19 +97,6 @@ func createSvc(kubeClient *kubernetes.Clientset, ns string, name string, targetP
return svc return svc
} }
func httpGet(url string) string {
resp, err := http.Get(url)
if err != nil {
log.Panicf("HTTP Get failed: URL %v: %v", url, err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Panicf("HTTP Get failed to read body: URL %v: %v", url, err)
}
return string(body)
}
func TestExecutor(t *testing.T) { func TestExecutor(t *testing.T) {
// run in a random namespace so we can have concurrent tests // run in a random namespace so we can have concurrent tests
// on a given cluster // on a given cluster
+8 -10
View File
@@ -68,15 +68,13 @@ type (
requestChannel chan *fscRequest requestChannel chan *fscRequest
} }
fscRequest struct { fscRequest struct {
requestType fscRequestType requestType fscRequestType
address string address string
kubernetesObjects []apiv1.ObjectReference age time.Duration
age time.Duration responseChannel chan *fscResponse
responseChannel chan *fscResponse
} }
fscResponse struct { fscResponse struct {
objects []*FuncSvc objects []*FuncSvc
deleted bool
error error
} }
) )
@@ -180,7 +178,7 @@ func (fsc *FunctionServiceCache) GetByFunctionUID(uid types.UID) (*FuncSvc, erro
} }
func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) { func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
err, existing := fsc.byFunction.Set(crd.CacheKey(fsvc.Function), &fsvc) existing, err := fsc.byFunction.Set(crd.CacheKey(fsvc.Function), &fsvc)
if err != nil { if err != nil {
if IsNameExistError(err) { if IsNameExistError(err) {
f := existing.(*FuncSvc) f := existing.(*FuncSvc)
@@ -199,7 +197,7 @@ func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
// Add to byAddress cache. Ignore NameExists errors // Add to byAddress cache. Ignore NameExists errors
// because of multiple-specialization. See issue #331. // because of multiple-specialization. See issue #331.
err, _ = fsc.byAddress.Set(fsvc.Address, *fsvc.Function) _, err = fsc.byAddress.Set(fsvc.Address, *fsvc.Function)
if err != nil { if err != nil {
if IsNameExistError(err) { if IsNameExistError(err) {
err = nil err = nil
@@ -211,7 +209,7 @@ func (fsc *FunctionServiceCache) Add(fsvc FuncSvc) (*FuncSvc, error) {
// Add to byFunctionUID cache. Ignore NameExists errors // Add to byFunctionUID cache. Ignore NameExists errors
// because of multiple-specialization. See issue #331. // because of multiple-specialization. See issue #331.
err, _ = fsc.byFunctionUID.Set(fsvc.Function.UID, *fsvc.Function) _, err = fsc.byFunctionUID.Set(fsvc.Function.UID, *fsvc.Function)
if err != nil { if err != nil {
if IsNameExistError(err) { if IsNameExistError(err) {
err = nil err = nil
@@ -257,7 +255,7 @@ func (fsc *FunctionServiceCache) DeleteEntry(fsvc *FuncSvc) {
fsc.byFunctionUID.Delete(fsvc.Function.UID) fsc.byFunctionUID.Delete(fsvc.Function.UID)
fsc.observeFuncRunningTime(fsvc.Function.Name, string(fsvc.Function.UID), fsvc.Atime.Sub(fsvc.Ctime).Seconds()) fsc.observeFuncRunningTime(fsvc.Function.Name, string(fsvc.Function.UID), fsvc.Atime.Sub(fsvc.Ctime).Seconds())
fsc.observeFuncAliveTime(fsvc.Function.Name, string(fsvc.Function.UID), time.Now().Sub(fsvc.Ctime).Seconds()) fsc.observeFuncAliveTime(fsvc.Function.Name, string(fsvc.Function.UID), time.Since(fsvc.Ctime).Seconds())
fsc.setFuncAlive(fsvc.Function.Name, string(fsvc.Function.UID), false) fsc.setFuncAlive(fsvc.Function.Name, string(fsvc.Function.UID), false)
} }
@@ -74,12 +74,12 @@ func TestFunctionServiceCache(t *testing.T) {
log.Panicf("Failed to add fsvc: %v", err) log.Panicf("Failed to add fsvc: %v", err)
} }
f, err := fsc.GetByFunction(fsvc.Function) _, err = fsc.GetByFunction(fsvc.Function)
if err != nil { if err != nil {
fsc.Log() fsc.Log()
log.Panicf("Failed to get fsvc: %v", err) log.Panicf("Failed to get fsvc: %v", err)
} }
f, err = fsc.GetByFunctionUID(fsvc.Function.UID) f, err := fsc.GetByFunctionUID(fsvc.Function.UID)
if err != nil { if err != nil {
fsc.Log() fsc.Log()
log.Panicf("Failed to get fsvc by function uid: %v", err) log.Panicf("Failed to get fsvc by function uid: %v", err)
-2
View File
@@ -5,8 +5,6 @@ import (
) )
var ( var (
metricAddr = ":8080"
// funcname: the function's name // funcname: the function's name
// funcuid: the function's version id // funcuid: the function's version id
coldStarts = prometheus.NewCounterVec( coldStarts = prometheus.NewCounterVec(
-4
View File
@@ -143,10 +143,6 @@ func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *fv1.Function)
return nil return nil
} }
func (deploy *NewDeploy) getDeployment(ns, name string) (*appsv1.Deployment, error) {
return deploy.kubernetesClient.AppsV1().Deployments(ns).Get(name, metav1.GetOptions{})
}
func (deploy *NewDeploy) updateDeployment(deployment *appsv1.Deployment, ns string) error { func (deploy *NewDeploy) updateDeployment(deployment *appsv1.Deployment, ns string) error {
_, err := deploy.kubernetesClient.AppsV1().Deployments(ns).Update(deployment) _, err := deploy.kubernetesClient.AppsV1().Deployments(ns).Update(deployment)
return err return err
+1 -16
View File
@@ -61,7 +61,6 @@ type (
runtimeImagePullPolicy apiv1.PullPolicy runtimeImagePullPolicy apiv1.PullPolicy
namespace string namespace string
useIstio bool useIstio bool
collectorEndpoint string
fsCache *fscache.FunctionServiceCache // cache funcSvc's by function, address and pod name fsCache *fscache.FunctionServiceCache // cache funcSvc's by function, address and pod name
@@ -523,7 +522,7 @@ func (deploy *NewDeploy) updateFunction(oldFn *fv1.Function, newFn *fv1.Function
} }
} }
if deployChanged == true { if deployChanged {
env, err := deploy.fissionClient.Environments(newFn.Spec.Environment.Namespace). env, err := deploy.fissionClient.Environments(newFn.Spec.Environment.Namespace).
Get(newFn.Spec.Environment.Name) Get(newFn.Spec.Environment.Name)
if err != nil { if err != nil {
@@ -624,20 +623,6 @@ func (deploy *NewDeploy) getDeployLabels(fnMeta metav1.ObjectMeta, envMeta metav
} }
} }
// updateKubeObjRefRV update the resource version of kubeObjectRef with
// given kind and return error if failed to find the reference.
func (deploy *NewDeploy) updateKubeObjRefRV(fsvc *fscache.FuncSvc, objKind string, rv string) error {
kubeObjs := fsvc.KubernetesObjects
for i, obj := range kubeObjs {
if obj.Kind == objKind {
kubeObjs[i].ResourceVersion = rv
return nil
}
}
fsvc.KubernetesObjects = kubeObjs
return fmt.Errorf("error finding kubernetes object reference with kind: %v", objKind)
}
// updateStatus is a function which updates status of update. // updateStatus is a function which updates status of update.
// Current implementation only logs messages, in future it will update function status // Current implementation only logs messages, in future it will update function status
func (deploy *NewDeploy) updateStatus(fn *fv1.Function, err error, message string) { func (deploy *NewDeploy) updateStatus(fn *fv1.Function, err error, message string) {
+12 -13
View File
@@ -154,16 +154,13 @@ func (gp *GenericPool) getDeployLabels() map[string]string {
// choosePodService serializes the choosing of pods // choosePodService serializes the choosing of pods
func (gp *GenericPool) choosePodService() { func (gp *GenericPool) choosePodService() {
for { for req := range gp.requestChannel {
select { pod, err := gp._choosePod(req.newLabels)
case req := <-gp.requestChannel: if err != nil {
pod, err := gp._choosePod(req.newLabels) req.responseChannel <- &choosePodResponse{error: err}
if err != nil { continue
req.responseChannel <- &choosePodResponse{error: err}
continue
}
req.responseChannel <- &choosePodResponse{pod: pod}
} }
req.responseChannel <- &choosePodResponse{pod: pod}
} }
} }
@@ -287,11 +284,13 @@ func (gp *GenericPool) getFetcherUrl(podIP string) string {
} }
isv6 := IsIPv6(podIP) isv6 := IsIPv6(podIP)
var baseUrl string var baseUrl string
if isv6 == false {
baseUrl = fmt.Sprintf("http://%v:8000/", podIP) if isv6 { // We use bracket if the IP is in IPv6.
} else if isv6 == true { // We use bracket if the IP is in IPv6.
baseUrl = fmt.Sprintf("http://[%v]:8000/", podIP) baseUrl = fmt.Sprintf("http://[%v]:8000/", podIP)
} else {
baseUrl = fmt.Sprintf("http://%v:8000/", podIP)
} }
return baseUrl return baseUrl
} }
@@ -477,7 +476,7 @@ func (gp *GenericPool) waitForReadyPod() error {
pod := podList.Items[0] pod := podList.Items[0]
multierr := &multierror.Error{} multierr := &multierror.Error{}
for _, cStatus := range pod.Status.ContainerStatuses { for _, cStatus := range pod.Status.ContainerStatuses {
if cStatus.Ready != true { if !cStatus.Ready {
multierr = multierror.Append(multierr, errors.New(fmt.Sprintf("%v: %v", cStatus.State.Waiting.Reason, cStatus.State.Waiting.Message))) multierr = multierror.Append(multierr, errors.New(fmt.Sprintf("%v: %v", cStatus.State.Waiting.Reason, cStatus.State.Waiting.Message)))
} }
} }
+3 -11
View File
@@ -120,17 +120,9 @@ func MergePodSpec(srcPodSpec *apiv1.PodSpec, targetPodSpec *apiv1.PodSpec) (*api
srcPodSpec.Hostname = targetPodSpec.Hostname srcPodSpec.Hostname = targetPodSpec.Hostname
} }
for _, obj := range targetPodSpec.ImagePullSecrets { srcPodSpec.ImagePullSecrets = append(srcPodSpec.ImagePullSecrets, targetPodSpec.ImagePullSecrets...)
srcPodSpec.ImagePullSecrets = append(srcPodSpec.ImagePullSecrets, obj) srcPodSpec.Tolerations = append(srcPodSpec.Tolerations, targetPodSpec.Tolerations...)
} srcPodSpec.HostAliases = append(srcPodSpec.HostAliases, targetPodSpec.HostAliases...)
for _, obj := range targetPodSpec.Tolerations {
srcPodSpec.Tolerations = append(srcPodSpec.Tolerations, obj)
}
for _, obj := range targetPodSpec.HostAliases {
srcPodSpec.HostAliases = append(srcPodSpec.HostAliases, obj)
}
err = mergo.Merge(&srcPodSpec.NodeSelector, targetPodSpec.NodeSelector) err = mergo.Merge(&srcPodSpec.NodeSelector, targetPodSpec.NodeSelector)
if err != nil { if err != nil {
+7 -6
View File
@@ -7,8 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/fission/fission/pkg/types" "github.com/pkg/errors"
"github.com/fission/fission/pkg/utils"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -16,6 +15,8 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils"
) )
type Config struct { type Config struct {
@@ -30,9 +31,9 @@ type Config struct {
sharedSecretPath string sharedSecretPath string
sharedCfgMapPath string sharedCfgMapPath string
dockerRegistryAuthDomain string // dockerRegistryAuthDomain string
dockerRegistryUsername string // dockerRegistryUsername string
dockerRegistryPassword string // dockerRegistryPassword string
serviceAccount string serviceAccount string
@@ -289,7 +290,7 @@ func (cfg *Config) addFetcherToPodSpecWithCommand(podSpec *apiv1.PodSpec, mainCo
for _, existingContainer := range podSpec.Containers { for _, existingContainer := range podSpec.Containers {
existingContainerNames = append(existingContainerNames, existingContainer.Name) existingContainerNames = append(existingContainerNames, existingContainer.Name)
} }
return fmt.Errorf("Could not find main container '%s' in given PodSpec. Found: %v", return errors.Errorf("could not find main container '%s' in given PodSpec. Found: %v",
mainContainerName, mainContainerName,
existingContainerNames) existingContainerNames)
} }
+1 -1
View File
@@ -151,7 +151,7 @@ func writeSecretOrConfigMap(dataMap map[string][]byte, dirPath string) error {
func (fetcher *Fetcher) VersionHandler(w http.ResponseWriter, r *http.Request) { func (fetcher *Fetcher) VersionHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, info.BuildInfo().String()) w.Write([]byte(info.BuildInfo().String()))
} }
func (fetcher *Fetcher) FetchHandler(w http.ResponseWriter, r *http.Request) { func (fetcher *Fetcher) FetchHandler(w http.ResponseWriter, r *http.Request) {
-1
View File
@@ -54,7 +54,6 @@ type (
kubernetesClient *kubernetes.Clientset kubernetesClient *kubernetes.Clientset
requestChannel chan *kubeWatcherRequest requestChannel chan *kubeWatcherRequest
publisher publisher.Publisher publisher publisher.Publisher
routerUrl string
} }
watchSubscription struct { watchSubscription struct {
+1 -1
View File
@@ -69,7 +69,7 @@ func makeKafkaMessageQueue(logger *zap.Logger, routerUrl string, mqCfg MessageQu
version: kafkaVersion, version: kafkaVersion,
} }
if tls, _ := strconv.ParseBool(os.Getenv("TLS_ENABLED")); tls == true { if tls, _ := strconv.ParseBool(os.Getenv("TLS_ENABLED")); tls {
kafka.tls = true kafka.tls = true
authKeys := make(map[string][]byte) authKeys := make(map[string][]byte)
@@ -55,7 +55,6 @@ type (
MessageQueueTriggerManager struct { MessageQueueTriggerManager struct {
logger *zap.Logger logger *zap.Logger
reqChan chan request reqChan chan request
mqCfg MessageQueueConfig
triggers map[string]*triggerSubscription triggers map[string]*triggerSubscription
fissionClient *crd.FissionClient fissionClient *crd.FissionClient
messageQueue MessageQueue messageQueue MessageQueue
+2 -3
View File
@@ -154,8 +154,7 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (*http.Res
roundTripper.addForwardedHostHeader(req) roundTripper.addForwardedHostHeader(req)
// TODO: Keep? --> Needed for queries encoded in URL before they're stripped by the proxy // TODO: Keep? --> Needed for queries encoded in URL before they're stripped by the proxy
var originalUrl url.URL originalUrl := *req.URL
originalUrl = *req.URL
// Iff this request needs to be recorded, we save the body // Iff this request needs to be recorded, we save the body
var postedBody string var postedBody string
@@ -245,7 +244,7 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (*http.Res
Body: ioutil.NopCloser(bytes.NewBufferString(errMsg)), Body: ioutil.NopCloser(bytes.NewBufferString(errMsg)),
ContentLength: int64(len(errMsg)), ContentLength: int64(len(errMsg)),
Request: req, Request: req,
Header: make(http.Header, 0), Header: make(http.Header),
}, nil }, nil
} }
return nil, ferror.MakeError(http.StatusInternalServerError, err.Error()) return nil, ferror.MakeError(http.StatusInternalServerError, err.Error())
+1 -1
View File
@@ -51,7 +51,7 @@ func (frmap *functionRecorderMap) lookup(function string) (*fv1.Recorder, error)
} }
func (frmap *functionRecorderMap) assign(function string, recorder *fv1.Recorder) { func (frmap *functionRecorderMap) assign(function string, recorder *fv1.Recorder) {
err, _ := frmap.cache.Set(function, recorder) _, err := frmap.cache.Set(function, recorder)
if err != nil { if err != nil {
if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNameExists { if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNameExists {
return return
+5 -25
View File
@@ -20,11 +20,8 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/rest"
k8sCache "k8s.io/client-go/tools/cache" k8sCache "k8s.io/client-go/tools/cache"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
@@ -37,9 +34,7 @@ type (
functionReferenceResolver struct { functionReferenceResolver struct {
// FunctionReference -> function metadata // FunctionReference -> function metadata
refCache *cache.Cache refCache *cache.Cache
store k8sCache.Store
stopCh chan struct{}
store k8sCache.Store
} }
resolveResultType int resolveResultType int
@@ -81,21 +76,6 @@ func makeFunctionReferenceResolver(store k8sCache.Store) *functionReferenceResol
return frr return frr
} }
func makeK8SCache(crdClient *rest.RESTClient) (k8sCache.Store, k8sCache.Controller) {
watchlist := k8sCache.NewListWatchFromClient(crdClient, "functions", metav1.NamespaceDefault, fields.Everything())
listWatch := &k8sCache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return watchlist.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return watchlist.Watch(options)
},
}
resyncPeriod := 30 * time.Second
return k8sCache.NewInformer(listWatch, &fv1.Function{}, resyncPeriod,
k8sCache.ResourceEventHandlerFuncs{})
}
// resolve translates a trigger's function reference to a resolveResult. // resolve translates a trigger's function reference to a resolveResult.
func (frr *functionReferenceResolver) resolve(trigger fv1.HTTPTrigger) (*resolveResult, error) { func (frr *functionReferenceResolver) resolve(trigger fv1.HTTPTrigger) (*resolveResult, error) {
nfr := namespacedTriggerReference{ nfr := namespacedTriggerReference{
@@ -128,7 +108,7 @@ func (frr *functionReferenceResolver) resolve(trigger fv1.HTTPTrigger) (*resolve
} }
default: default:
return nil, fmt.Errorf("Unrecognized function reference type %v", trigger.Spec.FunctionReference.Type) return nil, errors.Errorf("unrecognized function reference type %v", trigger.Spec.FunctionReference.Type)
} }
// cache resolve result // cache resolve result
@@ -150,7 +130,7 @@ func (frr *functionReferenceResolver) resolveByName(namespace, name string) (*re
return nil, err return nil, err
} }
if !isExist { if !isExist {
return nil, fmt.Errorf("function %v does not exist", name) return nil, errors.Errorf("function %v does not exist", name)
} }
f := obj.(*fv1.Function) f := obj.(*fv1.Function)
@@ -167,7 +147,7 @@ func (frr *functionReferenceResolver) resolveByName(namespace, name string) (*re
func (frr *functionReferenceResolver) resolveByFunctionWeights(namespace string, fr *fv1.FunctionReference) (*resolveResult, error) { func (frr *functionReferenceResolver) resolveByFunctionWeights(namespace string, fr *fv1.FunctionReference) (*resolveResult, error) {
functionMetadataMap := make(map[string]*metav1.ObjectMeta, 0) functionMetadataMap := make(map[string]*metav1.ObjectMeta)
fnWtDistrList := make([]FunctionWeightDistribution, 0) fnWtDistrList := make([]FunctionWeightDistribution, 0)
sumPrefix := 0 sumPrefix := 0
+1 -1
View File
@@ -68,7 +68,7 @@ func (fmap *functionServiceMap) lookup(f *metav1.ObjectMeta) (*url.URL, error) {
func (fmap *functionServiceMap) assign(f *metav1.ObjectMeta, serviceUrl *url.URL) { func (fmap *functionServiceMap) assign(f *metav1.ObjectMeta, serviceUrl *url.URL) {
mk := keyFromMetadata(f) mk := keyFromMetadata(f)
err, old := fmap.cache.Set(*mk, serviceUrl) old, err := fmap.cache.Set(*mk, serviceUrl)
if err != nil { if err != nil {
if *serviceUrl == *(old.(*url.URL)) { if *serviceUrl == *(old.(*url.URL)) {
return return
+2 -2
View File
@@ -72,12 +72,12 @@ func deleteIngress(logger *zap.Logger, trigger *fv1.HTTPTrigger, kubeClient *kub
func updateIngress(logger *zap.Logger, oldT *fv1.HTTPTrigger, newT *fv1.HTTPTrigger, kubeClient *kubernetes.Clientset) { func updateIngress(logger *zap.Logger, oldT *fv1.HTTPTrigger, newT *fv1.HTTPTrigger, kubeClient *kubernetes.Clientset) {
if oldT.Spec.CreateIngress == false && newT.Spec.CreateIngress == true { if !oldT.Spec.CreateIngress && newT.Spec.CreateIngress {
createIngress(logger, newT, kubeClient) createIngress(logger, newT, kubeClient)
return return
} }
if newT.Spec.CreateIngress == false && oldT.Spec.CreateIngress == true { if !newT.Spec.CreateIngress && oldT.Spec.CreateIngress {
deleteIngress(logger, oldT, kubeClient) deleteIngress(logger, oldT, kubeClient)
return return
} }
+1 -1
View File
@@ -47,7 +47,7 @@ func spamServer(quit chan bool) {
for { for {
select { select {
case <-quit: case <-quit:
break return
default: default:
i = i + 1 i = i + 1
resp, err := http.Get("http://localhost:3333") resp, err := http.Get("http://localhost:3333")
+1 -1
View File
@@ -113,7 +113,7 @@ func (rs *RecorderSet) disableRecorder(r *fv1.Recorder) {
} }
func (rs *RecorderSet) updateRecorder(old *fv1.Recorder, newer *fv1.Recorder) { func (rs *RecorderSet) updateRecorder(old *fv1.Recorder, newer *fv1.Recorder) {
if newer.Spec.Enabled == true { if newer.Spec.Enabled {
rs.newRecorder(newer) // TODO: Test this rs.newRecorder(newer) // TODO: Test this
} else { } else {
rs.disableRecorder(old) rs.disableRecorder(old)
+1 -1
View File
@@ -50,7 +50,7 @@ func (trmap *triggerRecorderMap) lookup(trigger string) (*fv1.Recorder, error) {
} }
func (trmap *triggerRecorderMap) assign(trigger string, recorder *fv1.Recorder) { func (trmap *triggerRecorderMap) assign(trigger string, recorder *fv1.Recorder) {
err, _ := trmap.cache.Set(trigger, recorder) _, err := trmap.cache.Set(trigger, recorder)
if err != nil { if err != nil {
if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNameExists { if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNameExists {
return return
+13 -21
View File
@@ -28,7 +28,7 @@ import (
type ArchivePruner struct { type ArchivePruner struct {
logger *zap.Logger logger *zap.Logger
crdClient *crd.FissionClient crdClient *crd.FissionClient
archiveChan chan (string) archiveChan chan string
stowClient *StowClient stowClient *StowClient
pruneInterval time.Duration pruneInterval time.Duration
} }
@@ -53,18 +53,15 @@ func MakeArchivePruner(logger *zap.Logger, stowClient *StowClient, pruneInterval
// pruneArchives listens to archiveChannel for archive ids that need to be deleted // pruneArchives listens to archiveChannel for archive ids that need to be deleted
func (pruner *ArchivePruner) pruneArchives() { func (pruner *ArchivePruner) pruneArchives() {
pruner.logger.Debug("listening to archiveChannel to prune archives") pruner.logger.Debug("listening to archiveChannel to prune archives")
for { for archiveID := range pruner.archiveChan {
select { pruner.logger.Info("sending delete request for archive",
case archiveID := <-pruner.archiveChan: zap.String("archive_id", archiveID))
pruner.logger.Info("sending delete request for archive", if err := pruner.stowClient.removeFileByID(archiveID); err != nil {
// logging the error and continuing with other deletions.
// hopefully this archive will be deleted in the next iteration.
pruner.logger.Error("ignoring error while deleting archive",
zap.Error(err),
zap.String("archive_id", archiveID)) zap.String("archive_id", archiveID))
if err := pruner.stowClient.removeFileByID(archiveID); err != nil {
// logging the error and continuing with other deletions.
// hopefully this archive will be deleted in the next iteration.
pruner.logger.Error("ignoring error while deleting archive",
zap.Error(err),
zap.String("archive_id", archiveID))
}
} }
} }
} }
@@ -134,8 +131,6 @@ func (pruner *ArchivePruner) getOrphanArchives() {
for _, archiveID = range orphanedArchives { for _, archiveID = range orphanedArchives {
pruner.insertArchive(archiveID) pruner.insertArchive(archiveID)
} }
return
} }
// Start starts a go routine that listens to a channel for archive IDs that need to deleted. // Start starts a go routine that listens to a channel for archive IDs that need to deleted.
@@ -144,12 +139,9 @@ func (pruner *ArchivePruner) getOrphanArchives() {
func (pruner *ArchivePruner) Start() { func (pruner *ArchivePruner) Start() {
ticker := time.NewTicker(pruner.pruneInterval * time.Minute) ticker := time.NewTicker(pruner.pruneInterval * time.Minute)
go pruner.pruneArchives() go pruner.pruneArchives()
for { for range ticker.C {
select { // This method fetches unused archive IDs and sends them to archiveChannel for deletion
case <-ticker.C: // silencing the errors, hoping they go away in next iteration.
// This method fetches unused archive IDs and sends them to archiveChannel for deletion pruner.getOrphanArchives()
// silencing the errors, hoping they go away in next iteration.
pruner.getOrphanArchives()
}
} }
} }
+3 -3
View File
@@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@@ -30,6 +29,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp" "go.opencensus.io/plugin/ochttp"
"golang.org/x/net/context/ctxhttp" "golang.org/x/net/context/ctxhttp"
@@ -127,7 +127,7 @@ func (c *Client) Download(ctx context.Context, id string, filePath string) error
// quit if file exists // quit if file exists
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
if err == nil || !os.IsNotExist(err) { if err == nil || !os.IsNotExist(err) {
return errors.New(fmt.Sprintf("file already exists: %v", filePath)) return errors.Errorf("file already exists: %v", filePath)
} }
// create // create
@@ -175,7 +175,7 @@ func (c *Client) Delete(ctx context.Context, id string) error {
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.New(fmt.Sprintf("HTTP error %v", resp.StatusCode)) return errors.Errorf("HTTP error %v", resp.StatusCode)
} }
return nil return nil
+2 -2
View File
@@ -18,7 +18,6 @@ package storagesvc
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
@@ -27,6 +26,7 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
_ "github.com/graymeta/stow/local" _ "github.com/graymeta/stow/local"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp" "go.opencensus.io/plugin/ochttp"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -109,7 +109,7 @@ func (ss *StorageService) getIdFromRequest(r *http.Request) (string, error) {
values := r.URL.Query() values := r.URL.Query()
ids, ok := values["id"] ids, ok := values["id"]
if !ok || len(ids) == 0 { if !ok || len(ids) == 0 {
return "", errors.New("Missing `id' query param") return "", errors.New("missing `id' query param")
} }
return ids[0], nil return ids[0], nil
} }
+2 -2
View File
@@ -136,7 +136,7 @@ func AddSaToRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernetes.Cli
// someone may have deleted the object between us checking if the object is present and deciding to patch // someone may have deleted the object between us checking if the object is present and deciding to patch
// so just create the object again // so just create the object again
rbObj := makeRoleBindingObj(roleBinding, roleBindingNs, role, roleKind, sa, saNamespace) rbObj := makeRoleBindingObj(roleBinding, roleBindingNs, role, roleKind, sa, saNamespace)
rbObj, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Create(rbObj) _, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Create(rbObj)
if err == nil { if err == nil {
logger.Debug("created rolebinding", logger.Debug("created rolebinding",
zap.String("role_binding", roleBinding), zap.String("role_binding", roleBinding),
@@ -263,7 +263,7 @@ func SetupRoleBinding(logger *zap.Logger, k8sClient *kubernetes.Clientset, roleB
zap.String("role_binding", roleBinding), zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs)) zap.String("role_binding_namespace", roleBindingNs))
rbObj = makeRoleBindingObj(roleBinding, roleBindingNs, role, roleKind, sa, saNamespace) rbObj = makeRoleBindingObj(roleBinding, roleBindingNs, role, roleKind, sa, saNamespace)
rbObj, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Create(rbObj) _, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Create(rbObj)
if k8serrors.IsAlreadyExists(err) { if k8serrors.IsAlreadyExists(err) {
logger.Debug("rolebinding already exists in namespace - adding service account to rolebinding", logger.Debug("rolebinding already exists in namespace - adding service account to rolebinding",
zap.String("service_account_name", sa), zap.String("service_account_name", sa),
+2 -2
View File
@@ -19,7 +19,6 @@ package utils
import ( import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@@ -29,6 +28,7 @@ import (
"strings" "strings"
"github.com/mholt/archiver" "github.com/mholt/archiver"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -105,7 +105,7 @@ func FindAllGlobs(inputList []string) ([]string, error) {
for _, glob := range inputList { for _, glob := range inputList {
f, err := filepath.Glob(glob) f, err := filepath.Glob(glob)
if err != nil { if err != nil {
return nil, fmt.Errorf("Invalid glob %v: %v", glob, err) return nil, errors.Errorf("invalid glob %v: %v", glob, err)
} }
files = append(files, f...) files = append(files, f...)
} }
+21 -21
View File
@@ -99,24 +99,24 @@ type (
errorCode int errorCode int
) )
const ( //const (
ErrorInternal = iota // ErrorInternal = iota
//
ErrorNotAuthorized // ErrorNotAuthorized
ErrorNotFound // ErrorNotFound
ErrorNameExists // ErrorNameExists
ErrorInvalidArgument // ErrorInvalidArgument
ErrorNoSpace // ErrorNoSpace
ErrorNotImplmented // ErrorNotImplmented
) //)
//
// must match order and len of the above const //// must match order and len of the above const
var errorDescriptions = []string{ //var errorDescriptions = []string{
"Internal error", // "Internal error",
"Not authorized", // "Not authorized",
"Resource not found", // "Resource not found",
"Resource exists", // "Resource exists",
"Invalid argument", // "Invalid argument",
"No space", // "No space",
"Not implemented", // "Not implemented",
} //}
+2 -8
View File
@@ -72,7 +72,6 @@ func generateContinuousSeries(file string) chart.Series {
reader := bufio.NewReader(f) reader := bufio.NewReader(f)
var points []*MetricPoint
var xVals []float64 var xVals []float64
var yVals []float64 var yVals []float64
@@ -95,8 +94,6 @@ func generateContinuousSeries(file string) chart.Series {
continue continue
} }
points = append(points, point)
if initTime == nil { if initTime == nil {
initTime = &point.Data.Time initTime = &point.Data.Time
} }
@@ -119,7 +116,7 @@ func generateContinuousSeries(file string) chart.Series {
func generateChart(title string, file string, format chart.RendererProvider, series []chart.Series) error { func generateChart(title string, file string, format chart.RendererProvider, series []chart.Series) error {
if series == nil { if series == nil {
return errors.New("Series cannot be nil") return errors.New("series cannot be nil")
} }
cs := chart.ConcatSeries(series) cs := chart.ConcatSeries(series)
@@ -190,16 +187,13 @@ func listJsonFiles(path string) ([]string, error) {
if err != nil { if err != nil {
return err return err
} }
if strings.HasSuffix(path, ".json") && !info.IsDir() { if strings.HasSuffix(path, ".json") && !info.IsDir() {
files = append(files, path) files = append(files, path)
return nil
} }
return nil return nil
}) })
return files, nil return files, err
} }
func main() { func main() {