Created GetObjects() method for ApplyOptions and integrated into apply
Kubernetes-commit: 02af4c9be20db201f2a2069816e97004a96bf760
This commit is contained in:
parent
395bc6fc90
commit
dd819b3425
|
@ -92,6 +92,16 @@ type ApplyOptions struct {
|
||||||
EnforceNamespace bool
|
EnforceNamespace bool
|
||||||
|
|
||||||
genericclioptions.IOStreams
|
genericclioptions.IOStreams
|
||||||
|
|
||||||
|
// Objects (and some denormalized data) which are to be
|
||||||
|
// applied. The standard way to fill in this structure
|
||||||
|
// is by calling "GetObjects()", which will use the
|
||||||
|
// resource builder if "objectsCached" is false. The other
|
||||||
|
// way to set this field is to use "SetObjects()".
|
||||||
|
// Subsequent calls to "GetObjects()" after setting would
|
||||||
|
// not call the resource builder; only return the set objects.
|
||||||
|
objects []*resource.Info
|
||||||
|
objectsCached bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -146,6 +156,9 @@ func NewApplyOptions(ioStreams genericclioptions.IOStreams) *ApplyOptions {
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
|
||||||
IOStreams: ioStreams,
|
IOStreams: ioStreams,
|
||||||
|
|
||||||
|
objects: []*resource.Info{},
|
||||||
|
objectsCached: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,18 +343,13 @@ func isIncompatibleServerError(err error) bool {
|
||||||
return err.(*errors.StatusError).Status().Code == http.StatusUnsupportedMediaType
|
return err.(*errors.StatusError).Status().Code == http.StatusUnsupportedMediaType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run executes the `apply` command.
|
// GetObjects returns a (possibly cached) version of all the objects to apply
|
||||||
func (o *ApplyOptions) Run() error {
|
// as a slice of pointer to resource.Info. The resource.Info contains the object
|
||||||
var openapiSchema openapi.Resources
|
// and some other denormalized data. This function should not be called until
|
||||||
if o.OpenAPIPatch {
|
// AFTER the "complete" and "validate" methods have been called to ensure that
|
||||||
openapiSchema = o.OpenAPISchema
|
// the ApplyOptions is filled in and valid.
|
||||||
}
|
func (o *ApplyOptions) GetObjects() ([]*resource.Info, error) {
|
||||||
|
if !o.objectsCached {
|
||||||
dryRunVerifier := &DryRunVerifier{
|
|
||||||
Finder: cmdutil.NewCRDFinder(cmdutil.CRDFromDynamic(o.DynamicClient)),
|
|
||||||
OpenAPIGetter: o.DiscoveryClient,
|
|
||||||
}
|
|
||||||
|
|
||||||
// include the uninitialized objects by default if --prune is true
|
// include the uninitialized objects by default if --prune is true
|
||||||
// unless explicitly set --include-uninitialized=false
|
// unless explicitly set --include-uninitialized=false
|
||||||
r := o.Builder.
|
r := o.Builder.
|
||||||
|
@ -354,7 +362,28 @@ func (o *ApplyOptions) Run() error {
|
||||||
Flatten().
|
Flatten().
|
||||||
Do()
|
Do()
|
||||||
if err := r.Err(); err != nil {
|
if err := r.Err(); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
|
}
|
||||||
|
infos, err := r.Infos()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.objects = infos
|
||||||
|
o.objectsCached = true
|
||||||
|
}
|
||||||
|
return o.objects, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes the `apply` command.
|
||||||
|
func (o *ApplyOptions) Run() error {
|
||||||
|
var openapiSchema openapi.Resources
|
||||||
|
if o.OpenAPIPatch {
|
||||||
|
openapiSchema = o.OpenAPISchema
|
||||||
|
}
|
||||||
|
|
||||||
|
dryRunVerifier := &DryRunVerifier{
|
||||||
|
Finder: cmdutil.NewCRDFinder(cmdutil.CRDFromDynamic(o.DynamicClient)),
|
||||||
|
OpenAPIGetter: o.DiscoveryClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -375,11 +404,10 @@ func (o *ApplyOptions) Run() error {
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
infos, err := r.Infos()
|
infos, err := o.GetObjects()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
|
|
||||||
// If server-dry-run is requested but the type doesn't support it, fail right away.
|
// If server-dry-run is requested but the type doesn't support it, fail right away.
|
||||||
|
|
Loading…
Reference in New Issue