Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logger calls #274

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions controllers/transaction_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ func isJDBCLogStoreInUse(pod *corev1.Pod) (bool, error) {
// to be deleted by statefulset update. This is used for cases when recovery process should be skipped.
func (r *WildFlyServerReconciler) skipRecoveryAndForceScaleDown(w *wildflyv1alpha1.WildFlyServer, totalNumberOfPods int,
numberOfPodsToScaleDown int, podList *corev1.PodList) (mustReconcile int, err error) {
log := r.Log

for scaleDownIndex := 1; scaleDownIndex <= numberOfPodsToScaleDown; scaleDownIndex++ {
scaleDownPodName := podList.Items[totalNumberOfPods-scaleDownIndex].ObjectMeta.Name
Expand All @@ -481,7 +480,7 @@ func (r *WildFlyServerReconciler) skipRecoveryAndForceScaleDown(w *wildflyv1alph
// process update on the WildFlyServer resource
err = resources.UpdateWildFlyServerStatus(w, r.Client)
if err != nil {
log.Error(err, "Error on updating WildFlyServer when skipping recovery scale down")
r.Log.Error(err, "Error on updating WildFlyServer when skipping recovery scale down")
}
return requeueOff, nil
}
22 changes: 10 additions & 12 deletions controllers/wildflyserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (

"k8s.io/client-go/tools/record"
"os"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"strconv"
"strings"
Expand Down Expand Up @@ -305,7 +304,6 @@ func (r *WildFlyServerReconciler) SetupWithManager(mgr ctrl.Manager) error {
// A non-nil error if an error happens while updating/deleting the statefulset.
func (r *WildFlyServerReconciler) checkStatefulSet(wildflyServer *wildflyv1alpha1.WildFlyServer, foundStatefulSet *appsv1.StatefulSet,
podList *corev1.PodList) (mustReconcile int, err error) {
log := log.FromContext(context.TODO())

var update bool
var requeue = requeueOff
Expand All @@ -314,14 +312,14 @@ func (r *WildFlyServerReconciler) checkStatefulSet(wildflyServer *wildflyv1alpha
desiredStatefulSetReplicaSize := wildflyServerSpecSize
// - for scale up
if wildflyServerSpecSize > *foundStatefulSet.Spec.Replicas {
log.Info("Scaling up and updating replica size to "+strconv.Itoa(int(wildflyServerSpecSize)),
r.Log.Info("Scaling up and updating replica size to "+strconv.Itoa(int(wildflyServerSpecSize)),
"StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
foundStatefulSet.Spec.Replicas = &desiredStatefulSetReplicaSize
update = true
}
// - for scale down
if wildflyServerSpecSize < *foundStatefulSet.Spec.Replicas {
log.Info("For statefulset scaling down need to verify if pods were cleaned by recovery",
r.Log.Info("For statefulset scaling down need to verify if pods were cleaned by recovery",
"StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
// Change the number of replicas in statefulset, changing based on the pod state
nameToPodState := make(map[string]string)
Expand All @@ -348,14 +346,14 @@ func (r *WildFlyServerReconciler) checkStatefulSet(wildflyServer *wildflyv1alpha
calculatedStatefulSetReplicaSize := int32(numberOfPods - numberOfPodsToShutdown)
desiredStatefulSetReplicaSize = calculatedStatefulSetReplicaSize
if wildflyServerSpecSize <= calculatedStatefulSetReplicaSize && *foundStatefulSet.Spec.Replicas > calculatedStatefulSetReplicaSize {
log.Info("Scaling down and updating replica size to "+strconv.Itoa(int(calculatedStatefulSetReplicaSize)),
r.Log.Info("Scaling down and updating replica size to "+strconv.Itoa(int(calculatedStatefulSetReplicaSize)),
"StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
foundStatefulSet.Spec.Replicas = &desiredStatefulSetReplicaSize
update = true
}
// There are some unclean pods which can't be scaled down
if wildflyServerSpecSize < calculatedStatefulSetReplicaSize {
log.Info("Statefulset was not scaled to the desired replica size "+strconv.Itoa(int(wildflyServerSpecSize))+
r.Log.Info("Statefulset was not scaled to the desired replica size "+strconv.Itoa(int(wildflyServerSpecSize))+
" (current StatefulSet size: "+strconv.Itoa(int(calculatedStatefulSetReplicaSize))+
"). Transaction recovery scaledown process has not cleaned all pods. Please, check status of the WildflyServer "+wildflyServer.Name,
"StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
Expand Down Expand Up @@ -393,10 +391,10 @@ func (r *WildFlyServerReconciler) checkStatefulSet(wildflyServer *wildflyv1alpha
if delete {
// VolumeClaimTemplates has changed, the statefulset can not be updated and must be deleted
if err = resources.Delete(wildflyServer, r.Client, foundStatefulSet); err != nil {
log.Error(err, "Failed to Delete StatefulSet.", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
r.Log.Error(err, "Failed to Delete StatefulSet.", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
return requeueNow, err
}
log.Info("Deleting StatefulSet that is not up to date with the WildFlyServer StorageSpec", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
r.Log.Info("Deleting StatefulSet that is not up to date with the WildFlyServer StorageSpec", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
return requeueNow, nil
}

Expand All @@ -405,17 +403,17 @@ func (r *WildFlyServerReconciler) checkStatefulSet(wildflyServer *wildflyv1alpha
foundStatefulSet.Spec.Replicas = &desiredStatefulSetReplicaSize
foundStatefulSet.Annotations[resources.MarkerServerGeneration] = strconv.FormatInt(wildflyServer.Generation, 10)
if err = resources.Update(wildflyServer, r.Client, foundStatefulSet); err != nil {
log.Error(err, "Failed to Update StatefulSet.", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
r.Log.Error(err, "Failed to Update StatefulSet.", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
return requeueNow, err
}
log.Info("Updating StatefulSet to be up to date with the WildFlyServer Spec", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
r.Log.Info("Updating StatefulSet to be up to date with the WildFlyServer Spec", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
return requeueNow, nil
}

if update {
log.Info("Updating statefulset", "StatefulSet.Replicas", foundStatefulSet.Spec.Replicas)
r.Log.Info("Updating statefulset", "StatefulSet.Replicas", foundStatefulSet.Spec.Replicas)
if err = resources.Update(wildflyServer, r.Client, foundStatefulSet); err != nil {
log.Error(err, "Failed to update StatefulSet.", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
r.Log.Error(err, "Failed to update StatefulSet.", "StatefulSet.Namespace", foundStatefulSet.Namespace, "StatefulSet.Name", foundStatefulSet.Name)
return requeueNow, err
}
return requeueNow, nil
Expand Down