1 package patch 2 3 // Option is some configuration that modifies options for a patch request. 4 type Option interface { 5 // ApplyToHelper applies this configuration to the given Helper options. 6 ApplyToHelper(*HelperOptions) 7 } 8 9 // HelperOptions contains options for patch options. 10 type HelperOptions struct { 11 // IncludeStatusObservedGeneration sets the status.observedGeneration field on the incoming object to match 12 // metadata.generation, only if there is a change. 13 IncludeStatusObservedGeneration bool 14 15 // ForceOverwriteConditions allows the patch helper to overwrite conditions in case of conflicts. 16 // This option should only ever be set in controller managing the object being patched. 17 ForceOverwriteConditions bool 18 19 // OwnedConditions defines condition types owned by the controller. 20 // In case of conflicts for the owned conditions, the patch helper will always use the value provided by the 21 // controller. 22 OwnedConditions []string 23 24 // FieldOwner defines the field owner configuration for Kubernetes patch operations. 25 FieldOwner string 26 } 27 28 // WithForceOverwriteConditions allows the patch helper to overwrite conditions in case of conflicts. 29 // This option should only ever be set in controller managing the object being patched. 30 type WithForceOverwriteConditions struct{} 31 32 // ApplyToHelper applies this configuration to the given HelperOptions. 33 func (w WithForceOverwriteConditions) ApplyToHelper(in *HelperOptions) { 34 in.ForceOverwriteConditions = true 35 } 36 37 // WithStatusObservedGeneration sets the status.observedGeneration field on the incoming object to match 38 // metadata.generation, only if there is a change. 39 type WithStatusObservedGeneration struct{} 40 41 // ApplyToHelper applies this configuration to the given HelperOptions. 42 func (w WithStatusObservedGeneration) ApplyToHelper(in *HelperOptions) { 43 in.IncludeStatusObservedGeneration = true 44 } 45 46 // WithOwnedConditions allows to define condition types owned by the controller. 47 // In case of conflicts for the owned conditions, the patch helper will always use the value provided by the controller. 48 type WithOwnedConditions struct { 49 Conditions []string 50 } 51 52 // ApplyToHelper applies this configuration to the given HelperOptions. 53 func (w WithOwnedConditions) ApplyToHelper(in *HelperOptions) { 54 in.OwnedConditions = w.Conditions 55 } 56 57 // WithFieldOwner set the field manager name for the patch operations. 58 type WithFieldOwner string 59 60 // ApplyToHelper applies this configuration to the given HelperOptions. 61 func (w WithFieldOwner) ApplyToHelper(in *HelperOptions) { 62 in.FieldOwner = string(w) 63 } 64