Skip to content
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

[JUJU-2030]Kill unconverted api workers 2 9 #14834

Merged
merged 14 commits into from Nov 2, 2022

Conversation

hmlanigan
Copy link
Member

@hmlanigan hmlanigan commented Oct 26, 2022

Split the unconverted-api-workers into two new workers and remove.

machine-setup runs setup on machines which require an API Connection. Once setup is done it can be uninstalled.

kvm-container-provisioner and lxd-container-provisioner both wait for a machine of their container type to be provisioned if the machine supports their container type. If it doesn't, the worker uninstalls. The first container provisioned of their type will cause setup for the container systems to run, then a container provisioner is started.

QA steps

$ juju bootstrap openstack dot --constraints allocate-public-ip=true
$ juju bootstrap openstack src --constraints allocate-public-ip=true
$ juju add-model move-me 
$ juju set-model-constraints allocate-public-ip=true
$ juju add-machine lxd
$ juju add-machine kvm
$ juju add-machine 
$ juju remove-machine 0/lxd/0
$ juju add-machine lxd:0

# once settled
$ juju migrate move-me dst
$ juju switch dst:move-me

$ juju add-machine lxd:1

# checkout the juju_engine_report on each.  The kvm-container-provisioner and lxd-container-provisioner have reports on whether the container watchers are still running and if the provisioners are running. 

Bug reference

https://bugs.launchpad.net/juju/+bug/1994488
https://bugs.launchpad.net/juju/+bug/1983140

Due to unconverted-api-worker refactor into workers using manifolds,
WatchAllContainers is no longer used by the provisioner.
A step in refactoring the unconverted-api-workers into pieces using
individual manifolds. MachineStartup will handle machine setup necessary
but requiring an API Connection. The actual work is part of the machine
agent and will be done via a config method.
A step in refactoring the unconverted-api-worker manifold into
individual pieces. These will hold a container provisioner based on
container type.
The unconverted-api-worker is being split into three pieces. machine-setup is short lived and does setup on the machine which required an API Connection. The other two are container provisioner workers for lxd and kvm.

The functionality of the container-watcher for setup is placed into the container provisioner worker. It waits for a container to be provisioned, configures the container system on the machine and starts an container provisioner worker.
Always verify LXD and KVM in setupContainerSupport.
Renamed ContainerWorker to containerSetupAndProvisioner for understandability. Updated unit tests for container setup.
Change Report() results to make tests easier. Remove unused code from
unit tests. Change capitalization of ContainerSetupAndProvisioner.
Changes to code to faciliate mocks, including adding a couple of
interfaces and a shim. Moved code out of start to a new method for same.
This can be resolved once we have good mocking in this package.
@hmlanigan hmlanigan marked this pull request as ready for review November 1, 2022 13:10
@hmlanigan hmlanigan force-pushed the kill-unconverted-api-workers-2-9 branch from df1ccae to 9af39de Compare November 1, 2022 13:10
"machine-action-runner",
//"machine-setup", exits when done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I left on purpose to explain that the machine-setup manifold isn't running when at first glance it should be.

}

if err := a.setupContainerSupport(apiConn, logger); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we annotate this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can return errors from the dependency pkg. I've noticed that if wrapped, the dependency engine doesn't handle them as expected. I added logging messages to explain why we were calling ErrUninstall. Check that they make sense so we can find answers in the future.

}
if result.Code != 0 {
return nil, errors.New(fmt.Sprintf("cannot patch /etc/update-manager/release-upgrades: %s", result.Stderr))
return errors.New(fmt.Sprintf("cannot patch /etc/update-manager/release-upgrades: %s", result.Stderr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as an fmt.Errorf call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very old juju 1 code, will do

if len(result) != 1 {
return errors.Errorf("expected 1 result, got %d", len(result))
}
if errors.IsNotFound(result[0].Err) || (result[0].Err == nil && result[0].Machine.Life() == life.Dead) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Is(err, errors.NotFound)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

func (cs *ContainerSetup) initialiseContainerProvisioner() (Provisioner, error) {
cs.logger.Debugf("setup provisioner for %s containers", cs.containerType)
if cs.managerConfig == nil {
return nil, errors.New("Programming error, manager config not setup")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a notvalid ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

var _ = gc.Suite(&containerSetupSuite{})

func (s *containerSetupSuite) TestStartContainerStartsContainerProvisioner(c *gc.C) {
defer s.patch(c).Finish()
func (s *containerSetupSuite) TestInitialiseContainersLXD(c *gc.C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think these are around the wrong way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// Adding one new container machine.
s.notify([]string{"0/lxd/0"})
func (s *containerSetupSuite) TestInitialiseContainersKVM(c *gc.C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again


s.cleanKill(c, runner)
func (s *containerSetupSuite) TestInitialiseContainerProvisionerLXD(c *gc.C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Around the wrong way.

s.testInitialiseContainers(c, instance.KVM)
}

func (s *containerSetupSuite) TestInitialiseContainerProvisonerKVM(c *gc.C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Around the wrong way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
pr := apiprovisioner.NewState(apiCaller)

m, err := cfg.machineSupportsContainers(&containerShim{api: pr}, mTag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit can we name m to something better?

typeSet.Add(string(v))
}
if !typeSet.Contains(string(cfg.ContainerType)) {
cfg.Logger.Infof("%s does not support %s containers", mTag, string(cfg.ContainerType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/containers/container

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"github.com/juju/juju/core/watcher"
)

// NewContainerSetupAndProvisioner return a ContainerSetupAndProvisioner.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/return/returns

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Use errors.Is rather than deprecated methods and update very old style
messages.
The kvm-container-provisioner is only running on hardware which supports kvm. Thus the test is hardware dependent and gives different results. Allow for this by specifying  optional workers.

Startup of kvm-container-provisioner is tested in the provisioner worker.
@hmlanigan hmlanigan force-pushed the kill-unconverted-api-workers-2-9 branch from a6d3c7f to 9f7bea7 Compare November 2, 2022 10:29
Copy link
Member

@tlm tlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

cmd/jujud/agent/agenttest/engine.go Show resolved Hide resolved
@hmlanigan
Copy link
Member Author

/merge

of unconverted-api-workers to manifold workers.
@hmlanigan
Copy link
Member Author

/merge

1 similar comment
@hmlanigan
Copy link
Member Author

/merge

@jujubot jujubot merged commit 51672c0 into juju:2.9 Nov 2, 2022
@hmlanigan hmlanigan deleted the kill-unconverted-api-workers-2-9 branch November 3, 2022 07:21
@jack-w-shaw jack-w-shaw mentioned this pull request Nov 4, 2022
jujubot added a commit that referenced this pull request Nov 7, 2022
#14862

Merge Conflicts (which I resolved):
- .github/workflows/smoke.yml
- cmd/jujud/agent/machine/manifolds_test.go
- cmd/jujud/agent/machine_test.go
- go.mod
- go.sum
- scripts/win-installer/setup.iss
- snap/snapcraft.yaml
- tests/suites/manual/deploy_manual.sh
- version/version.go

Merges:
- #14837
- #14846
- #14834
- #14851
- #14857
- #14853
@wallyworld wallyworld mentioned this pull request Nov 21, 2022
jujubot added a commit that referenced this pull request Nov 21, 2022
#14902

Merge 3.0 branch

#14837
#14846
#14834
#14854
#14851

```
# Conflicts:
# scripts/win-installer/setup.iss
# snap/snapcraft.yaml
# version/version.go
```
jujubot added a commit that referenced this pull request Jan 12, 2023
#15042

The kvm-provisioner worker is expected to run in all machine manifolds, but uninstalls itself if KVM support is not detected.

#14834 Softened the check for the worker by adding optional workers to the engine test logic.

#14862 was merged incorrectly resulting in an extra worker assertion before including the kvm-provisioner was added as an optional worker. This causes tests to fail depending on where they are run.

Here we remove the duplicate assertion along with the optional worker logic. Instead we just patch `IsKVMSupported` to return true and use a hard expectation that the working is running.

## QA steps

`go test -v ./cmd/jujud/agent/ -check.v -check.f=MachineSuite.TestMachineWorkers`

## Documentation changes

None.

## Bug reference

N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants