Skip to content

Commit 4079a69

Browse files
committed
[seaweedfs] Add Client topology
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 5e8f6e0 commit 4079a69

15 files changed

Lines changed: 263 additions & 22 deletions

‎packages/extra/seaweedfs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ include ../../../scripts/package.mk
44

55
generate:
66
readme-generator-for-helm -v values.yaml -s values.schema.json -r README.md
7-
yq -o json -i '.properties.topology.enum = ["Simple","MultiZone"]' values.schema.json
7+
yq -o json -i '.properties.topology.enum = ["Simple","MultiZone","Client"]' values.schema.json

‎packages/extra/seaweedfs/README.md‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
### Common parameters
66

7-
| Name | Description | Value |
8-
| ------------------- | ------------------------------------------------------------------------------------------------------ | -------- |
9-
| `host` | The hostname used to access the SeaweedFS externally (defaults to 's3' subdomain for the tenant host). | `""` |
10-
| `topology` | The topology of the SeaweedFS cluster. (allowed values: Simple, MultiZone) | `Simple` |
11-
| `replicationFactor` | The number of replicas for each volume in the SeaweedFS cluster. | `2` |
12-
| `replicas` | Persistent Volume size for SeaweedFS | `2` |
13-
| `size` | Persistent Volume size | `10Gi` |
14-
| `storageClass` | StorageClass used to store the data | `""` |
15-
| `zones` | A map of zones for MultiZone topology. Each zone can have its own number of replicas and size. | `{}` |
7+
| Name | Description | Value |
8+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------ | --------------- |
9+
| `host` | The hostname used to access the SeaweedFS externally (defaults to 's3' subdomain for the tenant host). | `""` |
10+
| `topology` | The topology of the SeaweedFS cluster. (allowed values: Simple, MultiZone, Client) | `Simple` |
11+
| `replicationFactor` | The number of replicas for each volume in the SeaweedFS cluster. | `2` |
12+
| `replicas` | Persistent Volume size for SeaweedFS | `2` |
13+
| `size` | Persistent Volume size | `10Gi` |
14+
| `storageClass` | StorageClass used to store the data | `""` |
15+
| `zones` | A map of zones for MultiZone topology. Each zone can have its own number of replicas and size. | `{}` |
16+
| `filer.external` | Enable external access to the SeaweedFS filer from outside the cluster. Use this when `topology` is not set to `Client`. | `false` |
17+
| `remoteEndpoint` | The endpoint of the remote filer GRPC service. Used when `topology` is set to `Client`. | `1.2.3.4:18888` |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ghcr.io/cozystack/cozystack/objectstorage-sidecar
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: "{{ .Release.Name }}-deployed-topology"
5+
data:
6+
topology: {{ quote .Values.topology }}

‎packages/extra/seaweedfs/templates/dashboard-resourcemap.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ kind: Role
33
metadata:
44
name: {{ .Release.Name }}-dashboard-resources
55
rules:
6+
{{- if not (eq .Values.topology "Client") }}
67
- apiGroups:
78
- ""
89
resources:
@@ -27,13 +28,15 @@ rules:
2728
- {{ $.Release.Name }}-volume
2829
- {{ $.Release.Name }}-db
2930
verbs: ["get", "list", "watch"]
31+
{{- end }}
32+
3033
---
3134
kind: RoleBinding
3235
apiVersion: rbac.authorization.k8s.io/v1
3336
metadata:
3437
name: {{ .Release.Name }}-dashboard-resources
3538
subjects:
36-
{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "admin" .Release.Namespace) }}
39+
{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "super-admin" .Release.Namespace) }}
3740
roleRef:
3841
kind: Role
3942
name: {{ .Release.Name }}-dashboard-resources
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if eq .Values.topology "Client" }}
2+
---
3+
kind: BucketClass
4+
apiVersion: objectstorage.k8s.io/v1alpha1
5+
metadata:
6+
name: {{ .Release.Namespace }}
7+
driverName: {{ .Release.Namespace }}.seaweedfs.objectstorage.k8s.io
8+
deletionPolicy: Delete
9+
---
10+
kind: BucketAccessClass
11+
apiVersion: objectstorage.k8s.io/v1alpha1
12+
metadata:
13+
name: {{ .Release.Namespace }}
14+
driverName: {{ .Release.Namespace }}.seaweedfs.objectstorage.k8s.io
15+
authenticationType: KEY
16+
{{- end }}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{{- if eq .Values.topology "Client" }}
2+
---
3+
kind: ClusterRole
4+
apiVersion: rbac.authorization.k8s.io/v1
5+
metadata:
6+
name: {{ .Release.Namespace }}-objectstorage-provisioner
7+
rules:
8+
- apiGroups: ["objectstorage.k8s.io"]
9+
resources:
10+
- "buckets"
11+
- "bucketaccesses"
12+
- "bucketclaims"
13+
- "bucketclasses"
14+
- "bucketclasses/status"
15+
- "bucketaccessclasses"
16+
- "buckets/status"
17+
- "bucketaccesses/status"
18+
- "bucketclaims/status"
19+
- "bucketaccessclasses/status"
20+
verbs:
21+
- "get"
22+
- "list"
23+
- "watch"
24+
- "update"
25+
- "create"
26+
- "delete"
27+
- apiGroups: ["coordination.k8s.io"]
28+
resources: ["leases"]
29+
verbs:
30+
- "get"
31+
- "watch"
32+
- "list"
33+
- "delete"
34+
- "update"
35+
- "create"
36+
- apiGroups: [""]
37+
resources:
38+
- "secrets"
39+
- "events"
40+
verbs:
41+
- "get"
42+
- "list"
43+
- "watch"
44+
- "update"
45+
- "create"
46+
- "delete"
47+
- "patch"
48+
---
49+
kind: ClusterRoleBinding
50+
apiVersion: rbac.authorization.k8s.io/v1
51+
metadata:
52+
name: {{ .Release.Namespace }}-objectstorage-provisioner
53+
subjects:
54+
- kind: ServiceAccount
55+
name: {{ .Release.Name }}-objectstorage-provisioner
56+
namespace: {{ .Release.Namespace }}
57+
roleRef:
58+
kind: ClusterRole
59+
name: {{ .Release.Namespace }}-objectstorage-provisioner
60+
apiGroup: rbac.authorization.k8s.io
61+
{{- end }}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{{- if eq .Values.topology "Client" }}
2+
{{- $myNS := lookup "v1" "Namespace" "" .Release.Namespace }}
3+
{{- $ingress := index $myNS.metadata.annotations "namespace.cozystack.io/ingress" }}
4+
{{- $host := index $myNS.metadata.annotations "namespace.cozystack.io/host" }}
5+
---
6+
apiVersion: apps/v1
7+
kind: Deployment
8+
metadata:
9+
name: {{ $.Release.Name }}-objectstorage-provisioner
10+
namespace: {{ $.Release.Namespace }}
11+
labels:
12+
app.kubernetes.io/component: objectstorage-provisioner
13+
app.kubernetes.io/instance: seaweedfs
14+
app.kubernetes.io/name: {{ $.Release.Name }}
15+
spec:
16+
replicas: 1
17+
selector:
18+
matchLabels:
19+
app.kubernetes.io/component: objectstorage-provisioner
20+
app.kubernetes.io/instance: seaweedfs
21+
app.kubernetes.io/name: {{ $.Release.Name }}
22+
strategy:
23+
rollingUpdate:
24+
maxSurge: 25%
25+
maxUnavailable: 25%
26+
type: RollingUpdate
27+
template:
28+
metadata:
29+
creationTimestamp: null
30+
labels:
31+
policy.cozystack.io/allow-to-apiserver: "true"
32+
app.kubernetes.io/component: objectstorage-provisioner
33+
app.kubernetes.io/instance: seaweedfs
34+
app.kubernetes.io/name: {{ $.Release.Name }}
35+
spec:
36+
containers:
37+
- name: seaweedfs-cosi-driver
38+
image: ghcr.io/seaweedfs/seaweedfs-cosi-driver:v0.1.2
39+
imagePullPolicy: IfNotPresent
40+
env:
41+
- name: DRIVERNAME
42+
value: {{ .Release.Namespace }}.seaweedfs.objectstorage.k8s.io
43+
- name: ENDPOINT
44+
value: https://{{ .Values.host | default (printf "s3.%s" $host) }}
45+
- name: SEAWEEDFS_FILER
46+
value: {{ .Values.remoteEndpoint }}
47+
- name: WEED_GRPC_CLIENT_KEY
48+
value: /usr/local/share/ca-certificates/client/tls.key
49+
- name: WEED_GRPC_CLIENT_CERT
50+
value: /usr/local/share/ca-certificates/client/tls.crt
51+
- name: WEED_GRPC_CA
52+
value: /usr/local/share/ca-certificates/client/ca.crt
53+
resources:
54+
limits:
55+
cpu: 500m
56+
memory: 512Mi
57+
requests:
58+
cpu: 100m
59+
memory: 128Mi
60+
volumeMounts:
61+
- mountPath: /var/lib/cosi
62+
name: socket
63+
- mountPath: /usr/local/share/ca-certificates/client/
64+
name: client-cert
65+
readOnly: true
66+
- name: seaweedfs-cosi-sidecar
67+
image: "{{ $.Files.Get "images/objectstorage-sidecar.tag" | trim }}"
68+
imagePullPolicy: IfNotPresent
69+
args:
70+
- --v=5
71+
env:
72+
- name: POD_NAMESPACE
73+
value: {{ .Release.Namespace }}
74+
volumeMounts:
75+
- mountPath: /var/lib/cosi
76+
name: socket
77+
enableServiceLinks: false
78+
restartPolicy: Always
79+
terminationGracePeriodSeconds: 10
80+
serviceAccountName: {{ .Release.Name }}-objectstorage-provisioner
81+
volumes:
82+
- name: socket
83+
emptyDir: {}
84+
- name: client-cert
85+
secret:
86+
defaultMode: 420
87+
secretName: seaweedfs-client-cert
88+
{{- end }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{- if eq .Values.topology "Client" }}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ .Release.Name }}-objectstorage-provisioner
6+
namespace: {{ .Release.Namespace }}
7+
automountServiceAccountToken: true
8+
{{- end }}

‎packages/extra/seaweedfs/templates/seaweedfs.yaml‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{{- /* Preflight checks for Helm template */ -}}
2-
{{- if not (has .Values.topology (list "Simple" "MultiZone")) }}
3-
{{- fail "Invalid value for .Values.topology. Must be one of 'Simple' or 'MultiZone'." }}
2+
{{- if not (has .Values.topology (list "Simple" "MultiZone" "Client")) }}
3+
{{- fail "Invalid value for .Values.topology. Must be one of 'Simple', 'MultiZone' or 'Client'." }}
4+
{{- end }}
5+
{{- if and (eq .Values.topology "Client") (not .Values.remoteEndpoint) }}
6+
{{- fail "When topology is 'Client', .Values.remoteEndpoint must be set to a valid remote filer GRPC service endpoint." }}
47
{{- end }}
58
{{- if lt (int .Values.replicationFactor) 1 }}
69
{{- fail "Invalid value for .Values.replicationFactor. Must be at least 1." }}
@@ -13,16 +16,24 @@
1316
{{- fail "replicationFactor must be less than or equal to the number of zones defined in .Values.zones." }}
1417
{{- end }}
1518
{{- end }}
16-
{{- if lookup "v1" "PersistentVolumeClaim" "" (printf "%s-data1-seaweedfs-volume-0" .Release.Name) }}
17-
{{- if eq .Values.topology "MultiZone" }}
18-
{{- fail "Not allowed to switch between Simple and MultiZone topologies after the first deployment." }}
19-
{{- end }}
19+
20+
{{- $detectedTopology := "Unknown" }}
21+
{{- $configMap := lookup "v1" "ConfigMap" .Release.Namespace (printf "%s-deployed-topology" .Release.Name) }}
22+
{{- if $configMap }}
23+
{{- $detectedTopology = dig "data" "topology" "Unknown" $configMap }}
2024
{{- else }}
21-
{{- if and (eq .Values.topology "Simple") (.Release.IsUpgrade) }}
22-
{{- fail "Not allowed to switch between Simple and MultiZone topologies after the first deployment." }}
25+
{{- if lookup "v1" "PersistentVolumeClaim" .Release.Namespace (printf "data1-%s-volume-0" .Release.Name) }}
26+
{{- $detectedTopology = "Simple" }}
27+
{{- else if lookup "apps/v1" "StatefulSet" .Release.Namespace (printf "%s-master" .Release.Name) }}
28+
{{- $detectedTopology = "MultiZone" }}
2329
{{- end }}
2430
{{- end }}
2531

32+
{{- if not (has $detectedTopology (list .Values.topology "Unknown")) }}
33+
{{- fail (printf "Not allowed to switch between topologies after the first deployment: %s" $detectedTopology) }}
34+
{{- end }}
35+
36+
{{- if not (eq .Values.topology "Client") }}
2637
{{- $myNS := lookup "v1" "Namespace" "" .Release.Namespace }}
2738
{{- $ingress := index $myNS.metadata.annotations "namespace.cozystack.io/ingress" }}
2839
{{- $host := index $myNS.metadata.annotations "namespace.cozystack.io/host" }}
@@ -198,3 +209,4 @@ spec:
198209
cnpg.io/cluster: seaweedfs-db
199210
cnpg.io/podRole: instance
200211
version: {{ $.Chart.Version }}
212+
{{- end }}

0 commit comments

Comments
 (0)