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

simple support for disabling uploaders #567

Merged
merged 1 commit into from
Nov 8, 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
13 changes: 10 additions & 3 deletions cmds/ocm/commands/ocmcmds/components/transfer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/ocm/transfer/transferhandler/spiff"
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/generics"
"github.com/open-component-model/ocm/pkg/out"
)

var (
Expand All @@ -50,9 +51,10 @@ var (
type Command struct {
utils.BaseCommand

Refs []string
TargetName string
BOMFile string
Refs []string
TargetName string
BOMFile string
DisableBlobHandlers bool
}

// NewCommand creates a new ctf command.
Expand Down Expand Up @@ -94,6 +96,7 @@ $ ocm transfer components -t tgz --repo OCIRegistry::ghcr.io mandelsoft/kubelink
func (o *Command) AddFlags(fs *pflag.FlagSet) {
o.BaseCommand.AddFlags(fs)
fs.StringVarP(&o.BOMFile, "bom-file", "B", "", "file name to write the component version BOM")
fs.BoolVarP(&o.DisableBlobHandlers, "disable-uploads", "", false, "disable standard upload handlers for transport")
}

func (o *Command) Complete(args []string) error {
Expand All @@ -110,6 +113,10 @@ func (o *Command) Run() error {
defer session.Close()
session.Finalize(o.OCMContext())

if o.DisableBlobHandlers {
out.Outln(o.Context, "standard blob upload handlers are disabled.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out.Outln(o.Context, "standard blob upload handlers are disabled.")
out.Outln(o.Context, "Standard blob upload handlers are disabled.")

o.Context.OCMContext().DisableBlobHandlers()
}
err := o.ProcessOnOptions(ocmcommon.CompleteOptionsWithSession(o, session))
if err != nil {
return err
Expand Down
119 changes: 119 additions & 0 deletions cmds/ocm/commands/ocmcmds/components/transfer/disableupload_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package transfer_test

import (
"bytes"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/open-component-model/ocm/cmds/ocm/testhelper"
. "github.com/open-component-model/ocm/pkg/contexts/oci/testhelper"
. "github.com/open-component-model/ocm/pkg/testutils"

"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/common/accessobj"
"github.com/open-component-model/ocm/pkg/contexts/oci"
"github.com/open-component-model/ocm/pkg/contexts/oci/artdesc"
ocictf "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact"
storagecontext "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/oci"
"github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/oci/ocirepo"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/cpi"
ctfocm "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
)

const BASEURL = "baseurl.io"

func FakeOCIRegBaseFunction(ctx *storagecontext.StorageContext) string {
return BASEURL
}

var _ = Describe("disable upload", func() {
var env *TestEnv

BeforeEach(func() {
env = NewTestEnv()

FakeOCIRepo(env.Builder, OCIPATH, OCIHOST)

env.OCICommonTransport(OCIPATH, accessio.FormatDirectory, func() {
OCIManifest1(env.Builder)
})

env.OCMCommonTransport(ARCH, accessio.FormatDirectory, func() {
env.Component(COMPONENT, func() {
env.Version(VERSION, func() {
env.Provider(PROVIDER)
env.Resource("artifact", "", resourcetypes.OCI_IMAGE, metav1.LocalRelation, func() {
env.Access(
ociartifact.New(oci.StandardOCIRef(OCIHOST+".alias", OCINAMESPACE, OCIVERSION)),
)
})
})
})
})

env.OCMContext().BlobHandlers().Register(ocirepo.NewArtifactHandler(FakeOCIRegBaseFunction),
cpi.ForRepo(oci.CONTEXT_TYPE, ocictf.Type), cpi.ForMimeType(artdesc.ToContentMediaType(artdesc.MediaTypeImageManifest)))
})

AfterEach(func() {
env.Cleanup()
})

It("transfers ctf with upload", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("transfer", "components", "--copy-resources", ARCH, OUT)).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`
transferring version "github.com/mandelsoft/test:v1"...
...resource 0 artifact[ociImage](ocm/value:v2.0)...
...adding component version...
1 versions transferred
`))

Expect(env.DirExists(OUT)).To(BeTrue())

ctf := Must(ctfocm.Open(env, accessobj.ACC_READONLY, OUT, 0, env))
defer Close(ctf, "ctf")

cv := Must(ctf.LookupComponentVersion(COMPONENT, VERSION))
defer Close(cv, "version")

res := Must(cv.GetResource(metav1.NewIdentity("artifact")))

acc := Must(res.Access())
Expect(acc.GetKind()).To(Equal(ociartifact.Type))
Expect(acc.Describe(env.OCMContext())).To(Equal("OCI artifact " + BASEURL + "/" + OCINAMESPACE + ":" + OCIVERSION))
})

It("transfers ctf without upload", func() {
buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("transfer", "components", "--disable-uploads", "--copy-resources", ARCH, OUT)).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`
standard blob upload handlers are disabled.
transferring version "github.com/mandelsoft/test:v1"...
...resource 0 artifact[ociImage](ocm/value:v2.0)...
...adding component version...
1 versions transferred
`))

Expect(env.DirExists(OUT)).To(BeTrue())

ctf := Must(ctfocm.Open(env, accessobj.ACC_READONLY, OUT, 0, env))
defer Close(ctf, "ctf")

cv := Must(ctf.LookupComponentVersion(COMPONENT, VERSION))
defer Close(cv, "version")

res := Must(cv.GetResource(metav1.NewIdentity("artifact")))

acc := Must(res.Access())
Expect(acc.GetKind()).To(Equal(localblob.Type))
})
})
8 changes: 7 additions & 1 deletion docs/reference/ocm_add_resource-configuration.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should quickly move this from the spec, too

Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputHelmRepository</code>, <code>--inputPath</code>, <code>--inputVersion</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>
- Input type <code>ociArtifact</code>

The path must denote an OCI image reference.

Expand All @@ -372,6 +372,12 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>

DEPRECATED: This type is deprecated, please use ociArtifact instead.

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>spiff</code>

The path must denote a [spiff](https://github.com/mandelsoft/spiff) template relative the resources file.
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/ocm_add_resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputHelmRepository</code>, <code>--inputPath</code>, <code>--inputVersion</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>
- Input type <code>ociArtifact</code>

The path must denote an OCI image reference.

Expand All @@ -382,6 +382,12 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>

DEPRECATED: This type is deprecated, please use ociArtifact instead.

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>spiff</code>

The path must denote a [spiff](https://github.com/mandelsoft/spiff) template relative the resources file.
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/ocm_add_source-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputHelmRepository</code>, <code>--inputPath</code>, <code>--inputVersion</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>
- Input type <code>ociArtifact</code>

The path must denote an OCI image reference.

Expand All @@ -372,6 +372,12 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>

DEPRECATED: This type is deprecated, please use ociArtifact instead.

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>spiff</code>

The path must denote a [spiff](https://github.com/mandelsoft/spiff) template relative the resources file.
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/ocm_add_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputHelmRepository</code>, <code>--inputPath</code>, <code>--inputVersion</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>
- Input type <code>ociArtifact</code>

The path must denote an OCI image reference.

Expand All @@ -379,6 +379,12 @@ with the field <code>type</code> in the <code>input</code> field:

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>ociImage</code>

DEPRECATED: This type is deprecated, please use ociArtifact instead.

Options used to configure fields: <code>--hint</code>, <code>--inputCompress</code>, <code>--inputPath</code>, <code>--mediaType</code>

- Input type <code>spiff</code>

The path must denote a [spiff](https://github.com/mandelsoft/spiff) template relative the resources file.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ocm_controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ ocm controller [<options>] <sub command> ...

##### Sub Commands

* [ocm controller <b>install</b>](ocm_controller_install.md) &mdash; Install either a specific or latest version of the ocm-controller.
* [ocm controller <b>install</b>](ocm_controller_install.md) &mdash; Install either a specific or latest version of the ocm-controller. Optionally install prerequisites required by the controller.

23 changes: 14 additions & 9 deletions docs/reference/ocm_controller_install.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ocm controller install &mdash; Install Either A Specific Or Latest Version Of The Ocm-Controller.
## ocm controller install &mdash; Install Either A Specific Or Latest Version Of The Ocm-Controller. Optionally Install Prerequisites Required By The Controller.

### Synopsis

Expand All @@ -9,14 +9,19 @@ ocm controller install controller {--version v0.0.1}
### Options

```
-u, --base-url string the base url to the ocm-controller's release page (default "https://github.com/open-component-model/ocm-controller/releases")
-c, --controller-name string name of the controller that's used for status check (default "ocm-controller")
-d, --dry-run if enabled, prints the downloaded manifest file
-h, --help help for install
-n, --namespace string the namespace into which the controller is installed (default "ocm-system")
-a, --release-api-url string the base url to the ocm-controller's API release page (default "https://api.github.com/repos/open-component-model/ocm-controller/releases")
-t, --timeout duration maximum time to wait for deployment to be ready (default 1m0s)
-v, --version string the version of the controller to install (default "latest")
-u, --base-url string the base url to the ocm-controller's release page (default "https://github.com/open-component-model/ocm-controller/releases")
--cert-manager-base-url string the base url to the cert-manager's release page (default "https://github.com/cert-manager/cert-manager/releases")
--cert-manager-release-api-url string the base url to the cert-manager's API release page (default "https://api.github.com/repos/cert-manager/cert-manager/releases")
--cert-manager-version string version for cert-manager (default "v1.13.2")
-c, --controller-name string name of the controller that's used for status check (default "ocm-controller")
-d, --dry-run if enabled, prints the downloaded manifest file
-h, --help help for install
-i, --install-prerequisites install prerequisites required by ocm-controller (default true)
-n, --namespace string the namespace into which the controller is installed (default "ocm-system")
-a, --release-api-url string the base url to the ocm-controller's API release page (default "https://api.github.com/repos/open-component-model/ocm-controller/releases")
-s, --skip-pre-flight-check skip the pre-flight check for clusters
-t, --timeout duration maximum time to wait for deployment to be ready (default 1m0s)
-v, --version string the version of the controller to install (default "latest")
```

### SEE ALSO
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 @@ -19,6 +19,7 @@ The following *realms* are used by the command line tool:
- <code>ocm</code>: general realm used for the ocm go library.
- <code>ocm/accessmethod/ociartifact</code>: access method ociArtifact
- <code>ocm/compdesc</code>: component descriptor handling
- <code>ocm/context</code>: context lifecycle
- <code>ocm/credentials/dockerconfig</code>: docker config handling as credential repository
- <code>ocm/credentials/vault</code>: HashiCorp Vault Access
- <code>ocm/downloader</code>: Downloaders
Expand Down
1 change: 1 addition & 0 deletions docs/reference/ocm_transfer_componentversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ componentversions, componentversion, cv, components, component, comps, comp, c
-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
--disable-uploads disable standard upload handlers for transport
-h, --help help for componentversions
--latest restrict component versions to latest
--lookup stringArray repository name or spec for closure lookup fallback
Expand Down
5 changes: 5 additions & 0 deletions pkg/contexts/ocm/internal/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Context interface {
RepositorySpecHandlers() RepositorySpecHandlers
MapUniformRepositorySpec(u *UniformRepositorySpec) (RepositorySpec, error)

DisableBlobHandlers()
BlobHandlers() BlobHandlerRegistry
BlobDigesters() BlobDigesterRegistry

Expand Down Expand Up @@ -216,6 +217,10 @@ func (c *_context) MapUniformRepositorySpec(u *UniformRepositorySpec) (Repositor
return c.specHandlers.MapUniformRepositorySpec(c, u)
}

func (c *_context) DisableBlobHandlers() {
c.blobHandlers = NewBlobHandlerRegistry(nil)
}

func (c *_context) BlobHandlers() BlobHandlerRegistry {
c.Update()
return c.blobHandlers
Expand Down