func()

in internal/controllers/scheduling/op.go [162:208]


func (o *op) BuildPatch() any {
	ops := []jsonPatch{}

	if o.id == uuid.Nil {
		// defer generating the uuid until we know the op is definitely going to be dispatched
		o.id = uuid.Must(uuid.NewRandom())
	}

	// Initialize the status if it's nil (zero value struct on the client == nil on the server side)
	if reflect.DeepEqual(o.Composition.Status, apiv1.CompositionStatus{}) {
		ops = append(ops,
			jsonPatch{Op: "test", Path: "/status", Value: nil},
			jsonPatch{Op: "add", Path: "/status", Value: map[string]any{}})
	}

	// The input watch controller might have concurrently modified the input revisions
	ops = append(ops, jsonPatch{Op: "test", Path: "/status/inputRevisions", Value: o.Composition.Status.InputRevisions})

	// Protect against zombie leaders running this controller
	if syn := o.Composition.Status.InFlightSynthesis; syn == nil {
		ops = append(ops, jsonPatch{Op: "test", Path: "/status/inFlightSynthesis", Value: nil})
	} else {
		ops = append(ops,
			jsonPatch{Op: "test", Path: "/status/inFlightSynthesis/uuid", Value: syn.UUID},
			jsonPatch{Op: "test", Path: "/status/inFlightSynthesis/observedCompositionGeneration", Value: syn.ObservedCompositionGeneration},
			jsonPatch{Op: "test", Path: "/status/inFlightSynthesis/synthesized", Value: syn.Synthesized})
	}

	var attempts int
	if syn := o.Composition.Status.InFlightSynthesis; syn != nil && o.Reason == retrySynthesisOp {
		attempts = syn.Attempts
	}

	ops = append(ops, jsonPatch{
		Op:   "replace",
		Path: "/status/inFlightSynthesis",
		Value: map[string]any{
			"observedCompositionGeneration": o.Composition.Generation,
			"initialized":                   time.Now().Format(time.RFC3339),
			"uuid":                          o.id.String(),
			"deferred":                      o.Reason.Deferred(),
			"attempts":                      attempts + 1,
		},
	})

	return ops
}