mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 09:49:13 +00:00
Adds PrependGroupingObject() as apply pre-processor
This commit is contained in:
@@ -6,6 +6,7 @@ package kubectlcobra
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -80,6 +81,7 @@ func updateHelp(names []string, c *cobra.Command) {
|
||||
func NewCmdApply(baseName string, f util.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := apply.NewApplyOptions(ioStreams)
|
||||
so := newStatusOptions(f, ioStreams)
|
||||
o.PreProcessorFn = PrependGroupingObject(o)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "apply (-f FILENAME | -k DIRECTORY)",
|
||||
@@ -118,3 +120,27 @@ func NewCmdApply(baseName string, f util.Factory, ioStreams genericclioptions.IO
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// PrependGroupingObject orders the objects to apply so the "grouping"
|
||||
// object stores the inventory, and it is first to be applied.
|
||||
func PrependGroupingObject(o *apply.ApplyOptions) func() error {
|
||||
return func() error {
|
||||
if o == nil {
|
||||
return fmt.Errorf("ApplyOptions are nil")
|
||||
}
|
||||
infos, err := o.GetObjects()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, exists := findGroupingObject(infos)
|
||||
if exists {
|
||||
if err := addInventoryToGroupingObj(infos); err != nil {
|
||||
return err
|
||||
}
|
||||
if !sortGroupingObject(infos) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user