Skip to content

Commit

Permalink
Merge pull request #33 from stevendborrelli/github-ci
Browse files Browse the repository at this point in the history
Add Github CI actions for kafka cluster
  • Loading branch information
stevendborrelli authored Apr 6, 2022
2 parents 16dd299 + bf2d975 commit 9176819
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 11 deletions.
78 changes: 75 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ env:
GO_VERSION: '1.17'
GOLANGCI_VERSION: 'v1.31'
DOCKER_BUILDX_VERSION: 'v0.4.2'
KIND_VERSION: 'v0.12.0'
HELM_VERSION: 'v3.8.1'
CROSSPLANE_VERSION: 'stable'
KUBECTL_VERSION: 'v1.23.4'
KUBEFWD_VERSION: '1.22.0'

# Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run
# a step 'if env.AWS_USR' != ""', so we copy these to succinctly test whether
Expand Down Expand Up @@ -167,7 +172,74 @@ jobs:
- name: Vendor Dependencies
run: make vendor vendor.check

- name: Set up Kind Cluster
uses: helm/[email protected]
with:
version: ${{ env.KIND_VERSION }}
cluster_name: 'kafka'

- name: Install Crossplane
run: |
kubectl create ns crossplane-system
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm install crossplane --namespace crossplane-system crossplane-stable/crossplane
- name: Install Provider-Kafka CRDs
run: kubectl apply -f package/crds

- name: Install Kafka
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
kubectl create ns kafka-cluster
helm upgrade --install kafka-dev -n kafka-cluster bitnami/kafka \
--version 15.0.1 \
--set auth.clientProtocol=sasl \
--set deleteTopicEnable=true \
--set authorizerClassName="kafka.security.authorizer.AclAuthorizer" \
--wait
- name: Get Kafka Client Password
id: kafka
run: echo "::set-output name=password::$(kubectl get secret kafka-dev-jaas --namespace kafka-cluster -o jsonpath='{.data.client-passwords}' | base64 --decode | cut -d , -f 1)"

- name: Create Kafka Credentials File
env:
KAFKA_PASSWORD: ${{ steps.kafka.outputs.password }}
run: |
echo "{
"brokers": [
"kafka-dev-0.kafka-dev-headless:9092"
],
"sasl": {
"mechanism": "PLAIN",
"username": "user",
"password": "${KAFKA_PASSWORD}"
}
}" > kc.json
- name: Show kc.json file
run: cat kc.json

- name: create Kafka K8s secret
run: kubectl -n kafka-cluster create secret generic kafka-creds --from-file=credentials=kc.json


- name: Test downloading external binary
uses: giantswarm/[email protected]
with:
binary: "kubefwd"
version: "${{ env.KUBEFWD_VERSION }}"
download_url: "https://github.com/txn2/kubefwd/releases/download/${version}/${binary}_Linux_x86_64.tar.gz"
tarball_binary_path: "${binary}"
smoke_test: "${binary} version"

- name: run Kubefwd
run: sudo -E /opt/hostedtoolcache/kubefwd/${{ env.KUBEFWD_VERSION }}/x64/kubefwd svc -n kafka-cluster &

- name: Run Unit Tests
env:
KAFKA_PASSWORD: ${{ steps.kafka.outputs.password }}
run: make -j2 test

- name: Publish Unit Test Coverage
Expand Down Expand Up @@ -235,8 +307,8 @@ jobs:
# builds by default. Specifying --load does so.
BUILD_ARGS: "--load"

- name: Run E2E Tests
run: make e2e USE_HELM3=true
# - name: Run E2E Tests
# run: make e2e USE_HELM3=true

publish-artifacts:
runs-on: ubuntu-18.04
Expand Down Expand Up @@ -324,4 +396,4 @@ jobs:
BRANCH_NAME: main
CHANNEL: main
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_USR }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }}
21 changes: 13 additions & 8 deletions internal/clients/kafka/topic/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package topic
import (
"context"
"fmt"
"os"
"testing"

"github.com/crossplane-contrib/provider-kafka/apis/topic/v1alpha1"
Expand All @@ -12,14 +13,18 @@ import (
"github.com/twmb/franz-go/pkg/kadm"
)

var dataTesting = []byte(`{
"brokers": [ "kafka-dev-0.kafka-dev-headless:9092"],
"sasl": {
"mechanism": "PLAIN",
"username": "user",
"password": ""
}
}`)
var kafkaPassword = os.Getenv("KAFKA_PASSWORD")

var dataTesting = []byte(
fmt.Sprintf(`{
"brokers": [ "kafka-dev-0.kafka-dev-headless:9092"],
"sasl": {
"mechanism": "PLAIN",
"username": "user",
"password": "%s"
}
}`, kafkaPassword),
)

func TestCreate(t *testing.T) {

Expand Down

0 comments on commit 9176819

Please sign in to comment.