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
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
2 changes: 1 addition & 1 deletion pkg/commands/completion_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 6 additions & 12 deletions pkg/commands/completion_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/flags/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"},
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/commands/source/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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"),
)
Expand All @@ -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"))
Expand Down Expand Up @@ -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"),
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/source/ping/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/source/ping/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/source/ping/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand All @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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 != "" {
Expand Down
22 changes: 11 additions & 11 deletions pkg/commands/source/ping/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"))
Expand All @@ -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",
Expand All @@ -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{
Expand All @@ -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
Expand Up @@ -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 {
Expand Down Expand Up @@ -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},
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
Loading
Loading