Skip to content

Commit

Permalink
Merge pull request juju#13092 from hpidcock/fix-1929364
Browse files Browse the repository at this point in the history
juju#13092

During UnitIntroduction call, store the PodIP and Ports in state.

## QA steps

See repro steps on bug.

## Documentation changes

N/A

## Bug reference

https://bugs.launchpad.net/juju/+bug/1929364
  • Loading branch information
jujubot authored Jun 21, 2021
2 parents efd0260 + bd22e29 commit d62cb95
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
21 changes: 21 additions & 0 deletions apiserver/facades/agent/caasapplication/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,29 @@ func (f *Facade) UnitIntroduction(args params.CAASUnitIntroductionArgs) (params.
}
}

// Find the pod/unit in the provider.
caasApp := f.broker.Application(application.Name(), caas.DeploymentStateful)
pods, err := caasApp.Units()
if err != nil {
return errResp(err)
}
var pod *caas.Unit
for _, p := range pods {
if p.Id == args.PodName {
pod = &p
break
}
}
if pod == nil {
return errResp(errors.NotFoundf("pod %s in provider", args.PodName))
}

// Force update of provider-id.
if unit != nil {
update := unit.UpdateOperation(state.UnitUpdateProperties{
ProviderId: &containerID,
Address: &pod.Address,
Ports: &pod.Ports,
})
var unitUpdate state.UpdateUnitsOperation
unitUpdate.Updates = append(unitUpdate.Updates, update)
Expand All @@ -239,6 +258,8 @@ func (f *Facade) UnitIntroduction(args params.CAASUnitIntroductionArgs) (params.
unit, err = application.AddUnit(state.AddUnitParams{
UnitName: unitName,
ProviderId: &containerID,
Address: &pod.Address,
Ports: &pod.Ports,
})
if err != nil {
return errResp(err)
Expand Down
40 changes: 36 additions & 4 deletions apiserver/facades/agent/caasapplication/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func (s *CAASApplicationSuite) TestAddUnit(c *gc.C) {
updateOp: nil,
}

s.broker.app = &mockCAASApplication{
units: []caas.Unit{{
Id: "gitlab-0",
Address: "1.2.3.4",
Ports: []string{"80"},
}},
}

results, err := s.facade.UnitIntroduction(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Error, gc.IsNil)
Expand All @@ -80,10 +88,12 @@ func (s *CAASApplicationSuite) TestAddUnit(c *gc.C) {

s.st.CheckCallNames(c, "Model", "Application", "Unit", "ControllerConfig", "APIHostPortsForAgents")
s.st.CheckCall(c, 1, "Application", "gitlab")
s.st.app.CheckCallNames(c, "Life", "Name", "AddUnit")
c.Assert(s.st.app.Calls()[2].Args[0], gc.DeepEquals, state.AddUnitParams{
s.st.app.CheckCallNames(c, "Life", "Name", "Name", "AddUnit")
c.Assert(s.st.app.Calls()[3].Args[0], gc.DeepEquals, state.AddUnitParams{
ProviderId: strPtr("gitlab-0"),
UnitName: strPtr("gitlab/0"),
Address: strPtr("1.2.3.4"),
Ports: &[]string{"80"},
})
}

Expand All @@ -101,6 +111,14 @@ func (s *CAASApplicationSuite) TestReuseUnitByName(c *gc.C) {
},
}

s.broker.app = &mockCAASApplication{
units: []caas.Unit{{
Id: "gitlab-0",
Address: "1.2.3.4",
Ports: []string{"80"},
}},
}

results, err := s.facade.UnitIntroduction(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Error, gc.IsNil)
Expand All @@ -109,8 +127,14 @@ func (s *CAASApplicationSuite) TestReuseUnitByName(c *gc.C) {

s.st.CheckCallNames(c, "Model", "Application", "Unit", "ControllerConfig", "APIHostPortsForAgents")
s.st.CheckCall(c, 1, "Application", "gitlab")
s.st.app.CheckCallNames(c, "Life", "Name", "UpdateUnits")
c.Assert(s.st.app.Calls()[2].Args[0], gc.DeepEquals, &state.UpdateUnitsOperation{
s.st.units["gitlab/0"].CheckCallNames(c, "Life", "UpdateOperation", "SetPassword")
c.Assert(s.st.units["gitlab/0"].Calls()[1].Args[0], gc.DeepEquals, state.UnitUpdateProperties{
ProviderId: strPtr("gitlab-0"),
Address: strPtr("1.2.3.4"),
Ports: &[]string{"80"},
})
s.st.app.CheckCallNames(c, "Life", "Name", "Name", "UpdateUnits")
c.Assert(s.st.app.Calls()[3].Args[0], gc.DeepEquals, &state.UpdateUnitsOperation{
Updates: []*state.UpdateUnitOperation{nil},
})
}
Expand Down Expand Up @@ -158,6 +182,14 @@ func (s *CAASApplicationSuite) TestAgentConf(c *gc.C) {
updateOp: nil,
}

s.broker.app = &mockCAASApplication{
units: []caas.Unit{{
Id: "gitlab-0",
Address: "1.2.3.4",
Ports: []string{"80"},
}},
}

results, err := s.facade.UnitIntroduction(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Error, gc.IsNil)
Expand Down
6 changes: 6 additions & 0 deletions apiserver/facades/agent/caasapplication/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,15 @@ type mockCAASApplication struct {
caas.Application

state caas.ApplicationState
units []caas.Unit
}

func (a *mockCAASApplication) State() (caas.ApplicationState, error) {
a.MethodCall(a, "State")
return a.state, a.NextErr()
}

func (a *mockCAASApplication) Units() ([]caas.Unit, error) {
a.MethodCall(a, "Units")
return a.units, a.NextErr()
}

0 comments on commit d62cb95

Please sign in to comment.