Skip to content

Commit 9baddba

Browse files
authored
Refactor PingSourve to v1 API version (#1991)
* Refactor PingSourve to v1 API version * Fix unit test for older api version
1 parent 8d10f67 commit 9baddba

27 files changed

+155
-226
lines changed

pkg/commands/completion_helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func completePingSource(config *completionConfig) (suggestions []string) {
354354
return
355355
}
356356

357-
client, err := config.params.NewSourcesV1beta2Client(namespace)
357+
client, err := config.params.NewSourcesClient(namespace)
358358
if err != nil {
359359
return
360360
}

pkg/commands/completion_helper_test.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ import (
2929
v1beta1 "knative.dev/client/pkg/messaging/v1"
3030
clientv1beta1 "knative.dev/client/pkg/serving/v1beta1"
3131
clientsourcesv1 "knative.dev/client/pkg/sources/v1"
32-
"knative.dev/client/pkg/sources/v1beta2"
3332
eventingv1beta2 "knative.dev/eventing/pkg/apis/eventing/v1beta2"
3433
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
3534
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
36-
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
3735
sourcesv1fake "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1/fake"
38-
sourcesv1beta2fake "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2/fake"
3936

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

313310
var (
314-
testPingSource1 = sourcesv1beta2.PingSource{
311+
testPingSource1 = sourcesv1.PingSource{
315312
TypeMeta: metav1.TypeMeta{
316313
Kind: "PingSource",
317314
APIVersion: "sources.knative.dev/v1",
318315
},
319316
ObjectMeta: metav1.ObjectMeta{Name: "test-ping-source-1", Namespace: testNs},
320317
}
321-
testPingSource2 = sourcesv1beta2.PingSource{
318+
testPingSource2 = sourcesv1.PingSource{
322319
TypeMeta: metav1.TypeMeta{
323320
Kind: "PingSource",
324321
APIVersion: "sources.knative.dev/v1",
325322
},
326323
ObjectMeta: metav1.ObjectMeta{Name: "test-ping-source-2", Namespace: testNs},
327324
}
328-
testPingSource3 = sourcesv1beta2.PingSource{
325+
testPingSource3 = sourcesv1.PingSource{
329326
TypeMeta: metav1.TypeMeta{
330327
Kind: "PingSource",
331328
APIVersion: "sources.knative.dev/v1",
332329
},
333330
ObjectMeta: metav1.ObjectMeta{Name: "test-ping-source-3", Namespace: testNs},
334331
}
335-
testNsPingSources = []sourcesv1beta2.PingSource{testPingSource1, testPingSource2, testPingSource3}
336-
fakeSourcesV1Beta2 = &sourcesv1beta2fake.FakeSourcesV1beta2{Fake: &clienttesting.Fake{}}
332+
testNsPingSources = []sourcesv1.PingSource{testPingSource1, testPingSource2, testPingSource3}
333+
fakeSourcesV1Beta2 = &sourcesv1fake.FakeSourcesV1{Fake: &clienttesting.Fake{}}
337334
)
338335

339336
var (
@@ -449,9 +446,6 @@ current-context: x
449446
NewSourcesClient: func(namespace string) (clientsourcesv1.KnSourcesClient, error) {
450447
return clientsourcesv1.NewKnSourcesClient(fakeSources, namespace), nil
451448
},
452-
NewSourcesV1beta2Client: func(namespace string) (v1beta2.KnSourcesClient, error) {
453-
return v1beta2.NewKnSourcesClient(fakeSourcesV1Beta2, namespace), nil
454-
},
455449
NewEventingV1beta2Client: func(namespace string) (clienteventingv1beta2.KnEventingV1Beta2Client, error) {
456450
return clienteventingv1beta2.NewKnEventingV1Beta2Client(fakeEventingBeta2Client, namespace), nil
457451
},
@@ -1254,7 +1248,7 @@ func TestResourceNameCompletionFuncPingSource(t *testing.T) {
12541248
if a.GetNamespace() == errorNs {
12551249
return true, nil, errors.NewInternalError(fmt.Errorf("unable to list ping sources"))
12561250
}
1257-
return true, &sourcesv1beta2.PingSourceList{Items: testNsPingSources}, nil
1251+
return true, &sourcesv1.PingSourceList{Items: testNsPingSources}, nil
12581252
})
12591253

12601254
tests := []testType{

pkg/commands/flags/sink_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"knative.dev/client/pkg/commands/flags"
2626
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
2727
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
28-
"knative.dev/eventing/pkg/apis/sources/v1beta2"
28+
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
2929
"knative.dev/pkg/apis"
3030
duckv1 "knative.dev/pkg/apis/duck/v1"
3131
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
@@ -85,7 +85,7 @@ func TestResolve(t *testing.T) {
8585
TypeMeta: metav1.TypeMeta{Kind: "Channel", APIVersion: "messaging.knative.dev/v1"},
8686
ObjectMeta: metav1.ObjectMeta{Name: "pipe", Namespace: "default"},
8787
}
88-
pingSource := &v1beta2.PingSource{
88+
pingSource := &sourcesv1.PingSource{
8989
TypeMeta: metav1.TypeMeta{Kind: "PingSource", APIVersion: "sources.knative.dev/v1"},
9090
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
9191
}

pkg/commands/source/list_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestSourceListTypesNoSourcesWithJsonOutput(t *testing.T) {
7373

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

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

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

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

209209
func TestSourceListAllNamespace(t *testing.T) {
210210
output, err := sourceFakeCmd([]string{"source", "list", "--all-namespaces"},
211-
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1beta2", "PingSource"),
211+
newSourceCRDObjWithSpec("pingsources", "sources.knative.dev", "v1", "PingSource"),
212212
newSourceCRDObjWithSpec("sinkbindings", "sources.knative.dev", "v1", "SinkBinding"),
213213
newSourceCRDObjWithSpec("apiserversources", "sources.knative.dev", "v1", "ApiServerSource"),
214-
newSourceUnstructuredObj("p1", "sources.knative.dev/v1beta2", "PingSource"),
214+
newSourceUnstructuredObj("p1", "sources.knative.dev/v1", "PingSource"),
215215
newSourceUnstructuredObj("s1", "sources.knative.dev/v1", "SinkBinding"),
216216
newSourceUnstructuredObj("a1", "sources.knative.dev/v1", "ApiServerSource"),
217217
)

pkg/commands/source/ping/create.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"knative.dev/client/pkg/commands"
2424
"knative.dev/client/pkg/commands/flags"
25-
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
25+
clientsourcesv1 "knative.dev/client/pkg/sources/v1"
2626
"knative.dev/client/pkg/util"
2727
)
2828

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

79-
err = pingSourceClient.CreatePingSource(cmd.Context(), clientsourcesv1beta2.NewPingSourceBuilder(name).
79+
err = pingSourceClient.CreatePingSource(cmd.Context(), clientsourcesv1.NewPingSourceBuilder(name).
8080
Schedule(updateFlags.schedule).
8181
Data(data).
8282
DataBase64(dataBase64).

pkg/commands/source/ping/create_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
2323

2424
dynamicfake "knative.dev/client/pkg/dynamic/fake"
25-
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
25+
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1"
2626

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

pkg/commands/source/ping/delete_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919
"testing"
2020

2121
"gotest.tools/v3/assert"
22-
clientsourcesv1beta2 "knative.dev/client/pkg/sources/v1beta2"
22+
clientsourcesv1 "knative.dev/client/pkg/sources/v1"
2323

2424
"knative.dev/client/pkg/util"
2525
)
2626

2727
func TestSimpleDelete(t *testing.T) {
28-
pingClient := clientsourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
28+
pingClient := clientsourcesv1.NewMockKnPingSourceClient(t, "mynamespace")
2929

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

4040
func TestDeleteWithError(t *testing.T) {
41-
pingClient := clientsourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
41+
pingClient := clientsourcesv1.NewMockKnPingSourceClient(t, "mynamespace")
4242

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

5353
func TestPingDeleteErrorForNoArgs(t *testing.T) {
54-
pingClient := clientsourcesv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
54+
pingClient := clientsourcesv1.NewMockKnPingSourceClient(t, "mynamespace")
5555
out, err := executePingSourceCommand(pingClient, nil, "delete")
5656
assert.ErrorContains(t, err, "single argument")
5757
assert.Assert(t, util.ContainsAll(out, "requires", "single argument"))

pkg/commands/source/ping/describe.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"knative.dev/client/pkg/commands"
2626
"knative.dev/client/pkg/printers"
27-
clientsourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
27+
clientsourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
2828
)
2929

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

118-
func writePingSource(dw printers.PrefixWriter, source *clientsourcesv1beta2.PingSource, printDetails bool) {
118+
func writePingSource(dw printers.PrefixWriter, source *clientsourcesv1.PingSource, printDetails bool) {
119119
commands.WriteMetadata(dw, &source.ObjectMeta, printDetails)
120120
dw.WriteAttribute("Schedule", source.Spec.Schedule)
121121
if source.Spec.DataBase64 != "" {

pkg/commands/source/ping/describe_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import (
2020

2121
"gotest.tools/v3/assert"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23-
sourcesv1beta "knative.dev/eventing/pkg/apis/sources/v1beta2"
23+
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
2424
duckv1 "knative.dev/pkg/apis/duck/v1"
2525

26-
clientv1beta2 "knative.dev/client/pkg/sources/v1beta2"
26+
clientv1 "knative.dev/client/pkg/sources/v1"
2727
"knative.dev/client/pkg/util"
2828
"knative.dev/pkg/apis"
2929
)
3030

3131
func TestDescribeRef(t *testing.T) {
32-
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
32+
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")
3333

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

5353
func TestDescribeURI(t *testing.T) {
54-
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
54+
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")
5555

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

6666
func TestDescribeMachineReadable(t *testing.T) {
67-
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
67+
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")
6868

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

7878
func TestDescribeError(t *testing.T) {
79-
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
79+
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")
8080

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

9292
func TestPingDescribeErrorForNoArgs(t *testing.T) {
93-
pingClient := clientv1beta2.NewMockKnPingSourceClient(t, "mynamespace")
93+
pingClient := clientv1.NewMockKnPingSourceClient(t, "mynamespace")
9494
out, err := executePingSourceCommand(pingClient, nil, "describe")
9595
assert.ErrorContains(t, err, "single argument")
9696
assert.Assert(t, util.ContainsAll(out, "requires", "single argument"))
9797
}
9898

99-
func getPingSourceSinkURI() *sourcesv1beta.PingSource {
100-
return &sourcesv1beta.PingSource{
99+
func getPingSourceSinkURI() *sourcesv1.PingSource {
100+
return &sourcesv1.PingSource{
101101
TypeMeta: metav1.TypeMeta{
102102
Kind: "PingSource",
103103
APIVersion: "sources.knative.dev/v1beta2",
@@ -106,7 +106,7 @@ func getPingSourceSinkURI() *sourcesv1beta.PingSource {
106106
Name: "testsource-uri",
107107
Namespace: "mynamespace",
108108
},
109-
Spec: sourcesv1beta.PingSourceSpec{
109+
Spec: sourcesv1.PingSourceSpec{
110110
Schedule: "1 2 3 4 5",
111111
Data: "honeymoon",
112112
SourceSpec: duckv1.SourceSpec{
@@ -118,6 +118,6 @@ func getPingSourceSinkURI() *sourcesv1beta.PingSource {
118118
},
119119
},
120120
},
121-
Status: sourcesv1beta.PingSourceStatus{},
121+
Status: sourcesv1.PingSourceStatus{},
122122
}
123123
}

pkg/commands/source/ping/flags.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"knative.dev/client/pkg/commands"
2727
hprinters "knative.dev/client/pkg/printers"
2828

29-
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
29+
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
3030
)
3131

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

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

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

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

141141
// temporary slice for sorting services in non-default namespace

0 commit comments

Comments
 (0)