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] upgrade/resume backport (#1524)
Browse files Browse the repository at this point in the history
* Hook 'system cluster-info' command
* Use self-binary for collecting kubernetes logs
* Backport of #1495.
  • Loading branch information
a-palchikov committed May 11, 2020
1 parent 620e004 commit 7aa83a7
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 191 deletions.
7 changes: 6 additions & 1 deletion lib/expand/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,12 @@ func (p *Peer) tryConnect(operationID string) (ctx *operationContext, err error)
return nil, utils.Abort(err)
}
if trace.IsCompareFailed(err) {
p.printStep("Waiting for another operation to finish at %v", addr)
p.Warnf("Waiting for precondition to create expand operation: %v.", err)
if utils.IsClusterDegradedError(err) {
p.printStep("Cluster is degraded, waiting for it to become healthy")
} else {
p.printStep("Waiting for another operation to complete at %v", addr)
}
}
}
return ctx, trace.Wrap(err)
Expand Down
4 changes: 2 additions & 2 deletions lib/install/client/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (r *ResumeStrategy) checkAndSetDefaults() (err error) {
r.ServicePath, err = environ.GetServicePath(stateDir)
if err != nil {
if trace.IsNotFound(err) {
return trace.Wrap(err,
"failed to find installer service. Start the installation with 'gravity install'")
return trace.Wrap(err, "failed to find installer service. "+
"Use 'gravity install' to start new installation or 'gravity join' to join an existing cluster.")
}
return trace.Wrap(err)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/ops/opsservice/operationgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ func (g *operationGroup) canCreateExpandOperation(site ops.Site, operation ops.S
}

// cluster is not active, but there are no expand operations so there is either
// other type of operation is in progress, or it's degraded
// other type of operation in progress, or it's degraded
if len(operations) == 0 {
if site.State == ops.SiteStateDegraded {
return utils.ClusterDegradedError{}
}
return trace.CompareFailed("cannot expand %v cluster", site.State)
}

Expand Down
3 changes: 1 addition & 2 deletions lib/report/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io"

"github.com/gravitational/gravity/lib/constants"
"github.com/gravitational/gravity/lib/defaults"
"github.com/gravitational/gravity/lib/utils"
"github.com/gravitational/gravity/lib/utils/kubectl"
Expand All @@ -38,7 +37,7 @@ func NewKubernetesCollector(ctx context.Context, runner utils.CommandRunner) Col
Cmd("k8s-nodes", utils.PlanetCommand(kubectl.Command("get", "nodes", "--output", "wide"))...),
Cmd("k8s-describe-nodes", utils.PlanetCommand(kubectl.Command("describe", "nodes"))...),
Cmd("k8s-cluster-info-dump.tgz",
constants.GravityBin, "system", "cluster-info"),
utils.Exe.Path, "system", "cluster-info"),
}
for _, resourceType := range defaults.KubernetesReportResourceTypes {
commands = append(commands,
Expand Down
6 changes: 4 additions & 2 deletions lib/system/environ/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ValidateInstall(env *localenv.LocalEnvironment) func() error {
"(see https://gravitational.com/gravity/docs/cluster/#deleting-a-cluster for more details)",
stateDir)
}
if err := validateNoPackageState(env.Packages, env.StateDir); err != nil {
if err := ValidateNoPackageState(env.Packages, env.StateDir); err != nil {
return trace.Wrap(err)
}
return nil
Expand Down Expand Up @@ -126,7 +126,9 @@ func validateNoActiveService(stateDir string) error {
}
}

func validateNoPackageState(packages pack.PackageService, stateDir string) error {
// ValidateNoPackageState checks whether the specified package service
// has state (i.e. has packages) and returns an error in this case.
func ValidateNoPackageState(packages pack.PackageService, stateDir string) error {
// make sure that there are no packages in the local state left from
// some improperly cleaned up installation
installedPackages, err := packages.GetPackages(defaults.SystemAccountOrg)
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,36 @@ func ExitStatusFromError(err error) *int {
return nil
}

// IsCompareFailedError returns true to indicate this error
// complies with compare failed error protocol
func (ClusterDegradedError) IsCompareFailedError() bool {
return true
}

// Error returns the text representation of this error
func (ClusterDegradedError) Error() string {
return "cluster is degraded"
}

// ClusterDegradedError indicates that the cluster is degraded
type ClusterDegradedError struct{}

// ExitCode interprets this value as exit code.
// Implements ExitCodeError
func (r exitCodeError) ExitCode() int {
return r.code
}

// IsClusterDegradedError determines if the error indicates that
// the cluster is degraded
func IsClusterDegradedError(err error) bool {
if _, ok := trace.Unwrap(err).(ClusterDegradedError); ok {
return true
}
// Handle the case when the error has come over the wire
return strings.Contains(err.Error(), "cluster is degraded")
}

// Error returns this exit code as error string.
// Implements error
func (r exitCodeError) Error() string {
Expand Down
8 changes: 4 additions & 4 deletions tool/gravity/cli/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func newConfigUpdater(ctx context.Context, localEnv, updateEnv *localenv.LocalEn
return newUpdater(ctx, localEnv, updateEnv, init)
}

func executeConfigPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
func executeConfigPhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -98,7 +98,7 @@ func executeConfigPhase(env *localenv.LocalEnvironment, environ LocalEnvironment
return trace.Wrap(err)
}

func setConfigPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params SetPhaseParams, operation ops.SiteOperation) error {
func setConfigPhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params SetPhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -112,7 +112,7 @@ func setConfigPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFact
return updater.SetPhase(context.TODO(), params.PhaseID, params.State)
}

func rollbackConfigPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
func rollbackConfigPhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -127,7 +127,7 @@ func rollbackConfigPhase(env *localenv.LocalEnvironment, environ LocalEnvironmen
return trace.Wrap(err)
}

func completeConfigPlan(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, operation ops.SiteOperation) error {
func completeConfigPlanForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand Down
22 changes: 18 additions & 4 deletions tool/gravity/cli/clusterupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,21 @@ func newClusterUpdater(
return updater, nil
}

func executeUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
func executeUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams) error {
operation, err := getActiveOperation(env, environ, params.OperationID)
if err != nil {
if trace.IsNotFound(err) {
return trace.NotFound("no active update operation found")
}
return trace.Wrap(err)
}
if operation.Type != ops.OperationUpdate {
return trace.NotFound("no active update operation found")
}
return executeUpdatePhaseForOperation(env, environ, params, operation.SiteOperation)
}

func executeUpdatePhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -144,7 +158,7 @@ func executeUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironment
return trace.Wrap(err)
}

func rollbackUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
func rollbackUpdatePhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -159,7 +173,7 @@ func rollbackUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironmen
return trace.Wrap(err)
}

func setUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params SetPhaseParams, operation ops.SiteOperation) error {
func setUpdatePhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params SetPhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -173,7 +187,7 @@ func setUpdatePhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFact
return updater.SetPhase(context.TODO(), params.PhaseID, params.State)
}

func completeUpdatePlan(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, operation ops.SiteOperation) error {
func completeUpdatePlanForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand Down
8 changes: 8 additions & 0 deletions tool/gravity/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ type Application struct {
SystemReinstallCmd SystemReinstallCmd
// SystemHistoryCmd displays system update history
SystemHistoryCmd SystemHistoryCmd
// SystemClusterInfoCmd dumps cluster info suitable for debugging
SystemClusterInfoCmd SystemClusterInfoCmd
// SystemStepDownCmd asks active gravity master to step down
SystemStepDownCmd SystemStepDownCmd
// SystemRollbackCmd rolls back last system update
Expand Down Expand Up @@ -1514,6 +1516,12 @@ type SystemHistoryCmd struct {
*kingpin.CmdClause
}

// SystemClusterInfoCmd dumps kubernetes cluster info suitable for debugging.
// It is a convenience wrapper around 'kubectl cluster-info dump --all-namespaces'
type SystemClusterInfoCmd struct {
*kingpin.CmdClause
}

// SystemStepDownCmd asks active gravity master to step down
type SystemStepDownCmd struct {
*kingpin.CmdClause
Expand Down
8 changes: 4 additions & 4 deletions tool/gravity/cli/environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newEnvironUpdater(ctx context.Context, localEnv, updateEnv *localenv.LocalE
return newUpdater(ctx, localEnv, updateEnv, init)
}

func executeEnvironPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
func executeEnvironPhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -87,7 +87,7 @@ func executeEnvironPhase(env *localenv.LocalEnvironment, environ LocalEnvironmen
return trace.Wrap(err)
}

func setEnvironPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params SetPhaseParams, operation ops.SiteOperation) error {
func setEnvironPhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params SetPhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -101,7 +101,7 @@ func setEnvironPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFac
return updater.SetPhase(context.TODO(), params.PhaseID, params.State)
}

func rollbackEnvironPhase(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
func rollbackEnvironPhaseForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, params PhaseParams, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand All @@ -116,7 +116,7 @@ func rollbackEnvironPhase(env *localenv.LocalEnvironment, environ LocalEnvironme
return trace.Wrap(err)
}

func completeEnvironPlan(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, operation ops.SiteOperation) error {
func completeEnvironPlanForOperation(env *localenv.LocalEnvironment, environ LocalEnvironmentFactory, operation ops.SiteOperation) error {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return trace.Wrap(err)
Expand Down
4 changes: 2 additions & 2 deletions tool/gravity/cli/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ func getGarbageCollector(env *localenv.LocalEnvironment, operation ops.SiteOpera
})
}

func executeGarbageCollectPhase(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
func executeGarbageCollectPhaseForOperation(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
collector, err := getGarbageCollector(env, operation)
if err != nil {
return trace.Wrap(err)
}
return collector.RunPhase(context.TODO(), params.PhaseID, params.Timeout, params.Force)
}

func setGarbageCollectPhase(env *localenv.LocalEnvironment, params SetPhaseParams, operation ops.SiteOperation) error {
func setGarbageCollectPhaseForOperation(env *localenv.LocalEnvironment, params SetPhaseParams, operation ops.SiteOperation) error {
collector, err := getGarbageCollector(env, operation)
if err != nil {
return trace.Wrap(err)
Expand Down
12 changes: 6 additions & 6 deletions tool/gravity/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,32 +534,32 @@ func agent(env *localenv.LocalEnvironment, config agentConfig) error {
return trace.Wrap(agent.Serve())
}

func executeInstallPhase(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
func executeInstallPhaseForOperation(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
return trace.Wrap(executePhaseFromService(
env, params, operation, "Connecting to installer", "Connected to installer"))
}

func rollbackInstallPhase(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
func rollbackInstallPhaseForOperation(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
return trace.Wrap(rollbackPhaseFromService(
env, params, operation, "Connecting to installer", "Connected to installer"))
}

func completeInstallPlan(env *localenv.LocalEnvironment, operation ops.SiteOperation) error {
func completeInstallPlanForOperation(env *localenv.LocalEnvironment, operation ops.SiteOperation) error {
return trace.Wrap(completePlanFromService(
env, operation, "Connecting to installer", "Connected to installer"))
}

func executeJoinPhase(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
func executeJoinPhaseForOperation(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
return trace.Wrap(executePhaseFromService(
env, params, operation, "Connecting to agent", "Connected to agent"))
}

func rollbackJoinPhase(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
func rollbackJoinPhaseForOperation(env *localenv.LocalEnvironment, params PhaseParams, operation ops.SiteOperation) error {
return trace.Wrap(rollbackPhaseFromService(
env, params, operation, "Connecting to agent", "Connected to agent"))
}

func completeJoinPlan(env *localenv.LocalEnvironment, operation ops.SiteOperation) error {
func completeJoinPlanForOperation(env *localenv.LocalEnvironment, operation ops.SiteOperation) error {
err := completePlanFromService(
env, operation, "Connecting to agent", "Connected to agent")
if err == nil {
Expand Down

0 comments on commit 7aa83a7

Please sign in to comment.