@@ -36,7 +36,6 @@ import (
3636 "k8s.io/component-base/logs"
3737 logsv1 "k8s.io/component-base/logs/api/v1"
3838
39- "github.com/kube-bind/kube-bind/cli/pkg/client"
4039 "github.com/kube-bind/kube-bind/cli/pkg/kubectl/base"
4140 kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2"
4241)
@@ -64,6 +63,7 @@ type BindAPIServiceOptions struct {
6463 NoBanner bool
6564 DryRun bool
6665 Template string
66+ Name string
6767}
6868
6969// NewBindAPIServiceOptions returns new BindAPIServiceOptions.
@@ -98,6 +98,9 @@ func (b *BindAPIServiceOptions) AddCmdFlags(cmd *cobra.Command) {
9898
9999// Complete ensures all fields are initialized.
100100func (b * BindAPIServiceOptions ) Complete (args []string ) error {
101+ if len (args ) > 0 {
102+ b .Name = args [0 ]
103+ }
101104 if err := b .Options .Complete (false ); err != nil {
102105 return err
103106 }
@@ -130,6 +133,9 @@ func (b *BindAPIServiceOptions) Validate() error {
130133 return errors .New ("remote-kubeconfig or remote-kubeconfig-namespace and remote-kubeconfig-name are required" )
131134 }
132135 }
136+ if b .Name == "" {
137+ return errors .New ("name is required" )
138+ }
133139
134140 return b .Options .Validate ()
135141}
@@ -271,9 +277,18 @@ func (b *BindAPIServiceOptions) bindTemplate(ctx context.Context) (*bindTemplate
271277 return nil , fmt .Errorf ("failed to create authenticated client: %w" , err )
272278 }
273279
274- bindResponse , err := getBindResponse (ctx , client , b .Template )
280+ bindRequest := & kubebindv1alpha2.BindableResourcesRequest {
281+ ObjectMeta : metav1.ObjectMeta {
282+ Name : b .Name ,
283+ },
284+ TemplateRef : kubebindv1alpha2.APIServiceExportTemplateRef {
285+ Name : b .Template ,
286+ },
287+ }
288+
289+ bindResponse , err := client .Bind (ctx , bindRequest )
275290 if err != nil {
276- return nil , fmt .Errorf ("failed to bind template: %w" , err )
291+ return nil , fmt .Errorf ("failed to bind to template %q : %w" , b . Template , err )
277292 }
278293
279294 if bindResponse .Authentication .OAuth2CodeGrant == nil {
@@ -299,7 +314,7 @@ func (b *BindAPIServiceOptions) bindTemplate(ctx context.Context) (*bindTemplate
299314 return nil , err
300315 }
301316 if created {
302- fmt .Fprintf (b .Options .IOStreams .ErrOut , "reated secret %s/%s for host %s, namespace %s\n " , "kube-bind" , secret .Name , remoteHost , remoteNamespace )
317+ fmt .Fprintf (b .Options .IOStreams .ErrOut , "Created secret %s/%s for host %s, namespace %s\n " , "kube-bind" , secret .Name , remoteHost , remoteNamespace )
303318 } else {
304319 fmt .Fprintf (b .Options .IOStreams .ErrOut , "Updated secret %s/%s for host %s, namespace %s\n " , "kube-bind" , secret .Name , remoteHost , remoteNamespace )
305320 }
@@ -309,17 +324,3 @@ func (b *BindAPIServiceOptions) bindTemplate(ctx context.Context) (*bindTemplate
309324 name : secret .Name ,
310325 }, nil
311326}
312-
313- // getBindResponse retrieves the binding response for a template.
314- func getBindResponse (ctx context.Context , client client.Client , templateName string ) (* kubebindv1alpha2.BindingResourceResponse , error ) {
315- bindRequest := & kubebindv1alpha2.BindableResourcesRequest {
316- ObjectMeta : metav1.ObjectMeta {
317- Name : "bind-request" ,
318- },
319- TemplateRef : kubebindv1alpha2.APIServiceExportTemplateRef {
320- Name : templateName ,
321- },
322- }
323-
324- return client .Bind (ctx , bindRequest )
325- }
0 commit comments