Skip to content

Commit

Permalink
update validation call (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mir Shahriar authored and tamalsaha committed Feb 26, 2018
1 parent 3ad56dc commit 0a3817f
Show file tree
Hide file tree
Showing 18 changed files with 1,213 additions and 135 deletions.
22 changes: 11 additions & 11 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pkg/cmds/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"

tapi "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1"
cs "github.com/kubedb/apimachinery/client/clientset/versioned/typed/kubedb/v1alpha1"
"github.com/kubedb/cli/pkg/kube"
"github.com/kubedb/cli/pkg/util"
"github.com/kubedb/cli/pkg/validator"
Expand Down Expand Up @@ -81,6 +82,11 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *re
return err
}

extClient, err := cs.NewForConfig(config)
if err != nil {
return err
}

infoList := make([]*resource.Info, 0)
err = r.Visit(func(info *resource.Info, err error) error {
if err != nil {
Expand All @@ -97,7 +103,7 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *re
}

fmt.Println(fmt.Sprintf(`validating "%v"`, info.Source))
if err := validator.Validate(client, info); err != nil {
if err := validator.Validate(client, extClient, info); err != nil {
return cmdutil.AddSourceToErr("validating", info.Source, err)
}

Expand Down
27 changes: 14 additions & 13 deletions pkg/validator/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ghodss/yaml"
tapi "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1"
cs "github.com/kubedb/apimachinery/client/clientset/versioned/typed/kubedb/v1alpha1"
amv "github.com/kubedb/apimachinery/pkg/validator"
"github.com/kubedb/cli/pkg/encoder"
esv "github.com/kubedb/elasticsearch/pkg/validator"
Expand All @@ -17,7 +18,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
)

func Validate(client kubernetes.Interface, info *resource.Info) error {
func Validate(client kubernetes.Interface, extClient cs.KubedbV1alpha1Interface, info *resource.Info) error {
objByte, err := encoder.Encode(info.Object)
if err != nil {
return err
Expand All @@ -30,37 +31,37 @@ func Validate(client kubernetes.Interface, info *resource.Info) error {
if err := yaml.Unmarshal(objByte, &elasticsearch); err != nil {
return err
}
return esv.ValidateElasticsearch(client, elasticsearch)
return esv.ValidateElasticsearch(client, extClient, elasticsearch)
case tapi.ResourceKindPostgres:
var postgres *tapi.Postgres
if err := yaml.Unmarshal(objByte, &postgres); err != nil {
return err
}
return pgv.ValidatePostgres(client, postgres)
return pgv.ValidatePostgres(client, extClient, postgres)
case tapi.ResourceKindMySQL:
var mysql *tapi.MySQL
if err := yaml.Unmarshal(objByte, &mysql); err != nil {
return err
}
return msv.ValidateMySQL(client, mysql)
return msv.ValidateMySQL(client, extClient, mysql)
case tapi.ResourceKindMongoDB:
var mongodb *tapi.MongoDB
if err := yaml.Unmarshal(objByte, &mongodb); err != nil {
return err
}
return mgv.ValidateMongoDB(client, mongodb)
return mgv.ValidateMongoDB(client, extClient, mongodb)
case tapi.ResourceKindRedis:
var redis *tapi.Redis
if err := yaml.Unmarshal(objByte, &redis); err != nil {
return err
}
return rdv.ValidateRedis(client, redis)
return rdv.ValidateRedis(client, extClient, redis)
case tapi.ResourceKindMemcached:
var memcached *tapi.Memcached
if err := yaml.Unmarshal(objByte, &memcached); err != nil {
return err
}
return memv.ValidateMemcached(client, memcached)
return memv.ValidateMemcached(client, extClient, memcached)
case tapi.ResourceKindSnapshot:
var snapshot *tapi.Snapshot
if err := yaml.Unmarshal(objByte, &snapshot); err != nil {
Expand All @@ -85,47 +86,47 @@ func ValidateDeletion(info *resource.Info) error {
return err
}
if elasticsearch.Spec.DoNotPause {
return fmt.Errorf(`Elasticsearch "%v" can't be paused. To continue delete, unset spec.doNotPause and retry.`, elasticsearch.Name)
return fmt.Errorf(`elasticsearch "%v" can't be paused. To continue delete, unset spec.doNotPause and retry`, elasticsearch.Name)
}
case tapi.ResourceKindPostgres:
var postgres *tapi.Postgres
if err := yaml.Unmarshal(objByte, &postgres); err != nil {
return err
}
if postgres.Spec.DoNotPause {
return fmt.Errorf(`Postgres "%v" can't be paused. To continue delete, unset spec.doNotPause and retry.`, postgres.Name)
return fmt.Errorf(`postgres "%v" can't be paused. To continue delete, unset spec.doNotPause and retry`, postgres.Name)
}
case tapi.ResourceKindMySQL:
var mysql *tapi.MySQL
if err := yaml.Unmarshal(objByte, &mysql); err != nil {
return err
}
if mysql.Spec.DoNotPause {
return fmt.Errorf(`MySQL "%v" can't be paused. To continue delete, unset spec.doNotPause and retry.`, mysql.Name)
return fmt.Errorf(`mysql "%v" can't be paused. To continue delete, unset spec.doNotPause and retry`, mysql.Name)
}
case tapi.ResourceKindMongoDB:
var mongodb *tapi.MongoDB
if err := yaml.Unmarshal(objByte, &mongodb); err != nil {
return err
}
if mongodb.Spec.DoNotPause {
return fmt.Errorf(`MongoDB "%v" can't be paused. To continue delete, unset spec.doNotPause and retry.`, mongodb.Name)
return fmt.Errorf(`mongodb "%v" can't be paused. To continue delete, unset spec.doNotPause and retry`, mongodb.Name)
}
case tapi.ResourceKindRedis:
var redis *tapi.Redis
if err := yaml.Unmarshal(objByte, &redis); err != nil {
return err
}
if redis.Spec.DoNotPause {
return fmt.Errorf(`Redis "%v" can't be paused. To continue delete, unset spec.doNotPause and retry.`, redis.Name)
return fmt.Errorf(`redis "%v" can't be paused. To continue delete, unset spec.doNotPause and retry`, redis.Name)
}
case tapi.ResourceKindMemcached:
var memcached *tapi.Memcached
if err := yaml.Unmarshal(objByte, &memcached); err != nil {
return err
}
if memcached.Spec.DoNotPause {
return fmt.Errorf(`Memcached "%v" can't be paused. To continue delete, unset spec.doNotPause and retry.`, memcached.Name)
return fmt.Errorf(`memcached "%v" can't be paused. To continue delete, unset spec.doNotPause and retry`, memcached.Name)
}
}
return nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion vendor/github.com/kubedb/memcached/pkg/validator/validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a3817f

Please sign in to comment.