Skip to content

Commit ac42609

Browse files
bxy4543claude
andauthored
feat(terminal): migrate from manifests to helm charts (#6644)
Refactor terminal controller deployment to use Helm charts for better manageability, following the pattern established by account controller. Major changes: - Replace manifests with Helm chart structure - Add terminal-controller-entrypoint.sh for automated deployment - Remove kube-rbac-proxy sidecar container - Remove kube-proxy-rbac (metrics-reader and proxy-role) - Metrics now bind to 127.0.0.1:8080 (internal only) - Update values.yaml with full image name format - Namespace created via helm --create-namespace flag - Support resource backup, adopt, and auto-configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 57c02c4 commit ac42609

File tree

16 files changed

+740
-486
lines changed

16 files changed

+740
-486
lines changed
File renamed without changes.

controllers/terminal/deploy/Kubefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ FROM scratch
33
USER 65532:65532
44

55
COPY registry registry
6-
COPY manifests manifests
6+
COPY charts charts
7+
COPY terminal-controller-entrypoint.sh terminal-controller-entrypoint.sh
78

8-
ENV userNamespace="user-system"
9-
ENV cloudDomain="127.0.0.1.nip.io"
10-
ENV cloudPort=""
11-
ENV wildcardCertSecretName="wildcard-cert"
12-
ENV wildcardCertSecretNamespace="sealos-system"
13-
14-
CMD ["kubectl apply -f manifests"]
9+
CMD ["bash terminal-controller-entrypoint.sh"]
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
### How to build image
22

33
```shell
4-
sealos build -t docker.io/labring/sealos-terminal-controller:latest -f Dockerfile .
4+
sealos build -t docker.io/labring/sealos-terminal-controller:latest -f Kubefile .
55
```
66

77
### How to run
88

99
```shell
10-
sealos run docker.io/labring/sealos-terminal-controller:latest
10+
sealos run docker.io/labring/sealos-terminal-controller:latest
1111
```
12+
13+
### Configuration
14+
15+
The terminal controller supports the following environment variables:
16+
17+
- `RELEASE_NAME`: Helm release name (default: `terminal`)
18+
- `RELEASE_NAMESPACE`: Deployment namespace (default: `terminal-system`)
19+
- `CHART_PATH`: Path to helm chart (default: `./charts/terminal-controller`)
20+
- `HELM_OPTS`: Additional helm options
21+
- `SEALOS_CLOUD_DOMAIN`: Cloud domain (auto-detected from sealos-config)
22+
- `SEALOS_CLOUD_PORT`: Cloud port (auto-detected from sealos-config)
23+
- `TERMINAL_BACKUP_ENABLED`: Enable resource backup (default: `true`)
24+
- `TERMINAL_BACKUP_DIR`: Backup directory (default: `/tmp/sealos-backup/terminal-controller`)
25+
26+
### Deployment Structure
27+
28+
This deployment uses Helm charts for better manageability:
29+
30+
- **Chart**: `charts/terminal-controller/`
31+
- **Entrypoint**: `terminal-controller-entrypoint.sh`
32+
- **CRD**: Terminals.terminal.sealos.io
33+
34+
The controller will automatically:
35+
- Create namespace if it doesn't exist (via `--create-namespace`)
36+
- Adopt existing resources for smooth migration
37+
- Backup resources before upgrades
38+
- Configure from sealos-system configmap
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: terminal
3+
description: Helm chart for the sealos terminal controller
4+
type: application
5+
version: 0.1.0
6+
appVersion: "0.1.0"
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.9.0
6+
creationTimestamp: null
7+
name: terminals.terminal.sealos.io
8+
spec:
9+
group: terminal.sealos.io
10+
names:
11+
kind: Terminal
12+
listKind: TerminalList
13+
plural: terminals
14+
singular: terminal
15+
scope: Namespaced
16+
versions:
17+
- additionalPrinterColumns:
18+
- jsonPath: .spec.user
19+
name: User
20+
type: string
21+
- jsonPath: .spec.keepalived
22+
name: Keepalived
23+
type: string
24+
- jsonPath: .status.domain
25+
name: Domain
26+
type: string
27+
- jsonPath: .metadata.annotations.lastUpdateTime
28+
name: LastUpdateTime
29+
priority: 1
30+
type: string
31+
- jsonPath: .metadata.creationTimestamp
32+
name: Age
33+
type: date
34+
name: v1
35+
schema:
36+
openAPIV3Schema:
37+
description: Terminal is the Schema for the terminals API
38+
properties:
39+
apiVersion:
40+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
41+
type: string
42+
kind:
43+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
44+
type: string
45+
metadata:
46+
type: object
47+
spec:
48+
description: TerminalSpec defines the desired state of Terminal
49+
properties:
50+
apiServer:
51+
type: string
52+
ingressType:
53+
default: nginx
54+
enum:
55+
- nginx
56+
type: string
57+
keepalived:
58+
type: string
59+
replicas:
60+
format: int32
61+
type: integer
62+
token:
63+
type: string
64+
ttyImage:
65+
type: string
66+
user:
67+
type: string
68+
required:
69+
- keepalived
70+
- replicas
71+
- token
72+
- ttyImage
73+
- user
74+
type: object
75+
status:
76+
description: TerminalStatus defines the observed state of Terminal
77+
properties:
78+
availableReplicas:
79+
format: int32
80+
type: integer
81+
domain:
82+
type: string
83+
secretHeader:
84+
type: string
85+
serviceName:
86+
type: string
87+
required:
88+
- availableReplicas
89+
- domain
90+
- secretHeader
91+
- serviceName
92+
type: object
93+
type: object
94+
served: true
95+
storage: true
96+
subresources:
97+
status: {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Thank you for installing {{ .Chart.Name }}.
2+
3+
Your release is named {{ .Release.Name }}.
4+
5+
To learn more about the release, try:
6+
7+
$ helm status {{ .Release.Name }}
8+
$ helm get all {{ .Release.Name }}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "terminal.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
*/}}
11+
{{- define "terminal.fullname" -}}
12+
{{- if .Values.fullnameOverride }}
13+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
14+
{{- else }}
15+
{{- $name := default .Chart.Name .Values.nameOverride }}
16+
{{- if contains $name .Release.Name }}
17+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
18+
{{- else }}
19+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
20+
{{- end }}
21+
{{- end }}
22+
{{- end }}
23+
24+
{{/*
25+
Create chart name and version as used by the chart label.
26+
*/}}
27+
{{- define "terminal.chart" -}}
28+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
29+
{{- end }}
30+
31+
{{/*
32+
Common labels
33+
*/}}
34+
{{- define "terminal.labels" -}}
35+
helm.sh/chart: {{ include "terminal.chart" . }}
36+
{{ include "terminal.selectorLabels" . }}
37+
{{- if .Chart.AppVersion }}
38+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
39+
{{- end }}
40+
app.kubernetes.io/managed-by: {{ .Release.Service }}
41+
{{- end }}
42+
43+
{{/*
44+
Selector labels
45+
*/}}
46+
{{- define "terminal.selectorLabels" -}}
47+
app.kubernetes.io/name: {{ include "terminal.name" . }}
48+
app.kubernetes.io/instance: {{ .Release.Name }}
49+
{{- end }}
50+
51+
{{/*
52+
Create the name of the service account to use
53+
*/}}
54+
{{- define "terminal.serviceAccountName" -}}
55+
{{- if .Values.serviceAccount.create }}
56+
{{- default (include "terminal.fullname" .) .Values.serviceAccount.name }}
57+
{{- else }}
58+
{{- default "default" .Values.serviceAccount.name }}
59+
{{- end }}
60+
{{- end }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "terminal.fullname" . }}-manager-config
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
control-plane: controller-manager
8+
{{- include "terminal.labels" . | nindent 4 }}
9+
data:
10+
controller_manager_config.yaml: |
11+
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
12+
kind: ControllerManagerConfig
13+
health:
14+
healthProbeBindAddress: :8081
15+
metrics:
16+
bindAddress: 127.0.0.1:8080
17+
leaderElection:
18+
leaderElect: true
19+
resourceName: 50686b4e.sealos.io
20+
config.yaml: |
21+
global:
22+
cloudDomain: {{ .Values.config.cloudDomain | quote }}
23+
{{- if .Values.config.cloudPort }}
24+
cloudPort: {{ .Values.config.cloudPort | quote }}
25+
{{- end }}
26+
terminalController:
27+
ingressTLSSecretName: {{ .Values.config.ingressTLSSecretName | quote }}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "terminal.fullname" . }}-controller-manager
5+
labels:
6+
control-plane: controller-manager
7+
{{- include "terminal.labels" . | nindent 4 }}
8+
spec:
9+
replicas: {{ .Values.replicaCount }}
10+
selector:
11+
matchLabels:
12+
control-plane: controller-manager
13+
template:
14+
metadata:
15+
annotations:
16+
kubectl.kubernetes.io/default-container: manager
17+
checksum/terminal-manager-config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
18+
{{- with .Values.podAnnotations }}
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
control-plane: controller-manager
23+
{{- include "terminal.labels" . | nindent 8 }}
24+
{{- with .Values.podLabels }}
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
spec:
28+
{{- with .Values.imagePullSecrets }}
29+
imagePullSecrets:
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
serviceAccountName: {{ include "terminal.serviceAccountName" . }}
33+
securityContext:
34+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
35+
containers:
36+
- name: manager
37+
command:
38+
- /manager
39+
args:
40+
- --health-probe-bind-address=:8081
41+
- --metrics-bind-address=127.0.0.1:8080
42+
- --leader-elect
43+
- --config-file-path=/config.yaml
44+
env:
45+
- name: TERMINAL_SYSTEM_NAMESPACE
46+
valueFrom:
47+
fieldRef:
48+
apiVersion: v1
49+
fieldPath: metadata.namespace
50+
image: "{{ .Values.image }}"
51+
imagePullPolicy: {{ .Values.imagePullPolicy }}
52+
livenessProbe:
53+
{{- toYaml .Values.livenessProbe | nindent 12 }}
54+
readinessProbe:
55+
{{- toYaml .Values.readinessProbe | nindent 12 }}
56+
resources:
57+
{{- toYaml .Values.resources | nindent 12 }}
58+
securityContext:
59+
{{- toYaml .Values.securityContext | nindent 12 }}
60+
volumeMounts:
61+
{{- with .Values.volumeMounts }}
62+
{{- toYaml . | nindent 12 }}
63+
{{- end }}
64+
- name: terminal-manager-config
65+
mountPath: /config.yaml
66+
subPath: config.yaml
67+
terminationGracePeriodSeconds: 10
68+
affinity:
69+
{{- if .Values.affinity }}
70+
{{- toYaml .Values.affinity | nindent 8 }}
71+
{{- else }}
72+
podAntiAffinity:
73+
preferredDuringSchedulingIgnoredDuringExecution:
74+
- weight: 100
75+
podAffinityTerm:
76+
labelSelector:
77+
matchExpressions:
78+
- key: control-plane
79+
operator: In
80+
values:
81+
- controller-manager
82+
topologyKey: kubernetes.io/hostname
83+
{{- end }}
84+
{{- with .Values.nodeSelector }}
85+
nodeSelector:
86+
{{- toYaml . | nindent 8 }}
87+
{{- end }}
88+
{{- with .Values.tolerations }}
89+
tolerations:
90+
{{- toYaml . | nindent 8 }}
91+
{{- end }}
92+
volumes:
93+
{{- with .Values.volumes }}
94+
{{- toYaml . | nindent 8 }}
95+
{{- end }}
96+
- name: terminal-manager-config
97+
configMap:
98+
name: {{ include "terminal.fullname" . }}-manager-config

0 commit comments

Comments
 (0)