Skip to content

Commit d69157d

Browse files
authored
feat: enable configurable namespaces, expose more options in helm chart, add stable tag, fix v2 API routing (#36)
* ci: tag stable release * chore: refactor helm chart * feat: add option for tolerations * feat: make namespace configurable * fix: correct syntax issues * fix: address route registration issue * feat: auto-detect pod namespace * refactor: update var name * fix: address if check * tests: add root handler tests * ci: reduce diff coverage target
1 parent b71ac9f commit d69157d

29 files changed

+458
-226
lines changed

.github/.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ coverage:
1111
target: 65%
1212
patch:
1313
default:
14-
target: 65%
14+
target: 55%
1515

1616
ignore:
1717
- tests/**/*

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,33 @@ jobs:
107107
run: |
108108
PEERD_IMAGE_TAG=${{ env.TAG }} make tests-deps-install ci-aks-streaming
109109
110+
tag:
111+
name: Tag Release
112+
runs-on: ubuntu-latest
113+
needs: [publish, ciCtr, ciStreaming]
114+
permissions:
115+
contents: read
116+
packages: write
117+
env:
118+
REGISTRY: ghcr.io
119+
REPO_PREFIX: ${{ format('azure/acr/dev/') }}
120+
SOURCE_TAG: ${{ needs.publish.outputs.git_tag }}
121+
TARGET_TAG: stable
122+
steps:
123+
- name: Login to GitHub Container Registry
124+
uses: docker/login-action@v1
125+
with:
126+
registry: ${{ env.REGISTRY }}
127+
username: ${{ github.actor }}
128+
password: ${{ secrets.GITHUB_TOKEN }}
129+
130+
- name: Pull Tag ${{ env.SOURCE_TAG }}
131+
if: ${{ success() }}
132+
run: |
133+
docker pull ${{ env.REGISTRY }}/${{ env.REPO_PREFIX }}peerd:${{ env.SOURCE_TAG }}
134+
135+
- name: Push Tag ${{ env.TARGET_TAG }}
136+
if: ${{ success() }}
137+
run: |
138+
docker tag ${{ env.REGISTRY }}/${{ env.REPO_PREFIX }}peerd:${{ env.SOURCE_TAG }} ${{ env.REGISTRY }}/${{ env.REPO_PREFIX }}peerd:${{ env.TARGET_TAG }} && \
139+
docker push ${{ env.REGISTRY }}/${{ env.REPO_PREFIX }}peerd:${{ env.TARGET_TAG }}

README.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ in a Kubernetes cluster. The source of the content could be another node in the
1919
This is **work in progress** and not yet production ready. We are actively working on this project and would love to
2020
hear your feedback. Please feel free to open an issue or a pull request.
2121

22+
## Features
23+
24+
* **Peer to Peer File Sharing**: Peerd allows a node to act as a mirror for files obtained from any HTTP upstream source
25+
(such as an [Azure Blob] using a [SAS URL]), and can discover and serve a specified byte range of the file to/from
26+
other nodes in the cluster. Peerd will first attempt to discover and serve this range from its peers. If not found, it
27+
will fallback to download the range from the upstream URL. Peerd caches downloaded ranges as well as optionally, can
28+
prefetch the entire file.
29+
30+
With this facility, `peerd` can be used as the [p2p proxy] for [Overlaybd].
31+
32+
```json
33+
"p2pConfig": {
34+
"enable": true,
35+
"address": "localhost:30000/blobs"
36+
}
37+
```
38+
39+
* **Peer to Peer Container Image Sharing**: Pulling a container image to a node in Kubernetes is often a time consuming
40+
process, especially in scenarios where the registry becomes a bottleneck, such as deploying a large cluster or scaling
41+
out in response to bursty traffic. To increase throughput, nodes in the cluster which already have the image can be
42+
used as an alternate image source. Peerd subscribes to events in the containerd content store, and advertises local
43+
images to peers. When a node needs an image, it can query its peers for the image, and download it from them instead
44+
of the registry. Containerd has a [mirror][containerd hosts] facility that can be used to configure Peerd as the
45+
mirror for container images.
46+
47+
The APIs are described in the [swagger.yaml].
48+
2249
## Quickstart
2350

2451
To see all available commands, run `make help`.
@@ -31,19 +58,17 @@ container images.
3158

3259
```bash
3360
CLUSTER_CONTEXT=<your-cluster-context> && \
34-
TAG=<docker-image-tag> && \
3561
helm --kube-context=$CLUSTER_CONTEXT install --wait peerd ./build/package/peerd-helm \
36-
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:$TAG
62+
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:stable
3763
```
3864

39-
By default, `mcr.microsoft.com` and `ghcr.io` are mirrored, but this is configurable. For example, to mirror `docker.io`
40-
as well, run the following.
65+
By default, some well known registries are mirrored (see [values.yml]), but this is configurable. For example, to mirror
66+
`docker.io`, `mcr.microsoft.com` and `ghcr.io`, run the following.
4167

4268
```bash
4369
CLUSTER_CONTEXT=<your-cluster-context> && \
44-
TAG=<docker-image-tag> && \
4570
helm --kube-context=$CLUSTER_CONTEXT install --wait peerd ./build/package/peerd-helm \
46-
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:$TAG
71+
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:stable
4772
--set peerd.hosts="mcr.microsoft.com ghcr.io docker.io"
4873
```
4974

@@ -63,39 +88,15 @@ kubectl --context=$CLUSTER_CONTEXT -n peerd-ns logs -l app=peerd -f
6388

6489
### Observe Metrics
6590

66-
Peerd exposes metrics on the `/metrics/prometheus` endpoint. Mmetrics are prefixed with `peerd_`. `libp2p` metrics are
91+
Peerd exposes metrics on the `/metrics/prometheus` endpoint. Metrics are prefixed with `peerd_`. `libp2p` metrics are
6792
prefixed with `libp2p_`.
6893

69-
#### Examples on a 5 node AKS cluster, node sizes: `Standard_D2s_v3` and `Standard_D8ds_v5`
94+
#### Example
7095

71-
<img src="./assets/images/peer-metrics.png" alt="peer metrics" width="1000">
72-
73-
## Features
74-
75-
* **Peer to Peer File Sharing**: Peerd allows a node to act as a mirror for files obtained from any HTTP upstream source
76-
(such as an [Azure Blob] using a [SAS URL]), and can discover and serve a specified byte range of the file to/from
77-
other nodes in the cluster. Peerd will first attempt to discover and serve this range from its peers. If not found, it
78-
will fallback to download the range from the upstream URL. Peerd caches downloaded ranges as well as optionally, can
79-
prefetch the entire file.
96+
On a 100 nodes AKS cluster of VM size `Standard_D2s_v3`, sample throughput observed by a single pod is shown below.
8097

81-
With this facility, `peerd` can be used as the [p2p proxy] for [Overlaybd].
8298

83-
```json
84-
"p2pConfig": {
85-
"enable": true,
86-
"address": "localhost:30000/blobs"
87-
}
88-
```
89-
90-
* **Peer to Peer Container Image Sharing**: Pulling a container image to a node in Kubernetes is often a time consuming
91-
process, especially in scenarios where the registry becomes a bottleneck, such as deploying a large cluster or scaling
92-
out in response to bursty traffic. To increase throughput, nodes in the cluster which already have the image can be
93-
used as an alternate image source. Peerd subscribes to events in the containerd content store, and advertises local
94-
images to peers. When a node needs an image, it can query its peers for the image, and download it from them instead
95-
of the registry. Containerd has a [mirror][containerd hosts] facility that can be used to configure Peerd as the
96-
mirror for container images.
97-
98-
The APIs are described in the [swagger.yaml].
99+
<img src="./assets/images/peer-metrics.png" alt="peer metrics" width="1000">
99100

100101
## Build
101102

@@ -155,3 +156,4 @@ integration with [Overlaybd].
155156
[release-tag]: https://img.shields.io/github/v/tag/Azure/peerd?label=Docker%20Image%20Tag
156157
[peerd-pkgs]: https://github.com/Azure/peerd/pkgs/container/acr%2Fdev%2Fpeerd
157158
[build.md]: ./docs/build.md
159+
[values.yml]: ./build/package/peerd-helm/values.yaml

assets/images/peer-metrics.png

-9.36 KB
Loading

build/ci/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ifndef NODEPOOL
5252
$(eval NODEPOOL := $(shell date +"prel%y%m%d"))
5353
endif
5454
ifndef PEERD_IMAGE_TAG
55-
$(eval PEERD_IMAGE_TAG := "dev")
55+
$(eval PEERD_IMAGE_TAG := "stable")
5656
endif
5757
@echo "\033[92mRunning CI NODEPOOL: $(NODEPOOL)\033[0m"
5858
@( PEERD_IMAGE_TAG=$(PEERD_IMAGE_TAG) PEERD_CONFIGURE_MIRRORS=true $(SCRIPTS_DIR)/azure.sh nodepool up -y $(NODEPOOL) )
@@ -66,7 +66,7 @@ ifndef NODEPOOL
6666
$(eval NODEPOOL := $(shell date +"prels%y%m%d"))
6767
endif
6868
ifndef PEERD_IMAGE_TAG
69-
$(eval PEERD_IMAGE_TAG := "dev")
69+
$(eval PEERD_IMAGE_TAG := "stable")
7070
endif
7171
@echo "\033[92mRunning CI NODEPOOL: $(NODEPOOL)\033[0m"
7272
@( PEERD_IMAGE_TAG=$(PEERD_IMAGE_TAG) PEERD_CONFIGURE_MIRRORS=false $(SCRIPTS_DIR)/azure.sh nodepool up -y $(NODEPOOL) )

build/package/peerd-helm/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.0.2-alpha
18+
version: 0.0.3-alpha
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.0.5-alpha"
24+
appVersion: "0.0.6-alpha"

build/package/peerd-helm/templates/_helpers.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ Expand the name of the chart.
66
{{- end }}
77

88
{{- define "peerd.namespace" -}}
9+
{{- if .Values.peerd.namespace.k8s }}
10+
{{- .Values.peerd.namespace.k8s }}
11+
{{- else }}
912
{{ include "peerd.name" . }}-ns
1013
{{- end }}
14+
{{- end }}
1115

1216
{{- define "peerd.serviceAccountName" -}}
1317
{{ include "peerd.name" . }}-sa
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{ if .Values.peerd.metrics.prometheus.aksAutoDiscovery }}
2+
kind: ConfigMap
3+
apiVersion: v1
4+
data:
5+
prometheus-config: |-
6+
global:
7+
scrape_interval: 15s
8+
scrape_configs:
9+
- job_name: peerd
10+
kubernetes_sd_configs:
11+
- role: pod
12+
relabel_configs:
13+
- source_labels: [__meta_kubernetes_pod_label_app]
14+
action: keep
15+
regex: peerd
16+
- source_labels: [__meta_kubernetes_pod_container_port_number]
17+
action: keep
18+
regex: "5004"
19+
metrics_path: /metrics/prometheus
20+
metadata:
21+
name: ama-metrics-prometheus-config
22+
namespace: kube-system
23+
labels:
24+
{{- include "peerd.labels" . | nindent 4 }}
25+
{{ end }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: node-reader-and-event-creator-clusterrole
5+
labels:
6+
{{- include "peerd.labels" . | nindent 4 }}
7+
rules:
8+
- apiGroups: [""]
9+
resources: ["nodes"]
10+
verbs: ["get", "list", "watch"]
11+
- apiGroups: [""]
12+
resources: ["events"]
13+
verbs: ["create", "patch", "update"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: node-reader-and-event-creator-clusterrole-binding
5+
labels:
6+
{{- include "peerd.labels" . | nindent 4 }}
7+
subjects:
8+
- kind: ServiceAccount
9+
name: {{ include "peerd.serviceAccountName" . }}
10+
namespace: {{ include "peerd.namespace" . }}
11+
roleRef:
12+
kind: ClusterRole
13+
name: node-reader-and-event-creator-clusterrole
14+
apiGroup: rbac.authorization.k8s.io
Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
1-
apiVersion: v1
2-
kind: Namespace
3-
metadata:
4-
name: {{ include "peerd.namespace" . }}
5-
labels:
6-
{{- include "peerd.labels" . | nindent 4 }}
7-
---
8-
kind: ConfigMap
9-
apiVersion: v1
10-
data:
11-
prometheus-config: |-
12-
global:
13-
scrape_interval: 15s
14-
scrape_configs:
15-
- job_name: peerd
16-
kubernetes_sd_configs:
17-
- role: pod
18-
relabel_configs:
19-
- source_labels: [__meta_kubernetes_pod_label_app]
20-
action: keep
21-
regex: peerd
22-
- source_labels: [__meta_kubernetes_pod_container_port_number]
23-
action: keep
24-
regex: "5004"
25-
metrics_path: /metrics/prometheus
26-
metadata:
27-
name: ama-metrics-prometheus-config
28-
namespace: kube-system
29-
labels:
30-
{{- include "peerd.labels" . | nindent 4 }}
31-
---
321
apiVersion: apps/v1
332
kind: DaemonSet
343
metadata:
354
name: &name {{ include "peerd.name" . }}
365
namespace: {{ include "peerd.namespace" . }}
376
labels:
387
{{- include "peerd.labels" . | nindent 4 }}
8+
{{- if .Values.peerd.metrics.prometheus.aksAutoDiscovery }}
399
annotations:
4010
prometheus.io/scrape: 'true'
4111
prometheus.io/path: '/metrics/prometheus'
4212
prometheus.io/port: '5004'
13+
{{- end }}
4314
spec:
4415
selector:
4516
matchLabels:
@@ -54,7 +25,7 @@ spec:
5425
- image: "{{ .Values.peerd.image.ref }}"
5526
imagePullPolicy: "{{ .Values.peerd.image.pullPolicy }}"
5627
args:
57-
- "--log-level=debug"
28+
- "--log-level={{ .Values.peerd.logLevel }}"
5829
- "run"
5930
- "--http-addr=0.0.0.0:5000"
6031
- "--add-mirror-configuration={{ .Values.peerd.configureMirrors }}"
@@ -95,35 +66,7 @@ spec:
9566
hostPath:
9667
path: /etc/containerd/certs.d
9768
type: DirectoryOrCreate
98-
---
99-
apiVersion: v1
100-
kind: Service
101-
metadata:
102-
name: &name {{ include "peerd.name" . }}
103-
namespace: {{ include "peerd.namespace" . }}
104-
labels:
105-
{{- include "peerd.labels" . | nindent 4 }}
106-
annotations:
107-
prometheus.io/scrape: 'true'
108-
prometheus.io/path: '/metrics/prometheus'
109-
prometheus.io/port: '30004'
110-
spec:
111-
type: NodePort
112-
selector:
113-
app: *name
114-
ports:
115-
- name: http
116-
protocol: TCP
117-
port: 5000
118-
nodePort: 30000
119-
targetPort: http
120-
- name: https
121-
protocol: TCP
122-
port: 5001
123-
nodePort: 30001
124-
targetPort: https
125-
- name: metrics
126-
protocol: TCP
127-
port: 5004
128-
nodePort: 30004
129-
targetPort: metrics
69+
{{- with .Values.peerd.tolerations }}
70+
tolerations:
71+
{{- toYaml . | nindent 8 }}
72+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
name: {{ include "peerd.name" . }}-manager-role-binding
5+
namespace: {{ include "peerd.namespace" . }}
6+
labels:
7+
{{- include "peerd.labels" . | nindent 4 }}
8+
roleRef:
9+
apiGroup: rbac.authorization.k8s.io
10+
kind: Role
11+
name: {{ include "peerd.name" . }}-manager-role
12+
subjects:
13+
- kind: ServiceAccount
14+
name: {{ include "peerd.serviceAccountName" . }}
15+
namespace: {{ include "peerd.namespace" . }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: {{ include "peerd.name" . }}-manager-role
5+
namespace: {{ include "peerd.namespace" . }}
6+
labels:
7+
{{- include "peerd.labels" . | nindent 4 }}
8+
rules:
9+
- apiGroups: ["coordination.k8s.io"]
10+
resources: ["configmaps"]
11+
verbs: ["get", "watch", "list", "create", "update"]
12+
- apiGroups: ["coordination.k8s.io"]
13+
resources: ["leases"]
14+
verbs: ["get", "list", "watch", "create", "update"]
15+
- apiGroups: [""]
16+
resources: ["pods"]
17+
verbs: ["get", "watch", "list"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: {{ include "peerd.namespace" . }}
5+
labels:
6+
{{- include "peerd.labels" . | nindent 4 }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: {{ include "peerd.serviceAccountName" . }}-secret
5+
namespace: {{ include "peerd.namespace" . }}
6+
labels:
7+
{{- include "peerd.labels" . | nindent 4 }}
8+
annotations:
9+
kubernetes.io/service-account.name: {{ include "peerd.serviceAccountName" . }}
10+
type: kubernetes.io/service-account-token

0 commit comments

Comments
 (0)