test-connection.yaml 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: "{{ include "kafka.fullname" . }}-test"
  5. annotations:
  6. "helm.sh/hook": test
  7. "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
  8. spec:
  9. serviceAccountName: {{ include "kafka.fullname" . }}-sa
  10. restartPolicy: Never
  11. containers:
  12. - name: {{ include "kafka.fullname" . }}-test
  13. image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
  14. imagePullPolicy: "{{ .Values.image.pullPolicy }}"
  15. {{- if not .Values.kerberos.enabled }}
  16. command:
  17. - sh
  18. - -c
  19. - |
  20. set -ex
  21. # Delete the topic if it exists
  22. kafka-topics --bootstrap-server ${BOOTSTRAP_SERVER} --topic ${TOPIC_NAME} --delete --if-exists
  23. # Create the topic
  24. kafka-topics --bootstrap-server ${BOOTSTRAP_SERVER} --create --topic ${TOPIC_NAME} --partitions {{ .Values.replicaCount }} --replication-factor 1 --if-not-exists || exit 1
  25. # Create a message
  26. MESSAGE="`date -u`" || exit 1
  27. # Produce a test message to the topic
  28. (echo "$MESSAGE" | kafka-console-producer --broker-list ${BOOTSTRAP_SERVER} --topic ${TOPIC_NAME}) || exit 1
  29. # Consume a test message from the topic
  30. kafka-console-consumer --bootstrap-server ${BOOTSTRAP_SERVER} --topic ${TOPIC_NAME} --group ${GROUP_NAME} --from-beginning --timeout-ms 10000 --max-messages 1 | grep "$MESSAGE"
  31. {{- end }}
  32. {{- if .Values.kerberos.enabled }}
  33. command:
  34. - sh
  35. - -c
  36. - |
  37. set -ex
  38. # Delete the topic if it exists
  39. kafka-topics --bootstrap-server ${BOOTSTRAP_SERVER} --topic ${TOPIC_NAME} --delete --if-exists --command-config /etc/kafka/kafka-client.properties
  40. # Create the topic
  41. kafka-topics --bootstrap-server ${BOOTSTRAP_SERVER} --create --topic ${TOPIC_NAME} --partitions {{ .Values.replicaCount }} --replication-factor 1 --if-not-exists --command-config /etc/kafka/kafka-client.properties || exit 1
  42. # Create a message
  43. MESSAGE="`date -u`" || exit 1
  44. # Produce a test message to the topic
  45. (echo "$MESSAGE" | kafka-console-producer --broker-list ${BOOTSTRAP_SERVER} --topic ${TOPIC_NAME} --producer.config /etc/kafka/kafka-client.properties) || exit 1
  46. # Consume a test message from the topic
  47. kafka-console-consumer --bootstrap-server ${BOOTSTRAP_SERVER} --topic ${TOPIC_NAME} --group ${GROUP_NAME} --from-beginning --timeout-ms 10000 --max-messages 1 --consumer.config /etc/kafka/kafka-client.properties | grep "$MESSAGE"
  48. {{- end }}
  49. env:
  50. - name: TOPIC_NAME
  51. value: {{ include "kafka.fullname" . }}-test-topic
  52. - name: GROUP_NAME
  53. value: {{ include "kafka.fullname" . }}-test
  54. - name: BOOTSTRAP_SERVER
  55. value: {{ include "kafka.bootstrap.server" . }}:{{ .Values.port.kafkaInternal }}
  56. resources:
  57. requests:
  58. memory: "1024Mi"
  59. cpu: "500m"
  60. limits:
  61. memory: "1024Mi"
  62. cpu: "500m"
  63. {{- if .Values.kerberos.enabled }}
  64. volumeMounts:
  65. - name: krb5
  66. mountPath: /etc/krb5.conf
  67. subPath: krb5.conf
  68. - name: client-conf
  69. mountPath: /etc/kafka/kafka-client.properties
  70. subPath: kafka-client.properties
  71. - name: generic-user-keytab
  72. mountPath: "/keytabs"
  73. readOnly: true
  74. resources:
  75. requests:
  76. memory: "1024Mi"
  77. cpu: "500m"
  78. limits:
  79. memory: "1024Mi"
  80. cpu: "500m"
  81. volumes:
  82. - name: krb5
  83. configMap:
  84. name: {{ required "The .Values.kerberos.krb5Conf is required when kerberos enabled!" .Values.kerberos.krb5Conf }}
  85. - name: client-conf
  86. configMap:
  87. name: {{ required "The .Values.kerberos.kafkaCltProperties is required when kerberos enabled!" .Values.kerberos.kafkaCltProperties }}
  88. - name: generic-user-keytab
  89. secret:
  90. secretName: {{ required "The .Values.kerberos.testUserKeytabSecret is required when kerberos enabled!" .Values.kerberos.testUserKeytabSecret }}
  91. {{- end }}