Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support value transport for local resources, only #332

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,32 @@ func New() *Option {

type Option struct {
ResourcesByValue bool
LocalByValue bool
}

var _ transferhandler.TransferOption = (*Option)(nil)

func (o *Option) AddFlags(fs *pflag.FlagSet) {
fs.BoolVarP(&o.ResourcesByValue, "copy-resources", "V", false, "transfer referenced resources by-value")
fs.BoolVarP(&o.LocalByValue, "copy-local-resources", "L", false, "transfer referenced local resources by-value")
}

func (o *Option) Usage() string {
s := `
It the option <code>--copy-resources</code> is given, all referential
resources will potentially be localized, mapped to component version local
resources in the target repository.
This behaviour can be further influenced by specifying a transfer script
with the <code>script</code> option family.
resources in the target repository. It the option <code>--copy-local-resources</code>
is given, instead, only resources with the relation <code>local</code> will be
transferred. This behaviour can be further influenced by specifying a transfer
script with the <code>script</code> option family.
`
return s
}

func (o *Option) ApplyTransferOption(opts transferhandler.TransferOptions) error {
return standard.ResourcesByValue(o.ResourcesByValue).ApplyTransferOption(opts)
err := standard.ResourcesByValue(o.ResourcesByValue).ApplyTransferOption(opts)
if err == nil {
err = standard.LocalResourcesByValue(o.LocalByValue).ApplyTransferOption(opts)
}
return err
}
26 changes: 24 additions & 2 deletions cmds/ocm/commands/ocmcmds/componentarchive/transfer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/spf13/cobra"

"github.com/open-component-model/ocm/cmds/ocm/commands/common/options/formatoption"
ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/lookupoption"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/overwriteoption"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/rscbyvalueoption"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/srcbyvalueoption"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/names"
"github.com/open-component-model/ocm/cmds/ocm/commands/verbs"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
Expand All @@ -17,6 +22,7 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/comparch"
"github.com/open-component-model/ocm/pkg/contexts/ocm/transfer"
"github.com/open-component-model/ocm/pkg/contexts/ocm/transfer/transferhandler/standard"
)

var (
Expand All @@ -32,7 +38,7 @@ type Command struct {

// NewCommand creates a new transfer command.
func NewCommand(ctx clictx.Context, names ...string) *cobra.Command {
return utils.SetupCommand(&Command{BaseCommand: utils.NewBaseCommand(ctx, formatoption.New())}, utils.Names(Names, names...)...)
return utils.SetupCommand(&Command{BaseCommand: utils.NewBaseCommand(ctx, formatoption.New(), lookupoption.New(), overwriteoption.New(), rscbyvalueoption.New(), srcbyvalueoption.New())}, utils.Names(Names, names...)...)
}

func (o *Command) ForName(name string) *cobra.Command {
Expand Down Expand Up @@ -62,6 +68,13 @@ func (o *Command) Complete(args []string) error {
func (o *Command) Run() error {
session := ocm.NewSession(nil)
defer session.Close()
session.Finalize(o.OCMContext())

err := o.ProcessOnOptions(ocmcommon.CompleteOptionsWithSession(o, session))
if err != nil {
return err
}

source, err := comparch.Open(o.Context.OCMContext(), accessobj.ACC_READONLY, o.Path, 0, o.Context)
if err != nil {
return err
Expand All @@ -74,5 +87,14 @@ func (o *Command) Run() error {
return err
}

return transfer.TransferVersion(common.NewPrinter(o.Context.StdOut()), nil, source, target, nil)
thdlr, err := standard.New(
lookupoption.From(o),
overwriteoption.From(o),
rscbyvalueoption.From(o),
srcbyvalueoption.From(o),
)
if err != nil {
return err
}
return transfer.TransferVersion(common.NewPrinter(o.Context.StdOut()), nil, source, target, thdlr)
}
8 changes: 5 additions & 3 deletions docs/reference/ocm_add_componentversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ocm add componentversions [<options>] [--version <version>] [<ctf archive>] {<co
```
--addenv access environment for templating
-C, --complete include all referenced component version
-L, --copy-local-resources transfer referenced local resources by-value
-V, --copy-resources transfer referenced resources by-value
-c, --create (re)create archive
--dry-run evaluate and print component specifications
Expand Down Expand Up @@ -124,9 +125,10 @@ references.

It the option <code>--copy-resources</code> is given, all referential
resources will potentially be localized, mapped to component version local
resources in the target repository.
This behaviour can be further influenced by specifying a transfer script
with the <code>script</code> option family.
resources in the target repository. It the option <code>--copy-local-resources</code>
is given, instead, only resources with the relation <code>local</code> will be
transferred. This behaviour can be further influenced by specifying a transfer
script with the <code>script</code> option family.


### Examples
Expand Down
1 change: 1 addition & 0 deletions docs/reference/ocm_logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following *realms* are used by the command line tool:
- <code>ocm/accessmethod/ociartifact</code>: access method ociArtifact
- <code>ocm/credentials/dockerconfig</code>: docker config handling as credential repository
- <code>ocm/oci.ocireg</code>: OCI repository handling
- <code>ocm/ocimapping</code>: OCM to OCI Registry Mapping
- <code>ocm/plugins</code>: OCM plugin handling
- <code>ocm/processing</code>: output processing chains
- <code>ocm/toi</code>: TOI logging
Expand Down
8 changes: 5 additions & 3 deletions docs/reference/ocm_transfer_commontransportarchive.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ocm transfer commontransportarchive [<options>] <ctf> <target>
### Options

```
-L, --copy-local-resources transfer referenced local resources by-value
-V, --copy-resources transfer referenced resources by-value
-h, --help help for commontransportarchive
--lookup stringArray repository name or spec for closure lookup fallback
Expand Down Expand Up @@ -51,9 +52,10 @@ target repository will be overwritten, if they already exist.

It the option <code>--copy-resources</code> is given, all referential
resources will potentially be localized, mapped to component version local
resources in the target repository.
This behaviour can be further influenced by specifying a transfer script
with the <code>script</code> option family.
resources in the target repository. It the option <code>--copy-local-resources</code>
is given, instead, only resources with the relation <code>local</code> will be
transferred. This behaviour can be further influenced by specifying a transfer
script with the <code>script</code> option family.

It the option <code>--stop-on-existing</code> is given together with the <code>--recursive</code>
option, the recursion is stopped for component versions already existing in the
Expand Down
35 changes: 33 additions & 2 deletions docs/reference/ocm_transfer_componentarchive.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ ocm transfer componentarchive [<options>] <source> <target>
### Options

```
-h, --help help for componentarchive
-t, --type string archive format (directory, tar, tgz) (default "directory")
-L, --copy-local-resources transfer referenced local resources by-value
-V, --copy-resources transfer referenced resources by-value
--copy-sources transfer referenced sources by-value
-h, --help help for componentarchive
--lookup stringArray repository name or spec for closure lookup fallback
-f, --overwrite overwrite existing component versions
-t, --type string archive format (directory, tar, tgz) (default "directory")
```

### Description
Expand All @@ -32,6 +37,32 @@ target archive to use. The following formats are supported:

The default format is <code>directory</code>.

If a component lookup for building a reference closure is required
the <code>--lookup</code> option can be used to specify a fallback
lookup repository.
By default the component versions are searched in the repository
holding the component version for which the closure is determined.
For *Component Archives* this is never possible, because it only
contains a single component version. Therefore, in this scenario
this option must always be specified to be able to follow component
references.

It the option <code>--overwrite</code> is given, component version in the
target repository will be overwritten, if they already exist.

It the option <code>--copy-resources</code> is given, all referential
resources will potentially be localized, mapped to component version local
resources in the target repository. It the option <code>--copy-local-resources</code>
is given, instead, only resources with the relation <code>local</code> will be
transferred. This behaviour can be further influenced by specifying a transfer
script with the <code>script</code> option family.

It the option <code>--copy-sources</code> is given, all referential
sources will potentially be localized, mapped to component version local
resources in the target repository.
This behaviour can be further influenced by specifying a transfer script
with the <code>script</code> option family.


### SEE ALSO

Expand Down
8 changes: 5 additions & 3 deletions docs/reference/ocm_transfer_componentversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ocm transfer componentversions [<options>] {<component-reference>} <target>

```
-c, --constraints constraints version constraint
-L, --copy-local-resources transfer referenced local resources by-value
-V, --copy-resources transfer referenced resources by-value
-h, --help help for componentversions
--latest restrict component versions to latest
Expand Down Expand Up @@ -105,9 +106,10 @@ target repository will be overwritten, if they already exist.

It the option <code>--copy-resources</code> is given, all referential
resources will potentially be localized, mapped to component version local
resources in the target repository.
This behaviour can be further influenced by specifying a transfer script
with the <code>script</code> option family.
resources in the target repository. It the option <code>--copy-local-resources</code>
is given, instead, only resources with the relation <code>local</code> will be
transferred. This behaviour can be further influenced by specifying a transfer
script with the <code>script</code> option family.

It the option <code>--stop-on-existing</code> is given together with the <code>--recursive</code>
option, the recursion is stopped for component versions already existing in the
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/contexts/ocm"
"github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/transfer/transferhandler"
"github.com/open-component-model/ocm/pkg/errors"
)
Expand Down Expand Up @@ -51,6 +52,11 @@ func (h *Handler) TransferVersion(repo ocm.Repository, src ocm.ComponentVersionA
}

func (h *Handler) TransferResource(src ocm.ComponentVersionAccess, a ocm.AccessSpec, r ocm.ResourceAccess) (bool, error) {
if h.opts.IsLocalResourcesByValue() {
if r.Meta().Relation == metav1.LocalRelation {
return true, nil
}
}
return h.opts.IsResourcesByValue(), nil
}

Expand Down
Loading