Demo entry 6759853

zerzer

   

Submitted by anonymous on Sep 03, 2018 at 20:39
Language: Go. Code size: 2.4 kB.

 func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
         // raw only makes sense for a single file resource multiple objects aren't likely to do what you want.
         // the validator enforces this, so
         if len(o.Raw) > 0 {
                 return o.raw(f)
         }

         if o.EditBeforeCreate {
                 return RunEditOnCreate(f, o.PrintFlags, o.RecordFlags, o.IOStreams, cmd, &o.FilenameOptions)
         }
         schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate"))
         if err != nil {
                 return err
         }

         cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
         if err != nil {
                 return err
         }

         r := f.NewBuilder().
                 Unstructured().
                 Schema(schema).
                 ContinueOnError().
                 NamespaceParam(cmdNamespace).DefaultNamespace().
                 FilenameParam(enforceNamespace, &o.FilenameOptions).
                 LabelSelectorParam(o.Selector).
                 Flatten().
                 Do()
         err = r.Err()
         if err != nil {
                 return err
         }

         count := 0
         err = r.Visit(func(info *resource.Info, err error) error {
                 if err != nil {
                         return err
                 }
                 if err := kubectl.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info.Object, cmdutil.InternalVersionJSONEncoder()); err != nil {
                         return cmdutil.AddSourceToErr("creating", info.Source, err)
                 }

                 if err := o.Recorder.Record(info.Object); err != nil {
                         glog.V(4).Infof("error recording current command: %v", err)
                 }

                 if !o.DryRun {
                         if err := createAndRefresh(info); err != nil {
                                 return cmdutil.AddSourceToErr("creating", info.Source, err)
                         }
                 }

                 count++

                 return o.PrintObj(info.Object)
         })
         if err != nil {
                 return err
         }
         if count == 0 {
                 return fmt.Errorf("no objects passed to create")
         }
         return nil
 }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).