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

Refactor PingSourve to v1 API version #1991

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pkg/commands/completion_helper.go
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ func completePingSource(config *completionConfig) (suggestions []string) {
return
}

client, err := config.params.NewSourcesV1beta2Client(namespace)
client, err := config.params.NewSourcesClient(namespace)
if err != nil {
return
}
18 changes: 6 additions & 12 deletions pkg/commands/completion_helper_test.go
Original file line number Diff line number Diff line change
@@ -29,13 +29,10 @@ import (
v1beta1 "knative.dev/client/pkg/messaging/v1"
clientv1beta1 "knative.dev/client/pkg/serving/v1beta1"
clientsourcesv1 "knative.dev/client/pkg/sources/v1"
"knative.dev/client/pkg/sources/v1beta2"
eventingv1beta2 "knative.dev/eventing/pkg/apis/eventing/v1beta2"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1fake "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1/fake"
sourcesv1beta2fake "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2/fake"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions"
@@ -311,29 +308,29 @@ var (
)

var (
testPingSource1 = sourcesv1beta2.PingSource{
testPingSource1 = sourcesv1.PingSource{
TypeMeta: metav1.TypeMeta{
Kind: "PingSource",
APIVersion: "sources.knative.dev/v1",
},
ObjectMeta: metav1.ObjectMeta{Name: "test-ping-source-1", Namespace: testNs},
}
testPingSource2 = sourcesv1beta2.PingSource{
testPingSource2 = sourcesv1.PingSource{
TypeMeta: metav1.TypeMeta{
Kind: "PingSource",
APIVersion: "sources.knative.dev/v1",
},
ObjectMeta: metav1.ObjectMeta{Name: "test-ping-source-2", Namespace: testNs},
}
testPingSource3 = sourcesv1beta2.PingSource{
testPingSource3 = sourcesv1.PingSource{
TypeMeta: metav1.TypeMeta{
Kind: "PingSource",
APIVersion: "sources.knative.dev/v1",
},
ObjectMeta: metav1.ObjectMeta{Name: "test-ping-source-3", Namespace: testNs},
}
testNsPingSources = []sourcesv1beta2.PingSource{testPingSource1, testPingSource2, testPingSource3}
fakeSourcesV1Beta2 = &sourcesv1beta2fake.FakeSourcesV1beta2{Fake: &clienttesting.Fake{}}
testNsPingSources = []sourcesv1.PingSource{testPingSource1, testPingSource2, testPingSource3}
fakeSourcesV1Beta2 = &sourcesv1fake.FakeSourcesV1{Fake: &clienttesting.Fake{}}
)

var (
@@ -449,9 +446,6 @@ current-context: x
NewSourcesClient: func(namespace string) (clientsourcesv1.KnSourcesClient, error) {
return clientsourcesv1.NewKnSourcesClient(fakeSources, namespace), nil
},
NewSourcesV1beta2Client: func(namespace string) (v1beta2.KnSourcesClient, error) {
return v1beta2.NewKnSourcesClient(fakeSourcesV1Beta2, namespace), nil
},
NewEventingV1beta2Client: func(namespace string) (clienteventingv1beta2.KnEventingV1Beta2Client, error) {
return clienteventingv1beta2.NewKnEventingV1Beta2Client(fakeEventingBeta2Client, namespace), nil
},
@@ -1254,7 +1248,7 @@ func TestResourceNameCompletionFuncPingSource(t *testing.T) {
if a.GetNamespace() == errorNs {
return true, nil, errors.NewInternalError(fmt.Errorf("unable to list ping sources"))
}
return true, &sourcesv1beta2.PingSourceList{Items: testNsPingSources}, nil
return true, &sourcesv1.PingSourceList{Items: testNsPingSources}, nil
})

tests := []testType{
4 changes: 2 additions & 2 deletions pkg/commands/flags/sink_test.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import (
"knative.dev/client/pkg/commands/flags"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
"knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
@@ -85,7 +85,7 @@ func TestResolve(t *testing.T) {
TypeMeta: metav1.TypeMeta{Kind: "Channel", APIVersion: "messaging.knative.dev/v1"},
ObjectMeta: metav1.ObjectMeta{Name: "pipe", Namespace: "default"},
}
pingSource := &v1beta2.PingSource{
pingSource := &sourcesv1.PingSource{
TypeMeta: metav1.TypeMeta{Kind: "PingSource", APIVersion: "sources.knative.dev/v1"},
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
}
16 changes: 8 additions & 8 deletions pkg/commands/source/list_test.go
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ func TestSourceListTypesNoSourcesWithJsonOutput(t *testing.T) {

func TestSourceListTypes(t *testing.T) {
output, err := sourceFakeCmd([]string{"source", "list-types"},
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
newSourceCRDObjWithSpec("apiserversources", "sources.knative.dev", "v1", "ApiServerSource"),
)
assert.NilError(t, err)
@@ -108,7 +108,7 @@ func TestSourceListNoSourcesInstalled(t *testing.T) {

func TestSourceListEmpty(t *testing.T) {
output, err := sourceFakeCmd([]string{"source", "list", "-o", "json"},
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
)
assert.NilError(t, err)
outputJson := strings.Join(output[:], "\n")
@@ -117,10 +117,10 @@ func TestSourceListEmpty(t *testing.T) {

func TestSourceList(t *testing.T) {
output, err := sourceFakeCmd([]string{"source", "list"},
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
newSourceCRDObjWithSpec("sinkbindings", "sources.knative.dev", "v1", "SinkBinding"),
newSourceCRDObjWithSpec("apiserversources", "sources.knative.dev", "v1", "ApiServerSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1beta2", "PingSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1", "PingSource"),
newSourceUnstructuredObj("s1", "sources.knative.dev/v1", "SinkBinding"),
newSourceUnstructuredObj("a1", "sources.knative.dev/v1", "ApiServerSource"),
)
@@ -145,8 +145,8 @@ func TestSourceListUntyped(t *testing.T) {

func TestSourceListNoHeaders(t *testing.T) {
output, err := sourceFakeCmd([]string{"source", "list", "--no-headers"},
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1", "PingSource"),
)
assert.NilError(t, err)
assert.Check(t, util.ContainsNone(output[0], "NAME", "TYPE", "RESOURCE", "SINK", "READY"))
@@ -208,10 +208,10 @@ func newSourceUnstructuredObj(name, apiVersion, kind string) *unstructured.Unstr

func TestSourceListAllNamespace(t *testing.T) {
output, err := sourceFakeCmd([]string{"source", "list", "--all-namespaces"},
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
newSourceCRDObjWithSpec("sinkbindings", "sources.knative.dev", "v1", "SinkBinding"),
newSourceCRDObjWithSpec("apiserversources", "sources.knative.dev", "v1", "ApiServerSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1beta2", "PingSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1", "PingSource"),
newSourceUnstructuredObj("s1", "sources.knative.dev/v1", "SinkBinding"),
newSourceUnstructuredObj("a1", "sources.knative.dev/v1", "ApiServerSource"),
)
4 changes: 2 additions & 2 deletions pkg/commands/source/ping/create.go
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import (

"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/commands/flags"
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
clientsourcesv1 "knative.dev/client/pkg/sources/v1"
"knative.dev/client/pkg/util"
)

@@ -76,7 +76,7 @@ func NewPingCreateCommand(p *commands.KnParams) *cobra.Command {
"%q because: %s", name, namespace, err)
}

err = pingSourceClient.CreatePingSource(cmd.Context(), clientsourcesv1beta2.NewPingSourceBuilder(name).
err = pingSourceClient.CreatePingSource(cmd.Context(), clientsourcesv1.NewPingSourceBuilder(name).
Schedule(updateFlags.schedule).
Data(data).
DataBase64(dataBase64).
2 changes: 1 addition & 1 deletion pkg/commands/source/ping/create_test.go
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import (
servingv1 "knative.dev/serving/pkg/apis/serving/v1"

dynamicfake "knative.dev/client/pkg/dynamic/fake"
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1"

"knative.dev/client/pkg/util"
)
8 changes: 4 additions & 4 deletions pkg/commands/source/ping/delete_test.go
Original file line number Diff line number Diff line change
@@ -19,13 +19,13 @@ import (
"testing"

"gotest.tools/v3/assert"
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
clientsourcesv1 "knative.dev/client/pkg/sources/v1"

"knative.dev/client/pkg/util"
)

func TestSimpleDelete(t *testing.T) {
pingClient := clientsourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientsourcesv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.DeletePingSource("testsource", nil)
@@ -38,7 +38,7 @@ func TestSimpleDelete(t *testing.T) {
}

func TestDeleteWithError(t *testing.T) {
pingClient := clientsourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientsourcesv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.DeletePingSource("testsource", errors.New("no such Ping source testsource"))
@@ -51,7 +51,7 @@ func TestDeleteWithError(t *testing.T) {
}

func TestPingDeleteErrorForNoArgs(t *testing.T) {
pingClient := clientsourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientsourcesv1.NewMockKnPingSourceClient(t, "mynamespace")
out, err := executePingSourceCommand(pingClient, nil, "delete")
assert.ErrorContains(t, err, "single argument")
assert.Assert(t, util.ContainsAll(out, "requires", "single argument"))
4 changes: 2 additions & 2 deletions pkg/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import (

"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/printers"
clientsourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
clientsourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
)

var describeExample = `
@@ -115,7 +115,7 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
return command
}

func writePingSource(dw printers.PrefixWriter, source *clientsourcesv1beta2.PingSource, printDetails bool) {
func writePingSource(dw printers.PrefixWriter, source *clientsourcesv1.PingSource, printDetails bool) {
commands.WriteMetadata(dw, &source.ObjectMeta, printDetails)
dw.WriteAttribute("Schedule", source.Spec.Schedule)
if source.Spec.DataBase64 != "" {
22 changes: 11 additions & 11 deletions pkg/commands/source/ping/describe_test.go
Original file line number Diff line number Diff line change
@@ -20,16 +20,16 @@ import (

"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
sourcesv1beta "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"

clientv1beta2 "knative.dev/client/pkg/sources/v1beta2"
clientv1 "knative.dev/client/pkg/sources/v1"
"knative.dev/client/pkg/util"
"knative.dev/pkg/apis"
)

func TestDescribeRef(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testping",
@@ -51,7 +51,7 @@ func TestDescribeRef(t *testing.T) {
}

func TestDescribeURI(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource-uri", getPingSourceSinkURI(), nil)
@@ -64,7 +64,7 @@ func TestDescribeURI(t *testing.T) {
}

func TestDescribeMachineReadable(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource-uri", getPingSourceSinkURI(), nil)
@@ -76,7 +76,7 @@ func TestDescribeMachineReadable(t *testing.T) {
}

func TestDescribeError(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource", nil, errors.New("no Ping source testsource"))
@@ -90,14 +90,14 @@ func TestDescribeError(t *testing.T) {
}

func TestPingDescribeErrorForNoArgs(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")
out, err := executePingSourceCommand(pingClient, nil, "describe")
assert.ErrorContains(t, err, "single argument")
assert.Assert(t, util.ContainsAll(out, "requires", "single argument"))
}

func getPingSourceSinkURI() *sourcesv1beta.PingSource {
return &sourcesv1beta.PingSource{
func getPingSourceSinkURI() *sourcesv1.PingSource {
return &sourcesv1.PingSource{
TypeMeta: metav1.TypeMeta{
Kind: "PingSource",
APIVersion: "sources.knative.dev/v1beta2",
@@ -106,7 +106,7 @@ func getPingSourceSinkURI() *sourcesv1beta.PingSource {
Name: "testsource-uri",
Namespace: "mynamespace",
},
Spec: sourcesv1beta.PingSourceSpec{
Spec: sourcesv1.PingSourceSpec{
Schedule: "1 2 3 4 5",
Data: "honeymoon",
SourceSpec: duckv1.SourceSpec{
@@ -118,6 +118,6 @@ func getPingSourceSinkURI() *sourcesv1beta.PingSource {
},
},
},
Status: sourcesv1beta.PingSourceStatus{},
Status: sourcesv1.PingSourceStatus{},
}
}
8 changes: 4 additions & 4 deletions pkg/commands/source/ping/flags.go
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ import (
"knative.dev/client/pkg/commands"
hprinters "knative.dev/client/pkg/printers"

sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
)

type pingUpdateFlags struct {
@@ -78,7 +78,7 @@ func PingSourceListHandlers(h hprinters.PrintHandler) {
}

// printSource populates a single row of Ping source list
func printSource(source *sourcesv1beta2.PingSource, options hprinters.PrintOptions) ([]metav1.TableRow, error) {
func printSource(source *sourcesv1.PingSource, options hprinters.PrintOptions) ([]metav1.TableRow, error) {
row := metav1.TableRow{
Object: runtime.RawExtension{Object: source},
}
@@ -111,7 +111,7 @@ func printSource(source *sourcesv1beta2.PingSource, options hprinters.PrintOptio
}

// printSourceList populates the Ping source list table rows
func printSourceList(sourceList *sourcesv1beta2.PingSourceList, options hprinters.PrintOptions) ([]metav1.TableRow, error) {
func printSourceList(sourceList *sourcesv1.PingSourceList, options hprinters.PrintOptions) ([]metav1.TableRow, error) {
if options.AllNamespaces {
return printSourceListWithNamespace(sourceList, options)
}
@@ -135,7 +135,7 @@ func printSourceList(sourceList *sourcesv1beta2.PingSourceList, options hprinter
}

// printSourceListWithNamespace populates the knative service table rows with namespace column
func printSourceListWithNamespace(sourceList *sourcesv1beta2.PingSourceList, options hprinters.PrintOptions) ([]metav1.TableRow, error) {
func printSourceListWithNamespace(sourceList *sourcesv1.PingSourceList, options hprinters.PrintOptions) ([]metav1.TableRow, error) {
rows := make([]metav1.TableRow, 0, len(sourceList.Items))

// temporary slice for sorting services in non-default namespace
22 changes: 11 additions & 11 deletions pkg/commands/source/ping/list_test.go
Original file line number Diff line number Diff line change
@@ -21,19 +21,19 @@ import (

"gotest.tools/v3/assert"

sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"

clientv1beta2 "knative.dev/client/pkg/sources/v1beta2"
clientv1 "knative.dev/client/pkg/sources/v1"
"knative.dev/client/pkg/util"
)

func TestListPingSource(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t)
pingClient := clientv1.NewMockKnPingSourceClient(t)

pingRecorder := pingClient.Recorder()
cJSource := createPingSource("testsource", "* * * * */2", "maxwell", "", "mysvc", nil)
cJSourceList := sourcesv1beta2.PingSourceList{}
cJSourceList.Items = []sourcesv1beta2.PingSource{*cJSource}
cJSourceList := sourcesv1.PingSourceList{}
cJSourceList.Items = []sourcesv1.PingSource{*cJSource}

pingRecorder.ListPingSource(&cJSourceList, nil)

@@ -46,10 +46,10 @@ func TestListPingSource(t *testing.T) {
}

func TestListPingJobSourceEmpty(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t)
pingClient := clientv1.NewMockKnPingSourceClient(t)

pingRecorder := pingClient.Recorder()
cJSourceList := sourcesv1beta2.PingSourceList{}
cJSourceList := sourcesv1.PingSourceList{}

pingRecorder.ListPingSource(&cJSourceList, nil)

@@ -62,16 +62,16 @@ func TestListPingJobSourceEmpty(t *testing.T) {
}

func TestListPingJobSourceEmptyWithJsonOutput(t *testing.T) {
pingClient := clientv1beta2.NewMockKnPingSourceClient(t)
pingClient := clientv1.NewMockKnPingSourceClient(t)

pingRecorder := pingClient.Recorder()
cJSourceList := sourcesv1beta2.PingSourceList{}
_ = util.UpdateGroupVersionKindWithScheme(&cJSourceList, sourcesv1beta2.SchemeGroupVersion, scheme.Scheme)
cJSourceList := sourcesv1.PingSourceList{}
_ = util.UpdateGroupVersionKindWithScheme(&cJSourceList, sourcesv1.SchemeGroupVersion, scheme.Scheme)
pingRecorder.ListPingSource(&cJSourceList, nil)

out, err := executePingSourceCommand(pingClient, nil, "list", "-o", "json")
assert.NilError(t, err, "Sources should be listed")
assert.Assert(t, util.ContainsAll(out, "\"apiVersion\": \"sources.knative.dev/v1beta2\"", "\"items\": []", "\"kind\": \"PingSourceList\""))
assert.Assert(t, util.ContainsAll(out, "\"apiVersion\": \"sources.knative.dev/v1\"", "\"items\": []", "\"kind\": \"PingSourceList\""))

pingRecorder.Validate()
}
12 changes: 6 additions & 6 deletions pkg/commands/source/ping/ping.go
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ import (
"k8s.io/client-go/tools/clientcmd"

"knative.dev/client/pkg/commands"
clientv1beta2 "knative.dev/client/pkg/sources/v1beta2"
sourcesv1beta2 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2"
clientv1 "knative.dev/client/pkg/sources/v1"
sourcesv1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1"
)

// NewPingCommand is the root command for all Ping source related commands
@@ -38,9 +38,9 @@ func NewPingCommand(p *commands.KnParams) *cobra.Command {
return pingImporterCmd
}

var pingSourceClientFactory func(config clientcmd.ClientConfig, namespace string) (clientv1beta2.KnPingSourcesClient, error)
var pingSourceClientFactory func(config clientcmd.ClientConfig, namespace string) (clientv1.KnPingSourcesClient, error)

func newPingSourceClient(p *commands.KnParams, cmd *cobra.Command) (clientv1beta2.KnPingSourcesClient, error) {
func newPingSourceClient(p *commands.KnParams, cmd *cobra.Command) (clientv1.KnPingSourcesClient, error) {
namespace, err := p.GetNamespace(cmd)
if err != nil {
return nil, err
@@ -59,10 +59,10 @@ func newPingSourceClient(p *commands.KnParams, cmd *cobra.Command) (clientv1beta
return nil, err
}

client, err := sourcesv1beta2.NewForConfig(clientConfig)
client, err := sourcesv1.NewForConfig(clientConfig)
if err != nil {
return nil, err
}

return clientv1beta2.NewKnSourcesClient(client, namespace).PingSourcesClient(), nil
return clientv1.NewKnSourcesClient(client, namespace).PingSourcesClient(), nil
}
14 changes: 7 additions & 7 deletions pkg/commands/source/ping/ping_test.go
Original file line number Diff line number Diff line change
@@ -21,12 +21,12 @@ import (
"gotest.tools/v3/assert"

"k8s.io/client-go/tools/clientcmd"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"

"knative.dev/client/pkg/commands"
kndynamic "knative.dev/client/pkg/dynamic"
clientv1beta2 "knative.dev/client/pkg/sources/v1beta2"
clientv1 "knative.dev/client/pkg/sources/v1"
)

// Helper methods
@@ -37,7 +37,7 @@ var blankConfig clientcmd.ClientConfig
func init() {
var err error
blankConfig, err = clientcmd.NewClientConfigFromBytes([]byte(`kind: Config
version: v1beta2
version: v1
users:
- name: u
clusters:
@@ -72,7 +72,7 @@ func TestPingBuilder(t *testing.T) {
assert.DeepEqual(t, ceOverrideMap, ps.Spec.CloudEventOverrides.Extensions)
}

func executePingSourceCommand(pingSourceClient clientv1beta2.KnPingSourcesClient, dynamicClient kndynamic.KnDynamicClient, args ...string) (string, error) {
func executePingSourceCommand(pingSourceClient clientv1.KnPingSourcesClient, dynamicClient kndynamic.KnDynamicClient, args ...string) (string, error) {
knParams := &commands.KnParams{}
knParams.ClientConfig = blankConfig

@@ -86,7 +86,7 @@ func executePingSourceCommand(pingSourceClient clientv1beta2.KnPingSourcesClient
cmd.SetArgs(args)
cmd.SetOutput(output)

pingSourceClientFactory = func(config clientcmd.ClientConfig, namespace string) (clientv1beta2.KnPingSourcesClient, error) {
pingSourceClientFactory = func(config clientcmd.ClientConfig, namespace string) (clientv1.KnPingSourcesClient, error) {
return pingSourceClient, nil
}
defer cleanupPingMockClient()
@@ -100,11 +100,11 @@ func cleanupPingMockClient() {
pingSourceClientFactory = nil
}

func createPingSource(name, schedule, data, dataBase64, service string, ceOverridesMap map[string]string) *sourcesv1beta2.PingSource {
func createPingSource(name, schedule, data, dataBase64, service string, ceOverridesMap map[string]string) *sourcesv1.PingSource {
sink := &duckv1.Destination{
Ref: &duckv1.KReference{Name: service, Kind: "Service", APIVersion: "serving.knative.dev/v1", Namespace: "default"},
}
return clientv1beta2.NewPingSourceBuilder(name).
return clientv1.NewPingSourceBuilder(name).
Schedule(schedule).
Data(data).
DataBase64(dataBase64).
8 changes: 4 additions & 4 deletions pkg/commands/source/ping/update.go
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ import (

"knative.dev/client/pkg/commands"
"knative.dev/client/pkg/commands/flags"
sourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
eventingsourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/client/pkg/sources/v1"
eventingsourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"

"knative.dev/client/pkg/util"
)
@@ -63,8 +63,8 @@ func NewPingUpdateCommand(p *commands.KnParams) *cobra.Command {
return err
}

updateFunc := func(origSource *eventingsourcesv1beta2.PingSource) (*eventingsourcesv1beta2.PingSource, error) {
b := sourcesv1beta2.NewPingSourceBuilderFromExisting(origSource)
updateFunc := func(origSource *eventingsourcesv1.PingSource) (*eventingsourcesv1.PingSource, error) {
b := sourcesv1.NewPingSourceBuilderFromExisting(origSource)
if cmd.Flags().Changed("schedule") {
b.Schedule(updateFlags.schedule)
}
14 changes: 7 additions & 7 deletions pkg/commands/source/ping/update_test.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

dynamicfake "knative.dev/client/pkg/dynamic/fake"
sourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
sourcesv1 "knative.dev/client/pkg/sources/v1"
"knative.dev/client/pkg/util"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)
@@ -34,7 +34,7 @@ func TestSimplePingUpdate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "mysvc1", Namespace: "default"},
}
dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default", mysvc1)
pingSourceClient := sourcesv1beta2.NewMockKnPingSourceClient(t)
pingSourceClient := sourcesv1.NewMockKnPingSourceClient(t)
pingRecorder := pingSourceClient.Recorder()
pingRecorder.GetPingSource("testsource", createPingSource("testsource", "* * * * */1", "maxwell", "", "mysvc", nil), nil)
pingRecorder.UpdatePingSource(createPingSource("testsource", "* * * * */3", "maxwell", "", "mysvc1", nil), nil)
@@ -70,7 +70,7 @@ func TestSimplePingUpdate(t *testing.T) {

// TestSimplePingUpdateCEOverrides updates ce override, schedule, data and sink
func TestSimplePingUpdateCEOverrides(t *testing.T) {
pingSourceClient := sourcesv1beta2.NewMockKnPingSourceClient(t)
pingSourceClient := sourcesv1.NewMockKnPingSourceClient(t)
pingRecorder := pingSourceClient.Recorder()
ceOverrideMap := map[string]string{"bla": "blub", "foo": "bar"}
ceOverrideMapUpdated := map[string]string{"foo": "baz", "new": "ceoverride"}
@@ -85,7 +85,7 @@ func TestSimplePingUpdateCEOverrides(t *testing.T) {
}

func TestUpdateError(t *testing.T) {
pingClient := sourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := sourcesv1.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource", nil, errors.New("no Ping source testsource"))
@@ -98,7 +98,7 @@ func TestUpdateError(t *testing.T) {
}

func TestPingUpdateDeletionTimestampNotNil(t *testing.T) {
pingSourceClient := sourcesv1beta2.NewMockKnPingSourceClient(t)
pingSourceClient := sourcesv1.NewMockKnPingSourceClient(t)
present := createPingSource("test", "", "", "", "", nil)
present.DeletionTimestamp = &metav1.Time{Time: time.Now()}
pingRecorder := pingSourceClient.Recorder()
@@ -111,15 +111,15 @@ func TestPingUpdateDeletionTimestampNotNil(t *testing.T) {
}

func TestPingUpdateErrorForNoArgs(t *testing.T) {
pingClient := sourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
pingClient := sourcesv1.NewMockKnPingSourceClient(t, "mynamespace")
out, err := executePingSourceCommand(pingClient, nil, "update")
assert.ErrorContains(t, err, "required")
assert.Assert(t, util.ContainsAll(out, "Ping", "name", "required"))
}

func TestPingUpdateNoSinkError(t *testing.T) {
dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default")
pingClient := sourcesv1beta2.NewMockKnPingSourceClient(t)
pingClient := sourcesv1.NewMockKnPingSourceClient(t)
pingRecorder := pingClient.Recorder()

pingRecorder.GetPingSource("testsource", createPingSource("testsource", "* * * * */1", "maxwell", "", "mysvc", nil), nil)
17 changes: 0 additions & 17 deletions pkg/commands/types.go
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ import (
eventingv1beta2 "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1beta2"
messagingv1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1"
sourcesv1client "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1"
sourcesv1beta2client "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2"
servingv1client "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1"
servingv1beta1client "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1beta1"

@@ -42,7 +41,6 @@ import (
clientservingv1 "knative.dev/client/pkg/serving/v1"
clientservingv1beta1 "knative.dev/client/pkg/serving/v1beta1"
clientsourcesv1 "knative.dev/client/pkg/sources/v1"
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
)

// KnParams for creating commands. Useful for inserting mocks for testing.
@@ -54,7 +52,6 @@ type KnParams struct {
NewServingV1beta1Client func(namespace string) (clientservingv1beta1.KnServingClient, error)
NewGitopsServingClient func(namespace string, dir string) (clientservingv1.KnServingClient, error)
NewSourcesClient func(namespace string) (clientsourcesv1.KnSourcesClient, error)
NewSourcesV1beta2Client func(namespace string) (clientsourcesv1beta2.KnSourcesClient, error)
NewEventingClient func(namespace string) (clienteventingv1.KnEventingClient, error)
NewMessagingClient func(namespace string) (clientmessagingv1.KnMessagingClient, error)
NewDynamicClient func(namespace string) (clientdynamic.KnDynamicClient, error)
@@ -104,10 +101,6 @@ func (params *KnParams) Initialize() {
params.NewDynamicClient = params.newDynamicClient
}

if params.NewSourcesV1beta2Client == nil {
params.NewSourcesV1beta2Client = params.newSourcesClientV1beta2
}

if params.NewEventingV1beta2Client == nil {
params.NewEventingV1beta2Client = params.newEventingV1Beta2Client
}
@@ -167,16 +160,6 @@ func (params *KnParams) newSourcesClient(namespace string) (clientsourcesv1.KnSo
return clientsourcesv1.NewKnSourcesClient(client, namespace), nil
}

func (params *KnParams) newSourcesClientV1beta2(namespace string) (clientsourcesv1beta2.KnSourcesClient, error) {
restConfig, err := params.RestConfig()
if err != nil {
return nil, err
}

client, _ := sourcesv1beta2client.NewForConfig(restConfig)
return clientsourcesv1beta2.NewKnSourcesClient(client, namespace), nil
}

func (params *KnParams) newEventingClient(namespace string) (clienteventingv1.KnEventingClient, error) {
restConfig, err := params.RestConfig()
if err != nil {
2 changes: 1 addition & 1 deletion pkg/commands/types_test.go
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ func TestNewSourcesV1beta2Client(t *testing.T) {
LogHTTP: tc.logHttp,
}

sourcesClient, err := p.newSourcesClientV1beta2(namespace)
sourcesClient, err := p.newSourcesClient(namespace)

switch len(tc.expectedErrString) {
case 0:
15 changes: 7 additions & 8 deletions pkg/dynamic/client_test.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ import (
"knative.dev/eventing/pkg/apis/messaging"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
dynamicclientfake "knative.dev/pkg/injection/clients/dynamicclient/fake"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"

@@ -113,7 +112,7 @@ func TestListSources(t *testing.T) {

t.Run("source list empty", func(t *testing.T) {
client := createFakeKnDynamicClient(testNamespace,
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
)
sources, err := client.ListSources(context.Background())
assert.NilError(t, err)
@@ -122,9 +121,9 @@ func TestListSources(t *testing.T) {

t.Run("source list non empty", func(t *testing.T) {
client := createFakeKnDynamicClient(testNamespace,
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
newSourceCRDObjWithSpec("apiserversources", "sources.knative.dev", "v1", "ApiServerSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1beta2", "PingSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1", "PingSource"),
newSourceUnstructuredObj("a1", "sources.knative.dev/v1", "ApiServerSource"),
)
sources, err := client.ListSources(context.Background(), WithTypeFilter("pingsource"), WithTypeFilter("ApiServerSource"))
@@ -145,14 +144,14 @@ func TestListSourcesUsingGVKs(t *testing.T) {

t.Run("source list with given GVKs", func(t *testing.T) {
client := createFakeKnDynamicClient(testNamespace,
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
newSourceCRDObjWithSpec("apiserversources", "sources.knative.dev", "v1", "ApiServerSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1beta2", "PingSource"),
newSourceUnstructuredObj("p1", "sources.knative.dev/v1", "PingSource"),
newSourceUnstructuredObj("a1", "sources.knative.dev/v1", "ApiServerSource"),
)
assert.Check(t, client.RawClient() != nil)
gvks := []schema.GroupVersionKind{
{Group: "sources.knative.dev", Version: "v1beta2", Kind: "PingSource"},
{Group: "sources.knative.dev", Version: "v1", Kind: "PingSource"},
{Group: "sources.knative.dev", Version: "v1", Kind: "ApiServerSource"},
}

@@ -184,7 +183,7 @@ func createFakeKnDynamicClient(testNamespace string, objects ...runtime.Object)
eventingv1.AddToScheme(scheme)
messagingv1.AddToScheme(scheme)
sourcesv1.AddToScheme(scheme)
sourcesv1beta2.AddToScheme(scheme)
sourcesv1.AddToScheme(scheme)
apiextensionsv1.AddToScheme(scheme)
_, dynamicClient := dynamicclientfake.With(context.TODO(), scheme, objects...)
return NewKnDynamicClient(dynamicClient, testNamespace)
2 changes: 0 additions & 2 deletions pkg/dynamic/fake/fake.go
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ import (
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
dynamicclientfake "knative.dev/pkg/injection/clients/dynamicclient/fake"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)
@@ -43,7 +42,6 @@ func CreateFakeKnDynamicClient(testNamespace string, objects ...runtime.Object)
_ = eventingv1.AddToScheme(scheme)
_ = messagingv1.AddToScheme(scheme)
_ = sourcesv1.AddToScheme(scheme)
_ = sourcesv1beta2.AddToScheme(scheme)
_ = apiextensionsv1.AddToScheme(scheme)
_, dynamicClient := dynamicclientfake.With(context.TODO(), scheme, objects...)
return dynamic.NewKnDynamicClient(dynamicClient, testNamespace)
3 changes: 1 addition & 2 deletions pkg/sources/common.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ package sources
import (
"k8s.io/apimachinery/pkg/runtime/schema"
v1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/pkg/apis/sources/v1beta2"
)

// BuiltInSourcesGVKs returns the GVKs for built in sources
@@ -26,6 +25,6 @@ func BuiltInSourcesGVKs() []schema.GroupVersionKind {
v1.SchemeGroupVersion.WithKind("ApiServerSource"),
v1.SchemeGroupVersion.WithKind("ContainerSource"),
v1.SchemeGroupVersion.WithKind("SinkBinding"),
v1beta2.SchemeGroupVersion.WithKind("PingSource"),
v1.SchemeGroupVersion.WithKind("PingSource"),
}
}
8 changes: 8 additions & 0 deletions pkg/sources/v1/client.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,9 @@ import (
// KnSinkBindingClient to Eventing Sources. All methods are relative to the
// namespace specified during construction
type KnSourcesClient interface {
// Get client for Ping sources
PingSourcesClient() KnPingSourcesClient

// Get client for sink binding sources
SinkBindingClient() KnSinkBindingClient

@@ -47,6 +50,11 @@ func NewKnSourcesClient(client clientv1.SourcesV1Interface, namespace string) Kn
}
}

// Get the client for dealing with Ping sources
func (c *sourcesClient) PingSourcesClient() KnPingSourcesClient {
return newKnPingSourcesClient(c.client.PingSources(c.namespace), c.namespace)
}

// ApiServerSourcesClient for dealing with ApiServer sources
func (c *sourcesClient) SinkBindingClient() KnSinkBindingClient {
return newKnSinkBindingClient(c.client.SinkBindings(c.namespace), c.namespace)
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta2
package v1

import (
"context"
@@ -29,25 +29,25 @@ import (
knerrors "knative.dev/client/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"

clientv1beta2 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2"
clientv1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

type PingSourceUpdateFunc func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error)
type PingSourceUpdateFunc func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error)

// Interface for interacting with a Ping source
type KnPingSourcesClient interface {

// GetPingSource fetches a Ping source by its name
GetPingSource(ctx context.Context, name string) (*sourcesv1beta2.PingSource, error)
GetPingSource(ctx context.Context, name string) (*sourcesv1.PingSource, error)

// CreatePingSource creates a Ping source
CreatePingSource(ctx context.Context, pingSource *sourcesv1beta2.PingSource) error
CreatePingSource(ctx context.Context, pingSource *sourcesv1.PingSource) error

// UpdatePingSource updates a Ping source
UpdatePingSource(ctx context.Context, pingSource *sourcesv1beta2.PingSource) error
UpdatePingSource(ctx context.Context, pingSource *sourcesv1.PingSource) error

// UpdatePingSourceWithRetry updates a Ping source and retries on conflict
UpdatePingSourceWithRetry(ctx context.Context, name string, updateFunc PingSourceUpdateFunc, nrRetries int) error
@@ -57,7 +57,7 @@ type KnPingSourcesClient interface {

// ListPingSource lists all Ping sources
// TODO: Support list configs like in service list
ListPingSource(ctx context.Context) (*sourcesv1beta2.PingSourceList, error)
ListPingSource(ctx context.Context) (*sourcesv1.PingSourceList, error)

// Get namespace for this source
Namespace() string
@@ -67,12 +67,12 @@ type KnPingSourcesClient interface {
// Temporarily help to add sources dependencies
// May be changed when adding real sources features
type pingSourcesClient struct {
client clientv1beta2.PingSourceInterface
client clientv1.PingSourceInterface
namespace string
}

// NewKnSourcesClient is to invoke Eventing Sources Client API to create object
func newKnPingSourcesClient(client clientv1beta2.PingSourceInterface, namespace string) KnPingSourcesClient {
func newKnPingSourcesClient(client clientv1.PingSourceInterface, namespace string) KnPingSourcesClient {
return &pingSourcesClient{
client: client,
namespace: namespace,
@@ -84,7 +84,7 @@ func (c *pingSourcesClient) Namespace() string {
return c.namespace
}

func (c *pingSourcesClient) CreatePingSource(ctx context.Context, pingsource *sourcesv1beta2.PingSource) error {
func (c *pingSourcesClient) CreatePingSource(ctx context.Context, pingsource *sourcesv1.PingSource) error {
if pingsource.Spec.Sink.Ref == nil && pingsource.Spec.Sink.URI == nil {
return fmt.Errorf("a sink is required for creating a source")
}
@@ -95,7 +95,7 @@ func (c *pingSourcesClient) CreatePingSource(ctx context.Context, pingsource *so
return nil
}

func (c *pingSourcesClient) UpdatePingSource(ctx context.Context, pingSource *sourcesv1beta2.PingSource) error {
func (c *pingSourcesClient) UpdatePingSource(ctx context.Context, pingSource *sourcesv1.PingSource) error {
_, err := c.client.Update(ctx, pingSource, metav1.UpdateOptions{})
if err != nil {
return knerrors.GetError(err)
@@ -140,20 +140,20 @@ func (c *pingSourcesClient) DeletePingSource(ctx context.Context, name string) e
return nil
}

func (c *pingSourcesClient) GetPingSource(ctx context.Context, name string) (*sourcesv1beta2.PingSource, error) {
func (c *pingSourcesClient) GetPingSource(ctx context.Context, name string) (*sourcesv1.PingSource, error) {
source, err := c.client.Get(ctx, name, metav1.GetOptions{})
if err != nil {
return nil, knerrors.GetError(err)
}
err = updateSourceGVK(source)
err = updatePingSourceGVK(source)
if err != nil {
return nil, err
}
return source, nil
}

// ListPingSource returns the available Ping sources
func (c *pingSourcesClient) ListPingSource(ctx context.Context) (*sourcesv1beta2.PingSourceList, error) {
func (c *pingSourcesClient) ListPingSource(ctx context.Context) (*sourcesv1.PingSourceList, error) {
sourceList, err := c.client.List(ctx, metav1.ListOptions{})
if err != nil {
return nil, knerrors.GetError(err)
@@ -162,21 +162,21 @@ func (c *pingSourcesClient) ListPingSource(ctx context.Context) (*sourcesv1beta2
return updatePingSourceListGVK(sourceList)
}

func updateSourceGVK(obj runtime.Object) error {
return util.UpdateGroupVersionKindWithScheme(obj, sourcesv1beta2.SchemeGroupVersion, scheme.Scheme)
func updatePingSourceGVK(obj runtime.Object) error {
return util.UpdateGroupVersionKindWithScheme(obj, sourcesv1.SchemeGroupVersion, scheme.Scheme)
}

func updatePingSourceListGVK(sourceList *sourcesv1beta2.PingSourceList) (*sourcesv1beta2.PingSourceList, error) {
func updatePingSourceListGVK(sourceList *sourcesv1.PingSourceList) (*sourcesv1.PingSourceList, error) {
sourceListNew := sourceList.DeepCopy()
err := updateSourceGVK(sourceListNew)
err := updatePingSourceGVK(sourceListNew)
if err != nil {
return nil, err
}

sourceListNew.Items = make([]sourcesv1beta2.PingSource, len(sourceList.Items))
sourceListNew.Items = make([]sourcesv1.PingSource, len(sourceList.Items))
for idx, source := range sourceList.Items {
sourceClone := source.DeepCopy()
err := updateSourceGVK(sourceClone)
err := updatePingSourceGVK(sourceClone)
if err != nil {
return nil, err
}
@@ -188,18 +188,18 @@ func updatePingSourceListGVK(sourceList *sourcesv1beta2.PingSourceList) (*source
// Builder for building up Ping sources

type PingSourceBuilder struct {
pingSource *sourcesv1beta2.PingSource
pingSource *sourcesv1.PingSource
}

func NewPingSourceBuilder(name string) *PingSourceBuilder {
return &PingSourceBuilder{pingSource: &sourcesv1beta2.PingSource{
return &PingSourceBuilder{pingSource: &sourcesv1.PingSource{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}}
}

func NewPingSourceBuilderFromExisting(pingsource *sourcesv1beta2.PingSource) *PingSourceBuilder {
func NewPingSourceBuilderFromExisting(pingsource *sourcesv1.PingSource) *PingSourceBuilder {
return &PingSourceBuilder{pingSource: pingsource.DeepCopy()}
}

@@ -244,6 +244,6 @@ func (b *PingSourceBuilder) CloudEventOverrides(ceo map[string]string, toRemove
return b
}

func (b *PingSourceBuilder) Build() *sourcesv1beta2.PingSource {
func (b *PingSourceBuilder) Build() *sourcesv1.PingSource {
return b.pingSource
}
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta2
package v1

import (
"context"
"testing"

"knative.dev/client/pkg/util/mock"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
)

type MockKnPingSourceClient struct {
@@ -63,20 +63,20 @@ func (sr *PingSourcesRecorder) CreatePingSource(pingSource interface{}, err erro
}

// CreatePingSource performs a previously recorded action, failing if non has been registered
func (c *MockKnPingSourceClient) CreatePingSource(ctx context.Context, pingSource *sourcesv1beta2.PingSource) error {
func (c *MockKnPingSourceClient) CreatePingSource(ctx context.Context, pingSource *sourcesv1.PingSource) error {
call := c.recorder.r.VerifyCall("CreatePingSource", pingSource)
return mock.ErrorOrNil(call.Result[0])
}

// GetPingSource records a call for GetPingSource with the expected object or error. Either pingsource or err should be nil
func (sr *PingSourcesRecorder) GetPingSource(name interface{}, pingSource *sourcesv1beta2.PingSource, err error) {
func (sr *PingSourcesRecorder) GetPingSource(name interface{}, pingSource *sourcesv1.PingSource, err error) {
sr.r.Add("GetPingSource", []interface{}{name}, []interface{}{pingSource, err})
}

// GetPingSource performs a previously recorded action, failing if non has been registered
func (c *MockKnPingSourceClient) GetPingSource(ctx context.Context, name string) (*sourcesv1beta2.PingSource, error) {
func (c *MockKnPingSourceClient) GetPingSource(ctx context.Context, name string) (*sourcesv1.PingSource, error) {
call := c.recorder.r.VerifyCall("GetPingSource", name)
return call.Result[0].(*sourcesv1beta2.PingSource), mock.ErrorOrNil(call.Result[1])
return call.Result[0].(*sourcesv1.PingSource), mock.ErrorOrNil(call.Result[1])
}

// UpdatePingSource records a call for UpdatePingSource with the expected error (nil if none)
@@ -85,7 +85,7 @@ func (sr *PingSourcesRecorder) UpdatePingSource(pingSource interface{}, err erro
}

// UpdatePingSource performs a previously recorded action, failing if non has been registered
func (c *MockKnPingSourceClient) UpdatePingSource(ctx context.Context, pingSource *sourcesv1beta2.PingSource) error {
func (c *MockKnPingSourceClient) UpdatePingSource(ctx context.Context, pingSource *sourcesv1.PingSource) error {
call := c.recorder.r.VerifyCall("UpdatePingSource", pingSource)
return mock.ErrorOrNil(call.Result[0])
}
@@ -106,14 +106,14 @@ func (c *MockKnPingSourceClient) DeletePingSource(ctx context.Context, name stri
}

// ListPingSource records a call for ListPingSource with the expected error (nil if none)
func (sr *PingSourcesRecorder) ListPingSource(pingSourceList *sourcesv1beta2.PingSourceList, err error) {
func (sr *PingSourcesRecorder) ListPingSource(pingSourceList *sourcesv1.PingSourceList, err error) {
sr.r.Add("ListPingSource", []interface{}{}, []interface{}{pingSourceList, err})
}

// ListPingSource performs a previously recorded action, failing if non has been registered
func (c *MockKnPingSourceClient) ListPingSource(context.Context) (*sourcesv1beta2.PingSourceList, error) {
func (c *MockKnPingSourceClient) ListPingSource(context.Context) (*sourcesv1.PingSourceList, error) {
call := c.recorder.r.VerifyCall("ListPingSource")
return call.Result[0].(*sourcesv1beta2.PingSourceList), mock.ErrorOrNil(call.Result[1])
return call.Result[0].(*sourcesv1.PingSourceList), mock.ErrorOrNil(call.Result[1])
}

// Validates validates whether every recorded action has been called
Original file line number Diff line number Diff line change
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta2
package v1

import (
"context"
"testing"

sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
)

func TestMockKnPingSourceClient(t *testing.T) {
@@ -29,20 +29,20 @@ func TestMockKnPingSourceClient(t *testing.T) {

// Record all services
recorder.GetPingSource("hello", nil, nil)
recorder.CreatePingSource(&sourcesv1beta2.PingSource{}, nil)
recorder.UpdatePingSource(&sourcesv1beta2.PingSource{}, nil)
recorder.CreatePingSource(&sourcesv1.PingSource{}, nil)
recorder.UpdatePingSource(&sourcesv1.PingSource{}, nil)

recorder.GetPingSource("hello", &sourcesv1beta2.PingSource{}, nil)
recorder.UpdatePingSource(&sourcesv1beta2.PingSource{}, nil)
recorder.GetPingSource("hello", &sourcesv1.PingSource{}, nil)
recorder.UpdatePingSource(&sourcesv1.PingSource{}, nil)

recorder.DeletePingSource("hello", nil)

// Call all service
ctx := context.Background()
client.GetPingSource(ctx, "hello")
client.CreatePingSource(ctx, &sourcesv1beta2.PingSource{})
client.UpdatePingSource(ctx, &sourcesv1beta2.PingSource{})
client.UpdatePingSourceWithRetry(ctx, "hello", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
client.CreatePingSource(ctx, &sourcesv1.PingSource{})
client.UpdatePingSource(ctx, &sourcesv1.PingSource{})
client.UpdatePingSourceWithRetry(ctx, "hello", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
return origSource, nil
}, 10)
client.DeletePingSource(ctx, "hello")
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta2
package v1

import (
"context"
@@ -25,13 +25,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clienttesting "k8s.io/client-go/testing"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
"knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2/fake"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1/fake"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

func setupPingSourcesClient(t *testing.T) (sources fake.FakeSourcesV1beta2, client KnPingSourcesClient) {
sources = fake.FakeSourcesV1beta2{Fake: &clienttesting.Fake{}}
func setupPingSourcesClient(t *testing.T) (sources fake.FakeSourcesV1, client KnPingSourcesClient) {
sources = fake.FakeSourcesV1{Fake: &clienttesting.Fake{}}
client = NewKnSourcesClient(&sources, "test-ns").PingSourcesClient()
assert.Equal(t, client.Namespace(), "test-ns")
return
@@ -71,7 +71,7 @@ func TestUpdatePingSource(t *testing.T) {
if name == "errorSource" {
return true, nil, fmt.Errorf("error while updating pingsource %s", name)
}
return true, NewPingSourceBuilderFromExisting(newSource.(*sourcesv1beta2.PingSource)).Build(), nil
return true, NewPingSourceBuilderFromExisting(newSource.(*sourcesv1.PingSource)).Build(), nil
})

err := client.UpdatePingSource(context.Background(), newPingSource("testsource", ""))
@@ -108,55 +108,55 @@ func TestUpdatePingSourceWithRetry(t *testing.T) {

if name == "testSource" && attemptCount > 0 {
attemptCount--
return true, nil, errors.NewConflict(sourcesv1beta2.Resource("pingsource"), "errorSource", fmt.Errorf("error updating because of conflict"))
return true, nil, errors.NewConflict(sourcesv1.Resource("pingsource"), "errorSource", fmt.Errorf("error updating because of conflict"))
}
if name == "errorSource" {
return true, nil, errors.NewInternalError(fmt.Errorf("mock internal error"))
}
return true, NewPingSourceBuilderFromExisting(newSource.(*sourcesv1beta2.PingSource)).Build(), nil
return true, NewPingSourceBuilderFromExisting(newSource.(*sourcesv1.PingSource)).Build(), nil
})

err := client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err := client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, nil
}, maxAttempts)
assert.NilError(t, err, "No retries required as no conflict error occurred")

attemptCount = maxAttempts - 1
err = client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err = client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, nil
}, maxAttempts)
assert.NilError(t, err, "Update retried %d times and succeeded", maxAttempts)
assert.Equal(t, attemptCount, 0)

attemptCount = maxAttempts
err = client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err = client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, nil
}, maxAttempts)
assert.ErrorType(t, err, errors.IsConflict, "Update retried %d times and failed", maxAttempts)
assert.Equal(t, attemptCount, 0)

err = client.UpdatePingSourceWithRetry(context.Background(), "errorSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err = client.UpdatePingSourceWithRetry(context.Background(), "errorSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, nil
}, maxAttempts)
assert.ErrorType(t, err, errors.IsInternalError)

err = client.UpdatePingSourceWithRetry(context.Background(), "deletedSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err = client.UpdatePingSourceWithRetry(context.Background(), "deletedSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, nil
}, maxAttempts)
assert.ErrorContains(t, err, "marked for deletion")

err = client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err = client.UpdatePingSourceWithRetry(context.Background(), "testSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, fmt.Errorf("error updating object")
}, maxAttempts)
assert.ErrorContains(t, err, "error updating object")

err = client.UpdatePingSourceWithRetry(context.Background(), "getErrorSource", func(origSource *sourcesv1beta2.PingSource) (*sourcesv1beta2.PingSource, error) {
err = client.UpdatePingSourceWithRetry(context.Background(), "getErrorSource", func(origSource *sourcesv1.PingSource) (*sourcesv1.PingSource, error) {
origSource.Spec.Data = newData
return origSource, nil
}, maxAttempts)
@@ -209,15 +209,15 @@ func TestListPingSource(t *testing.T) {
sourcesServer.AddReactor("list", "pingsources",
func(a clienttesting.Action) (bool, runtime.Object, error) {
cJSource := newPingSource("testsource", "mysvc")
return true, &sourcesv1beta2.PingSourceList{Items: []sourcesv1beta2.PingSource{*cJSource}}, nil
return true, &sourcesv1.PingSourceList{Items: []sourcesv1.PingSource{*cJSource}}, nil
})

sourceList, err := client.ListPingSource(context.Background())
assert.NilError(t, err)
assert.Equal(t, len(sourceList.Items), 1)
}

func newPingSource(name string, sink string) *sourcesv1beta2.PingSource {
func newPingSource(name string, sink string) *sourcesv1.PingSource {
b := NewPingSourceBuilder(name).
Schedule("* * * * *").
Data("mydata").
47 changes: 0 additions & 47 deletions pkg/sources/v1beta2/client.go

This file was deleted.