This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b98a544d147e2b0de215e5ac735a81882896d943 Author: John Poth <[email protected]> AuthorDate: Mon Aug 23 14:30:32 2021 +0200 Fix #2566: Support connect flag in bind command --- pkg/cmd/bind.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go index de66d85..87740a9 100644 --- a/pkg/cmd/bind.go +++ b/pkg/cmd/bind.go @@ -57,6 +57,7 @@ func newCmdBind(rootCmdOptions *RootCmdOptions) (*cobra.Command, *bindCmdOptions }, } + cmd.Flags().StringArrayP("connect", "c", nil, "A ServiceBinding or Provisioned Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name") cmd.Flags().String("error-handler", "", `Add error handler (none|log|dlc:<endpoint>|bean:<type>|ref:<registry-ref>). DLC endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`) cmd.Flags().String("name", "", "Name for the binding") cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml") @@ -78,6 +79,7 @@ type bindCmdOptions struct { *RootCmdOptions ErrorHandler string `mapstructure:"error-handler" yaml:",omitempty"` Name string `mapstructure:"name" yaml:",omitempty"` + Connects []string `mapstructure:"connects" yaml:",omitempty"` OutputFormat string `mapstructure:"output" yaml:",omitempty"` Properties []string `mapstructure:"properties" yaml:",omitempty"` SkipChecks bool `mapstructure:"skip-checks" yaml:",omitempty"` @@ -173,6 +175,24 @@ func (o *bindCmdOptions) run(cmd *cobra.Command, args []string) error { } } + if len(o.Connects) > 0 { + trait := make(map[string]interface{}) + trait["serviceBindings"] = o.Connects + specs := make(map[string]v1.TraitSpec) + data, err := json.Marshal(trait) + if err != nil { + return err + } + var spec v1.TraitSpec + err = json.Unmarshal(data, &spec.Configuration) + if err != nil { + return err + } + specs["service-binding"] = spec + binding.Spec.Integration = &v1.IntegrationSpec{} + binding.Spec.Integration.Traits = specs + } + client, err := o.GetCmdClient() if err != nil { return err @@ -398,7 +418,7 @@ func (o *bindCmdOptions) checkCompliance(cmd *cobra.Command, endpoint v1alpha1.E found = true } } - if !found { + if !found && len(o.Connects) == 0 { return fmt.Errorf("binding is missing required property %q for Kamelet %q", reqProp, key.Name) } }
