in pkg/controllers/statefulset_control.go [161:216]
func (ndbSfset *ndbNodeStatefulSetImpl) patchStatefulSet(ctx context.Context,
existingStatefulSet *appsv1.StatefulSet, updatedStatefulSet *appsv1.StatefulSet) syncResult {
// JSON encode both StatefulSets
existingJSON, err := json.Marshal(existingStatefulSet)
if err != nil {
klog.Errorf("Failed to encode existing StatefulSet: %v", err)
return errorWhileProcessing(err)
}
updatedJSON, err := json.Marshal(updatedStatefulSet)
if err != nil {
klog.Errorf("Failed to encode updated StatefulSet: %v", err)
return errorWhileProcessing(err)
}
// Generate the patch to be applied
patch, err := strategicpatch.CreateTwoWayMergePatch(existingJSON, updatedJSON, appsv1.StatefulSet{})
if err != nil {
klog.Errorf("Failed to generate the patch to be applied: %v", err)
return errorWhileProcessing(err)
}
// klog.Infof("Patching StatefulSets.\nExisting : %v\n. Modified : %v\nPatch : %v", string(existingJSON), string(updatedJSON), string(patch))
// Patch the StatefulSet
sfsetInterface := ndbSfset.statefulSetInterface(existingStatefulSet.Namespace)
updatedStatefulSet, err = sfsetInterface.Patch(
ctx, existingStatefulSet.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
if err != nil {
klog.Errorf("Failed to apply the patch to the StatefulSet %q : %s", getNamespacedName(existingStatefulSet), err)
return errorWhileProcessing(err)
}
// Successfully applied the patch - StatefulSet has been updated.
klog.Infof("StatefulSet %q has been patched successfully", getNamespacedName(updatedStatefulSet))
if updatedStatefulSet.Generation == existingStatefulSet.Generation {
// No changes to StatefulSet spec. Only annotations/labels were updated.
// Continue processing
return continueProcessing()
}
// StatefulSet was patched successfully.
//
// For the management node StatefulSet, the controller will
// handle rolling out the update to all the pods. Reconciliation
// will continue once the update has been rolled out, so finish
// processing.
//
// For the data node StatefulSet, the operator will handle
// rolling out the update over multiple reconciliation loops.
// The controller will update the status of the data node
// StatefulSet and that will immediately trigger the next
// reconciliation loop, so finish processing.
return finishProcessing()
}