-
Notifications
You must be signed in to change notification settings - Fork 69
/
spec.go
113 lines (97 loc) · 4.3 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Copyright 2019 PlanetScale Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package vttablet
import (
"fmt"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
corev1 "k8s.io/api/core/v1"
planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
)
// Spec specifies all the internal parameters needed to deploy a vttablet instance.
type Spec struct {
Alias topodatapb.TabletAlias
AliasStr string
Type planetscalev2.VitessTabletPoolType
Zone string
Labels map[string]string
Images planetscalev2.VitessKeyspaceImages
ImagePullPolicies planetscalev2.VitessImagePullPolicies
ImagePullSecrets []corev1.LocalObjectReference
Index int32
KeyRange planetscalev2.VitessKeyRange
KeyspaceName string
DatabaseName string
Vttablet *planetscalev2.VttabletSpec
Mysqld *planetscalev2.MysqldSpec
MysqldExporter *planetscalev2.MysqldExporterSpec
ExternalDatastore *planetscalev2.ExternalDatastore
DataVolumePVCSpec *corev1.PersistentVolumeClaimSpec
DataVolumePVCName string
GlobalLockserver planetscalev2.VitessLockserverParams
DatabaseInitScriptSecret planetscalev2.SecretSource
Annotations map[string]string
ExtraLabels map[string]string
BackupLocation *planetscalev2.VitessBackupLocation
BackupEngine planetscalev2.VitessBackupEngine
Affinity *corev1.Affinity
ExtraEnv []corev1.EnvVar
ExtraVolumes []corev1.Volume
ExtraVolumeMounts []corev1.VolumeMount
InitContainers []corev1.Container
SidecarContainers []corev1.Container
Tolerations []corev1.Toleration
TopologySpreadConstraints []corev1.TopologySpreadConstraint
}
// localDatabaseName returns the MySQL database name for a tablet Spec in the case of locally managed MySQL.
func (spec *Spec) localDatabaseName() string {
if spec.DatabaseName != "" {
return spec.DatabaseName
}
return "vt_" + spec.KeyspaceName
}
// shardLabels returns only the labels needed to select Pods in the same shard.
func (spec *Spec) shardLabels() map[string]string {
return map[string]string{
planetscalev2.ComponentLabel: spec.Labels[planetscalev2.ComponentLabel],
planetscalev2.ClusterLabel: spec.Labels[planetscalev2.ClusterLabel],
planetscalev2.KeyspaceLabel: spec.Labels[planetscalev2.KeyspaceLabel],
planetscalev2.ShardLabel: spec.Labels[planetscalev2.ShardLabel],
}
}
// poolLabels returns the labels to select Pods in the same tablet pool.
func (spec *Spec) poolLabels() map[string]string {
labels := spec.shardLabels()
labels[planetscalev2.CellLabel] = spec.Labels[planetscalev2.CellLabel]
labels[planetscalev2.TabletTypeLabel] = spec.Labels[planetscalev2.TabletTypeLabel]
return labels
}
// tabletDir returns the path to the tablet dir.
// This path must match what Vitess generates:
// https://github.com/vitessio/vitess/blob/3d3e63d0/go/vt/mysqlctl/mycnf_gen.go#L93
func (spec *Spec) tabletDir() string {
return fmt.Sprintf("%s/vt_%010d", vtDataRootPath, spec.Alias.Uid)
}
// myCnfFilePath returns the path to the my.cnf file for vttablet.
func (spec *Spec) myCnfFilePath() string {
return spec.tabletDir() + "/my.cnf"
}
// dbConfigCharset returns the charset for vttablet's mysql connection pools.
func (spec *Spec) dbConfigCharset() string {
// For flavors that we know are 8.0-compatible, use the new default charset
// that Vitess switched to for 8.0+.
if spec.Images.Mysqld != nil && spec.Images.Mysqld.Mysql80Compatible != "" {
return defaultMySQL80Charset
}
// For all others, use the old default that Vitess had since 5.6 until 8.0.
return defaultMySQL56Charset
}