@@ -77,6 +77,7 @@ const (
77
77
MaxSafeGRSize = 9
78
78
)
79
79
80
+ // Checks if the provided ClusterType is valid.
80
81
func (t ClusterType ) isValid () bool {
81
82
switch ClusterType (t ) {
82
83
case ClusterTypeGR , ClusterTypeAsync :
@@ -98,10 +99,12 @@ type MySQLSpec struct {
98
99
PodSpec `json:",inline"`
99
100
}
100
101
102
+ // Checks if the MySQL cluster type is asynchronous.
101
103
func (m MySQLSpec ) IsAsync () bool {
102
104
return m .ClusterType == ClusterTypeAsync
103
105
}
104
106
107
+ // Checks if the MySQL cluster type is Group Replication (GR).
105
108
func (m MySQLSpec ) IsGR () bool {
106
109
return m .ClusterType == ClusterTypeGR
107
110
}
@@ -158,6 +161,7 @@ type PodSpec struct {
158
161
ContainerSpec `json:",inline"`
159
162
}
160
163
164
+ // Retrieves the initialization image for the pod.
161
165
func (s * PodSpec ) GetInitImage () string {
162
166
return s .InitImage
163
167
}
@@ -185,6 +189,7 @@ type BackupSpec struct {
185
189
Storages map [string ]* BackupStorageSpec `json:"storages,omitempty"`
186
190
}
187
191
192
+ // Retrieves the initialization image for the backup.
188
193
func (s * BackupSpec ) GetInitImage () string {
189
194
return s .InitImage
190
195
}
@@ -230,11 +235,13 @@ type BackupStorageS3Spec struct {
230
235
// BucketWithPrefix contains a bucket name with or without a prefix in a format <bucket>/<prefix>
231
236
type BucketWithPrefix string
232
237
238
+ // Extracts the bucket name from a combined bucket with prefix string.
233
239
func (b BucketWithPrefix ) Bucket () string {
234
240
bucket , _ , _ := strings .Cut (string (b ), "/" )
235
241
return bucket
236
242
}
237
243
244
+ // Extracts the prefix from a combined bucket with prefix string.
238
245
func (b BucketWithPrefix ) Prefix () string {
239
246
_ , prefix , _ := strings .Cut (string (b ), "/" )
240
247
return prefix
@@ -331,6 +338,7 @@ type ServiceExpose struct {
331
338
ExternalTrafficPolicy corev1.ServiceExternalTrafficPolicyType `json:"externalTrafficPolicy,omitempty"`
332
339
}
333
340
341
+ // Determines if both annotations and labels of the service expose are empty.
334
342
func (e * ServiceExpose ) SaveOldMeta () bool {
335
343
return len (e .Annotations ) == 0 && len (e .Labels ) == 0
336
344
}
@@ -417,18 +425,22 @@ const (
417
425
UserXtraBackup SystemUser = "xtrabackup"
418
426
)
419
427
428
+ // MySQLSpec returns the MySQL specification from the PerconaServerMySQL custom resource.
420
429
func (cr * PerconaServerMySQL ) MySQLSpec () * MySQLSpec {
421
430
return & cr .Spec .MySQL
422
431
}
423
432
433
+ // PMMSpec returns the PMM specification from the PerconaServerMySQL custom resource.
424
434
func (cr * PerconaServerMySQL ) PMMSpec () * PMMSpec {
425
435
return cr .Spec .PMM
426
436
}
427
437
438
+ // OrchestratorSpec returns the Orchestrator specification from the PerconaServerMySQL custom resource.
428
439
func (cr * PerconaServerMySQL ) OrchestratorSpec () * OrchestratorSpec {
429
440
return & cr .Spec .Orchestrator
430
441
}
431
442
443
+ // SetVersion sets the CRVersion to the version value if it's not already set.
432
444
func (cr * PerconaServerMySQL ) SetVersion () {
433
445
if len (cr .Spec .CRVersion ) > 0 {
434
446
return
@@ -437,6 +449,7 @@ func (cr *PerconaServerMySQL) SetVersion() {
437
449
cr .Spec .CRVersion = version .Version
438
450
}
439
451
452
+ // CheckNSetDefaults validates and sets default values for the PerconaServerMySQL custom resource.
440
453
func (cr * PerconaServerMySQL ) CheckNSetDefaults (ctx context.Context , serverVersion * platform.ServerVersion ) error {
441
454
log := logf .FromContext (ctx ).WithName ("CheckNSetDefaults" )
442
455
if len (cr .Spec .MySQL .ClusterType ) == 0 {
@@ -690,6 +703,7 @@ const (
690
703
BinVolumePath = "/opt/percona"
691
704
)
692
705
706
+ // reconcileVol validates and sets default values for a given VolumeSpec, ensuring it is properly defined.
693
707
func reconcileVol (v * VolumeSpec ) (* VolumeSpec , error ) {
694
708
if v == nil || v .EmptyDir == nil && v .HostPath == nil && v .PersistentVolumeClaim == nil {
695
709
return nil , errors .New ("volumeSpec and it's internals should be specified" )
@@ -708,6 +722,7 @@ func reconcileVol(v *VolumeSpec) (*VolumeSpec, error) {
708
722
return v , nil
709
723
}
710
724
725
+ // defaultPVCSpec sets default access mode for a PersistentVolumeClaimSpec if not already defined.
711
726
func defaultPVCSpec (pvc * corev1.PersistentVolumeClaimSpec ) {
712
727
if pvc == nil {
713
728
return
@@ -754,6 +769,7 @@ func (p *PodSpec) reconcileAffinityOpts() {
754
769
}
755
770
}
756
771
772
+ // GetAffinity derives an Affinity configuration based on the provided PodSpec's affinity settings and labels.
757
773
func (p * PodSpec ) GetAffinity (labels map [string ]string ) * corev1.Affinity {
758
774
if p .Affinity == nil {
759
775
return nil
@@ -801,6 +817,7 @@ const (
801
817
ExposedLabel = "percona.com/exposed"
802
818
)
803
819
820
+ // Labels returns a standardized set of labels for the PerconaServerMySQL custom resource.
804
821
func (cr * PerconaServerMySQL ) Labels () map [string ]string {
805
822
return map [string ]string {
806
823
NameLabel : "percona-server" ,
@@ -810,10 +827,13 @@ func (cr *PerconaServerMySQL) Labels() map[string]string {
810
827
}
811
828
}
812
829
830
+ // ClusterHint generates a unique identifier for the PerconaServerMySQL
831
+ // cluster using its name and namespace.
813
832
func (cr * PerconaServerMySQL ) ClusterHint () string {
814
833
return fmt .Sprintf ("%s.%s" , cr .Name , cr .Namespace )
815
834
}
816
835
836
+ // GetClusterNameFromObject retrieves the cluster's name from the given client object's labels.
817
837
func GetClusterNameFromObject (obj client.Object ) (string , error ) {
818
838
labels := obj .GetLabels ()
819
839
instance , ok := labels [InstanceLabel ]
@@ -823,6 +843,7 @@ func GetClusterNameFromObject(obj client.Object) (string, error) {
823
843
return instance , nil
824
844
}
825
845
846
+ // FNVHash computes a hash of the provided byte slice using the FNV-1a algorithm.
826
847
func FNVHash (p []byte ) string {
827
848
hash := fnv .New32 ()
828
849
hash .Write (p )
@@ -844,17 +865,20 @@ func (cr *PerconaServerMySQL) ClusterHash() string {
844
865
return serverIDHash
845
866
}
846
867
868
+ // InternalSecretName generates a name for the internal secret based on the PerconaServerMySQL name.
847
869
func (cr * PerconaServerMySQL ) InternalSecretName () string {
848
870
return "internal-" + cr .Name
849
871
}
850
872
873
+ // PMMEnabled checks if PMM is enabled and if the provided secret contains PMM-specific data.
851
874
func (cr * PerconaServerMySQL ) PMMEnabled (secret * corev1.Secret ) bool {
852
875
if cr .Spec .PMM != nil && cr .Spec .PMM .Enabled && secret != nil && secret .Data != nil {
853
876
return cr .Spec .PMM .HasSecret (secret )
854
877
}
855
878
return false
856
879
}
857
880
881
+ // HasSecret determines if the provided secret contains the necessary PMM server key.
858
882
func (pmm * PMMSpec ) HasSecret (secret * corev1.Secret ) bool {
859
883
if secret .Data != nil {
860
884
v , ok := secret .Data [string (UserPMMServerKey )]
@@ -863,6 +887,7 @@ func (pmm *PMMSpec) HasSecret(secret *corev1.Secret) bool {
863
887
return false
864
888
}
865
889
890
+ // RouterEnabled checks if the router is enabled, considering the MySQL configuration.
866
891
func (cr * PerconaServerMySQL ) RouterEnabled () bool {
867
892
if cr .MySQLSpec ().IsAsync () {
868
893
return false
@@ -871,6 +896,7 @@ func (cr *PerconaServerMySQL) RouterEnabled() bool {
871
896
return cr .Spec .Proxy .Router != nil && cr .Spec .Proxy .Router .Enabled
872
897
}
873
898
899
+ // HAProxyEnabled verifies if HAProxy is enabled based on MySQL configuration and safety settings.
874
900
func (cr * PerconaServerMySQL ) HAProxyEnabled () bool {
875
901
if cr .MySQLSpec ().IsAsync () && ! cr .Spec .AllowUnsafeConfig {
876
902
return true
@@ -879,6 +905,8 @@ func (cr *PerconaServerMySQL) HAProxyEnabled() bool {
879
905
return cr .Spec .Proxy .HAProxy != nil && cr .Spec .Proxy .HAProxy .Enabled
880
906
}
881
907
908
+ // OrchestratorEnabled determines if the orchestrator is enabled,
909
+ // considering the MySQL configuration.
882
910
func (cr * PerconaServerMySQL ) OrchestratorEnabled () bool {
883
911
if cr .MySQLSpec ().IsGR () {
884
912
return false
@@ -893,10 +921,12 @@ func (cr *PerconaServerMySQL) OrchestratorEnabled() bool {
893
921
894
922
var NonAlphaNumeric = regexp .MustCompile ("[^a-zA-Z0-9_]+" )
895
923
924
+ // Generates a cluster name by sanitizing the PerconaServerMySQL name.
896
925
func (cr * PerconaServerMySQL ) InnoDBClusterName () string {
897
926
return NonAlphaNumeric .ReplaceAllString (cr .Name , "" )
898
927
}
899
928
929
+ // Registers PerconaServerMySQL types with the SchemeBuilder.
900
930
func init () {
901
931
SchemeBuilder .Register (& PerconaServerMySQL {}, & PerconaServerMySQLList {})
902
932
}
0 commit comments