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

Mandelsoft/fix #75

Merged
merged 2 commits into from
Aug 31, 2022
Merged

Mandelsoft/fix #75

merged 2 commits into from
Aug 31, 2022

Conversation

mandelsoft
Copy link
Contributor

What this PR does / why we need it:

Fix the tar input handling for the ocm add commands.

So far in uses two nested directory traverses, which leads to the packaging of file multiple times.

This has been extracted from the #70

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Release note:

Fix the tar input handling for the `ocm add` commands.

@mandelsoft mandelsoft requested a review from a team as a code owner August 29, 2022 10:14
@mandelsoft mandelsoft requested review from achimweigel and Diaphteiros and removed request for a team August 29, 2022 10:14
@Skarlso
Copy link
Contributor

Skarlso commented Aug 29, 2022

Thank you for extracting it! :)

}, nil
}

func (a *action) Add(e interface{}) error {
if a.count > 0 && !a.Ref.IsRegistry() {
return fmt.Errorf("cannot copy multiple source artefacts to the same artefact (%s)", &a.Ref)
src := e.(*artefacthdlr.Object)
Copy link
Contributor

@yitsushi yitsushi Aug 29, 2022

Choose a reason for hiding this comment

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

What happens if it fails to convert/cast type? An ok check would be useful here:

src, ok := e.(*artefacthdlr.Object)
if !ok {
  // return some error
  // or recover somehow
}

Copy link
Contributor Author

@mandelsoft mandelsoft Aug 30, 2022

Choose a reason for hiding this comment

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

Then it panics, This seems to be useful because then the complete code is wrong. The handler instantiated above declares this Object to be its implementation of the selected objects. The action now just processes the elements provided by this handler, and the contract between handler and action is this object type.

This does not appear in a dedicated case based on some input, but always.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see it's under cmd/ where it's totally fine to crash when something unexpected happens. Does not look nice to the user, but it does not cause pain to other devs.

Comment on lines 161 to 165
func (b *fileBuffer) Close() error {
err := b.file.Close()
err2 := os.Remove(b.path)
if err2 != nil {
return err2
}
return err
}
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
func (b *fileBuffer) Close() error {
err := b.file.Close()
err2 := os.Remove(b.path)
if err2 != nil {
return err2
}
return err
}
func (b *fileBuffer) Close() error {
if err := b.file.Close(); err != nil {
return err
}
return os.Remove(b.path)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is different behavior! But I'll do it differently....

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, so don't remove the file in the close method. :)

Comment on lines 100 to 125
type NamespaceLister struct{}

var anonymous cpi.NamespaceLister = &NamespaceLister{}

func (n *NamespaceLister) NumNamespaces(prefix string) (int, error) {
if prefix == "" {
return 1, nil
}
return 0, nil
}

func (n *NamespaceLister) GetNamespaces(prefix string, closure bool) ([]string, error) {
if prefix == "" {
return []string{""}, nil
}
return nil, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I tried. But I fail to understand what this is / does.

Also, GetNamsepaves doesn't appear to be using its closure value. These two are never called in this entire changeset. So I assume it must be working with some existing code?

Copy link
Contributor

Choose a reason for hiding this comment

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

The GetNamespaces function signature comes from this interface:

// NamespaceLister provides the optional repository list functionality of
// a repository
type NamespaceLister interface {
	// NumNamespaces returns the number of namespaces found for a prefix
	// If the given prefix does not end with a /, a repository with the
	// prefix name is included
	NumNamespaces(prefix string) (int, error)

	// GetNamespaces returns the name of namespaces found for a prefix
	// If the given prefix does not end with a /, a repository with the
	// prefix name is included
	GetNamespaces(prefix string, closure bool) ([]string, error)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I know where it comes from. :D I was just wondering what it's doing and maybe it's not using it by accident. :) ¯\_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An artifact set only has an empty namespace. Therefore is returns 1, if the empty namespace or prefix is requested for the number of available namespaces (OCI repositories).

GetNamespaces()return the list with the empty namespace, if an empty prefix is requests. This is the namespace it supports. If a prefix is requested, then there are no matching namespaces hosted by the artifact set,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add comments, here.

Expect(env.CatchOutput(buf).Execute("transfer", "artefact", ARCH+"//"+NS+":"+VERSION, "directory::"+OUT+"//changed")).To(Succeed())
Expect("\n" + buf.String()).To(Equal(
`
copying /tmp/ctf//mandelsoft/test:v1 to directory::` + OUT + `//changed:v1...
Copy link
Contributor

Choose a reason for hiding this comment

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

That's strange /tmp/ctf//mandelsoft/test:v1. Why is // good in this case? That seems like an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/tmp/ctf ithe file path of the CTF archive, mandelsoft/test:v1 is the repository+version of the OCI artefact to deal with.
Both is separated by a //.

This is similar to the OCM notation <repo>//<component>:<version>

@gardener-robot gardener-robot added size/m Medium and removed size/xl labels Aug 30, 2022
@mandelsoft mandelsoft requested a review from a team as a code owner August 30, 2022 16:44
@mandelsoft mandelsoft merged commit 5a3c7b9 into main Aug 31, 2022
@mandelsoft mandelsoft deleted the mandelsoft/fix branch August 31, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/m Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants