-
Notifications
You must be signed in to change notification settings - Fork 503
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
feat(dqlite): add service layer for cloud image metadata #18121
feat(dqlite): add service layer for cloud image metadata #18121
Conversation
f360fbb
to
a07610b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, looking very good. Just a few small remarks/questions.
// invalid. | ||
func (s Service) SaveMetadata(ctx context.Context, metadata []cloudimagemetadata.Metadata) error { | ||
if len(metadata) == 0 { | ||
return errors.NothingToSave |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this error? We don't return it on the legacy state, and it does feel a bit counter-intuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, it is not on the legacy. I think somewhere in my mind I think that caller shouldn't even try to save empty metadata... But there would be inconsistent of some generic function in go behave (like errors.Join
).
Will return nil.
|
||
supportedArchitectures := s.st.SupportedArchitectures(context.Background()) | ||
if !supportedArchitectures.Contains(m.Arch) { | ||
return jujuerrors.Errorf("unsupported architecture %s (should be any of %s): %w", m.Arch, supportedArchitectures.Values(), errors.Invalid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure, errors.NotValid(..)
returns an error that satisfies errors.Is(err, errors.Invalid)
right? If not, why not using errors.NotValidf(...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns an error who satisfies github.com/juju/juju/domain/cloudimagemetadata/errors.Invalid
.
I don't know from which errors package you get error.NotValidf
but I assumes it comes from github.com/juju/juju/errors
which we don't use anymore, as far i understand, in favor of domain-scoped errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, it's from your domain errors' package. That's fine then. IMO you should name the error NotValid
as well, just for consistency because that's what we have all around our codebase.
a07610b
to
889aadf
Compare
d4e7bfc
to
da8f8f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the changes!
// fields empty. | ||
Invalid = errors.ConstError("invalid metadata") | ||
NotValid = errors.ConstError("invalid metadata") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this context issue, then this is good to go.
if imageId == "" { | ||
return errors.EmptyImageID | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank-you.
da8f8f4
to
513a5e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for guiding this through.
/merge |
513a5e6
to
2c14502
Compare
@@ -0,0 +1,16 @@ | |||
// Copyright 2023 Canonical Ltd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: s/2023/2024
|
||
// FindMetadata retrieves a list of cloud image metadata based on the provided criteria. | ||
// It returns the matched metadata or a [github.com/juju/juju/domain/cloudimagemetadata/errors.NotFound] error | ||
// If there are no one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
// If there are no one. | |
// if there are not one. |
} | ||
|
||
// SaveMetadata saves the provided cloud image metadata if non-empty and valid. | ||
// It returns a [errors.NothingToSave] if the input are empty, or a [errors.NotValid] if at least one of the inputs are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: where is error NothingToSave defined? Looks like the method returns nil in this case, which is preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not. Removed it during review, forgot to remove this part of comment. Thanks for asking, I removed it.
return s.st.SaveMetadata(ctx, metadata) | ||
} | ||
|
||
// DeleteMetadataWithImageID removes all the metadata associated with the given imageID from the state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: add errors returned to the comments.
|
||
var missing []string | ||
if m.Version == "" { | ||
missing = append(missing, "version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it - gathering all the errors before returning.
2c14502
to
807d1c5
Compare
Signed-off-by: Guillaume Fouillet <guillaume.fouillet@canonical.com>
- Before this commit, the code lacked a service layer interface for managing cloud image metadata. - After this commit, a service interface for cloud image metadata management is added along with its unit tests. This commit introduces a new service layer for managing cloud image metadata, including methods for saving, deleting, and finding metadata. Signed-off-by: Guillaume Fouillet <guillaume.fouillet@canonical.com>
807d1c5
to
bc2521b
Compare
/merge |
Add the service layer for cloud image metadata.
It is basically a wrapper to state, with few functionnalities:
Checklist
- [ ] Integration tests, with comments saying what you're testing- [ ] doc.go added or updated in changed packagesQA steps
Unit test are self-sufficient
Documentation changes
None
Links
Jira card: JUJU-6630