Skip to content

Commit

Permalink
Update diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Sep 14, 2024
1 parent 06ed371 commit 22ef898
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion controllers/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (r *FunctionReconciler) checkIfStatefulSetNeedUpdate(ctx context.Context, s
if err != nil {
return false, err
}
diff, err := spec.CreateDiff(statefulSet, desiredStatefulSet)
diff, err := spec.CreateDiff(statefulSet.Spec, desiredStatefulSet.Spec)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (r *SinkReconciler) checkIfStatefulSetNeedUpdate(ctx context.Context, state
if err != nil {
return false, err
}
diff, err := spec.CreateDiff(statefulSet, desiredStatefulSet)
diff, err := spec.CreateDiff(statefulSet.Spec, desiredStatefulSet.Spec)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (r *SourceReconciler) checkIfStatefulSetNeedUpdate(ctx context.Context, sta
if err != nil {
return false, err
}
diff, err := spec.CreateDiff(statefulSet, desiredStatefulSet)
diff, err := spec.CreateDiff(statefulSet.Spec, desiredStatefulSet.Spec)
if err != nil {
return false, err
}
Expand Down
16 changes: 9 additions & 7 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/strategicpatch"
Expand Down Expand Up @@ -2377,15 +2376,18 @@ func makeFilebeatContainer(volumeMounts []corev1.VolumeMount, envVar []corev1.En
}
}

func CreateDiff(orj, modified runtime.Object) (string, error) {
orjCopy := orj.DeepCopyObject()
modifiedCopy := modified.DeepCopyObject()

orjData, err := json.Marshal(orjCopy)
func CreateDiff(orj, modified appsv1.StatefulSetSpec) (string, error) {
// remove auto generated fields
for i, i2 := range orj.Template.Spec.Containers {
i2.TerminationMessagePolicy = ""
i2.TerminationMessagePath = ""
orj.Template.Spec.Containers[i] = i2
}
orjData, err := json.Marshal(orj)
if err != nil {
return "", fmt.Errorf("marshal origin %w", err)
}
modifiedData, err := json.Marshal(modifiedCopy)
modifiedData, err := json.Marshal(modified)
if err != nil {
return "", fmt.Errorf("marshal modified %w", err)
}
Expand Down

0 comments on commit 22ef898

Please sign in to comment.