Skip to content

Commit

Permalink
Merge pull request #11858 from manadart/2.8-into-develop
Browse files Browse the repository at this point in the history
#11858

Merge from 2.8 bringing forward:
- #11856 from manadart/2.8-container-lld
- #11847 from ycliuhw/feature/lp-1887978
- #11843 from wallyworld/azure-instancetype-fix
  • Loading branch information
jujubot committed Jul 24, 2020
2 parents b04d637 + 744d504 commit 04305f7
Show file tree
Hide file tree
Showing 40 changed files with 1,016 additions and 839 deletions.
13 changes: 6 additions & 7 deletions api/provisioner/mocks/machine_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 2 additions & 27 deletions api/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,37 +246,12 @@ func (st *State) ReleaseContainerAddresses(containerTag names.MachineTag) (err e
// PrepareContainerInterfaceInfo allocates an address and returns information to
// configure networking for a container. It accepts container tags as arguments.
func (st *State) PrepareContainerInterfaceInfo(containerTag names.MachineTag) (corenetwork.InterfaceInfos, error) {
return st.prepareOrGetContainerInterfaceInfo(containerTag, true)
}

// GetContainerInterfaceInfo returns information to configure networking
// for a container. It accepts container tags as arguments.
func (st *State) GetContainerInterfaceInfo(containerTag names.MachineTag) (corenetwork.InterfaceInfos, error) {
return st.prepareOrGetContainerInterfaceInfo(containerTag, false)
}

// prepareOrGetContainerInterfaceInfo returns the necessary information to
// configure network interfaces of a container with allocated static
// IP addresses.
//
// TODO(dimitern): Before we start using this, we need to rename both
// the method and the network.InterfaceInfo type to be called
// InterfaceConfig.
func (st *State) prepareOrGetContainerInterfaceInfo(
containerTag names.MachineTag,
allocateNewAddress bool,
) (corenetwork.InterfaceInfos, error) {
var result params.MachineNetworkConfigResults
args := params.Entities{
Entities: []params.Entity{{Tag: containerTag.String()}},
}
methodName := ""
if allocateNewAddress {
methodName = "PrepareContainerInterfaceInfo"
} else {
methodName = "GetContainerInterfaceInfo"
}
if err := st.facade.FacadeCall(methodName, args, &result); err != nil {

if err := st.facade.FacadeCall("PrepareContainerInterfaceInfo", args, &result); err != nil {
return nil, err
}
if len(result.Results) != 1 {
Expand Down
8 changes: 1 addition & 7 deletions apiserver/common/networkingcommon/networkconfigapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ func (api *NetworkConfigAPI) SetObservedNetworkConfig(args params.SetMachineNetw
if err != nil {
return errors.Trace(err)
}
if m.IsContainer() {
return nil
}

observedConfig := args.Config
logger.Tracef("observed network config of machine %q: %+v", m.Id(), observedConfig)
if len(observedConfig) == 0 {
Expand Down Expand Up @@ -117,10 +115,6 @@ func (api *NetworkConfigAPI) getMachineForSettingNetworkConfig(machineTag string
return nil, errors.Trace(err)
}

if m.IsContainer() {
logger.Debugf("not updating network config for container %q", m.Id())
}

return m, nil
}

Expand Down
5 changes: 4 additions & 1 deletion apiserver/facades/agent/provisioner/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/juju/names/v4"

"github.com/juju/juju/core/instance"
corenetwork "github.com/juju/juju/core/network"
"github.com/juju/juju/network"
"github.com/juju/juju/network/containerizer"
)
Expand Down Expand Up @@ -36,7 +37,9 @@ type BridgePolicy interface {
// PopulateContainerLinkLayerDevices sets the link-layer devices of the input
// guest, setting each device to be a child of the corresponding bridge on the
// host machine.
PopulateContainerLinkLayerDevices(containerizer.Machine, containerizer.Container) error
PopulateContainerLinkLayerDevices(
containerizer.Machine, containerizer.Container, bool,
) (corenetwork.InterfaceInfos, error)
}

// Unit is an indirection for state.Unit.
Expand Down
13 changes: 7 additions & 6 deletions apiserver/facades/agent/provisioner/mocks/containerizer_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions apiserver/facades/agent/provisioner/mocks/package_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 7 additions & 81 deletions apiserver/facades/agent/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/life"
"github.com/juju/juju/core/lxdprofile"
corenetwork "github.com/juju/juju/core/network"
"github.com/juju/juju/core/status"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
Expand Down Expand Up @@ -951,6 +950,9 @@ func (api *ProvisionerAPI) PrepareContainerInterfaceInfo(args params.Entities) (

// GetContainerInterfaceInfo returns information to configure networking for a
// container. It accepts container tags as arguments.
// TODO (manadart 2020-07-23): This method is not used and can be removed when
// next this facade version is bumped.
// We then don't need the parameterised prepareOrGet...
func (api *ProvisionerAPI) GetContainerInterfaceInfo(args params.Entities) (
params.MachineNetworkConfigResults,
error,
Expand Down Expand Up @@ -1067,19 +1069,6 @@ func (ctx *prepareOrGetContext) ProcessOneContainer(
return errors.Trace(err)
}

// TODO(jam): 2017-01-31 PopulateContainerLinkLayerDevices should really
// just be returning the ones we'd like to exist, and then we turn those
// into things we'd like to tell the Host machine to create, and then *it*
// reports back what actually exists when its done.
if err := policy.PopulateContainerLinkLayerDevices(host, guest); err != nil {
return errors.Trace(err)
}

containerDevices, err := guest.AllLinkLayerDevices()
if err != nil {
return errors.Trace(err)
}

// We do not ask the provider to allocate addresses for manually provisioned
// machines as we do not expect such machines to be recognised (LP:1796106).
askProviderForAddress := false
Expand All @@ -1091,18 +1080,14 @@ func (ctx *prepareOrGetContext) ProcessOneContainer(
askProviderForAddress = environs.SupportsContainerAddresses(callContext, env)
}

preparedInfo := make(corenetwork.InterfaceInfos, len(containerDevices))
for i, device := range containerDevices {
info, err := ctx.infoForDevice(device, askProviderForAddress)
if err != nil {
return errors.Trace(err)
}
preparedInfo[i] = info
preparedInfo, err := policy.PopulateContainerLinkLayerDevices(host, guest, askProviderForAddress)
if err != nil {
return errors.Trace(err)
}

hostInstanceId, err := host.InstanceId()
if err != nil {
// this should have already been checked in the processEachContainer helper
// This should have already been checked in the processEachContainer helper.
return errors.Trace(err)
}

Expand All @@ -1126,65 +1111,6 @@ func (ctx *prepareOrGetContext) ProcessOneContainer(
return nil
}

// infoForDevice returns interface information for a link-layer device.
func (ctx *prepareOrGetContext) infoForDevice(
device containerizer.LinkLayerDevice, askProviderForAddress bool) (corenetwork.InterfaceInfo, error) {
parentDevice, err := device.ParentDevice()
if err != nil || parentDevice == nil {
return corenetwork.InterfaceInfo{}, errors.Errorf("cannot get parent %q of container device %q: %v",
device.ParentName(), device.Name(), err)
}
parentAddrs, err := parentDevice.Addresses()
if err != nil {
return corenetwork.InterfaceInfo{}, errors.Trace(err)
}

info := corenetwork.InterfaceInfo{
InterfaceName: device.Name(),
MACAddress: device.MACAddress(),
ConfigType: corenetwork.ConfigManual,
InterfaceType: corenetwork.InterfaceType(device.Type()),
NoAutoStart: !device.IsAutoStart(),
Disabled: !device.IsUp(),
MTU: int(device.MTU()),
ParentInterfaceName: parentDevice.Name(),
}

if len(parentAddrs) > 0 {
logger.Debugf("host machine device %q has addresses %v", parentDevice.Name(), parentAddrs)
firstAddress := parentAddrs[0]
if askProviderForAddress {
parentDeviceSubnet, err := firstAddress.Subnet()
if err != nil {
return info, errors.Annotatef(err,
"cannot get subnet %q used by address %q of host machine device %q",
firstAddress.SubnetCIDR(), firstAddress.Value(), parentDevice.Name(),
)
}
info.ConfigType = corenetwork.ConfigStatic
info.CIDR = parentDeviceSubnet.CIDR()
info.ProviderSubnetId = parentDeviceSubnet.ProviderId()
info.VLANTag = parentDeviceSubnet.VLANTag()
info.IsDefaultGateway = firstAddress.IsDefaultGateway()
} else {
info.ConfigType = corenetwork.ConfigDHCP
info.CIDR = firstAddress.SubnetCIDR()
info.ProviderSubnetId = ""
info.VLANTag = 0
}
} else {
logger.Infof("host machine device %q has no addresses %v", parentDevice.Name(), parentAddrs)
// TODO(jam): 2017-02-15, have a concrete test for this case, as it
// seems to be the common case in the wild.
info.ConfigType = corenetwork.ConfigDHCP
info.ProviderSubnetId = ""
info.VLANTag = 0
}

logger.Tracef("prepared info for container interface %q: %+v", info.InterfaceName, info)
return info, nil
}

func (api *ProvisionerAPI) prepareOrGetContainerInterfaceInfo(
args params.Entities, maintain bool,
) (params.MachineNetworkConfigResults, error) {
Expand Down
14 changes: 9 additions & 5 deletions apiserver/facades/agent/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/juju/juju/environs/config"
environtesting "github.com/juju/juju/environs/testing"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/network/containerizer"
"github.com/juju/juju/provider/dummy"
"github.com/juju/juju/state"
statetesting "github.com/juju/juju/state/testing"
Expand Down Expand Up @@ -1904,18 +1903,23 @@ func (s *provisionerMockSuite) TestManuallyProvisionedHostsUseDHCPForContainers(

func (s *provisionerMockSuite) expectManuallyProvisionedHostsUseDHCPForContainers() {
s.expectNetworkingEnviron()
s.expectLinkLayerDevices()

cExp := s.container.EXPECT()
cExp.InstanceId().Return(instance.UnknownId, errors.NotProvisionedf("idk-lol"))

s.policy.EXPECT().PopulateContainerLinkLayerDevices(s.host, s.container).Return(nil)
s.policy.EXPECT().PopulateContainerLinkLayerDevices(s.host, s.container, false).Return(
network.InterfaceInfos{
{
InterfaceName: "eth0",
ConfigType: network.ConfigDHCP,
},
}, nil)

cExp.Id().Return("lxd/0").AnyTimes()
cExp.AllLinkLayerDevices().Return([]containerizer.LinkLayerDevice{s.device}, nil)

hExp := s.host.EXPECT()
// Crucial behavioural trait. Set false to test failure.
// Crucial behavioural trait. Set false to test failure, whereupon the
// PopulateContainerLinkLayerDevices expectation will not be satisfied.
hExp.IsManual().Return(true, nil)
hExp.InstanceId().Return(instance.Id("manual:10.0.0.66"), nil)
}
Expand Down
2 changes: 1 addition & 1 deletion caas/kubernetes/provider/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (c *controllerStack) createControllerService() error {
}

logger.Debugf("creating controller service: \n%+v", spec)
if err := c.broker.ensureK8sService(spec); err != nil {
if _, err := c.broker.ensureK8sService(spec); err != nil {
return errors.Trace(err)
}

Expand Down

0 comments on commit 04305f7

Please sign in to comment.