in pkg/cmd/bind.go [180:286]
func (o *bindCmdOptions) run(cmd *cobra.Command, args []string) error {
client, err := o.GetCmdClient()
if err != nil {
return err
}
source, err := o.decode(args[0], sourceKey)
if err != nil {
return err
}
sink, err := o.decode(args[1], sinkKey)
if err != nil {
return err
}
name := o.nameFor(source, sink)
binding := v1.Pipe{
ObjectMeta: metav1.ObjectMeta{
Namespace: o.Namespace,
Name: name,
},
Spec: v1.PipeSpec{
Source: source,
Sink: sink,
},
}
if o.ErrorHandler != "" {
if errorHandler, err := o.parseErrorHandler(); err == nil {
binding.Spec.ErrorHandler = errorHandler
} else {
return err
}
}
if len(o.Steps) > 0 {
binding.Spec.Steps = make([]v1.Endpoint, 0)
for idx, stepDesc := range o.Steps {
stepIndex := idx + 1
stepKey := fmt.Sprintf("%s%d", stepKeyPrefix, stepIndex)
step, err := o.decode(stepDesc, stepKey)
if err != nil {
return err
}
binding.Spec.Steps = append(binding.Spec.Steps, step)
}
}
for _, item := range o.Connects {
o.Traits = append(o.Traits, fmt.Sprintf("service-binding.services=%s", item))
}
if len(o.Traits) > 0 {
if binding.Spec.Integration == nil {
binding.Spec.Integration = &v1.IntegrationSpec{}
}
catalog := trait.NewCatalog(client)
if err := configureTraits(o.Traits, &binding.Spec.Integration.Traits, catalog); err != nil {
return err
}
}
if binding.Annotations == nil {
binding.Annotations = make(map[string]string)
}
if o.ServiceAccount != "" {
binding.Spec.ServiceAccountName = o.ServiceAccount
}
if !isOfflineCommand(cmd) && o.OperatorID != "" {
if err := verifyOperatorID(o.Context, client, o.OperatorID); err != nil {
if o.Force {
o.PrintfVerboseErrf(cmd, "%s, use --force option or make sure to use a proper operator id", err.Error())
} else {
return err
}
}
}
// --operator-id={id} is a syntax sugar for '--annotation camel.apache.org/operator.id={id}'
binding.SetOperatorID(strings.TrimSpace(o.OperatorID))
for _, annotation := range o.Annotations {
parts := strings.SplitN(annotation, "=", 2)
if len(parts) == 2 {
binding.Annotations[parts[0]] = parts[1]
}
}
if o.OutputFormat != "" {
return showPipeOutput(cmd, &binding, o.OutputFormat, client.GetScheme())
}
replaced, err := kubernetes.ReplaceResource(o.Context, client, &binding)
if err != nil {
return err
}
if !replaced {
fmt.Fprintln(cmd.OutOrStdout(), `binding "`+name+`" created`)
} else {
fmt.Fprintln(cmd.OutOrStdout(), `binding "`+name+`" updated`)
}
return nil
}