Skip to content

Commit

Permalink
Merge pull request opensearch-project#149 from parca-dev/tilt
Browse files Browse the repository at this point in the history
Tilt for local dev
  • Loading branch information
kakkoyun authored Nov 30, 2021
2 parents 4ebdfd9 + 2629221 commit 474ed1c
Show file tree
Hide file tree
Showing 22 changed files with 528 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ go-fmt:
.PHONY: check-license
check-license:
./scripts/check-license.sh

.PHONY: dev/up
dev/up: deploy/manifests
source ./scripts/local-dev.sh && up

.PHONY: dev/down
dev/down:
source ./scripts/local-dev.sh && down
11 changes: 11 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
docker_prune_settings(num_builds=5)

## Parca Agent

docker_build(
'parca.io/parca/parca-agent:dev', '',
dockerfile='Dockerfile.dev',
only=['./cmd', './pkg', './3rdparty', './go.mod', './go.sum', './parca-agent.bpf.c', './vmlinux.h', './Makefile'],
)
k8s_yaml('deploy/tilt/parca-agent-daemonSet.yaml')
k8s_resource('parca-agent', port_forwards=[7071])
6 changes: 4 additions & 2 deletions deploy/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
VERSION ?= $(shell git describe --exact-match --tags $$(git log -n1 --pretty='%h') 2>/dev/null || echo "$$(git rev-parse --abbrev-ref HEAD)-$$(git rev-parse --short HEAD)")
SERVER_LATEST_VERSION ?= $(shell curl -s https://api.github.com/repos/parca-dev/parca/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' | xargs echo -n)

.PHONY: vendor
vendor:
jb install

.PHONY: manifests
manifests: vendor $(shell find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print)
rm -rf manifests
mkdir -p manifests/openshift manifests/kubernetes
rm -rf manifests tilt
mkdir -p manifests/openshift manifests/kubernetes tilt
jsonnet --tla-str version="$(VERSION)" -J vendor main.jsonnet -m manifests/kubernetes | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
awk 'BEGINFILE {print "---"}{print}' manifests/kubernetes/* > manifests/kubernetes/manifest.yaml
jsonnet --tla-str version="$(VERSION)" -J vendor openshift.jsonnet -m manifests/openshift | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
awk 'BEGINFILE {print "---"}{print}' manifests/openshift/* > manifests/openshift/manifest.yaml
jsonnet --tla-str serverVersion="$(SERVER_LATEST_VERSION)" -J vendor dev.jsonnet -m tilt | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}

fmt:
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
Expand Down
46 changes: 40 additions & 6 deletions deploy/dev.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
local agent = (import 'main.jsonnet');
function(serverVersion='v0.4.2')
local ns = {
apiVersion: 'v1',
kind: 'Namespace',
metadata: {
name: 'parca',
},
};

std.manifestYamlStream([
agent[name]
for name in std.objectFields(agent)
if agent[name] != null
])
local server = (import 'parca/parca.libsonnet')({
name: 'parca',
namespace: ns.metadata.name,
image: 'ghcr.io/parca-dev/parca:' + serverVersion,
version: serverVersion,
replicas: 1,
corsAllowedOrigins: '*',
});

local agent = (import 'parca-agent/parca-agent.libsonnet')({
name: 'parca-agent',
namespace: ns.metadata.name,
version: 'dev',
image: 'parca.io/parca/parca-agent:dev',
stores: ['%s.%s.svc.cluster.local:%d' % [server.service.metadata.name, server.service.metadata.namespace, server.config.port]],
logLevel: 'debug',
insecure: true,
insecureSkipVerify: true,
tempDir: 'tmp',
});

{
'0namespace': ns,
} + {
['parca-server-' + name]: server[name]
for name in std.objectFields(server)
if server[name] != null
} + {
['parca-agent-' + name]: agent[name]
for name in std.objectFields(agent)
if agent[name] != null
}
9 changes: 9 additions & 0 deletions deploy/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
}
},
"version": ""
},
{
"source": {
"git": {
"remote": "https://github.com/parca-dev/parca.git",
"subdir": "deploy/lib/parca"
}
},
"version": "main"
}
],
"legacyImports": true
Expand Down
10 changes: 10 additions & 0 deletions deploy/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"version": 1,
"dependencies": [
{
"source": {
"git": {
"remote": "https://github.com/parca-dev/parca.git",
"subdir": "deploy/lib/parca"
}
},
"version": "7dc4a2456d95b124459fbc7661c9d9b9099f126d",
"sum": "pg6sezCvcHFY2A3OE5Ijs8AsRWw27ENvxtEdzw91JrA="
},
{
"source": {
"local": {
Expand Down
4 changes: 4 additions & 0 deletions deploy/tilt/0namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: parca
24 changes: 24 additions & 0 deletions deploy/tilt/parca-agent-clusterRole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
18 changes: 18 additions & 0 deletions deploy/tilt/parca-agent-clusterRoleBinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: parca-agent
subjects:
- kind: ServiceAccount
name: parca-agent
namespace: parca
90 changes: 90 additions & 0 deletions deploy/tilt/parca-agent-daemonSet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
spec:
selector:
matchLabels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
template:
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
spec:
containers:
- args:
- /bin/parca-agent
- --log-level=debug
- --node=$(NODE_NAME)
- --kubernetes
- --store-address=parca.parca.svc.cluster.local:7070
- --insecure
- --insecure-skip-verify
- --temp-dir=tmp
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: parca.io/parca/parca-agent:dev
name: parca-agent
ports:
- containerPort: 7071
hostPort: 7071
name: http
resources: {}
securityContext:
privileged: true
readOnlyRootFilesystem: true
volumeMounts:
- mountPath: /tmp
name: tmp
- mountPath: /run
name: run
- mountPath: /lib/modules
name: modules
- mountPath: /sys/kernel/debug
name: debugfs
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /sys/fs/bpf
name: bpffs
hostPID: true
nodeSelector:
kubernetes.io/arch: amd64
kubernetes.io/os: linux
serviceAccountName: parca-agent
tolerations:
- effect: NoSchedule
operator: Exists
- effect: NoExecute
operator: Exists
volumes:
- emptyDir: {}
name: tmp
- hostPath:
path: /run
name: run
- hostPath:
path: /sys/fs/cgroup
name: cgroup
- hostPath:
path: /lib/modules
name: modules
- hostPath:
path: /sys/fs/bpf
name: bpffs
- hostPath:
path: /sys/kernel/debug
name: debugfs
41 changes: 41 additions & 0 deletions deploy/tilt/parca-agent-podSecurityPolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
spec:
allowPrivilegeEscalation: true
allowedCapabilities:
- '*'
allowedHostPaths:
- pathPrefix: /sys
- pathPrefix: /lib/modules
fsGroup:
rule: RunAsAny
hostIPC: true
hostNetwork: true
hostPID: true
hostPorts:
- max: 7071
min: 7071
privileged: true
readOnlyRootFilesystem: true
runAsUser:
rule: RunAsAny
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- configMap
- emptyDir
- projected
- secret
- downwardAPI
- persistentVolumeClaim
- hostPath
19 changes: 19 additions & 0 deletions deploy/tilt/parca-agent-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
rules:
- apiGroups:
- policy
resourceNames:
- parca-agent
resources:
- podsecuritypolicies
verbs:
- use
17 changes: 17 additions & 0 deletions deploy/tilt/parca-agent-roleBinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: parca-agent
subjects:
- kind: ServiceAccount
name: parca-agent
10 changes: 10 additions & 0 deletions deploy/tilt/parca-agent-serviceAccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/component: observability
app.kubernetes.io/instance: parca-agent
app.kubernetes.io/name: parca-agent
app.kubernetes.io/version: dev
name: parca-agent
namespace: parca
16 changes: 16 additions & 0 deletions deploy/tilt/parca-server-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
data:
parca.yaml: |-
"debug_info":
"bucket":
"config":
"directory": "./tmp"
"type": "FILESYSTEM"
"cache":
"config":
"directory": "./tmp"
"type": "FILESYSTEM"
kind: ConfigMap
metadata:
name: parca-config
namespace: parca
Loading

0 comments on commit 474ed1c

Please sign in to comment.