Add static code analysis to CI test (#1197)
This commit is contained in:
@@ -28,25 +28,10 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/log"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
func getFunctionsByEnvironment(client *client.Client, envName, envNamespace string) ([]fv1.Function, error) {
|
||||
fnList, err := client.FunctionList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fns := []fv1.Function{}
|
||||
for _, fn := range fnList {
|
||||
if fn.Spec.Environment.Name == envName && fn.Spec.Environment.Namespace == envNamespace {
|
||||
fns = append(fns, fn)
|
||||
}
|
||||
}
|
||||
return fns, nil
|
||||
}
|
||||
|
||||
func envCreate(c *cli.Context) error {
|
||||
client := util.GetApiClient(c.GlobalString("server"))
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fv1.InvokeStrateg
|
||||
case types.ExecutorTypeNewdeploy:
|
||||
newFnExecutor = types.ExecutorTypeNewdeploy
|
||||
default:
|
||||
return nil, errors.New("Executor type must be one of 'poolmgr' or 'newdeploy', defaults to 'poolmgr'")
|
||||
return nil, errors.New("executor type must be one of 'poolmgr' or 'newdeploy', defaults to 'poolmgr'")
|
||||
}
|
||||
|
||||
if existingInvokeStrategy != nil {
|
||||
@@ -138,12 +138,12 @@ func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fv1.InvokeStrateg
|
||||
if c.IsSet("maxscale") {
|
||||
maxScale = c.Int("maxscale")
|
||||
if maxScale <= 0 {
|
||||
return nil, errors.New("Maxscale must be greater than 0")
|
||||
return nil, errors.New("maxscale must be greater than 0")
|
||||
}
|
||||
}
|
||||
|
||||
if minScale > maxScale {
|
||||
return nil, errors.New(fmt.Sprintf("Minscale provided: %v can not be greater than maxscale value %v", minScale, maxScale))
|
||||
return nil, fmt.Errorf("minscale provided: %v can not be greater than maxscale value %v", minScale, maxScale)
|
||||
}
|
||||
|
||||
// Right now a simple single case strategy implementation
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/fission-cli/log"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
@@ -74,7 +75,7 @@ func setHtFunctionRef(functionList []string, functionWeightsList []int) (*fv1.Fu
|
||||
log.Fatal("The function weights should add up to 100")
|
||||
}
|
||||
|
||||
functionWeights := make(map[string]int, 0)
|
||||
functionWeights := make(map[string]int)
|
||||
for index := range functionList {
|
||||
functionWeights[functionList[index]] = functionWeightsList[index]
|
||||
}
|
||||
@@ -113,6 +114,9 @@ func htCreate(c *cli.Context) error {
|
||||
}
|
||||
|
||||
htTrigger, err := client.HTTPTriggerGet(m)
|
||||
if err != nil && !ferror.IsNotFound(err) {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
if htTrigger != nil {
|
||||
util.CheckErr(fmt.Errorf("duplicate trigger exists"), "choose a different name or leave it empty for fission to auto-generate it")
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ func (influx InfluxDB) query(query influxdbClient.Query) (*influxdbClient.Respon
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
decoder.UseNumber()
|
||||
if decoder.Decode(&response) != nil {
|
||||
return nil, fmt.Errorf("Failed to decode influxdb response: %v", err)
|
||||
return nil, fmt.Errorf("failed to decode influxdb response: %v", err)
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
@@ -403,6 +403,9 @@ func pkgDelete(c *cli.Context) error {
|
||||
util.CheckErr(err, "find package")
|
||||
|
||||
fnList, err := getFunctionsByPackage(client, pkgName, pkgNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !force && len(fnList) > 0 {
|
||||
log.Fatal("Package is used by at least one function, use -f to force delete")
|
||||
@@ -680,8 +683,8 @@ func writeArchiveToFile(fileName string, reader io.Reader) error {
|
||||
// and write it to temp file for further usage
|
||||
func downloadToTempFile(fileUrl string) string {
|
||||
reader, err := downloadURL(fileUrl)
|
||||
defer reader.Close()
|
||||
util.CheckErr(err, fmt.Sprintf("download from url: %v", fileUrl))
|
||||
defer reader.Close()
|
||||
|
||||
tmpDir, err := utils.GetTempDir()
|
||||
util.CheckErr(err, "create temp directory")
|
||||
|
||||
@@ -55,7 +55,9 @@ func recorderCreate(c *cli.Context) error {
|
||||
if len(triggersOriginal) != 0 {
|
||||
ts := strings.Split(triggersOriginal[0], ",")
|
||||
for _, name := range ts {
|
||||
triggers = append(triggers, name)
|
||||
if len(name) > 0 {
|
||||
triggers = append(triggers, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Define appropriate set of policies and defaults
|
||||
@@ -147,6 +149,9 @@ func recorderUpdate(c *cli.Context) error {
|
||||
Name: recName,
|
||||
Namespace: "default",
|
||||
})
|
||||
if err != nil {
|
||||
util.CheckErr(err, "get recorder")
|
||||
}
|
||||
|
||||
updated := false
|
||||
|
||||
@@ -174,7 +179,9 @@ func recorderUpdate(c *cli.Context) error {
|
||||
var newTriggers []string
|
||||
triggs := strings.Split(triggers[0], ",")
|
||||
for _, name := range triggs {
|
||||
newTriggers = append(newTriggers, name)
|
||||
if len(name) > 0 {
|
||||
newTriggers = append(newTriggers, name)
|
||||
}
|
||||
}
|
||||
recorder.Spec.Triggers = newTriggers
|
||||
updated = true
|
||||
|
||||
+14
-6
@@ -449,6 +449,10 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error {
|
||||
// unmarshal again into the "real" struct once we know the type.
|
||||
var tm TypeMeta
|
||||
err := yaml.Unmarshal(b, &tm)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("Failed to decode yaml %v", string(b)))
|
||||
}
|
||||
|
||||
switch tm.Kind {
|
||||
case "Package":
|
||||
var v fv1.Package
|
||||
@@ -578,6 +582,10 @@ func readSpecs(specDir string) (*FissionResources, error) {
|
||||
|
||||
// Users can organize the specdir into subdirs if they want to.
|
||||
err := filepath.Walk(specDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// For now just read YAML files. We'll add jsonnet at some point. Skip
|
||||
// unsupported files.
|
||||
if !(strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml")) {
|
||||
@@ -615,7 +623,7 @@ func readSpecs(specDir string) (*FissionResources, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := result.ErrorOrNil(); err != nil {
|
||||
if err = result.ErrorOrNil(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -634,7 +642,7 @@ func waitForFileWatcherToSettleDown(watcher *fsnotify.Watcher) error {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for {
|
||||
select {
|
||||
case _ = <-watcher.Events:
|
||||
case <-watcher.Events:
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
continue
|
||||
case err := <-watcher.Errors:
|
||||
@@ -878,7 +886,7 @@ func applyArchives(fclient *client.Client, specDir string, fr *FissionResources)
|
||||
if strings.HasPrefix(ar.URL, ARCHIVE_URL_PREFIX) {
|
||||
availableAr, ok := archiveFiles[ar.URL]
|
||||
if !ok {
|
||||
return fmt.Errorf("Unknown archive name %v", strings.TrimPrefix(ar.URL, ARCHIVE_URL_PREFIX))
|
||||
return fmt.Errorf("unknown archive name %v", strings.TrimPrefix(ar.URL, ARCHIVE_URL_PREFIX))
|
||||
}
|
||||
ar.Type = availableAr.Type
|
||||
ar.Literal = availableAr.Literal
|
||||
@@ -927,7 +935,7 @@ func applyResources(fclient *client.Client, specDir string, fr *FissionResources
|
||||
// spec. It may exist outside the spec, but we're going to treat
|
||||
// that as an error, so that we encourage self-contained specs.
|
||||
// Is there a good use case for non-self contained specs?
|
||||
return nil, nil, fmt.Errorf("Function %v/%v references package %v/%v, which doesn't exist in the specs",
|
||||
return nil, nil, fmt.Errorf("function %v/%v references package %v/%v, which doesn't exist in the specs",
|
||||
f.Metadata.Namespace, f.Metadata.Name, f.Spec.Package.PackageRef.Namespace, f.Spec.Package.PackageRef.Name)
|
||||
}
|
||||
fr.functions[i].Spec.Package.PackageRef.ResourceVersion = m.ResourceVersion
|
||||
@@ -998,7 +1006,7 @@ func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fv1.Archive,
|
||||
}
|
||||
|
||||
if len(files) == 0 {
|
||||
return nil, fmt.Errorf("Archive '%v' is empty", aus.Name)
|
||||
return nil, fmt.Errorf("archive '%v' is empty", aus.Name)
|
||||
}
|
||||
|
||||
// if it's just one file, use its path directly
|
||||
@@ -1092,7 +1100,7 @@ func waitForPackageBuild(fclient *client.Client, pkg *fv1.Package) (*fv1.Package
|
||||
return pkg, nil
|
||||
}
|
||||
if time.Since(start) > 5*time.Minute {
|
||||
return nil, fmt.Errorf("Package %v has been building for a while. Giving up on waiting for it.", pkg.Metadata.Name)
|
||||
return nil, fmt.Errorf("package %v has been building for a while, giving up on waiting for it", pkg.Metadata.Name)
|
||||
}
|
||||
|
||||
// TODO watch instead
|
||||
|
||||
@@ -115,8 +115,8 @@ func DumpInfo(c *cli.Context) error {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(res resources.Resource, dir string) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
res.Dump(dir)
|
||||
}(res, dir)
|
||||
|
||||
@@ -25,8 +25,7 @@ import (
|
||||
)
|
||||
|
||||
type FissionVersion struct {
|
||||
client *client.Client
|
||||
namespace string
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
func NewFissionVersion(client *client.Client) Resource {
|
||||
|
||||
@@ -244,6 +244,4 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) {
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -100,12 +100,6 @@ func wGet(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func wUpdate(c *cli.Context) error {
|
||||
// TODO
|
||||
log.Fatal("Not implemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func wDelete(c *cli.Context) error {
|
||||
client := util.GetApiClient(c.GlobalString("server"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user