Skip to content

Commit 9c94a4c

Browse files
author
Leonid Podolinskiy
committed
first commit
0 parents  commit 9c94a4c

File tree

88 files changed

+7843
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7843
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.github/workflows/e2e.yaml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
name: "Tests"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'lightrun-init-agent/**'
9+
- '.github/**'
10+
- 'docs/**'
11+
- 'grafana/**'
12+
13+
jobs:
14+
e2e_test:
15+
name: Build controller and install helm chart
16+
runs-on: ubuntu-latest
17+
services:
18+
registry:
19+
image: registry:2
20+
ports:
21+
- 5000:5000
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Spin up k3s cluster
26+
shell: bash
27+
run: |
28+
29+
# Add local registry to /etc/hosts
30+
echo '127.0.0.1 localreg.com' | sudo tee -a /etc/hosts
31+
32+
# Install kubectl
33+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
34+
35+
# Install helm
36+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
37+
chmod 700 get_helm.sh
38+
./get_helm.sh
39+
40+
#Install k3s
41+
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -s - --docker
42+
43+
mkdir ~/.kube || echo "~/.kube already existed"
44+
sudo chmod 777 /etc/rancher/k3s/k3s.yaml
45+
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
46+
sudo chmod 777 ~/.kube/config
47+
48+
cat <<EOF >> /tmp/registries.yaml
49+
mirrors:
50+
"localreg.com:5000":
51+
endpoint:
52+
- "http://localreg.com:5000"
53+
EOF
54+
55+
sudo cp /tmp/registries.yaml /etc/rancher/k3s/
56+
sudo chmod 777 /etc/rancher/k3s/registries.yaml
57+
58+
#printf "\nRegistry file\n"
59+
#cat /etc/rancher/k3s/registries.yaml
60+
61+
#printf "\nkube config\n"
62+
#cat ~/.kube/config
63+
64+
# ensure that node is created
65+
timeout 2m bash -c 'until kubectl get node $HOSTNAME; do sleep 1; done'
66+
67+
# test for 120 to see if node will go ready
68+
kubectl wait --timeout=120s --for=condition=Ready node/$(echo $HOSTNAME| awk '{print tolower($0)}')
69+
70+
# Restart need to update local registry config
71+
printf "Restart k3s service\n"
72+
sudo systemctl restart k3s
73+
kubectl wait --timeout=120s --for=condition=Ready node/$(echo $HOSTNAME| awk '{print tolower($0)}')
74+
75+
- name: Build and push to local repo
76+
uses: docker/build-push-action@v3
77+
with:
78+
context: .
79+
push: true
80+
tags: localreg.com:5000/lightrun-k8s-operator:0.0.0-${{ github.run_number }}
81+
82+
83+
- name: Install chart and test controller
84+
shell: bash
85+
run: |
86+
#printf "Check local registry image\n"
87+
#curl http://localreg.com:5000/v2/lightrun-k8s-operator/manifests/0.0.0-${{ github.run_number }}
88+
89+
90+
yq -i '.controllerManager.manager.image.repository = "localreg.com:5000/lightrun-k8s-operator"' .github/workflows/tests_data/chart_values.yaml
91+
yq -i '.controllerManager.manager.image.tag = "0.0.0-${{ github.run_number }}"' .github/workflows/tests_data/chart_values.yaml
92+
yq -i '.spec.agentName = "ci-k3s-controller-chart-test-${{ github.run_number }}"' .github/workflows/tests_data/lightrunjavaagent.yaml
93+
yq -i '.managerConfig.operatorScope.namespacedScope = true' .github/workflows/tests_data/chart_values.yaml
94+
95+
kubectl create ns lightrun-k8s-operator
96+
kubectl create ns app-ns
97+
kubectl config set-context --current --namespace=app-ns
98+
99+
printf "Deploy Java app\n"
100+
kubectl apply -f examples/deployment.yaml
101+
102+
103+
printf "Add agent secret\n"
104+
cat <<EOF | kubectl create -f -
105+
apiVersion: v1
106+
metadata:
107+
name: lightrun-secrets
108+
stringData:
109+
lightrun_key: ${{ secrets.DOGFOOD_KEY }}
110+
pinned_cert_hash: ${{ secrets.DOGFOOD_CERT }}
111+
kind: Secret
112+
type: Opaque
113+
EOF
114+
115+
116+
printf "Update generated parts of helm chart\n"
117+
make before-push
118+
printf "Install helm chart\n"
119+
helm install -n lightrun-k8s-operator lightrun-k8s-operator ./helm-chart -f .github/workflows/tests_data/chart_values.yaml
120+
121+
kubectl wait deployment app --for condition=Available=True --timeout=90s
122+
123+
kubectl get deployments -n lightrun-k8s-operator
124+
kubectl get pods -n lightrun-k8s-operator
125+
kubectl wait deployment -n lightrun-k8s-operator lightrun-k8s-operator-controller-manager --for condition=Available=True --timeout=200s
126+
kubectl get pods -n lightrun-k8s-operator
127+
128+
129+
kubectl apply -f .github/workflows/tests_data/lightrunjavaagent.yaml
130+
kubectl wait deployment app --for condition=Available=True --timeout=90s
131+
132+
133+
printf "Wait 1 minute\n"
134+
sleep 60
135+
printf "\nController logs\n\n"
136+
kubectl logs --tail=500 -l control-plane=controller-manager -n lightrun-k8s-operator
137+
138+
139+
140+
141+
printf "\n\nAgent INFO log\n"
142+
kubectl exec -t deploy/app -c app -- cat /tmp/lightrun_java_agent.INFO
143+
printf "\n\nAgent ERROR log\n"
144+
kubectl exec -t deploy/app -c app -- cat /tmp/lightrun_java_agent.ERROR || true
145+
146+
147+
printf "\nSearching for "registered" in INFO log\n"
148+
if kubectl exec -t deploy/app -c app -- cat /tmp/lightrun_java_agent.INFO | grep Debuggee |grep registered > /dev/null; then
149+
printf "\n----------------\nAgent registered succesfully!\n----------------\n"
150+
else
151+
printf "\n----------------\nAgent failed to register!\n----------------\n"
152+
export AGENT_REGISTERED=false
153+
fi
154+
155+
156+
157+
158+
printf "Add resources in restricted namespace\n"
159+
kubectl create ns restricted
160+
kubectl config set-context --current --namespace=restricted
161+
printf "Deploy Java app\n"
162+
kubectl apply -f examples/deployment.yaml
163+
164+
printf "Add agent secret\n"
165+
cat <<EOF | kubectl create -f -
166+
apiVersion: v1
167+
metadata:
168+
name: lightrun-secrets
169+
stringData:
170+
lightrun_key: ${{ secrets.DOGFOOD_KEY }}
171+
pinned_cert_hash: ${{ secrets.DOGFOOD_CERT }}
172+
kind: Secret
173+
type: Opaque
174+
EOF
175+
176+
kubectl apply -f .github/workflows/tests_data/lightrunjavaagent.yaml
177+
178+
sleep 5
179+
kubectl describe deployment app
180+
181+
printf "Controller logs\n\n\n"
182+
kubectl logs --tail=500 -l control-plane=controller-manager -n lightrun-k8s-operator
183+
184+
printf "LightrunJavaAgents status\n\n\n"
185+
kubectl get lrja --all-namespaces
186+
187+
printf "\nCleanup\n\n"
188+
bash /usr/local/bin/k3s-uninstall.sh
189+
rm -rf ~/.kube
190+
191+
if [[ $AGENT_REGISTERED == "false" ]]; then
192+
exit 1
193+
fi
194+
195+
196+
197+

.github/workflows/init_container.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "Init container for k8s operator"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_tag:
7+
description: 'Release tag of the agent'
8+
required: true
9+
init_image_tag:
10+
description: 'Image tag'
11+
required: true
12+
default: "0"
13+
14+
15+
16+
jobs:
17+
set_image_tag_variable:
18+
runs-on: ubuntu-latest
19+
name: Build and push Docker image
20+
steps:
21+
- name: Set release tag
22+
shell: bash
23+
run: |
24+
echo "::set-output name=TAG_NAME::$(echo ${{ inputs.release_tag }} | sed -E 's/^([0-9]*\.[0-9]*\.[0-9]*).*/\1/')-init.${{ inputs.init_image_tag }}"
25+
id: set_tag
26+
27+
- uses: actions/checkout@v3
28+
29+
30+
- name: Login to DockerHub
31+
if: ${{ success() }}
32+
uses: docker/login-action@v2
33+
with:
34+
username: ${{ secrets.DOCKERHUB_USER }}
35+
password: ${{ secrets.DOCKERHUB_PASS }}
36+
37+
- name: Build and push linux container
38+
uses: docker/build-push-action@v3
39+
with:
40+
context: .
41+
file: ./lightrun-init-agent/Dockerfile
42+
push: true
43+
tags: "lightruncom/k8s-operator-init-java-agent-linux:${{steps.set_tag.outputs.TAG_NAME}}"
44+
build-args: |
45+
GITHUB_TOKEN=${{ secrets.PRETTY_GITHUB_READ_TOKEN }}
46+
VERSION=${{ inputs.release_tag }}
47+
FILE=agent.zip
48+
49+
- name: Build and push alpine container
50+
uses: docker/build-push-action@v3
51+
with:
52+
context: .
53+
file: ./lightrun-init-agent/Dockerfile
54+
push: true
55+
tags: "lightruncom/k8s-operator-init-java-agent-alpine:${{steps.set_tag.outputs.TAG_NAME}}"
56+
build-args: |
57+
GITHUB_TOKEN=${{ secrets.PRETTY_GITHUB_READ_TOKEN }}
58+
VERSION=${{ inputs.release_tag }}
59+
FILE=agent-alpine.zip
60+

.github/workflows/release.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: "Release"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- lightrun-init-agent/*
9+
- .github/**
10+
- helm-chart/*
11+
- grafana/*
12+
- config/*
13+
- examples/*
14+
- docs/*
15+
- Makefile
16+
17+
18+
jobs:
19+
build:
20+
name: Build and push Docker image
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
with:
31+
path: 'helm-repo'
32+
ref: 'helm-repo'
33+
fetch-depth: 0
34+
35+
- name: Bump version and push tag
36+
uses: anothrNick/github-tag-action@1.40.0
37+
id: release_tag
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
DEFAULT_BUMP: patch
41+
VERBOSE: true
42+
WITH_V: false
43+
INITIAL_VERSION: 0.1.0
44+
45+
- name: Setup Go environment
46+
uses: actions/setup-go@v3.3.0
47+
with:
48+
go-version: '1.18.0'
49+
50+
- name: Run tests and prepare reports
51+
shell: bash
52+
run: |
53+
make test
54+
55+
- name: Install Helm
56+
uses: azure/setup-helm@v1
57+
58+
- name: Pack Helm chart
59+
shell: bash
60+
run: |
61+
yq -i '.version = "${{steps.release_tag.outputs.new_tag}}"' helm-chart/Chart.yaml
62+
yq -i '.controllerManager.manager.image.tag = "${{steps.release_tag.outputs.new_tag}}"' helm-chart/values.yaml
63+
helm package ./helm-chart -u -d ./helm-repo/
64+
65+
- name: Login to DockerHub
66+
if: ${{ success() }}
67+
uses: docker/login-action@v2
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USER }}
70+
password: ${{ secrets.DOCKERHUB_PASS }}
71+
72+
- name: Build and push
73+
uses: docker/build-push-action@v3
74+
with:
75+
context: .
76+
push: true
77+
tags: |
78+
lightruncom/lightrun-k8s-operator:${{steps.release_tag.outputs.new_tag}}
79+
lightruncom/lightrun-k8s-operator:latest
80+
81+
- name: Create Release
82+
if: ${{ success() }}
83+
uses: ncipollo/release-action@v1.10.0
84+
with:
85+
artifacts: helm-repo/lightrun-k8s-operator-${{steps.release_tag.outputs.new_tag}}.tgz
86+
tag: ${{steps.release_tag.outputs.new_tag}}
87+
generateReleaseNotes: true
88+
89+
90+
- name: Publish new chart version
91+
shell: bash
92+
working-directory: helm-repo
93+
run: |
94+
git switch helm-repo
95+
helm repo index . --url https://lightrun-platform.github.io/lightrun-k8s-operator
96+
git config user.name "Helm Updater"
97+
git config user.email "actions@users.noreply.github.com"
98+
git add $(git ls-files -o --exclude-standard)
99+
git add index.yaml
100+
git commit -m "Updated from ref: $GITHUB_SHA"
101+
git push
102+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
controllerManager:
2+
namespace: lightrun-k8s-operator
3+
manager:
4+
image:
5+
repository: lightruncom/lightrun-k8s-operator
6+
tag: latest
7+
8+
managerConfig:
9+
logLevel: 2 # higher number - mor logs
10+
operatorScope:
11+
namespaces:
12+
- default
13+
- app-ns
14+
namespacedScope: false

0 commit comments

Comments
 (0)