-
Notifications
You must be signed in to change notification settings - Fork 10
chore: use the juju client for model related methods #1633
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
base: v3
Are you sure you want to change the base?
Conversation
643ceb3 to
fca0e39
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.
This file was renamed and modified, see types.go for what existed previously.
b3b7330 to
f7aa97d
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.
1st pass review with a few comments
| // API Error types. | ||
| if ec, ok := e.Err.(interface{ ErrorCode() string }); ok { | ||
| e.Code = Code(ec.ErrorCode()) | ||
| var errCode interface{ ErrorCode() string } |
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 change?
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.
The error that comes out of the Juju client is wrapped internally due to a errors.Trace(err) call where that original err has an error code. Then, when do errors.E(err) and try to extract an error code, we get nothing because the error with the code is 2 levels deep. So we can try to unwrap the error until we find an error that implement ErrorCode() or we reach the end of the list of wrapped errors.
internal/jimm/juju/interface.go
Outdated
|
|
||
| // ChangeModelCredential replaces cloud credential for a given model with the provided one. | ||
| ChangeModelCredential(context.Context, names.ModelTag, names.CloudCredentialTag) error | ||
| ChangeModelCredential(model names.ModelTag, credential names.CloudCredentialTag) error |
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.
i'm not fond of named arguments in interface definitions.. feels like the godoc above does not fully explain what the method is expected to do
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.
Will remove the named arguments and update the godoc.
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.
Removed the named arguments where unneccessary (some were useful and I've left them).
Left the docstring since I didn't touch that in this PR.
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| func cloudFromParams(cloudName string, p jujuparams.Cloud) cloud.Cloud { |
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 would be nice to have some consistency in naming.. XYToZW where X is a package, Y a type, Z a package and W a type.. e.g. paramsCloudToCloudCloud wdyt?
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.
or have a type that embeds cloud.Cloud and has a FromParamsCloud method
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.
I hear you, I'll take a look at this
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.
Here are some thoughts, we either need to convert from an RPC struct to some type that we use internally or we need to convert to whatever type we use internally to an RPC type - speaking specifically about the jujuapi package.
For converting InternalType -> RPC, we can look at internal/jujuapi/cloud.go where we've got the API handler CloudInfo() which receives a dbmodel.Cloud and runs cloud.ToJujuCloudInfo() on the dbmodel object converting from the dbmodel type to the RPC type. I don't think that is great because it imports the RPC types into the dbmodel package for the purposes of putting the conversion logic in there.
Then for RPC -> InternalType we can look at AddCloud in the same file, which calls cloudFromParams to convert a jujuparams.Cloud to github.com/juju/juju/cloud.Cloud.
So ultimately, my idea is that it would be nice if the naming convention for the mapping functions easily indicated we are pushing data down vs surfacing it.
I.e. if we are converting to an internal type we could name the function toX where X is some type. And if we are converting to an RPC type we could name the function fromX.
The actual words don't matter to me but at least names that reflect which way the data is going. Another options might be rpcToX and xFromRPC.
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.
exactly.. some naming convention where i can tell which way we're converting just by looking at the method name
| return d.createLoginRequest1(ctx, ctl.ResourceTag(), user.ResourceTag(), p) | ||
| } | ||
|
|
||
| // toModelAccessString maps relation to a model access string. |
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.
hhmmm.. i vaguely remember we have a place for these conversion methods between openfga relations to juju access strings, don't we?
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.
Yeah inside internal/jimm/permissions , and you'll see that's where it was used from initially, but I don't think the jujuclient should be reaching in there for things so I've copied it here. Especially because internal/jimm/juju imports this package, so you can get into a dependency cycle very easily (can't remember if this import did cause a cycle but better to avoid importing anything internal/jimm from internal/jujuclient).
The issue makes me think the conversion of OpenFGA types to Juju strings should happen in some kind of adapter package that like internal/openfgaToJuju or at least something along those lines is worth thinking about.
| // types preferably of the form base.ModelInfo. Until either that inconsitency | ||
| // is fixed or we export the convertParamsModelInfo function, we copy it here | ||
| // here have better consistency in our domain layer. | ||
| func convertParamsModelInfo(modelInfo params.ModelInfo) (base.ModelInfo, error) { |
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.
again a comment about naming consistency, or having a type that wraps base.ModelInfo and has a method for conversion from params.ModelInfo and a method that returns the wrapped base.ModelInfo
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.
This function and name was copied from Juju so maybe this one should stay the same?
93eeabf to
ec13770
Compare
ec13770 to
82493fa
Compare
|
So this is a change to use the existing machinery that juju clients rely on for resolving RPC methods to specific ones in case of multiple versions or similar? Looks reasonable overall, but I don't know if I understand it enough to approve. |
| return j.bootstrapManager | ||
| } | ||
|
|
||
| // DialerAdapter is an adapter that implements the juju.Dialer interface |
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.
Doesn't jujuclient.Dialer also implement Dial in the same way?
Or is this to avoid the pointer?
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.
I'll need to go back and look at this one again.
| Status: "running", | ||
| Message: "ACTIVE", | ||
| }}, | ||
| SLA: &jujuparams.ModelSLAInfo{ |
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.
Is this no longer necessary? Or is the zero value actually useful for tests?
Description
This change started off as a simple one, a continuation of #1611 where we slowly move our
jujuclientpackage to use Juju's Go client so that we don't need to call facades directly and we get nicer types out of the client.The downside of this change is that I had to replace all usages of
jujuparams.*withbase.*where were were using the RPC object in many places (i.e. an object with JSON tags used for marshalling/unmarshalling over the wire). We are now using a different but similar type that simplifies a few rough edges.There was also a somewhat unrelated but necessary change in the
internal/rpcpackage where I had previously introduced a dependency oninternal/jimm/that was incorrect and caused cyclic dependencies during this PR. That's now been addressed.Finally, you'll see new functions in
internal/jujuapi/types.gothat convert from thebase.*types to the API type. I haven't written any tests for these as our integration tests cover this behavior, but as discussed before, if we have any objections to this approach we can always revisit it. Also, confusingly, the types in Juju'sbasepackage are not the same types used by Juju's apiserver, this might be worth looking at further.Fixes JUJU-8186
Engineering checklist