Skip to content

Commit

Permalink
Allow non leader to run upgrade-hook;
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed May 8, 2020
1 parent 6efc538 commit d91320c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apiserver/facades/agent/uniter/uniter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3478,7 +3478,7 @@ func (u *UniterAPI) CommitHookChanges(args params.CommitHookChangesArgs) (params
return params.ErrorResults{Results: res}, nil
}

func (u *UniterAPI) commitHookChangesForOneUnit(unitTag names.UnitTag, changes params.CommitHookChangesArg, canAccessUnit, canAccessApp common.AuthFunc) (err error) {
func (u *UniterAPI) commitHookChangesForOneUnit(unitTag names.UnitTag, changes params.CommitHookChangesArg, canAccessUnit, canAccessApp common.AuthFunc) error {
unit, err := u.getUnit(unitTag)
if err != nil {
return errors.Trace(err)
Expand Down
1 change: 1 addition & 0 deletions caas/kubernetes/provider/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (k *kubernetesClient) Upgrade(appName string, vers version.Number) error {
case <-timeout:
return errors.Timeoutf("timeout while waiting for the upgraded operator of %q ready", appName)
case <-k.clock.After(1 * time.Second):
// TODO(caas): change to use k8s watcher to trigger the polling.
ready, err := podChecker()
if err != nil {
return errors.Trace(err)
Expand Down
1 change: 0 additions & 1 deletion cmd/jujud/agent/caasunitinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func (c *CAASUnitInitCommand) Run(ctx *cmd.Context) (errOut error) {
} else if err != nil {
return errors.Annotatef(err, "failed to stat %s", jujucPath)
}
logger.Criticalf("CAASUnitInitCommand os.Environ -> %q", os.Environ())
unitPaths := uniter.NewPaths(cmdutil.DataDir, unitTag, nil)
if err = c.removeAllFunc(unitPaths.ToolsDir); err != nil && !os.IsNotExist(err) {
return errors.Annotatef(err, "failed to remove unit tools dir %s",
Expand Down
10 changes: 6 additions & 4 deletions worker/uniter/runner/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,8 @@ func (ctx *HookContext) doFlush(process string) error {
// we'll still trigger a change to a counter on the podspec so that we can
// ensure any other charm changes (eg storage) are acted on.
func (ctx *HookContext) addCommitHookChangesForCAAS(builder *uniter.CommitHookParamsBuilder, process string) error {
if ctx.podSpecYaml == nil && ctx.k8sRawSpecYaml == nil {
// No ops for any situation unless any k8s spec needs to be set.
// The "upgrade-charm" hook always runs with non nil k8s spec for the leader but with nil k8s spec for non leaders.
// So here we ignore the "upgrade-charm" hook for non leader.
if ctx.podSpecYaml == nil && ctx.k8sRawSpecYaml == nil && process != string(hooks.UpgradeCharm) {
// No ops for any situation unless any k8s spec needs to be set or "upgrade-charm" was run.
return nil
}
if ctx.podSpecYaml != nil && ctx.k8sRawSpecYaml != nil {
Expand All @@ -1163,6 +1161,10 @@ func (ctx *HookContext) addCommitHookChangesForCAAS(builder *uniter.CommitHookPa
}
// Only leader can set k8s spec.
if !isLeader {
if process == string(hooks.UpgradeCharm) {
// We do not want to fail the non leader unit's upgrade-charm hook.
return nil
}
logger.Errorf("%v is not the leader but is setting application k8s spec", ctx.unitName)
return ErrIsNotLeader
}
Expand Down

0 comments on commit d91320c

Please sign in to comment.