Added a pre/post-deploy steps to budle deploy for metric registration. #8175

Merged
merged 1 commit into from Dec 20, 2017

Conversation

Projects
None yet
6 participants
Member

alesstimec commented Dec 5, 2017

Description of change

With the latest changes to the bundle file format, authors are able to specify the plans under which individual applications are to be deployed.

Why is this change needed?

To improve the UX of bundle deployment for bundles that
contain charms that must be deployed under a specific plan.

QA steps

  1. set up charms and plans
  2. create a bundle that specifies a plan for at least one application
  3. deploy the bundle
  4. verify that charms were deployed under specified plans

Documentation changes

Need to add docs to describe changes in the bundle format.

Bug reference

N/A

Owner

jameinel commented Dec 5, 2017

Member

alesstimec commented Dec 5, 2017

!!build!!

Member

alesstimec commented Dec 5, 2017

!!build!!

Do we really need RunPreBundle?

cmd/juju/application/bundle_test.go
+ // `"hello registration"\n` (quotes and newline from json
+ // encoding) is returned by the fake http server. This is binary64
+ // encoded before the call into SetMetricCredentials.
+ //creds := append([]byte(`"aGVsbG8gcmVnaXN0cmF0aW9u"`), 0xA)
cmd/juju/application/bundle_test.go
+ _, err := cmdtesting.RunCommand(c, deploy, "bundle/wordpress-with-plans")
+ c.Assert(err, jc.ErrorIsNil)
+
+ //c.Check(setMetricCredentialsCall(), gc.Equals, 1)
cmd/juju/application/deploy.go
@@ -496,6 +496,9 @@ type DeployStep interface {
// RunPre runs before the call is made to add the charm to the environment.
RunPre(MeteredDeployAPI, *httpbakery.Client, *cmd.Context, DeploymentInfo) error
+ // RunPreBundle runs before the call is made to add a bundle charm to the environment.
+ RunPreBundle(MeteredDeployAPI, *httpbakery.Client, *cmd.Context, DeploymentInfo) error
@tasdomas

tasdomas Dec 7, 2017

Member

It looks like the purpose of RunPreBundle is to perform charm authorization without checking if the charm is metered. Is that right?

What is the meaning of obtaining an auth for a non-metered charm, when it's deployed in a bundle?

If we were to leave the check for whether the charm is metered or not, would we be able to get rid of RunPreBundle?

It's just that

  • the fact that there's no RunPostBundle and
  • that RunPre calls RunPreBundle
    make the DeployStep interface difficult to understand and deploy.go is not the lightest read as far as code goes already.
@cmars

cmars Dec 7, 2017

Owner

I'm ok with attempting to obtain the plan specified in the bundle unconditionally; if we get one from the API, it's reasonable to set it IMO. I agree with @tasdomas though that the method name RunPreBundle is confusing.. what does RunPre have to do with bundles? And the logic is getting complicated in there.

I think the general approach in deployBundle is fine, but let's please break up the logic and operations in such a way that they can be reused by both the "deploy charm" and "deploy bundle" flow in a clear and concise way.

cmd/juju/application/deploy.go
@@ -496,6 +496,9 @@ type DeployStep interface {
// RunPre runs before the call is made to add the charm to the environment.
RunPre(MeteredDeployAPI, *httpbakery.Client, *cmd.Context, DeploymentInfo) error
+ // RunPreBundle runs before the call is made to add a bundle charm to the environment.
+ RunPreBundle(MeteredDeployAPI, *httpbakery.Client, *cmd.Context, DeploymentInfo) error
@tasdomas

tasdomas Dec 7, 2017

Member

It looks like the purpose of RunPreBundle is to perform charm authorization without checking if the charm is metered. Is that right?

What is the meaning of obtaining an auth for a non-metered charm, when it's deployed in a bundle?

If we were to leave the check for whether the charm is metered or not, would we be able to get rid of RunPreBundle?

It's just that

  • the fact that there's no RunPostBundle and
  • that RunPre calls RunPreBundle
    make the DeployStep interface difficult to understand and deploy.go is not the lightest read as far as code goes already.
@cmars

cmars Dec 7, 2017

Owner

I'm ok with attempting to obtain the plan specified in the bundle unconditionally; if we get one from the API, it's reasonable to set it IMO. I agree with @tasdomas though that the method name RunPreBundle is confusing.. what does RunPre have to do with bundles? And the logic is getting complicated in there.

I think the general approach in deployBundle is fine, but let's please break up the logic and operations in such a way that they can be reused by both the "deploy charm" and "deploy bundle" flow in a clear and concise way.

cmd/juju/application/deploy.go
+ ModelUUID: modelUUID,
+ }
+
+ err = s.RunPreBundle(apiRoot, bakeryClient, ctx, deployInfo)
@cmars

cmars Dec 7, 2017

Owner

Here I'd just look up the plan if "default" with getDefaultPlan, then call registerMetrics, failing immediately on any error. If the bundle author specified a plan, the intent is to deploy as specified, no magic.

cmd/juju/application/register.go
info := deployInfo.CharmInfo
- if r.Plan == "" && info.Metrics != nil && !info.Metrics.PlanRequired() {
+ if r.Plan == "" && info != nil && info.Metrics != nil && !info.Metrics.PlanRequired() {
@cmars

cmars Dec 7, 2017

Owner

Hmm.. overloading logic here, deployInfo.CharmInfo == nil to mean "ignore the plan required checking logic we'd use otherwise" isn't very clear.

@cmars

cmars Dec 7, 2017

Owner

I think only RunPre cares about this check.

@cmars

cmars Dec 7, 2017

Owner

I'd also argue that only RunPre cares about ignoring registerMetrics errors for non-charmstore deployments.

+ return errors.Trace(err)
+ }
+
+ defer func() {
@mattyw

mattyw Dec 19, 2017

Member

I don't really like the pattern of having a defer that closes over an error like this

Member

alesstimec commented Dec 19, 2017

$$merge$$

Member

alesstimec commented Dec 19, 2017

$$merge$$

Member

alesstimec commented Dec 19, 2017

:shipit:

Member

alesstimec commented Dec 20, 2017

$$merge$$

Member

alesstimec commented Dec 20, 2017

$$merge$$

Owner

jameinel commented Dec 20, 2017

Build failed: Tests failed

Owner

jameinel commented Dec 20, 2017

$$merge$$

@jameinel jameinel deleted a comment from jujubot Dec 20, 2017

Contributor

jujubot commented Dec 20, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@jujubot jujubot merged commit 3cfeeed into juju:develop Dec 20, 2017

1 check passed

continuous-integration/jenkins/pr-merge This commit looks good
Details

@alesstimec alesstimec deleted the alesstimec:bundle-charm-registration branch Dec 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment