This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daisy Guo
committed
May 19, 2020
1 parent
909a4c3
commit 12422c9
Showing
72 changed files
with
16,847 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
kn-admin* | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// 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 client | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
client_testing "k8s.io/client-go/testing" | ||
"knative.dev/client-contrib/plugins/source-kafka/pkg/types" | ||
v1alpha1 "knative.dev/eventing-contrib/kafka/source/pkg/apis/sources/v1alpha1" | ||
fake "knative.dev/eventing-contrib/kafka/source/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake" | ||
) | ||
|
||
func TestKafkaSourceClient(t *testing.T) { | ||
fakeE := fake.FakeSourcesV1alpha1{Fake: &client_testing.Fake{}} | ||
knSourceClient := NewKafkaSourceClient(&types.KafkaSourceParams{}, &fakeE, "fake-namespace") | ||
assert.Assert(t, knSourceClient != nil) | ||
} | ||
|
||
func TestClient_KnSourceParams(t *testing.T) { | ||
fakeE := fake.FakeSourcesV1alpha1{Fake: &client_testing.Fake{}} | ||
fakeKafkaParams := &types.KafkaSourceParams{} | ||
knSourceClient := NewKafkaSourceClient(fakeKafkaParams, &fakeE, "fake-namespace") | ||
assert.Equal(t, knSourceClient.KnSourceParams(), fakeKafkaParams.KnSourceParams) | ||
} | ||
|
||
func TestNamespace(t *testing.T) { | ||
fakeE := fake.FakeSourcesV1alpha1{Fake: &client_testing.Fake{}} | ||
knSourceClient := NewKafkaSourceClient(&types.KafkaSourceParams{}, &fakeE, "fake-namespace") | ||
assert.Equal(t, knSourceClient.Namespace(), "fake-namespace") | ||
} | ||
func TestCreateKafka(t *testing.T) { | ||
fakeE := fake.FakeSourcesV1alpha1{Fake: &client_testing.Fake{}} | ||
cli := NewKafkaSourceClient(&types.KafkaSourceParams{}, &fakeE, "fake-namespace") | ||
objNew := newKafkaSource("samplekafka") | ||
err := cli.CreateKafkaSource(objNew) | ||
assert.NilError(t, err) | ||
} | ||
|
||
func TestDeleteKafka(t *testing.T) { | ||
fakeE := fake.FakeSourcesV1alpha1{Fake: &client_testing.Fake{}} | ||
cli := NewKafkaSourceClient(&types.KafkaSourceParams{}, &fakeE, "fake-namespace") | ||
objNew := newKafkaSource("samplekafka") | ||
err := cli.CreateKafkaSource(objNew) | ||
assert.NilError(t, err) | ||
err = cli.DeleteKafkaSource("samplekafka") | ||
assert.NilError(t, err) | ||
} | ||
|
||
func newKafkaSource(name string) *v1alpha1.KafkaSource { | ||
return NewKafkaSourceBuilder(name). | ||
BootstrapServers("test.server.org"). | ||
Topics("topic"). | ||
ConsumerGroup("mygroup"). | ||
Build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright © 2018 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 factories | ||
|
||
import ( | ||
"knative.dev/client-contrib/plugins/source-kafka/pkg/types" | ||
|
||
sourcefactories "github.com/maximilien/kn-source-pkg/pkg/factories" | ||
sourcetypes "github.com/maximilien/kn-source-pkg/pkg/types" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type kafkaSourceCommandFactory struct { | ||
kafkaSourceFactory types.KafkaSourceFactory | ||
defaultCommandFactory sourcetypes.CommandFactory | ||
} | ||
|
||
func NewKafkaSourceCommandFactory(kafkaFactory types.KafkaSourceFactory) types.KafkaSourceCommandFactory { | ||
return &kafkaSourceCommandFactory{ | ||
kafkaSourceFactory: kafkaFactory, | ||
defaultCommandFactory: sourcefactories.NewDefaultCommandFactory(kafkaFactory), | ||
} | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) KnSourceFactory() sourcetypes.KnSourceFactory { | ||
return f.kafkaSourceFactory | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) KafkaSourceFactory() types.KafkaSourceFactory { | ||
return f.kafkaSourceFactory | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) KafkaSourceParams() *types.KafkaSourceParams { | ||
return f.kafkaSourceFactory.KafkaSourceParams() | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) KnSourceParams() *sourcetypes.KnSourceParams { | ||
return f.kafkaSourceFactory.KnSourceParams() | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) SourceCommand() *cobra.Command { | ||
sourceCmd := f.defaultCommandFactory.SourceCommand() | ||
sourceCmd.Use = "kafka" | ||
sourceCmd.Short = "Knative eventing Kafka source plugin" | ||
sourceCmd.Long = "Manage your Knative Kafka eventing sources" | ||
return sourceCmd | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) CreateCommand() *cobra.Command { | ||
createCmd := f.defaultCommandFactory.CreateCommand() | ||
createCmd.Short = "create NAME" | ||
createCmd.Example = `#Creates a new Kafka source named as 'mykafkasrc' which subscribes a Kafka server 'my-cluster-kafka-bootstrap.kafka.svc:9092' at topic 'test-topic' using the consumer group ID 'test-consumer-group' and sends the event messages to service 'event-display' | ||
kn source_kafka create mykafkasrc --servers my-cluster-kafka-bootstrap.kafka.svc:9092 --topics test-topic --consumergroup test-consumer-group --sink svc:event-display` | ||
return createCmd | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) DeleteCommand() *cobra.Command { | ||
deleteCmd := f.defaultCommandFactory.DeleteCommand() | ||
deleteCmd.Short = "delete NAME" | ||
deleteCmd.Long = "delete a Kafka source" | ||
deleteCmd.Example = `#Deletes a Kafka source with name 'mykafkasrc' | ||
kn source_kafka delete mykafkasrc` | ||
return deleteCmd | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) UpdateCommand() *cobra.Command { | ||
updateCmd := f.defaultCommandFactory.UpdateCommand() | ||
updateCmd.Short = "update NAME" | ||
updateCmd.Long = "update a Kafka source" | ||
updateCmd.Example = `#Updates a Kafka source with NAME | ||
kn source_kafka update kafka-name --servers my-cluster-kafka-bootstrap.kafka.svc:9092 --topics test-topic --consumergroup test-consumer-group --sink svc:event-display` | ||
return updateCmd | ||
} | ||
|
||
func (f *kafkaSourceCommandFactory) DescribeCommand() *cobra.Command { | ||
describeCmd := f.defaultCommandFactory.DescribeCommand() | ||
describeCmd.Short = "describe NAME" | ||
describeCmd.Long = "update a Kafka source" | ||
describeCmd.Example = `#Describes a Kafka source with NAME | ||
kn source_kafka describe kafka-name` | ||
return describeCmd | ||
} |
Oops, something went wrong.