Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
[7.0.x] reconfiguration and custom planet package (#2191)
Browse files Browse the repository at this point in the history
* Use the correct node profile and runtime package locator for the reconfigure operation.
Updates #2026.
* Fix parameter types in reconfigurator
* Address review comments
  • Loading branch information
a-palchikov authored Nov 4, 2020
1 parent 2411a27 commit 9c5e23c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
12 changes: 12 additions & 0 deletions lib/app/service/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ func CreatePackageData(items []*archive.Item, c *C) bytes.Buffer {
return buf
}

var (
// PlanetPackage defines the runtime package for tests
PlanetPackage = loc.Locator{
Repository: defaults.SystemAccountOrg,
Name: loc.Planet.Name,
Version: "0.0.1",
}

// NodeProfile specifies the default node profile
NodeProfile = "node"
)

const hooks = `hooks:
preNodeAdd:
job: |
Expand Down
11 changes: 10 additions & 1 deletion lib/install/reconfigure/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
)

// NewPlanner returns reconfigure operation plan builder.
func NewPlanner(getter install.PlanBuilderGetter, cluster storage.Site) *Planner {
func NewPlanner(getter install.PlanBuilderGetter, cluster storage.Site, role string) *Planner {
return &Planner{
PlanBuilderGetter: getter,
Cluster: cluster,
nodeRole: role,
}
}

Expand All @@ -48,6 +49,11 @@ func (p *Planner) GetOperationPlan(operator ops.Operator, cluster ops.Site, oper
return nil, trace.Wrap(err)
}

runtimePackage, err := cluster.App.Manifest.RuntimePackageForProfileName(p.nodeRole)
if err != nil {
return nil, trace.Wrap(err)
}

// The "reconfigure" operation reuses a lot of the install fsm phases.
builder := &PlanBuilder{
PlanBuilder: &install.PlanBuilder{
Expand All @@ -63,6 +69,7 @@ func (p *Planner) GetOperationPlan(operator ops.Operator, cluster ops.Site, oper
ServiceUser: p.Cluster.ServiceUser,
TeleportPackage: *teleportPackage,
},
runtimePackage: *runtimePackage,
}

plan := &storage.OperationPlan{
Expand Down Expand Up @@ -104,4 +111,6 @@ type Planner struct {
install.PlanBuilderGetter
// Cluster is the installed cluster.
Cluster storage.Site
// nodeRole specifies the node's application role
nodeRole string
}
5 changes: 3 additions & 2 deletions lib/install/reconfigure/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"testing"

"github.com/gravitational/gravity/lib/app/service/test"
"github.com/gravitational/gravity/lib/install"
installphases "github.com/gravitational/gravity/lib/install/phases"
"github.com/gravitational/gravity/lib/install/reconfigure/phases"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (s *ReconfiguratorSuite) TestPlan(c *check.C) {
c.Assert(err, check.IsNil)

cluster := s.suite.Cluster()
planner := NewPlanner(s.suite.PlanBuilderGetter(), ops.ConvertOpsSite(*cluster))
planner := NewPlanner(s.suite.PlanBuilderGetter(), ops.ConvertOpsSite(*cluster), test.NodeProfile)
plan, err := planner.GetOperationPlan(s.suite.Services().Operator, *cluster, *operation)
c.Assert(err, check.IsNil)

Expand Down Expand Up @@ -201,7 +202,7 @@ func (s *ReconfiguratorSuite) verifyRestartPhase(c *check.C, phase storage.Opera
ID: fmt.Sprintf("%v%v", phases.RestartPhase, phases.PlanetPhase),
Data: &storage.OperationPhaseData{
Server: &master,
Package: &loc.Planet,
Package: &test.PlanetPackage,
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion lib/install/reconfigure/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
type PlanBuilder struct {
// PlanBuilder is the embedded installer plan builder.
*install.PlanBuilder
runtimePackage loc.Locator
}

// AddChecksPhase adds the preflight checks phase to the plan.
Expand Down Expand Up @@ -150,7 +151,7 @@ func (b *PlanBuilder) AddRestartPhase(plan *storage.OperationPlan) {
Description: "Restart Planet",
Data: &storage.OperationPhaseData{
Server: &b.Master,
Package: &loc.Planet,
Package: &b.runtimePackage,
},
},
},
Expand Down
18 changes: 9 additions & 9 deletions tool/gravity/cli/reconfigure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func reconfigureCluster(env *localenv.LocalEnvironment, config InstallConfig, co
}
log.Infof("Using config: %#v.", config)
if config.FromService {
err := startReconfiguratorFromService(env, config, localState)
err := startReconfiguratorFromService(env, config, *localState)
if utils.IsContextCancelledError(err) {
return trace.Wrap(err, "reconfigurator interrupted")
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func reconfigureCluster(env *localenv.LocalEnvironment, config InstallConfig, co
return trace.Wrap(err)
}

func startReconfiguratorFromService(env *localenv.LocalEnvironment, config InstallConfig, localState *localenv.LocalState) error {
func startReconfiguratorFromService(env *localenv.LocalEnvironment, config InstallConfig, localState localenv.LocalState) error {
ctx, cancel := context.WithCancel(context.Background())
interrupt := signals.NewInterruptHandler(ctx, cancel, InterruptSignals)
defer interrupt.Close()
Expand All @@ -118,28 +118,28 @@ func startReconfiguratorFromService(env *localenv.LocalEnvironment, config Insta
if err != nil {
return trace.Wrap(utils.NewPreconditionFailedError(err))
}
installer, err := newReconfigurator(ctx, installerConfig, localState)
installer, err := newReconfigurator(ctx, *installerConfig, localState)
if err != nil {
return trace.Wrap(utils.NewPreconditionFailedError(err))
}
interrupt.AddStopper(installer)
return trace.Wrap(installer.Run(listener))
}

func newReconfigurator(ctx context.Context, config *install.Config, state *localenv.LocalState) (*install.Installer, error) {
func newReconfigurator(ctx context.Context, config install.Config, state localenv.LocalState) (*install.Installer, error) {
engine, err := reconfigure.NewEngine(reconfigure.Config{
Operator: config.Operator,
State: state,
State: &state,
})
if err != nil {
return nil, trace.Wrap(err)
}
config.LocalAgent = false // To make sure agent does not get launched on this node.
installer, err := install.New(ctx, install.RuntimeConfig{
Config: *config,
Planner: reconfigure.NewPlanner(config, state.Cluster),
FSMFactory: reconfigure.NewFSMFactory(*config),
ClusterFactory: install.NewClusterFactory(*config),
Config: config,
Planner: reconfigure.NewPlanner(&config, state.Cluster, state.Cluster.ClusterState.Servers[0].Role),
FSMFactory: reconfigure.NewFSMFactory(config),
ClusterFactory: install.NewClusterFactory(config),
Engine: engine,
})
if err != nil {
Expand Down
25 changes: 8 additions & 17 deletions tool/gravity/cli/stop_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ func startGravity(env *localenv.LocalEnvironment, confirmed bool) error {
}
}

err := checkAdvertiseAddress(env.Packages)
nodeAddr, err := env.Backend.GetNodeAddr()
if err != nil {
return trace.Wrap(err)
}

err = checkAdvertiseAddress(nodeAddr)
if err != nil {
return trace.Wrap(err)
}
Expand Down Expand Up @@ -115,7 +120,7 @@ func startGravity(env *localenv.LocalEnvironment, confirmed bool) error {
}

func findInstalledPackages(packages pack.PackageService) ([]loc.Locator, error) {
planet, err := pack.FindInstalledPackage(packages, loc.Planet)
planet, err := pack.FindRuntimePackage(packages)
if err != nil {
return nil, trace.Wrap(err)
}
Expand All @@ -132,21 +137,7 @@ func findInstalledPackages(packages pack.PackageService) ([]loc.Locator, error)
// This helps prevent scenarios when, for example, a node is migrated to
// another machine and user does not provide a new advertise address to the
// start command.
func checkAdvertiseAddress(packages pack.PackageService) error {
// Use the runtime package label to determine the current advertise address.
locator, err := pack.FindInstalledConfigPackage(packages, loc.Planet)
if err != nil {
return trace.Wrap(err)
}
envelope, err := packages.ReadPackageEnvelope(*locator)
if err != nil {
return trace.Wrap(err)
}
advertiseIP := envelope.RuntimeLabels[pack.AdvertiseIPLabel]
if advertiseIP == "" {
log.Warnf("No %v label on %v.", pack.AdvertiseIPLabel, envelope)
return nil
}
func checkAdvertiseAddress(advertiseIP string) error {
ifaces, err := systeminfo.NetworkInterfaces()
if err != nil {
return trace.Wrap(err)
Expand Down

0 comments on commit 9c5e23c

Please sign in to comment.