Skip to content

Commit

Permalink
feat(installer): install influxdb chart (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-chen committed Apr 22, 2022
1 parent 0e2fba7 commit 5d961f5
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/tke-installer/app/installer/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ func (t *TKE) installPlatformApp(ctx context.Context, platformApp *types.Platfor
}
return err
}
t.log.Infof("End install platform app %s in %s namespace", platformApp.HelmInstallOptions.ReleaseName, platformApp.HelmInstallOptions.Namespace)
}
if platformApp.ConditionFunc != nil {
err := wait.PollImmediate(5*time.Second, 10*time.Minute, platformApp.ConditionFunc)
if err != nil {
return err
}
}
t.log.Infof("End install platform app %s in %s namespace", platformApp.HelmInstallOptions.ReleaseName, platformApp.HelmInstallOptions.Namespace)
return nil
}
79 changes: 61 additions & 18 deletions cmd/tke-installer/app/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ func (t *TKE) initSteps() {
t.Para.Config.Monitor.InfluxDBMonitor.LocalInfluxDBMonitor != nil {
t.steps = append(t.steps, []types.Handler{
{
Name: "Install InfluxDB",
Func: t.installInfluxDB,
Name: "Install InfluxDB chart",
Func: t.installInfluxDBChart,
},
}...)
}
Expand Down Expand Up @@ -1886,28 +1886,71 @@ func (t *TKE) installTKEBusinessController(ctx context.Context) error {
})
}

func (t *TKE) installInfluxDB(ctx context.Context) error {
func (t *TKE) installInfluxDBChart(ctx context.Context) error {

node, err := apiclient.GetNodeByMachineIP(ctx, t.globalClient, t.servers[0])
options, err := t.getInfluxDBOptions(ctx)
if err != nil {
return err
return fmt.Errorf("get influxdb options failed: %v", err)
}

err = apiclient.CreateResourceWithDir(ctx, t.globalClient, "manifests/influxdb/*.yaml",
map[string]interface{}{
"Image": images.Get().InfluxDB.FullName(),
"NodeName": node.Name,
})
if err != nil {
return err
influxDB := &types.PlatformApp{
HelmInstallOptions: &helmaction.InstallOptions{
Namespace: t.namespace,
ReleaseName: "influxdb",
Values: options,
DependencyUpdate: false,
ChartPathOptions: helmaction.ChartPathOptions{},
},
LocalChartPath: constants.ChartDirName + "influxdb/",
Enable: true,
ConditionFunc: func() (bool, error) {
ok, err := apiclient.CheckStatefulSet(ctx, t.globalClient, t.namespace, "influxdb")
if err != nil || !ok {
return false, nil
}
return ok, nil
},
}
return wait.PollImmediate(5*time.Second, 10*time.Minute, func() (bool, error) {
ok, err := apiclient.CheckStatefulSet(ctx, t.globalClient, t.namespace, "influxdb")
if err != nil || !ok {
return false, nil
return t.installPlatformApp(ctx, influxDB)
}

func (t *TKE) getInfluxDBOptions(ctx context.Context) (map[string]interface{}, error) {

options := map[string]interface{}{
"image": images.Get().InfluxDB.FullName(),
}

useCephRbd, useNFS := false, false
for _, platformApp := range t.Para.Config.PlatformApps {
if !platformApp.Enable || !platformApp.Installed {
continue
}
return ok, nil
})
if strings.EqualFold(platformApp.HelmInstallOptions.ReleaseName, constants.CephRBDChartReleaseName) {
useCephRbd = true
options["cephRbd"] = true
options["cephRbdPVCName"] = "ceph-rbd-influxdb-pvc"
options["cephRbdStorageClassName"] = constants.CephRBDStorageClassName
break
}
if strings.EqualFold(platformApp.HelmInstallOptions.ReleaseName, constants.NFSChartReleaseName) {
useNFS = true
options["nfs"] = true
options["nfsPVCName"] = "nfs-influxdb-pvc"
options["nfsStorageClassName"] = constants.NFSStorageClassName
break
}
}

if !(useCephRbd || useNFS) {
options["baremetalStorage"] = true
node, err := apiclient.GetNodeByMachineIP(ctx, t.globalClient, t.servers[0])
if err != nil {
return nil, err
}
options["nodeName"] = node.Name
}

return options, nil
}

func (t *TKE) installThanos(ctx context.Context) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: influxdb
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "influxdb.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "influxdb.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "influxdb.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "influxdb.labels" -}}
helm.sh/chart: {{ include "influxdb.chart" . }}
{{ include "influxdb.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "influxdb.selectorLabels" -}}
app.kubernetes.io/name: {{ include "influxdb.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "influxdb.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "influxdb.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: influxdb
namespace: tke
labels:
app: influxdb
spec:
replicas: 1
serviceName: influxdb
selector:
matchLabels:
app: influxdb
template:
metadata:
labels:
app: influxdb
spec:
containers:
- name: influxdb
image: {{ .Values.image }}
livenessProbe:
tcpSocket:
port: 8086
initialDelaySeconds: 1
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 8086
initialDelaySeconds: 1
periodSeconds: 10
volumeMounts:
- name: data
mountPath: /var/lib/influxdb
subPath:
{{- if .Values.baremetalStorage }}
nodeName: {{ .Values.nodeName }}
{{- end }}
hostNetwork: true
volumes:
- name: data
{{- if .Values.baremetalStorage }}
hostPath:
path: /var/lib/influxdb
type: DirectoryOrCreate
{{- end }}
{{- if .Values.cephRbd }}
persistentVolumeClaim:
claimName: {{ .Values.cephRbdPVCName }}
{{- end }}
{{- if .Values.nfs }}
persistentVolumeClaim:
claimName: {{ .Values.nfsPVCName }}
{{- end }}
{{- if .Values.cephRbd }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.cephRbdPVCName }}
namespace: tke
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 40Gi
storageClassName: {{ .Values.cephRbdStorageClassName }}
{{- end }}
{{- if .Values.nfs }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.nfsPVCName }}
namespace: tke
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 40Gi
storageClassName: {{ .Values.nfsStorageClassName }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
image:
nodeName:
baremetalStorage:
cephRbd:
cephRbdPVCName:
cephRbdStorageClassName:
nfs:
nfsPVCName:
nfsStorageClassName:
48 changes: 46 additions & 2 deletions cmd/tke-installer/app/installer/manifests/influxdb/influxdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: influxdb
image: {{ .Image }}
image: {{ .image }}
livenessProbe:
tcpSocket:
port: 8086
Expand All @@ -33,10 +33,54 @@ spec:
- name: data
mountPath: /var/lib/influxdb
subPath:
nodeName: {{ .NodeName }}
{{- if .baremetalStorage }}
nodeName: {{ .nodeName }}
{{- end }}
hostNetwork: true
volumes:
- name: data
{{- if .baremetalStorage }}
hostPath:
path: /var/lib/influxdb
type: DirectoryOrCreate
{{- end }}
{{- if .cephRbd }}
persistentVolumeClaim:
claimName: {{ .cephRbdPVCName }}
{{- end }}
{{- if .nfs }}
persistentVolumeClaim:
claimName: {{ .nfsPVCName }}
{{- end }}
{{- if .cephRbd }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .cephRbdPVCName }}
namespace: tke
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 40Gi
storageClassName: {{ .cephRbdStorageClassName }}
{{- end }}
{{- if .nfs }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .nfsPVCName }}
namespace: tke
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 40Gi
storageClassName: {{ .nfsStorageClassName }}
{{- end }}

0 comments on commit 5d961f5

Please sign in to comment.