Configmaps/secrets in function exist check (#1214)
This commit is contained in:
+26
-3
@@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||||
@@ -233,7 +234,7 @@ func specValidate(c *cli.Context) error {
|
|||||||
util.CheckErr(err, "read specs")
|
util.CheckErr(err, "read specs")
|
||||||
|
|
||||||
// this does the rest of the checks, like dangling refs
|
// this does the rest of the checks, like dangling refs
|
||||||
err = fr.validate()
|
err = fr.validate(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error validating specs: %v", err)
|
fmt.Printf("Error validating specs: %v", err)
|
||||||
}
|
}
|
||||||
@@ -241,7 +242,7 @@ func specValidate(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FissionResources) validate() error {
|
func (fr *FissionResources) validate(c *cli.Context) error {
|
||||||
var result *multierror.Error
|
var result *multierror.Error
|
||||||
|
|
||||||
// check references: both dangling refs + garbage
|
// check references: both dangling refs + garbage
|
||||||
@@ -343,6 +344,28 @@ func (fr *FissionResources) validate() error {
|
|||||||
packages[mapKey(pkgMeta)] = true
|
packages[mapKey(pkgMeta)] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client := util.GetApiClient(c.GlobalString("server"))
|
||||||
|
for _, cm := range f.Spec.ConfigMaps {
|
||||||
|
_, err := client.ConfigMapGet(&metav1.ObjectMeta{
|
||||||
|
Name: cm.Name,
|
||||||
|
Namespace: cm.Namespace,
|
||||||
|
})
|
||||||
|
if k8serrors.IsNotFound(err) {
|
||||||
|
log.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range f.Spec.Secrets {
|
||||||
|
_, err := client.SecretGet(&metav1.ObjectMeta{
|
||||||
|
Name: s.Name,
|
||||||
|
Namespace: s.Namespace,
|
||||||
|
})
|
||||||
|
if k8serrors.IsNotFound(err) {
|
||||||
|
log.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
result = multierror.Append(result, f.Validate())
|
result = multierror.Append(result, f.Validate())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,7 +727,7 @@ func specApply(c *cli.Context) error {
|
|||||||
util.CheckErr(err, "read specs")
|
util.CheckErr(err, "read specs")
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
err = fr.validate()
|
err = fr.validate(c)
|
||||||
util.CheckErr(err, "validate specs")
|
util.CheckErr(err, "validate specs")
|
||||||
|
|
||||||
// make changes to the cluster based on the specs
|
// make changes to the cluster based on the specs
|
||||||
|
|||||||
Reference in New Issue
Block a user