Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal
paas
drupalSite-operator
Commits
eeafd9a9
Commit
eeafd9a9
authored
Feb 11, 2021
by
Vineet Reddy Rajula
Committed by
Konstantinos Samaras-Tsakiris
Feb 11, 2021
Browse files
Add MySQL config support
parent
7b7a64f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
config/mysql-config.cnf
0 → 100644
View file @
eeafd9a9
[mysqld]
max_allowed_packet=200M
controllers/drupalsite_resources.go
View file @
eeafd9a9
...
...
@@ -128,7 +128,9 @@ func (r *DrupalSiteReconciler) ensureResources(drp *webservicesv1a1.DrupalSite,
if
transientErr
:=
r
.
ensureResourceX
(
ctx
,
drp
,
"svc_mysql"
,
log
);
transientErr
!=
nil
{
return
transientErr
.
Wrap
(
"%v: for Mysql SVC"
)
}
if
transientErr
:=
r
.
ensureResourceX
(
ctx
,
drp
,
"cm_mysql"
,
log
);
transientErr
!=
nil
{
return
transientErr
.
Wrap
(
"%v: for MySQL CM"
)
}
// 3. Serving layer
if
transientErr
:=
r
.
ensureResourceX
(
ctx
,
drp
,
"fpm_cm"
,
log
);
transientErr
!=
nil
{
...
...
@@ -479,15 +481,33 @@ func deploymentConfigForDrupalSiteMySQL(d *webservicesv1a1.DrupalSite) *appsv1.D
},
},
},
VolumeMounts
:
[]
corev1
.
VolumeMount
{{
Name
:
"mysql-persistent-storage"
,
MountPath
:
"/var/lib/mysql"
,
}},
}},
Volumes
:
[]
corev1
.
Volume
{{
Name
:
"mysql-persistent-storage"
,
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{}},
VolumeMounts
:
[]
corev1
.
VolumeMount
{
{
Name
:
"mysql-persistent-storage"
,
MountPath
:
"/var/lib/mysql"
,
},
{
Name
:
"config-volume"
,
MountPath
:
"/etc/mysql/conf.d/mysql-config.cnf"
,
SubPath
:
"mysql-config.cnf"
,
}},
}},
Volumes
:
[]
corev1
.
Volume
{
{
Name
:
"mysql-persistent-storage"
,
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{}},
},
{
Name
:
"config-volume"
,
VolumeSource
:
corev1
.
VolumeSource
{
ConfigMap
:
&
corev1
.
ConfigMapVolumeSource
{
LocalObjectReference
:
corev1
.
LocalObjectReference
{
Name
:
"mysql-cm-"
+
d
.
Name
,
},
},
},
},
},
},
},
},
...
...
@@ -582,13 +602,14 @@ func deploymentConfigForDrupalSite(d *webservicesv1a1.DrupalSite) *appsv1.Deploy
SubPath
:
"www.conf"
,
}},
}},
Volumes
:
[]
corev1
.
Volume
{{
Name
:
"drupal-directory-"
+
d
.
Name
,
VolumeSource
:
corev1
.
VolumeSource
{
PersistentVolumeClaim
:
&
corev1
.
PersistentVolumeClaimVolumeSource
{
ClaimName
:
"drupal-pv-claim-"
+
d
.
Name
,
},
}},
Volumes
:
[]
corev1
.
Volume
{
{
Name
:
"drupal-directory-"
+
d
.
Name
,
VolumeSource
:
corev1
.
VolumeSource
{
PersistentVolumeClaim
:
&
corev1
.
PersistentVolumeClaimVolumeSource
{
ClaimName
:
"drupal-pv-claim-"
+
d
.
Name
,
},
}},
{
Name
:
"config-volume"
,
VolumeSource
:
corev1
.
VolumeSource
{
...
...
@@ -736,7 +757,7 @@ func routeForDrupalSite(d *webservicesv1a1.DrupalSite) *routev1.Route {
Host
:
env
+
d
.
Name
+
"."
+
ClusterName
+
".cern.ch"
,
To
:
routev1
.
RouteTargetReference
{
Kind
:
"Service"
,
Name
:
"drupal-nginx"
,
Name
:
serviceForDrupalSite
(
d
)
.
Name
,
Weight
:
pointer
.
Int32Ptr
(
100
),
},
Port
:
&
routev1
.
RoutePort
{
...
...
@@ -829,7 +850,7 @@ func jobForDrupalSiteDrush(d *webservicesv1a1.DrupalSite) *batchv1.Job {
return
job
}
// configMapForPHPFPM returns a
job object thats runs drush
// configMapForPHPFPM returns a
configMaps object to configure PHP
func
configMapForPHPFPM
(
d
*
webservicesv1a1
.
DrupalSite
,
log
logr
.
Logger
)
*
corev1
.
ConfigMap
{
ls
:=
labelsForDrupalSite
(
d
.
Name
)
ls
[
"app"
]
=
"php"
...
...
@@ -856,6 +877,33 @@ func configMapForPHPFPM(d *webservicesv1a1.DrupalSite, log logr.Logger) *corev1.
return
cm
}
// configMapForMySQL returns a configmap object to configure MySQL
func
configMapForMySQL
(
d
*
webservicesv1a1
.
DrupalSite
,
log
logr
.
Logger
)
*
corev1
.
ConfigMap
{
ls
:=
labelsForDrupalSite
(
d
.
Name
)
ls
[
"app"
]
=
"mysql"
content
,
err
:=
ioutil
.
ReadFile
(
"config/mysql-config.cnf"
)
if
err
!=
nil
{
log
.
Error
(
err
,
fmt
.
Sprintf
(
"read failed"
))
return
nil
}
cm
:=
&
corev1
.
ConfigMap
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"mysql-cm-"
+
d
.
Name
,
Namespace
:
d
.
Namespace
,
},
Data
:
map
[
string
]
string
{
"mysql-config.cnf"
:
string
(
content
),
},
}
// Set DrupalSite instance as the owner and controller
// ctrl.SetControllerReference(d, dep, r.Scheme)
// Add owner reference
addOwnerRefToObject
(
cm
,
asOwner
(
d
))
return
cm
}
// createResource creates a given resource passed as an argument
func
createResource
(
ctx
context
.
Context
,
res
client
.
Object
,
name
string
,
namespace
string
,
r
*
DrupalSiteReconciler
,
log
logr
.
Logger
)
(
transientErr
reconcileError
)
{
deleteRecreate
:=
func
()
error
{
...
...
@@ -889,6 +937,7 @@ func createResource(ctx context.Context, res client.Object, name string, namespa
ensureResourceX ensure the requested resource is created, with the following valid values
- dc_mysql: DeploymentConfig for MySQL
- svc_mysql: Service for MySQL
- cm_mysql: Configmap for MySQL
- pvc: PersistentVolume for the drupalsite
- site_install_job: Kubernetes Job for the drush site-install
- is_base: ImageStream for sitebuilder-base
...
...
@@ -950,6 +999,12 @@ func (r *DrupalSiteReconciler) ensureResourceX(ctx context.Context, d *webservic
return
newApplicationError
(
nil
,
ErrFunctionDomain
)
}
return
createResource
(
ctx
,
res
,
res
.
Name
,
res
.
Namespace
,
r
,
log
)
case
"cm_mysql"
:
res
:=
configMapForMySQL
(
d
,
log
)
if
res
==
nil
{
return
newApplicationError
(
nil
,
ErrFunctionDomain
)
}
return
createResource
(
ctx
,
res
,
res
.
Name
,
res
.
Namespace
,
r
,
log
)
default
:
return
newApplicationError
(
nil
,
ErrFunctionDomain
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment