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

debug print patch when statefulset is going to be updated #111

Merged
merged 1 commit into from
Jun 27, 2023
Merged
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
23 changes: 22 additions & 1 deletion controllers/cassandracluster/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package cassandracluster

import (
"bytes"
"context"
"encoding/json"
"fmt"
"math"
"sort"
Expand Down Expand Up @@ -168,13 +170,32 @@ func statefulSetsAreEqual(sts1, sts2 *appsv1.StatefulSet) bool {
sts2.Status.Replicas = sts1.Status.Replicas

if patchResult, err := patch.DefaultPatchMaker.Calculate(sts1, sts2); err != nil || !patchResult.IsEmpty() {
logrus.Debug("Template is different: " + pretty.Compare(sts1.Spec, sts2.Spec))
if logrus.IsLevelEnabled(logrus.DebugLevel) {
logTemplateChange(sts1, sts2, patchResult.Patch)
}
return false
}

return true
}

func logTemplateChange(sts1 *appsv1.StatefulSet, sts2 *appsv1.StatefulSet, patchResult []byte) {
logrus.Debug("Template is different: " + pretty.Compare(sts1.Spec, sts2.Spec))
logrus.Debug("Generated patch is: " + tryJsonPrettyPrint(patchResult))
}

func tryJsonPrettyPrint(patchResult []byte) string {
AKamyshnikova marked this conversation as resolved.
Show resolved Hide resolved
var patchString string
var prettyPatch bytes.Buffer
err := json.Indent(&prettyPatch, patchResult, "", " ")
if err == nil {
patchString = string(prettyPatch.Bytes())
} else { // fallback to non-pretty json
patchString = string(patchResult)
}
return patchString
}

// CreateOrUpdateStatefulSet Create statefulset if not found, or update it
func (rcc *CassandraClusterReconciler) CreateOrUpdateStatefulSet(ctx context.Context, statefulSet *appsv1.StatefulSet,
status *api.CassandraClusterStatus, dcRackName string) (bool, error) {
Expand Down