func()

in pkg/controllers/statefulset_control.go [218:260]


func (ndbSfset *ndbNodeStatefulSetImpl) ReconcileStatefulSet(
	ctx context.Context, sfset *appsv1.StatefulSet, sc *SyncContext) syncResult {

	cs := sc.configSummary

	if workloadHasConfigGeneration(sfset, cs.NdbClusterGeneration) {
		// Check if it is the second iteration of the sync handler. In the first iteration,
		// the --initial flag will be added to the data node pods, and the ConfigMap will
		// be patched to remove the DataNodeInitialRestart field to trigger the second iteration.
		// During this second iteration, the change will be noted by the statefulset, and it will
		// be patched again to remove the --initial flag from the data node pod's command argument.
		if !(ndbSfset.GetTypeName() == constants.NdbNodeTypeNdbmtd &&
			isInitialFlagSet(sfset) &&
			!sc.configSummary.DataNodeInitialRestart) {
			// StatefulSet upto date
			return continueProcessing()
		}
	}

	// StatefulSet has to be patched
	// Patch the Governing Service first
	if err := sc.serviceController.patchService(ctx, sc, ndbSfset.ndbNodeStatefulset); err != nil {
		return errorWhileProcessing(err)
	}

	// Patch the StatefulSet
	nc := sc.ndb
	updatedStatefulSet, err := ndbSfset.ndbNodeStatefulset.NewStatefulSet(cs, nc)
	if err != nil {
		return errorWhileProcessing(err)
	}

	if ndbSfset.GetTypeName() == constants.NdbNodeTypeNdbmtd &&
		*(sfset.Spec.Replicas) < *(updatedStatefulSet.Spec.Replicas) {
		// New data nodes are being added to MySQL Cluster
		// config but do not start the new nodes yet.
		*(updatedStatefulSet.Spec.Replicas) = *(sfset.Spec.Replicas)
		// Set the AddNodeOnlineInProgress Annotation
		updatedStatefulSet.Annotations[AddNodeOnlineInProgress] = "true"
	}

	return ndbSfset.patchStatefulSet(ctx, sfset, updatedStatefulSet)
}