-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
24 changed files
with
174 additions
and
76 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
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,21 @@ | ||
import platform | ||
import sys | ||
import os | ||
|
||
from pathlib import Path | ||
|
||
BASE_FOLDER = ".strimzi-kafka-cli" | ||
BASE_PATH = (str(Path.home()) + "/" + BASE_FOLDER) if os.environ.get( | ||
'STRIMZI_KAFKA_CLI_BASE_PATH') is None else os.environ.get('STRIMZI_KAFKA_CLI_BASE_PATH') | ||
STRIMZI_VERSION = "0.18.0" if os.environ.get('STRIMZI_KAFKA_CLI_STRIMZI_VERSION') is None else os.environ.get('STRIMZI_KAFKA_CLI_STRIMZI_VERSION') | ||
STRIMZI_PATH = (BASE_PATH + "/strimzi-{version}".format(version=STRIMZI_VERSION)) if os.environ.get( | ||
'STRIMZI_KAFKA_CLI_STRIMZI_PATH') is None else os.environ.get('STRIMZI_KAFKA_CLI_STRIMZI_PATH') | ||
STRIMZI_RELEASE_URL = "https://github.com/strimzi/strimzi-kafka-operator/releases/download/{version}/strimzi-{version}.tar.gz".format( | ||
version=STRIMZI_VERSION) | ||
KUBECTL_VERSION = "v1.18.0" if os.environ.get('STRIMZI_KAFKA_CLI_KUBECTL_VERSION') is None else os.environ.get('STRIMZI_KAFKA_CLI_KUBECTL_VERSION') | ||
KUBECTL = "kubectl" if platform.system().lower() != "windows" else "kubectl.exe" | ||
KUBECTL_PATH = (BASE_PATH + "/" + KUBECTL) if os.environ.get( | ||
'STRIMZI_KAFKA_CLI_KUBECTL_PATH') is None else os.environ.get('STRIMZI_KAFKA_CLI_KUBECTL_PATH') | ||
PROCESSOR_TYPE = "amd64" if sys.maxsize > 2 ** 32 else "386" | ||
KUBECTL_RELEASE_URL = "https://storage.googleapis.com/kubernetes-release/release/{version}/bin/{operating_system}/{processor_type}/{kubectl}".format( | ||
version=KUBECTL_VERSION, operating_system=platform.system().lower(), processor_type=PROCESSOR_TYPE, kubectl=KUBECTL) |
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 |
---|---|---|
@@ -1,32 +1,70 @@ | ||
import click | ||
import os | ||
import ntpath | ||
|
||
from kfk.command import kfk | ||
from kfk.kubectl_command_builder import Kubectl | ||
from kfk.config import * | ||
from kfk.commons import get_kv_config_arr, transfer_file_to_container, SafeDict | ||
from kfk.constants import * | ||
|
||
|
||
@click.option('-n', '--namespace', help='Namespace to use', required=True) | ||
@click.option('-c', '--cluster', help='Cluster to use', required=True) | ||
@click.option('--topic', help='Topic Name', required=True) | ||
@click.option('--from-beginning', help='Consumes messages from beginning', is_flag=True) | ||
@click.option('--consumer.config', 'consumer_config', help='Consumer config properties file.') | ||
@click.option('--topic', help='Topic Name', required=True) | ||
@kfk.command() | ||
def console_consumer(topic, cluster, from_beginning, namespace): | ||
def console_consumer(topic, consumer_config, from_beginning, cluster, namespace): | ||
"""The console consumer is a tool that reads data from Kafka and outputs it to standard output.""" | ||
native_command = "bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic {" \ | ||
native_command = "bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:{port} --topic {" \ | ||
"topic} {from_beginning}" | ||
pod = cluster + "-kafka-0" | ||
container = "kafka" | ||
if consumer_config is not None: | ||
native_command = apply_client_config_from_file(native_command, consumer_config, "--consumer-property", | ||
container, pod, namespace) | ||
print(native_command) | ||
os.system( | ||
Kubectl().exec("-it", "{cluster}-kafka-0").container("kafka").namespace(namespace).exec_command( | ||
native_command).build().format(cluster=cluster, topic=topic, | ||
Kubectl().exec("-it", pod).container(container).namespace(namespace).exec_command( | ||
native_command).build().format(port=KAFKA_PORT, topic=topic, | ||
from_beginning=(from_beginning and '--from-beginning' or ''))) | ||
|
||
|
||
@click.option('-n', '--namespace', help='Namespace to use', required=True) | ||
@click.option('-c', '--cluster', help='Cluster to use', required=True) | ||
@click.option('--producer.config', 'producer_config', help='Producer config properties file.') | ||
@click.option('--topic', help='Topic Name', required=True) | ||
@kfk.command() | ||
def console_producer(topic, cluster, namespace): | ||
def console_producer(topic, producer_config, cluster, namespace): | ||
"""The console producer is a tool that reads data from standard input and publish it to Kafka.""" | ||
native_command = "bin/kafka-console-producer.sh --broker-list my-cluster-kafka-brokers:9092 --topic {topic}" | ||
native_command = "bin/kafka-console-producer.sh --broker-list my-cluster-kafka-brokers:{port} --topic {topic}" | ||
pod = cluster + "-kafka-0" | ||
container = "kafka" | ||
if producer_config is not None: | ||
native_command = apply_client_config_from_file(native_command, producer_config, "--producer-property", | ||
container, pod, namespace) | ||
os.system( | ||
Kubectl().exec("-it", "{cluster}-kafka-0").container("kafka").namespace(namespace).exec_command( | ||
native_command).build().format(cluster=cluster, topic=topic)) | ||
Kubectl().exec("-it", pod).container(container).namespace(namespace).exec_command( | ||
native_command).build().format(port=KAFKA_PORT, topic=topic)) | ||
|
||
|
||
def apply_client_config_from_file(native_command, config_file_path, property_flag, container, pod, namespace): | ||
port = KAFKA_PORT | ||
delete_file_command = "" | ||
with open(config_file_path) as file: | ||
for cnt, producer_property in enumerate(file): | ||
producer_property = producer_property.strip() | ||
if "security.protocol" in producer_property: | ||
producer_property_arr = get_kv_config_arr(producer_property) | ||
if producer_property_arr[1] == KAFKA_SSL: | ||
port = KAFKA_SECURE_PORT | ||
if "ssl.truststore.location" in producer_property or "ssl.keystore.location" in producer_property: | ||
producer_property_arr = get_kv_config_arr(producer_property) | ||
file_path = producer_property_arr[1] | ||
file_name = ntpath.basename(file_path) | ||
new_file_path = "/tmp/" + file_name | ||
transfer_file_to_container(file_path, new_file_path, container, pod, namespace) | ||
producer_property = producer_property_arr[0] + "=" + new_file_path | ||
delete_file_command = delete_file_command + "rm -rf" + SPACE + new_file_path + SEMICOLON | ||
native_command = native_command + SPACE + property_flag + SPACE + producer_property | ||
return native_command.format_map(SafeDict(port=port)) + SEMICOLON + delete_file_command |
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 |
---|---|---|
@@ -1,22 +1,6 @@ | ||
import platform | ||
import sys | ||
import os | ||
|
||
from pathlib import Path | ||
|
||
BASE_FOLDER = ".strimzi-kafka-cli" | ||
BASE_PATH = (str(Path.home()) + "/" + BASE_FOLDER) if os.environ.get( | ||
'STRIMZI_KAFKA_CLI_BASE_PATH') is None else os.environ.get('STRIMZI_KAFKA_CLI_BASE_PATH') | ||
STRIMZI_VERSION = "0.18.0" if os.environ.get('STRIMZI_KAFKA_CLI_STRIMZI_VERSION') is None else os.environ.get('STRIMZI_KAFKA_CLI_STRIMZI_VERSION') | ||
STRIMZI_PATH = (BASE_PATH + "/strimzi-{version}".format(version=STRIMZI_VERSION)) if os.environ.get( | ||
'STRIMZI_KAFKA_CLI_STRIMZI_PATH') is None else os.environ.get('STRIMZI_KAFKA_CLI_STRIMZI_PATH') | ||
STRIMZI_RELEASE_URL = "https://github.com/strimzi/strimzi-kafka-operator/releases/download/{version}/strimzi-{version}.tar.gz".format( | ||
version=STRIMZI_VERSION) | ||
KUBECTL_VERSION = "v1.18.0" if os.environ.get('STRIMZI_KAFKA_CLI_KUBECTL_VERSION') is None else os.environ.get('STRIMZI_KAFKA_CLI_KUBECTL_VERSION') | ||
KUBECTL = "kubectl" if platform.system().lower() != "windows" else "kubectl.exe" | ||
KUBECTL_PATH = (BASE_PATH + "/" + KUBECTL) if os.environ.get( | ||
'STRIMZI_KAFKA_CLI_KUBECTL_PATH') is None else os.environ.get('STRIMZI_KAFKA_CLI_KUBECTL_PATH') | ||
PROCESSOR_TYPE = "amd64" if sys.maxsize > 2 ** 32 else "386" | ||
KUBECTL_RELEASE_URL = "https://storage.googleapis.com/kubernetes-release/release/{version}/bin/{operating_system}/{processor_type}/{kubectl}".format( | ||
version=KUBECTL_VERSION, operating_system=platform.system().lower(), processor_type=PROCESSOR_TYPE, kubectl=KUBECTL) | ||
SPACE = " " | ||
SEMICOLON = ";" | ||
AMPERSAND = "&" | ||
KAFKA_PORT = "9092" | ||
KAFKA_SECURE_PORT = "9093" | ||
KAFKA_SSL = "SSL" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
security.protocol=SSL | ||
ssl.truststore.location=~/Desktop/truststore.jks | ||
ssl.truststore.password=123456 | ||
ssl.keystore.location=~/Desktop/user.p12 | ||
ssl.keystore.password=123456 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.