@@ -165,18 +165,29 @@ func buildOrderedVertices(transCtx *transformContext, currentTree *ObjectTree, d
165165 workloadVertices = append (workloadVertices , vertex )
166166 }
167167 }
168+ graphOptions := func (options ObjectOptions ) []model.GraphOption {
169+ opts := []model.GraphOption {
170+ inDataContext4G (),
171+ }
172+ for i := range options .Hooks {
173+ opts = append (opts , model .WithHook (options .Hooks [i ]))
174+ }
175+ return opts
176+ }
168177 createNewObjects := func () {
169178 for name := range createSet {
170- if desiredTree .childrenOptions [name ].SkipToReconcile {
179+ options := desiredTree .childrenOptions [name ]
180+ if options .SkipToReconcile {
171181 continue
172182 }
173- v := model .NewObjectVertex (nil , assign (ctx , newSnapshot [name ]), model .ActionCreatePtr (), inDataContext4G () )
183+ v := model .NewObjectVertex (nil , assign (ctx , newSnapshot [name ]), model .ActionCreatePtr (), graphOptions ( options ) ... )
174184 findAndAppend (v )
175185 }
176186 }
177187 updateObjects := func () {
178188 for name := range updateSet {
179- if desiredTree .childrenOptions [name ].SkipToReconcile {
189+ options := desiredTree .childrenOptions [name ]
190+ if options .SkipToReconcile {
180191 continue
181192 }
182193 oldObj := oldSnapshot [name ]
@@ -190,21 +201,23 @@ func buildOrderedVertices(transCtx *transformContext, currentTree *ObjectTree, d
190201 var v * model.ObjectVertex
191202 subResource := desiredTree .childrenOptions [* name ].SubResource
192203 if subResource != "" {
193- v = model .NewObjectVertex (oldObj , newObj , model .ActionUpdatePtr (), inDataContext4G (), model .WithSubResource (subResource ))
204+ opts := append (graphOptions (options ), model .WithSubResource (subResource ))
205+ v = model .NewObjectVertex (oldObj , newObj , model .ActionUpdatePtr (), opts ... )
194206 } else {
195- v = model .NewObjectVertex (oldObj , newObj , model .ActionUpdatePtr (), inDataContext4G () )
207+ v = model .NewObjectVertex (oldObj , newObj , model .ActionUpdatePtr (), graphOptions ( options ) ... )
196208 }
197209 findAndAppend (v )
198210 }
199211 }
200212 }
201- deleteOrphanObjects := func () {
213+ deleteObjects := func () {
202214 for name := range deleteSet {
203- if desiredTree .childrenOptions [name ].SkipToReconcile {
215+ options := desiredTree .childrenOptions [name ]
216+ if options .SkipToReconcile {
204217 continue
205218 }
206219 object := oldSnapshot [name ]
207- v := model .NewObjectVertex (nil , object , model .ActionDeletePtr (), inDataContext4G () )
220+ v := model .NewObjectVertex (nil , object , model .ActionDeletePtr (), graphOptions ( options ) ... )
208221 findAndAppend (v )
209222 }
210223 }
@@ -218,7 +231,7 @@ func buildOrderedVertices(transCtx *transformContext, currentTree *ObjectTree, d
218231 // objects to be updated
219232 updateObjects ()
220233 // objects to be deleted
221- deleteOrphanObjects ()
234+ deleteObjects ()
222235 // handle object dependencies
223236 handleDependencies ()
224237 return vertices
@@ -246,6 +259,9 @@ func (b *PlanBuilder) defaultWalkFunc(v graph.Vertex) error {
246259 if vertex .Action == nil {
247260 return errors .New ("vertex action can't be nil" )
248261 }
262+ if err := b .callHooks (vertex ); err != nil {
263+ return fmt .Errorf ("vertex call hooks failed: %v, obj: %s, action: %v" , err , vertex .Obj .GetName (), * vertex .Action )
264+ }
249265 ctx := b .transCtx .ctx
250266 switch * vertex .Action {
251267 case model .CREATE :
@@ -262,6 +278,15 @@ func (b *PlanBuilder) defaultWalkFunc(v graph.Vertex) error {
262278 return nil
263279}
264280
281+ func (b * PlanBuilder ) callHooks (vertex * model.ObjectVertex ) error {
282+ for i := range vertex .Hooks {
283+ if err := vertex.Hooks [i ](vertex .Obj ); err != nil {
284+ return err
285+ }
286+ }
287+ return nil
288+ }
289+
265290func (b * PlanBuilder ) createObject (ctx context.Context , vertex * model.ObjectVertex ) error {
266291 err := b .cli .Create (ctx , vertex .Obj , clientOption (vertex ))
267292 if err != nil && ! apierrors .IsAlreadyExists (err ) {
0 commit comments