sigs.k8s.io/cluster-api@v1.7.1/util/patch/options.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package patch 18 19 import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 20 21 // Option is some configuration that modifies options for a patch request. 22 type Option interface { 23 // ApplyToHelper applies this configuration to the given Helper options. 24 ApplyToHelper(*HelperOptions) 25 } 26 27 // HelperOptions contains options for patch options. 28 type HelperOptions struct { 29 // IncludeStatusObservedGeneration sets the status.observedGeneration field 30 // on the incoming object to match metadata.generation, only if there is a change. 31 IncludeStatusObservedGeneration bool 32 33 // ForceOverwriteConditions allows the patch helper to overwrite conditions in case of conflicts. 34 // This option should only ever be set in controller managing the object being patched. 35 ForceOverwriteConditions bool 36 37 // OwnedConditions defines condition types owned by the controller. 38 // In case of conflicts for the owned conditions, the patch helper will always use the value provided by the controller. 39 OwnedConditions []clusterv1.ConditionType 40 } 41 42 // WithForceOverwriteConditions allows the patch helper to overwrite conditions in case of conflicts. 43 // This option should only ever be set in controller managing the object being patched. 44 type WithForceOverwriteConditions struct{} 45 46 // ApplyToHelper applies this configuration to the given HelperOptions. 47 func (w WithForceOverwriteConditions) ApplyToHelper(in *HelperOptions) { 48 in.ForceOverwriteConditions = true 49 } 50 51 // WithStatusObservedGeneration sets the status.observedGeneration field 52 // on the incoming object to match metadata.generation, only if there is a change. 53 type WithStatusObservedGeneration struct{} 54 55 // ApplyToHelper applies this configuration to the given HelperOptions. 56 func (w WithStatusObservedGeneration) ApplyToHelper(in *HelperOptions) { 57 in.IncludeStatusObservedGeneration = true 58 } 59 60 // WithOwnedConditions allows to define condition types owned by the controller. 61 // In case of conflicts for the owned conditions, the patch helper will always use the value provided by the controller. 62 type WithOwnedConditions struct { 63 Conditions []clusterv1.ConditionType 64 } 65 66 // ApplyToHelper applies this configuration to the given HelperOptions. 67 func (w WithOwnedConditions) ApplyToHelper(in *HelperOptions) { 68 in.OwnedConditions = w.Conditions 69 }