-
Notifications
You must be signed in to change notification settings - Fork 44
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(update-app-base): add support to update base
for application charms
#652
base: main
Are you sure you want to change the base?
Conversation
cec578d
to
19c361e
Compare
804ac33
to
5431e7c
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.
We're on the right track, just a few details to iron out.
The commit message should include WHY were fixing the bug the way it's being fixed.
internal/juju/applications.go
Outdated
} else if input.Base != "" { | ||
base, err := corebase.ParseBaseFromString(input.Base) | ||
if err != nil { | ||
return nil, err | ||
} | ||
newOrigin.Base = base |
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.
comment: It may be okay, to not consider the revision and base together, in this if statement. When we resolve a charm by revision, the base is ignored by the upstream server.
internal/juju/applications.go
Outdated
} else if input.Base != "" { | ||
oldOrigin.Base = newOrigin.Base |
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.
issue: This means that the revision and the base cannot change at the same time. Given that every charm revision has only 1 base, that is a problem when refreshing by revision rather than channel.
Take a look at line 1401 as well:
if !basesContain(oldOrigin.Base, supportedBases)
It's validating that the new potential charm supports the old base - which will cause problems if the base is being changed.
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've moved base's ifs to a separate block.
Btw, the charmhub view is misleading because it seems that a revision can have multiple bases. (an example can be found here: https://charmhub.io/coredns).
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've done one more qa test on my machine:
(microk8s)
from
resource "juju_application" "this" {
model = juju_model.this.name
name = "test-app"
charm {
name = "coredns"
base = "[email protected]"
revision = 33
}
}
to
resource "juju_application" "this" {
model = juju_model.this.name
name = "test-app"
charm {
name = "coredns"
base = "[email protected]"
revision = 145
}
}
and now works.
@@ -590,6 +605,7 @@ func (r *applicationResource) Create(ctx context.Context, req resource.CreateReq | |||
plan.Placement = types.StringValue(readResp.Placement) | |||
plan.Principal = types.BoolNull() | |||
plan.ApplicationName = types.StringValue(createResp.AppName) | |||
plan.ModelType = types.StringValue(modelType.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.
todo: Use StringValue(), String() is a quoted value.
https://github.com/juju/terraform-provider-juju/wiki/Developing#model-tf-secret-test-not-found
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 doesn't have any ValueString
. It's a struct from the juju lib, it only has a String()
method
@@ -692,6 +708,12 @@ func (r *applicationResource) Read(ctx context.Context, req resource.ReadRequest | |||
} | |||
r.trace("read application", map[string]interface{}{"resource": appName, "response": response}) | |||
|
|||
modelType, err := r.client.Applications.ModelType(modelName) |
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: While technically harmless, this value should really be included in the CreateApplicationResponse and ReadApplicationResponse structures, rather than making a second call in each place. We're trying to keep a cleaner distinction between what the provider has to know and juju or other details.
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've add to both structs ModelType
if req.State.Raw.IsKnown() { | ||
var state applicationResourceModel | ||
diags := req.State.Get(ctx, &state) | ||
if diags.HasError() { | ||
resp.Diagnostics.Append(diags...) | ||
return | ||
} | ||
modelType := state.ModelType.ValueString() | ||
resp.RequiresReplace = modelType == model.IAAS.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.
comment: Checking IfKnown on all of state is good. Though you've asked it of ALL the saved state is known. Which maybe too broad a question? I'd ask if the specific element IsKnown instead.
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've now moved it to ask for the model type specifically.
e04c126
to
963a08e
Compare
…harms This PR adds support to update the base in application charms by requiring a replace in case of a machine charm, and perform the upgrade in case of a k8s charm. We add the model_type computed field on the application schema, and we use it to make a decision in the planmodifier RequiresReplaceIf. re juju#635
963a08e
to
c1e9afc
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 shaped up nicely.
Please let the code freeze end before merging.
Description
This PR adds support to update the base in application charms by requiring a replace in case of a machine charm, and perform the upgrade in case of a k8s charm.
Fixes: re #635
Type of change
base
for application charmsQA Steps
LXD
terraform apply
juju status
and you should see base=22.04Now update the base
terraform plan
and you should see~ base = "[email protected]" -> "[email protected]" # forces replacement
terraform apply
Now we have two scenarios:
juju status
and you should see base=20.04Microk8s
terraform apply
juju show-application test-app
-> check base ubuntu 22.04Update plan
terraform plan
-> check that the plan doesn't require replace.terraform apply
juju show-application test-app
-> check base ubuntu 20.04