mirror of https://github.com/knative/client.git
Refactor PingSourve to v1 API version (#1991)
* Refactor PingSourve to v1 API version * Fix unit test for older api version
This commit is contained in:
parent
8d10f67dd9
commit
9baddba98c
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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"},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -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 != "" {
|
||||
|
|
|
|||
|
|
@ -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{},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,7 +111,7 @@ 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"))
|
||||
|
|
@ -119,7 +119,7 @@ func TestPingUpdateErrorForNoArgs(t *testing.T) {
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,12 @@ import (
|
|||
"gotest.tools/v3/assert"
|
||||
|
||||
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
|
||||
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
|
||||
)
|
||||
|
||||
func TestBuiltInSourcesGVks(t *testing.T) {
|
||||
gvks := BuiltInSourcesGVKs()
|
||||
for _, each := range gvks {
|
||||
if each.Kind != "PingSource" {
|
||||
assert.DeepEqual(t, each.GroupVersion(), sourcesv1.SchemeGroupVersion)
|
||||
} else {
|
||||
assert.DeepEqual(t, each.GroupVersion(), sourcesv1beta2.SchemeGroupVersion)
|
||||
}
|
||||
assert.DeepEqual(t, each.GroupVersion(), sourcesv1.SchemeGroupVersion)
|
||||
}
|
||||
assert.Equal(t, len(gvks), 4)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,12 +140,12 @@ 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
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ func (c *pingSourcesClient) GetPingSource(ctx context.Context, name string) (*so
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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")
|
||||
|
|
@ -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,22 +108,22 @@ 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)
|
||||
|
|
@ -131,32 +131,32 @@ func TestUpdatePingSourceWithRetry(t *testing.T) {
|
|||
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,7 +209,7 @@ 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())
|
||||
|
|
@ -217,7 +217,7 @@ func TestListPingSource(t *testing.T) {
|
|||
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").
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// Copyright © 2019 The Knative Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package v1beta2
|
||||
|
||||
import (
|
||||
clientv1beta2 "knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2"
|
||||
)
|
||||
|
||||
// KnSinkBindingClient to Eventing Sources. All methods are relative to the
|
||||
// namespace specified during construction
|
||||
type KnSourcesClient interface {
|
||||
// Get client for Ping sources
|
||||
PingSourcesClient() KnPingSourcesClient
|
||||
}
|
||||
|
||||
// sourcesClient is a combination of Sources client interface and namespace
|
||||
// Temporarily help to add sources dependencies
|
||||
// May be changed when adding real sources features
|
||||
type sourcesClient struct {
|
||||
client clientv1beta2.SourcesV1beta2Interface
|
||||
namespace string
|
||||
}
|
||||
|
||||
// NewKnSourcesClient for managing all eventing built-in sources
|
||||
func NewKnSourcesClient(client clientv1beta2.SourcesV1beta2Interface, namespace string) KnSourcesClient {
|
||||
return &sourcesClient{
|
||||
client: client,
|
||||
namespace: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// Get the client for dealing with Ping sources
|
||||
func (c *sourcesClient) PingSourcesClient() KnPingSourcesClient {
|
||||
return newKnPingSourcesClient(c.client.PingSources(c.namespace), c.namespace)
|
||||
}
|
||||
Loading…
Reference in New Issue