MCPcopy
hub / github.com/kubernetes/kubectl / RunCreate

Method RunCreate

pkg/cmd/create/create.go:225–301  ·  view source on GitHub ↗

RunCreate performs the creation

(f cmdutil.Factory, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

223
224// RunCreate performs the creation
225func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
226 // raw only makes sense for a single file resource multiple objects aren't likely to do what you want.
227 // the validator enforces this, so
228 if len(o.Raw) > 0 {
229 restClient, err := f.RESTClient()
230 if err != nil {
231 return err
232 }
233 return rawhttp.RawPost(restClient, o.IOStreams, o.Raw, o.FilenameOptions.Filenames[0])
234 }
235
236 if o.EditBeforeCreate {
237 return RunEditOnCreate(f, o.PrintFlags, o.RecordFlags, o.IOStreams, cmd, &o.FilenameOptions, o.fieldManager)
238 }
239
240 schema, err := f.Validator(o.ValidationDirective)
241 if err != nil {
242 return err
243 }
244
245 cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
246 if err != nil {
247 return err
248 }
249
250 r := f.NewBuilder().
251 Unstructured().
252 Schema(schema).
253 ContinueOnError().
254 NamespaceParam(cmdNamespace).DefaultNamespace().
255 FilenameParam(enforceNamespace, &o.FilenameOptions).
256 LabelSelectorParam(o.Selector).
257 Flatten().
258 Do()
259 err = r.Err()
260 if err != nil {
261 return err
262 }
263
264 count := 0
265 err = r.Visit(func(info *resource.Info, err error) error {
266 if err != nil {
267 return err
268 }
269 if err := util.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info.Object, scheme.DefaultJSONEncoder()); err != nil {
270 return cmdutil.AddSourceToErr("creating", info.Source, err)
271 }
272
273 if err := o.Recorder.Record(info.Object); err != nil {
274 klog.V(4).Infof("error recording current command: %v", err)
275 }
276
277 if o.DryRunStrategy != cmdutil.DryRunClient {
278 obj, err := resource.
279 NewHelper(info.Client, info.Mapping).
280 DryRun(o.DryRunStrategy == cmdutil.DryRunServer).
281 WithFieldManager(o.fieldManager).
282 WithFieldValidation(o.ValidationDirective).

Callers 1

NewCmdCreateFunction · 0.95

Calls 10

RawPostFunction · 0.92
CreateOrUpdateAnnotationFunction · 0.92
DefaultJSONEncoderFunction · 0.92
RunEditOnCreateFunction · 0.85
RESTClientMethod · 0.65
ValidatorMethod · 0.65
NewBuilderMethod · 0.65
ToRawKubeConfigLoaderMethod · 0.45
VisitMethod · 0.45
PrintObjMethod · 0.45

Tested by

no test coverage detected