Skip to content

Commit

Permalink
Remove internal state handling for now (#80)
Browse files Browse the repository at this point in the history
Signed-off-by: Jussi Nummelin <[email protected]>
  • Loading branch information
jnummelin authored May 25, 2020
1 parent d41ecd1 commit c2bd18c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 223 deletions.
5 changes: 0 additions & 5 deletions pkg/apis/v1beta1/cluster.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package v1beta1

import (
"github.com/Mirantis/mcc/pkg/state"
)

// ClusterMeta defines cluster metadata
type ClusterMeta struct {
Name string `yaml:"name" validate:"required"`
Expand All @@ -15,7 +11,6 @@ type ClusterConfig struct {
Kind string `yaml:"kind" validate:"eq=UCP"`
Metadata *ClusterMeta `yaml:"metadata"`
Spec *ClusterSpec `yaml:"spec"`
State *state.State
ManagerJoinToken string
WorkerJoinToken string
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/v1beta1/cluster_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (c *ClusterSpec) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

func isSwarmLeader(host *Host) bool {
output, err := host.ExecWithOutput(host.Configurer.DockerCommandf(`info --format "{{ .Swarm.ControlAvailable}}"`))
// We can by-pass the Configurer interface as managers are always linux boxes
output, err := host.ExecWithOutput(`sudo docker info --format "{{ .Swarm.ControlAvailable}}"`)
if err != nil {
log.Warnf("failed to get host's swarm leader status, probably not part of swarm")
return false
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func Apply(configFile string) error {

phaseManager := phase.NewManager(&clusterConfig)

phaseManager.AddPhase(&phase.InitState{})
phaseManager.AddPhase(&phase.Connect{})
phaseManager.AddPhase(&phase.GatherFacts{})
phaseManager.AddPhase(&phase.PrepareHost{})
Expand All @@ -50,7 +49,6 @@ func Apply(configFile string) error {
phaseManager.AddPhase(&phase.UpgradeUcp{})
phaseManager.AddPhase(&phase.JoinManagers{})
phaseManager.AddPhase(&phase.JoinWorkers{})
phaseManager.AddPhase(&phase.SaveState{})
phaseManager.AddPhase(&phase.Disconnect{})
phaseManager.AddPhase(&phase.UcpInfo{})

Expand Down
26 changes: 16 additions & 10 deletions pkg/cmd/bundle/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
"io/ioutil"
"net/url"
"os"
"path"
"path/filepath"
"strings"

api "github.com/Mirantis/mcc/pkg/apis/v1beta1"
"github.com/Mirantis/mcc/pkg/config"
"github.com/Mirantis/mcc/pkg/state"
"github.com/Mirantis/mcc/pkg/constant"
"github.com/Mirantis/mcc/pkg/ucp"
"github.com/Mirantis/mcc/pkg/util"
"github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
)

Expand All @@ -34,7 +36,7 @@ func Download(clusterFile string, username string, password string) error {
return err
}

m := clusterConfig.Spec.SwarmLeader()
m := clusterConfig.Spec.Managers()[0] // Does not have to be real swarm leader
if err := m.Connect(); err != nil {
return fmt.Errorf("error while connecting to manager node: %w", err)
}
Expand All @@ -52,23 +54,27 @@ func Download(clusterFile string, username string, password string) error {
if err != nil {
return fmt.Errorf("failed to download admin bundle: %s", err)
}
// Need to initilize state directly, clusterConfig does not have it initilized outside of the phases which we do not use here.
state := &state.State{
Name: clusterConfig.Metadata.Name,
}
stateDir, err := state.GetDir()

bundleDir, err := getBundleDir(clusterConfig.Metadata.Name, username)
if err != nil {
return fmt.Errorf("failed to get state directory for cluster %s: %w", clusterConfig.Metadata.Name, err)
return err
}

err = writeBundle(filepath.Join(stateDir, "bundle", username), bundle)
err = writeBundle(bundleDir, bundle)
if err != nil {
return fmt.Errorf("failed to write admin bundle: %s", err)
}

return nil
}

func getBundleDir(clusterName, username string) (string, error) {
home, err := homedir.Dir()
if err != nil {
return "", err
}
return path.Join(home, constant.StateBaseDir, "cluster", clusterName, "bundle", username), nil
}

func resolveURL(serverURL string) (*url.URL, error) {
url, err := url.Parse(fmt.Sprintf("https://%s", serverURL))
if err != nil {
Expand Down
15 changes: 0 additions & 15 deletions pkg/phase/gather_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ func (p *GatherFacts) Run(conf *api.ClusterConfig) error {
conf.Spec.Ucp.Metadata.ClusterID = swarm.ClusterID(swarmLeader)
}

err = p.validateFacts(conf)
if err != nil {
return err
}
return nil
}

// Validates the facts check out:
// - if swarm is already initialized its cluster ID matches with the one in local state
func (p *GatherFacts) validateFacts(config *api.ClusterConfig) error {
if config.Spec.Ucp.Metadata != nil && config.State.ClusterID != "" && config.Spec.Ucp.Metadata.ClusterID != config.State.ClusterID {
return fmt.Errorf("cluster ID mismatch between local state (%s) and cluster state (%s). This configuration is probably for another cluster", config.State.ClusterID, config.Spec.Ucp.Metadata.ClusterID)
}

log.Infof("Facts check out against local state, safe to confinue")
return nil
}

Expand Down
69 changes: 0 additions & 69 deletions pkg/phase/init_state.go

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/phase/install_ucp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io/ioutil"
"strings"

"github.com/Mirantis/mcc/pkg/swarm"
"github.com/Mirantis/mcc/pkg/ucp"

api "github.com/Mirantis/mcc/pkg/apis/v1beta1"
Expand Down Expand Up @@ -70,6 +69,6 @@ func (p *InstallUCP) Run(config *api.ClusterConfig) error {
return fmt.Errorf("%s: failed to collect existing UCP details: %s", swarmLeader.Address, err.Error())
}
config.Spec.Ucp.Metadata = ucpMeta
config.State.ClusterID = swarm.ClusterID(swarmLeader)

return nil
}
27 changes: 0 additions & 27 deletions pkg/phase/save_state.go

This file was deleted.

92 changes: 0 additions & 92 deletions pkg/state/state.go

This file was deleted.

0 comments on commit c2bd18c

Please sign in to comment.