Skip to content

Commit 745b7f8

Browse files
nmarukovichhorspooknull
authored
K8SPS-172 add logs to operators (#950)
* K8SPS-172 add logs to operators * fix * change machine-type for GKE cluster * Update pkg/controller/psbackup/controller.go Co-authored-by: Andrii Dema <a.dema@jazzserve.com> --------- Co-authored-by: Viacheslav Sarzhan <slava.sarzhan@percona.com> Co-authored-by: Andrii Dema <a.dema@jazzserve.com>
1 parent 605e6ac commit 745b7f8

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void createCluster(String CLUSTER_SUFFIX) {
1313
gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
1414
gcloud config set project $GCP_PROJECT
1515
gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true
16-
gcloud container clusters create --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.30 --machine-type=n1-standard-4 --preemptible --disk-size 30 --num-nodes=\$NODES_NUM --network=jenkins-vpc --subnetwork=jenkins-${CLUSTER_SUFFIX} --no-enable-autoupgrade --cluster-ipv4-cidr=/21 --labels delete-cluster-after-hours=6 --enable-ip-alias && \
16+
gcloud container clusters create --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.30 --machine-type=c2d-standard-4 --preemptible --disk-size 30 --num-nodes=\$NODES_NUM --network=jenkins-vpc --subnetwork=jenkins-${CLUSTER_SUFFIX} --no-enable-autoupgrade --cluster-ipv4-cidr=/21 --labels delete-cluster-after-hours=6 --enable-ip-alias && \
1717
kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user jenkins@"$GCP_PROJECT".iam.gserviceaccount.com || ret_val=\$?
1818
if [ \${ret_val} -eq 0 ]; then break; fi
1919
ret_num=\$((ret_num + 1))

pkg/controller/ps/controller.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (r *PerconaServerMySQLReconciler) Reconcile(
127127
}
128128

129129
if cr.ObjectMeta.DeletionTimestamp != nil {
130+
log.Info("CR marked for deletion, applying finalizers", "name", cr.Name)
130131
if err := r.applyFinalizers(ctx, cr); err != nil {
131132
return ctrl.Result{}, errors.Wrap(err, "apply finalizers")
132133
}
@@ -231,17 +232,18 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPods(ctx context.Context, cr *
231232
return errors.Wrap(err, "get cluster status")
232233
}
233234

234-
log.Info("Got primary", "primary", clusterStatus.DefaultReplicaSet.Primary)
235+
log.Info("Cluster primary detected", "primary", clusterStatus.DefaultReplicaSet.Primary)
235236

236237
if !strings.HasPrefix(clusterStatus.DefaultReplicaSet.Primary, mysql.PodFQDN(cr, &firstPod)) {
237238
log.Info("Primary is not pod-0", "primary", clusterStatus.DefaultReplicaSet.Primary)
238239

239240
log.Info("Ensuring pod-0 is the primary")
240-
err := mysh.SetPrimaryInstanceWithExec(ctx, cr.InnoDBClusterName(), mysql.PodFQDN(cr, &firstPod))
241+
podFQDN := mysql.PodFQDN(cr, &firstPod)
242+
err := mysh.SetPrimaryInstanceWithExec(ctx, cr.InnoDBClusterName(), podFQDN)
241243
if err != nil {
242244
return errors.Wrap(err, "set primary instance")
243245
}
244-
246+
log.Info("Setting primary instance", "pod", podFQDN)
245247
return psrestore.ErrWaitingTermination
246248
}
247249

@@ -284,15 +286,16 @@ func (r *PerconaServerMySQLReconciler) deleteMySQLPods(ctx context.Context, cr *
284286
}
285287

286288
if sts.Spec.Replicas == nil || *sts.Spec.Replicas != 1 {
289+
log.Info("Downscaling StatefulSet to 1 replica", "sts", sts.Name)
287290
dscaleTo := int32(1)
288291
sts.Spec.Replicas = &dscaleTo
289292
err = r.Client.Update(ctx, sts)
290293
if err != nil {
291294
return errors.Wrap(err, "downscale StatefulSet")
292295
}
293-
log.Info("Statefulset downscaled", "sts", sts)
296+
log.Info("StatefulSet downscaled", "sts", sts.Name)
294297
}
295-
298+
log.Info("MySQL pod deletion finished. Waiting for termination")
296299
return psrestore.ErrWaitingTermination
297300
}
298301

@@ -317,6 +320,7 @@ func (r *PerconaServerMySQLReconciler) deleteCerts(ctx context.Context, cr *apiv
317320
if err != nil {
318321
return errors.Wrapf(err, "delete issuer %s", issuerName)
319322
}
323+
log.Info("Issuer deleted", "name", issuerName)
320324
}
321325

322326
certs := []string{
@@ -338,6 +342,7 @@ func (r *PerconaServerMySQLReconciler) deleteCerts(ctx context.Context, cr *apiv
338342
if err != nil {
339343
return errors.Wrapf(err, "delete certificate %s", certName)
340344
}
345+
log.Info("Certificate deleted", "name", certName)
341346
}
342347

343348
secretNames := []string{
@@ -359,15 +364,15 @@ func (r *PerconaServerMySQLReconciler) deleteCerts(ctx context.Context, cr *apiv
359364
if err != nil {
360365
return errors.Wrapf(err, "delete secret %s", secretName)
361366
}
367+
log.Info("Secret deleted", "name", secretName)
362368
}
363-
369+
log.V(1).Info("Finished deletion of SSL-related resources")
364370
return nil
365371
}
366372

367373
func (r *PerconaServerMySQLReconciler) deleteMySQLPvc(ctx context.Context, cr *apiv1alpha1.PerconaServerMySQL) error {
368374
log := logf.FromContext(ctx)
369-
370-
log.Info(fmt.Sprintf("Applying %s finalizer", naming.FinalizerDeleteMySQLPvc))
375+
log.Info("Starting PVC and secret deletion for MySQL cluster", "cluster", cr.Name, "finilizer", naming.FinalizerDeleteMySQLPvc)
371376

372377
exposer := mysql.Exposer(*cr)
373378

@@ -560,6 +565,7 @@ func (r *PerconaServerMySQLReconciler) reconcileDatabase(ctx context.Context, cr
560565
}
561566

562567
if cr.Spec.UpdateStrategy == apiv1alpha1.SmartUpdateStatefulSetStrategyType {
568+
log.Info("Performing smart update for StatefulSet")
563569
return r.smartUpdate(ctx, sts, cr)
564570
}
565571

@@ -671,10 +677,12 @@ func (r *PerconaServerMySQLReconciler) reconcileMySQLAutoConfig(ctx context.Cont
671677

672678
// for single-node clusters, we need to set read_only=0 if orchestrator is disabled
673679
if setWriteMode {
680+
log.Info("Single-node write mode detected, setting read_only=0")
674681
config = "\nsuper_read_only=0\nread_only=0"
675682
}
676683

677684
if memory != nil {
685+
log.V(1).Info("Generating auto-tune config based on memory", "memory", memory.String())
678686
autotuneParams, err := mysql.GetAutoTuneParams(cr, memory)
679687
if err != nil {
680688
return err
@@ -800,6 +808,7 @@ func (r *PerconaServerMySQLReconciler) reconcileOrchestrator(ctx context.Context
800808
}
801809

802810
func (r *PerconaServerMySQLReconciler) reconcileOrchestratorServices(ctx context.Context, cr *apiv1alpha1.PerconaServerMySQL) error {
811+
log := logf.FromContext(ctx)
803812
if err := k8s.EnsureService(ctx, r.Client, cr, orchestrator.Service(cr), r.Scheme, true); err != nil {
804813
return errors.Wrap(err, "reconcile Service")
805814
}
@@ -808,7 +817,7 @@ func (r *PerconaServerMySQLReconciler) reconcileOrchestratorServices(ctx context
808817
if err := r.reconcileServicePerPod(ctx, cr, &exposer); err != nil {
809818
return errors.Wrap(err, "reconcile service per pod")
810819
}
811-
820+
log.Info("Finished reconciling orchestrator services")
812821
return nil
813822
}
814823

@@ -945,7 +954,7 @@ func (r *PerconaServerMySQLReconciler) reconcileReplication(ctx context.Context,
945954
return errors.Wrap(err, "get cluster primary")
946955
}
947956
if primary.Alias == "" {
948-
log.Info("mysql is not ready, orchestrator cluster primary alias is empty. skip")
957+
log.Info("Mysql is not ready, orchestrator cluster primary alias is empty. skip")
949958
return nil
950959
}
951960

@@ -963,6 +972,7 @@ func (r *PerconaServerMySQLReconciler) reconcileReplication(ctx context.Context,
963972

964973
// In the case of a cluster downscale, we need to forget replicas that are not part of the cluster
965974
if len(clusterInstances) > int(cr.MySQLSpec().Size) {
975+
log.Info("Detected possible downscale, checking for replicas to forget")
966976
mysqlPods, err := k8s.PodsByLabels(ctx, r.Client, mysql.MatchLabels(cr), cr.Namespace)
967977
if err != nil {
968978
return errors.Wrap(err, "get mysql pods")
@@ -1008,7 +1018,7 @@ func (r *PerconaServerMySQLReconciler) reconcileBootstrapStatus(ctx context.Cont
10081018
log := logf.FromContext(ctx)
10091019

10101020
if cr.Status.MySQL.Ready == 0 || cr.Status.MySQL.Ready != cr.Spec.MySQL.Size {
1011-
log.V(1).Info("Waiting for MySQL pods to be ready")
1021+
log.V(1).Info("Waiting for all MySQL pods to be ready", "ready", cr.Status.MySQL.Ready, "expected", cr.Spec.MySQL.Size)
10121022
return nil
10131023
}
10141024

@@ -1380,6 +1390,7 @@ func (r *PerconaServerMySQLReconciler) cleanupOutdated(ctx context.Context, cr *
13801390
}
13811391

13821392
func (r *PerconaServerMySQLReconciler) getPrimaryFromOrchestrator(ctx context.Context, cr *apiv1alpha1.PerconaServerMySQL) (*orchestrator.Instance, error) {
1393+
log := logf.FromContext(ctx)
13831394
pod, err := getReadyOrcPod(ctx, r.Client, cr)
13841395
if err != nil {
13851396
return nil, err
@@ -1391,6 +1402,7 @@ func (r *PerconaServerMySQLReconciler) getPrimaryFromOrchestrator(ctx context.Co
13911402

13921403
if primary.Key.Hostname == "" {
13931404
primary.Key.Hostname = fmt.Sprintf("%s.%s.%s", primary.Alias, mysql.ServiceName(cr), cr.Namespace)
1405+
log.V(1).Info("Primary hostname was empty, constructed FQDN", "hostname", primary.Key.Hostname)
13941406
}
13951407

13961408
return primary, nil

pkg/controller/ps/status.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (r *PerconaServerMySQLReconciler) reconcileCRStatus(ctx context.Context, cr
192192
}
193193

194194
if !loadBalancersReady {
195+
log.Info("Not all load balancers are ready, setting state to initializing")
195196
cr.Status.State = apiv1alpha1.StateInitializing
196197
}
197198

@@ -228,6 +229,7 @@ func (r *PerconaServerMySQLReconciler) reconcileCRStatus(ctx context.Context, cr
228229
func (r *PerconaServerMySQLReconciler) isGRReady(ctx context.Context, cr *apiv1alpha1.PerconaServerMySQL) (bool, error) {
229230
log := logf.FromContext(ctx).WithName("groupReplicationStatus")
230231
if cr.Status.MySQL.Ready != cr.Spec.MySQL.Size {
232+
log.Info("Not all MySQL pods are ready", "ready", cr.Status.MySQL.Ready, "expected", cr.Spec.MySQL.Size)
231233
return false, nil
232234
}
233235

pkg/controller/psbackup/controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (r *PerconaServerMySQLBackupReconciler) Reconcile(ctx context.Context, req
107107
return r.Client.Status().Update(ctx, cr)
108108
})
109109
if err != nil {
110-
log.Error(err, "failed to update status")
110+
log.Error(err, "Failed to update backup status")
111111
}
112112
}()
113113

@@ -214,6 +214,7 @@ func (r *PerconaServerMySQLBackupReconciler) Reconcile(ctx context.Context, req
214214
}
215215

216216
func (r *PerconaServerMySQLBackupReconciler) isBackupJobRunning(ctx context.Context, job *batchv1.Job) (bool, error) {
217+
log := logf.FromContext(ctx)
217218
if len(job.Spec.Template.Spec.Containers) == 0 {
218219
return false, nil
219220
}
@@ -236,6 +237,7 @@ func (r *PerconaServerMySQLBackupReconciler) isBackupJobRunning(ctx context.Cont
236237
}
237238

238239
if cfg == nil || cfg.Destination != destination {
240+
log.Info("Running backup destination does not match expected or config is nil", "expected destination", destination)
239241
return false, nil
240242
}
241243

0 commit comments

Comments
 (0)