diff --git a/common.go b/common.go index e73bb237..27381e4d 100644 --- a/common.go +++ b/common.go @@ -149,7 +149,7 @@ func MakeArchive(targetName string, globs ...string) (string, error) { for _, glob := range globs { f, err := filepath.Glob(glob) if err != nil { - log.Warn(fmt.Sprintf("Invalid glob %v: %v", glob, err)) + log.Info(fmt.Sprintf("Invalid glob %v: %v", glob, err)) return "", err } files = append(files, f...) diff --git a/fission/function.go b/fission/function.go index 1530070d..4f421288 100644 --- a/fission/function.go +++ b/fission/function.go @@ -173,16 +173,18 @@ func fnCreate(c *cli.Context) error { log.Fatal("Need --env argument.") } - // examine existence of given environment - _, err := client.EnvironmentGet(&metav1.ObjectMeta{ - Namespace: envNamespace, - Name: envName, - }) - if err != nil { - if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNotFound { - fmt.Printf("Environment \"%v\" does not exist. Please create the environment before executing the function. \nFor example: `fission env create --name %v --envns %v --image `\n", envName, envName, envNamespace) - } else { - util.CheckErr(err, "retrieve environment information") + // examine existence of given environment. If specs - then spec validate will do it, don't check here. + if !spec { + _, err := client.EnvironmentGet(&metav1.ObjectMeta{ + Namespace: envNamespace, + Name: envName, + }) + if err != nil { + if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNotFound { + log.Warn(fmt.Sprintf("Environment \"%v\" does not exist. Please create the environment before executing the function. \nFor example: `fission env create --name %v --envns %v --image `\n", envName, envName, envNamespace)) + } else { + util.CheckErr(err, "retrieve environment information") + } } } diff --git a/fission/httptrigger.go b/fission/httptrigger.go index 2d12d75f..632fcd45 100644 --- a/fission/httptrigger.go +++ b/fission/httptrigger.go @@ -80,6 +80,7 @@ func htCreate(c *cli.Context) error { log.Fatal("Need a function name to create a trigger, use --function") } fnNamespace := c.String("fnNamespace") + spec := c.Bool("spec") triggerUrl := c.String("url") if len(triggerUrl) == 0 { @@ -94,7 +95,11 @@ func htCreate(c *cli.Context) error { method = "GET" } - checkFunctionExistence(client, fnName, fnNamespace) + // For Specs, the spec validate checks for function reference + if !spec { + checkFunctionExistence(client, fnName, fnNamespace) + } + createIngress := false if c.IsSet("createingress") { createIngress = c.Bool("createingress") @@ -123,7 +128,7 @@ func htCreate(c *cli.Context) error { } // if we're writing a spec, don't call the API - if c.Bool("spec") { + if spec { specFile := fmt.Sprintf("route-%v.yaml", triggerName) err := specSave(*ht, specFile) util.CheckErr(err, "create HTTP trigger spec") diff --git a/fission/log/log.go b/fission/log/log.go index ceba041a..b9da0447 100644 --- a/fission/log/log.go +++ b/fission/log/log.go @@ -32,6 +32,10 @@ func Fatal(msg interface{}) { } func Warn(msg interface{}) { + os.Stderr.WriteString(fmt.Sprintf("[WARNING] %v\n", msg)) +} + +func Info(msg interface{}) { os.Stderr.WriteString(fmt.Sprintf("%v\n", msg)) } diff --git a/fission/spec.go b/fission/spec.go index d677f89f..2d43c9a6 100644 --- a/fission/spec.go +++ b/fission/spec.go @@ -388,6 +388,18 @@ func (fr *FissionResources) validate() error { // we do not error on unreferenced functions (you can call a function through workflows, // `fission function test`, etc.) + // Index envs, warn on functions referencing an environment for which spes does not exist + environments := make(map[string]struct{}) + for _, e := range fr.environments { + environments[fmt.Sprintf("%s:%s", e.Metadata.Name, e.Metadata.Namespace)] = struct{}{} + } + + for _, f := range fr.functions { + if _, ok := environments[fmt.Sprintf("%s:%s", f.Spec.Environment.Name, f.Spec.Environment.Namespace)]; !ok { + log.Warn(fmt.Sprintf("Environment %s is referred in function %s but not declared in specs", f.Spec.Environment.Name, f.Metadata.Name)) + } + } + // (ErrorOrNil returns nil if there were no errors appended.) return result.ErrorOrNil() } @@ -961,7 +973,7 @@ func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fission.Arch absGlob := rootDir + "/" + relativeGlob f, err := filepath.Glob(absGlob) if err != nil { - log.Warn(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob)) + log.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob)) return nil, err } files = append(files, f...)