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 {
|
||||
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...)
|
||||
|
||||
+12
-10
@@ -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 <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 <image>`\n", envName, envName, envNamespace))
|
||||
} 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")
|
||||
}
|
||||
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")
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
+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,
|
||||
// `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...)
|
||||
|
||||
Reference in New Issue
Block a user