Skip to content

Commit b0c6bb0

Browse files
committed
Make orchestrator topology passwords static
1 parent 099ca7d commit b0c6bb0

File tree

9 files changed

+198
-232
lines changed

9 files changed

+198
-232
lines changed

cmd/mysql-helper/util/util.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,33 +137,33 @@ func getEnvValue(key string) string {
137137
}
138138

139139
// GetReplUser returns the replication user name from env variable
140-
// TITANIUM_REPLICATION_USER
140+
// MYSQL_REPLICATION_USER
141141
func GetReplUser() string {
142-
return getEnvValue("TITANIUM_REPLICATION_USER")
142+
return getEnvValue("MYSQL_REPLICATION_USER")
143143
}
144144

145145
// GetReplPass returns the replication password from env variable
146-
// TITANIUM_REPLICATION_PASSWORD
146+
// MYSQL_REPLICATION_PASSWORD
147147
func GetReplPass() string {
148-
return getEnvValue("TITANIUM_REPLICATION_PASSWORD")
148+
return getEnvValue("MYSQL_REPLICATION_PASSWORD")
149149
}
150150

151151
// GetExporterUser returns the replication user name from env variable
152-
// TITANIUM_EXPORTER_USER
152+
// MYSQL_METRICS_EXPORTER_USER
153153
func GetExporterUser() string {
154-
return getEnvValue("TITANIUM_EXPORTER_USER")
154+
return getEnvValue("MYSQL_METRICS_EXPORTER_USER")
155155
}
156156

157157
// GetExporterPass returns the replication password from env variable
158-
// TITANIUM_EXPORTER_PASSWORD
158+
// MYSQL_METRICS_EXPORTER_PASSWORD
159159
func GetExporterPass() string {
160-
return getEnvValue("TITANIUM_EXPORTER_PASSWORD")
160+
return getEnvValue("MYSQL_METRICS_EXPORTER_PASSWORD")
161161
}
162162

163163
// GetInitBucket returns the bucket uri from env variable
164-
// TITANIUM_INIT_BUCKET_URI
164+
// INIT_BUCKET_URI
165165
func GetInitBucket() string {
166-
return getEnvValue("TITANIUM_INIT_BUCKET_URI")
166+
return getEnvValue("INIT_BUCKET_URI")
167167
}
168168

169169
// GetMasterHost returns the master host
@@ -187,16 +187,16 @@ func GetMasterHost() string {
187187
return inst.Key.Hostname
188188
}
189189

190-
// GetOrcTopologyUser returns the orchestrator topology user. It is readed from
191-
// /var/run/orc-topology/TOPOLOGY_USER
190+
// GetOrcTopologyUser returns the orchestrator topology user from env variable
191+
// MYSQL_ORC_TOPOLOGY_USER
192192
func GetOrcUser() string {
193-
return readFileContent(OrcTopologyDir + "/TOPOLOGY_USER")
193+
return getEnvValue("MYSQL_ORC_TOPOLOGY_USER")
194194
}
195195

196-
// GetOrcTopologyPass returns the orchestrator topology user. It is readed from
197-
// /var/run/orc-topology/TOPOLOGY_PASSWORD
196+
// GetOrcTopologyPass returns the orchestrator topology passowrd from env variable
197+
// MYSQL_ORC_TOPOLOGY_PASSWORD
198198
func GetOrcPass() string {
199-
return readFileContent(OrcTopologyDir + "/TOPOLOGY_PASSWORD")
199+
return getEnvValue("MYSQL_ORC_TOPOLOGY_PASSWORD")
200200
}
201201

202202
func readFileContent(fileName string) string {
@@ -259,7 +259,7 @@ func RunQuery(q string) (string, error) {
259259
}
260260

261261
func getOrcUri() string {
262-
return getEnvValue("TITANIUM_ORC_URI")
262+
return getEnvValue("ORCHESTRATOR_URI")
263263
}
264264

265265
// CopyFile the src file to dst. Any existing file will be overwritten and will not

hack/charts/mysql-operator/templates/deployment.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,20 @@ spec:
2323
- name: mysql-operator
2424
image: "{{ .Values.image }}"
2525
imagePullPolicy: {{ .Values.imagePullPolicy }}
26+
env:
27+
- name: ORC_TOPOLOGY_USER
28+
valueFrom:
29+
secretKeyRef:
30+
name: {{ template "mysql-operator.orchestrator.fullname" . }}
31+
key: TOPOLOGY_USER
32+
- name: ORC_TOPOLOGY_PASSWORD
33+
valueFrom:
34+
secretKeyRef:
35+
name: {{ template "mysql-operator.orchestrator.fullname" . }}
36+
key: TOPOLOGY_PASSWORD
2637
args:
2738
- --orchestrator-uri=http://{{ template "mysql-operator.orchestrator.fullname" . }}.{{ .Release.Namespace }}/api
28-
- --orchestrator-secret={{ template "mysql-operator.orchestrator.fullname" . }}
39+
- --leader-election-namespace={{ .Release.Namespace }}
2940
{{- if .Values.helperImage }}
3041
- --helper-image={{ .Values.helperImage }}
3142
{{- end -}}

pkg/apis/mysql/v1alpha1/cluster.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@ func (c *ClusterSpec) GetOrcUri() string {
144144
return opt.OrchestratorUri
145145
}
146146

147-
// GetOrcTopologySecret return the name of the secret that contains the
148-
// credentaials for orc to connect to mysql nodes.
149-
func (c *ClusterSpec) GetOrcTopologySecret() string {
150-
return opt.OrchestratorTopologySecretName
151-
}
152-
153147
// GetMysqlImage returns mysql image, composed from oprions and Spec.MysqlVersion
154148
func (c *ClusterSpec) GetMysqlImage() string {
155149
return opt.MysqlImage + ":" + c.MysqlVersion

pkg/controller/clustercontroller/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (c *Controller) Sync(ctx context.Context, cluster *api.MysqlCluster, ns str
5858
}
5959

6060
// create a cluster factory and sync it.
61-
clusterFactory := mcfactory.New(copyCluster, c.k8client, c.myClient, ns, c.recorder)
61+
clusterFactory := mcfactory.New(copyCluster, opt, c.k8client, c.myClient, ns, c.recorder)
6262
if err := clusterFactory.Sync(ctx); err != nil {
6363
return fmt.Errorf("failed to set-up the cluster: %s", err)
6464
}

pkg/mysqlcluster/cluster.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Interface interface {
4040
// cluster factory
4141
type cFactory struct {
4242
cluster *api.MysqlCluster
43-
opt options.Options
43+
opt *options.Options
4444

4545
namespace string
4646

@@ -52,10 +52,11 @@ type cFactory struct {
5252
}
5353

5454
// New creates a new cluster factory
55-
func New(cluster *api.MysqlCluster, klient kubernetes.Interface,
55+
func New(cluster *api.MysqlCluster, opt *options.Options, klient kubernetes.Interface,
5656
myClient ticlientset.Interface, ns string, rec record.EventRecorder) Interface {
5757
return &cFactory{
5858
cluster: cluster,
59+
opt: opt,
5960
client: klient,
6061
myClient: myClient,
6162
namespace: ns,
@@ -87,19 +88,12 @@ type component struct {
8788
func (f *cFactory) getComponents() []component {
8889
return []component{
8990
component{
90-
alias: "db-secret",
91-
name: fmt.Sprintf("db-credentials(%s)", f.cluster.Spec.SecretName),
92-
syncFn: f.syncDbCredentialsSecret,
91+
alias: "cluster-secret",
92+
name: f.cluster.Spec.SecretName,
93+
syncFn: f.syncClusterSecret,
9394
reasonFailed: api.EventReasonDbSecretFailed,
9495
erUpdated: api.EventReasonDbSecretUpdated,
9596
},
96-
component{
97-
alias: "env-secret",
98-
name: f.cluster.GetNameForResource(api.EnvSecret),
99-
syncFn: f.syncEnvSecret,
100-
reasonFailed: api.EventReasonEnvSecretFailed,
101-
erUpdated: api.EventReasonEnvSecretUpdated,
102-
},
10397
component{
10498
alias: "config-map",
10599
name: f.cluster.GetNameForResource(api.ConfigMap),
@@ -135,12 +129,13 @@ func (f *cFactory) Sync(ctx context.Context) error {
135129
for _, comp := range f.getComponents() {
136130
state, err := comp.syncFn()
137131
if err != nil {
138-
glog.V(2).Infof("[%s]: %s ... (%s)", comp.alias, comp.name, state)
139-
err = fmt.Errorf("%s faild to sync with err: %s", comp.name, err)
132+
glog.Warningf("[%s]: failed syncing %s: ", comp.alias, comp.name, err.Error())
133+
err = fmt.Errorf("%s sync failed: %s", comp.name, err)
140134
f.rec.Event(f.cluster, api.EventWarning, comp.reasonFailed, err.Error())
141135
return err
136+
} else {
137+
glog.V(2).Infof("[%s]: %s ... (%s)", comp.alias, comp.name, state)
142138
}
143-
glog.V(2).Infof("[%s]: %s ... (%s)", comp.alias, comp.name, state)
144139
switch state {
145140
case statusCreated, statusUpdated:
146141
f.rec.Event(f.cluster, api.EventNormal, comp.erUpdated, "")
@@ -154,7 +149,7 @@ func (f *cFactory) Sync(ctx context.Context) error {
154149
for i := 0; i < int(f.cluster.Status.ReadyNodes); i++ {
155150
host := f.getHostForReplica(i)
156151
if err := client.Discover(host, MysqlPort); err != nil {
157-
glog.Infof("Failed to register %s with orchestrator: %s", host, err.Error())
152+
glog.Warningf("Failed to register %s with orchestrator: %s", host, err.Error())
158153
}
159154
}
160155
}
Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,11 @@ import (
2323
core "k8s.io/api/core/v1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/util/runtime"
26-
)
2726

28-
type dbCreds struct {
29-
User string
30-
Password string
31-
Database string
32-
RootPassword string
33-
}
27+
"github.com/presslabs/mysql-operator/pkg/util"
28+
)
3429

35-
func (f *cFactory) syncDbCredentialsSecret() (state string, err error) {
30+
func (f *cFactory) syncClusterSecret() (state string, err error) {
3631
state = statusUpToDate
3732
if len(f.cluster.Spec.SecretName) == 0 {
3833
err = fmt.Errorf("the Spec.SecretName is empty")
@@ -51,32 +46,25 @@ func (f *cFactory) syncDbCredentialsSecret() (state string, err error) {
5146

5247
_, act, err := kcore.PatchSecret(f.client, secret,
5348
func(in *core.Secret) *core.Secret {
54-
var creds dbCreds
5549
if _, ok := in.Data["ROOT_PASSWORD"]; !ok {
5650
runtime.HandleError(fmt.Errorf("ROOT_PASSWORD not set in secret: %s", in.Name))
5751
return in
5852
}
5953

60-
creds.RootPassword = string(in.Data["ROOT_PASSWORD"])
61-
creds.User = "root"
62-
creds.Password = creds.RootPassword
63-
creds.Database = ""
64-
65-
u, oku := in.Data["USER"]
66-
p, okp := in.Data["PASSWORD"]
67-
if oku && okp {
68-
creds.User = string(u)
69-
creds.Password = string(p)
54+
if len(in.Data["REPLICATION_USER"]) == 0 {
55+
in.Data["REPLICATION_USER"] = []byte("repl_" + util.RandStringUser(5))
7056
}
71-
if d, ok := in.Data["DATABASE"]; ok {
72-
creds.Database = string(d)
57+
if len(in.Data["REPLICATION_PASSWORD"]) == 0 {
58+
in.Data["REPLICATION_PASSWORD"] = []byte(util.RandomString(rStrLen))
7359
}
74-
75-
in.Data["DB_CONNECT_URL"] = []byte(fmt.Sprintf(
76-
"mysql://%s:%s@%s/%s",
77-
creds.User, creds.Password, f.cluster.GetMasterHost(), creds.Database,
78-
))
79-
60+
if len(in.Data["METRICS_EXPORTER_USER"]) == 0 {
61+
in.Data["METRICS_EXPORTER_USER"] = []byte("repl_" + util.RandStringUser(5))
62+
}
63+
if len(in.Data["METRICS_EXPORTER_PASSWORD"]) == 0 {
64+
in.Data["METRICS_EXPORTER_PASSWORD"] = []byte(util.RandomString(rStrLen))
65+
}
66+
in.Data["ORC_TOPOLOGY_USER"] = []byte(f.opt.OrchestratorTopologyUser)
67+
in.Data["ORC_TOPOLOGY_PASSWORD"] = []byte(f.opt.OrchestratorTopologyPassword)
8068
return in
8169
})
8270

pkg/mysqlcluster/secrets.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)