Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to SinkFlags in order to support plugin event sources #748

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pkg/kn/commands/flags/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"fmt"
"strings"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"

corev1 "k8s.io/api/core/v1"
clientdynamic "knative.dev/client/pkg/dynamic"
"knative.dev/client/pkg/kn/commands"
)
Expand All @@ -32,8 +34,8 @@ type SinkFlags struct {
sink string
}

func (i *SinkFlags) Add(cmd *cobra.Command) {
cmd.Flags().StringVarP(&i.sink, "sink", "s", "", "Addressable sink for events")
func (i *SinkFlags) Add(flagset *flag.FlagSet) {
flagset.StringVarP(&i.sink, "sink", "s", "", "Addressable sink for events")
}

// SinkPrefixes maps prefixes used for sinks to their GroupVersionResources.
Expand Down Expand Up @@ -132,3 +134,17 @@ func SinkToString(sink duckv1.Destination) string {
}
return ""
}

// SinkToDuckV1Beta1 converts a Destination from duckv1 to duckv1beta1
func SinkToDuckV1Beta1(destination *duckv1.Destination) *duckv1beta1.Destination {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not really a Sink but a Destination what you are converting (could be used for other destinations than sinks).

I would it call it ToDuckV1Beta1 as Destination is already clear from the signature, (alternative: DestinationAsDuckV1Beta1 if we want to be more verbose)

r := destination.Ref
return &duckv1beta1.Destination{
Ref: &corev1.ObjectReference{
Kind: r.Kind,
Namespace: r.Namespace,
Name: r.Name,
APIVersion: r.APIVersion,
},
URI: destination.URI,
}
}
16 changes: 0 additions & 16 deletions pkg/kn/commands/source/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ package apiserver

import (
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/clientcmd"
v1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/apis/duck/v1beta1"

clientv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha1"

Expand Down Expand Up @@ -69,16 +66,3 @@ func newAPIServerSourceClient(p *commands.KnParams, cmd *cobra.Command) (v1alpha

return v1alpha1.NewKnSourcesClient(client, namespace).APIServerSourcesClient(), nil
}

func toDuckV1Beta1(destination *v1.Destination) *v1beta1.Destination {
r := destination.Ref
return &v1beta1.Destination{
Ref: &corev1.ObjectReference{
Kind: r.Kind,
Namespace: r.Namespace,
Name: r.Name,
APIVersion: r.APIVersion,
},
URI: destination.URI,
}
}
4 changes: 2 additions & 2 deletions pkg/kn/commands/source/apiserver/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewAPIServerCreateCommand(p *commands.KnParams) *cobra.Command {
b := v1alpha1.NewAPIServerSourceBuilder(name).
ServiceAccount(updateFlags.ServiceAccountName).
Mode(updateFlags.Mode).
Sink(toDuckV1Beta1(objectRef))
Sink(flags.SinkToDuckV1Beta1(objectRef))

resources, err := updateFlags.getAPIServerResourceArray()
if err != nil {
Expand All @@ -90,7 +90,7 @@ func NewAPIServerCreateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
updateFlags.Add(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())
cmd.MarkFlagRequired("resource")
cmd.MarkFlagRequired("sink")
return cmd
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/commands/source/apiserver/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewAPIServerUpdateCommand(p *commands.KnParams) *cobra.Command {
if err != nil {
return err
}
b.Sink(toDuckV1Beta1(objectRef))
b.Sink(flags.SinkToDuckV1Beta1(objectRef))
}

err = sourcesClient.UpdateAPIServerSource(b.Build())
Expand All @@ -99,6 +99,6 @@ func NewAPIServerUpdateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
apiServerUpdateFlags.Add(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())
return cmd
}
2 changes: 1 addition & 1 deletion pkg/kn/commands/source/binding/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewBindingCreateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
bindingFlags.addBindingFlags(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())
cmd.MarkFlagRequired("subject")
cmd.MarkFlagRequired("sink")

Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/source/binding/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewBindingUpdateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
bindingFlags.addBindingFlags(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())

return cmd
}
2 changes: 1 addition & 1 deletion pkg/kn/commands/source/ping/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewPingCreateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
pingUpdateFlags.addPingFlags(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())
cmd.MarkFlagRequired("sink")

return cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/source/ping/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewPingUpdateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
pingUpdateFlags.addPingFlags(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())

return cmd
}
2 changes: 1 addition & 1 deletion pkg/kn/commands/trigger/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewTriggerCreateCommand(p *commands.KnParams) *cobra.Command {
}
commands.AddNamespaceFlags(cmd.Flags(), false)
triggerUpdateFlags.Add(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())
cmd.MarkFlagRequired("sink")

return cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/trigger/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewTriggerUpdateCommand(p *commands.KnParams) *cobra.Command {

commands.AddNamespaceFlags(cmd.Flags(), false)
triggerUpdateFlags.Add(cmd)
sinkFlags.Add(cmd)
sinkFlags.Add(cmd.Flags())

return cmd
}
Expand Down