Fixed the spec validation UX issue (#898)
Improved some of warnings/messages shown to the user when using `fission spec` command. The `spec validate` command now shows appropriate warnings instead
This commit is contained in:
@@ -149,7 +149,7 @@ func MakeArchive(targetName string, globs ...string) (string, error) {
|
|||||||
for _, glob := range globs {
|
for _, glob := range globs {
|
||||||
f, err := filepath.Glob(glob)
|
f, err := filepath.Glob(glob)
|
||||||
if err != nil {
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
files = append(files, f...)
|
files = append(files, f...)
|
||||||
|
|||||||
+12
-10
@@ -173,16 +173,18 @@ func fnCreate(c *cli.Context) error {
|
|||||||
log.Fatal("Need --env argument.")
|
log.Fatal("Need --env argument.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// examine existence of given environment
|
// examine existence of given environment. If specs - then spec validate will do it, don't check here.
|
||||||
_, err := client.EnvironmentGet(&metav1.ObjectMeta{
|
if !spec {
|
||||||
Namespace: envNamespace,
|
_, err := client.EnvironmentGet(&metav1.ObjectMeta{
|
||||||
Name: envName,
|
Namespace: envNamespace,
|
||||||
})
|
Name: envName,
|
||||||
if err != nil {
|
})
|
||||||
if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNotFound {
|
if err != nil {
|
||||||
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 <image>`\n", envName, envName, envNamespace)
|
if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNotFound {
|
||||||
} else {
|
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 <image>`\n", envName, envName, envNamespace))
|
||||||
util.CheckErr(err, "retrieve environment information")
|
} else {
|
||||||
|
util.CheckErr(err, "retrieve environment information")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ func htCreate(c *cli.Context) error {
|
|||||||
log.Fatal("Need a function name to create a trigger, use --function")
|
log.Fatal("Need a function name to create a trigger, use --function")
|
||||||
}
|
}
|
||||||
fnNamespace := c.String("fnNamespace")
|
fnNamespace := c.String("fnNamespace")
|
||||||
|
spec := c.Bool("spec")
|
||||||
|
|
||||||
triggerUrl := c.String("url")
|
triggerUrl := c.String("url")
|
||||||
if len(triggerUrl) == 0 {
|
if len(triggerUrl) == 0 {
|
||||||
@@ -94,7 +95,11 @@ func htCreate(c *cli.Context) error {
|
|||||||
method = "GET"
|
method = "GET"
|
||||||
}
|
}
|
||||||
|
|
||||||
checkFunctionExistence(client, fnName, fnNamespace)
|
// For Specs, the spec validate checks for function reference
|
||||||
|
if !spec {
|
||||||
|
checkFunctionExistence(client, fnName, fnNamespace)
|
||||||
|
}
|
||||||
|
|
||||||
createIngress := false
|
createIngress := false
|
||||||
if c.IsSet("createingress") {
|
if c.IsSet("createingress") {
|
||||||
createIngress = c.Bool("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 we're writing a spec, don't call the API
|
||||||
if c.Bool("spec") {
|
if spec {
|
||||||
specFile := fmt.Sprintf("route-%v.yaml", triggerName)
|
specFile := fmt.Sprintf("route-%v.yaml", triggerName)
|
||||||
err := specSave(*ht, specFile)
|
err := specSave(*ht, specFile)
|
||||||
util.CheckErr(err, "create HTTP trigger spec")
|
util.CheckErr(err, "create HTTP trigger spec")
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ func Fatal(msg interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Warn(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))
|
os.Stderr.WriteString(fmt.Sprintf("%v\n", msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -388,6 +388,18 @@ func (fr *FissionResources) validate() error {
|
|||||||
// we do not error on unreferenced functions (you can call a function through workflows,
|
// we do not error on unreferenced functions (you can call a function through workflows,
|
||||||
// `fission function test`, etc.)
|
// `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.)
|
// (ErrorOrNil returns nil if there were no errors appended.)
|
||||||
return result.ErrorOrNil()
|
return result.ErrorOrNil()
|
||||||
}
|
}
|
||||||
@@ -961,7 +973,7 @@ func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fission.Arch
|
|||||||
absGlob := rootDir + "/" + relativeGlob
|
absGlob := rootDir + "/" + relativeGlob
|
||||||
f, err := filepath.Glob(absGlob)
|
f, err := filepath.Glob(absGlob)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
files = append(files, f...)
|
files = append(files, f...)
|
||||||
|
|||||||
Reference in New Issue
Block a user