Skip to content

Commit

Permalink
Upgrade machine: use logrus logger
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose authored and praveenkumar committed Feb 1, 2021
1 parent 04e4d39 commit 162e13a
Show file tree
Hide file tree
Showing 39 changed files with 1,294 additions and 467 deletions.
9 changes: 3 additions & 6 deletions cmd/crc/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,9 @@ func newMachine() machine.Client {
}

func newMachineWithConfig(config crcConfig.Storage) machine.Client {
return machine.NewClient(
constants.DefaultName,
isDebugLog(),
network.ParseMode(config.Get(cmdConfig.NetworkMode).AsString()),
config.Get(cmdConfig.EnableClusterMonitoring).AsBool(),
)
networkMode := network.ParseMode(config.Get(cmdConfig.NetworkMode).AsString())
enableMonitoring := config.Get(cmdConfig.EnableClusterMonitoring).AsBool()
return machine.NewClient(constants.DefaultName, networkMode, enableMonitoring)
}

func addForceFlag(cmd *cobra.Command) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cheggaaa/pb/v3 v3.0.5
github.com/code-ready/clicumber v0.0.0-20200728062640-1203dda97f67
github.com/code-ready/gvisor-tap-vsock v0.0.0-20201105131011-9258bacc7a6c
github.com/code-ready/machine v0.0.0-20201202090222-9558ae8c05b9
github.com/code-ready/machine v0.0.0-20210122113819-281ccfbb4566
github.com/cucumber/godog v0.9.0
github.com/cucumber/messages-go/v10 v10.0.3
github.com/docker/docker v1.13.1 // indirect
Expand Down Expand Up @@ -43,7 +43,7 @@ require (
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/bugsnag/bugsnag-go v1.5.1/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/bugsnag-go v1.5.3/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/caddyserver/caddy v1.0.3/go.mod h1:G+ouvOY32gENkJC+jhgl62TyhvqEsFaDiZ4uw0RzP1E=
Expand Down Expand Up @@ -164,8 +163,8 @@ github.com/code-ready/clicumber v0.0.0-20200728062640-1203dda97f67 h1:C+EVPWw8sj
github.com/code-ready/clicumber v0.0.0-20200728062640-1203dda97f67/go.mod h1:ZPZUcYGpv/FQGnwakUuhiHP9x/IIcU2SKbn8xPe4ROc=
github.com/code-ready/gvisor-tap-vsock v0.0.0-20201105131011-9258bacc7a6c h1:j8S82O8ovWK7nmNJAQf+dFH/RCtXCZneBi33nx2fMPo=
github.com/code-ready/gvisor-tap-vsock v0.0.0-20201105131011-9258bacc7a6c/go.mod h1:tySPFyGlPN7nyc3u8RH2FAhRDC9JvbQVzJBOrlRJKgU=
github.com/code-ready/machine v0.0.0-20201202090222-9558ae8c05b9 h1:fUAQ1rYNefX/QPuU0HL7qxc1bURY3qDq/gca+NxiXt8=
github.com/code-ready/machine v0.0.0-20201202090222-9558ae8c05b9/go.mod h1:g30jKsf0FV9yJjsqZFAuFzVxwJE2h5cqDXSuMUV1G/U=
github.com/code-ready/machine v0.0.0-20210122113819-281ccfbb4566 h1:zBDinebc2kFq99UNTmLmTRfgxcxC6YieKQuXDRCljzw=
github.com/code-ready/machine v0.0.0-20210122113819-281ccfbb4566/go.mod h1:4JgMqho7KuxFifYCIi7cKVmh4yA2l0QHOPftv9f5PNc=
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
github.com/container-storage-interface/spec v1.2.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/containerd/cgroups v0.0.0-20181219155423-39b18af02c41/go.mod h1:X9rLEHIqSf/wfK8NsPqxJmeZgW4pcfzdXITDrUSJ6uI=
Expand Down Expand Up @@ -520,7 +519,6 @@ github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6/go.mod h1:RmeVYf9XrPRbRc3XIx0gLYA8qOFvNoPOfaEZduRlEp4=
github.com/ishidawataru/sctp v0.0.0-20190723014705-7c296d48a2b5/go.mod h1:DM4VvS+hD/kDi1U1QsX2fnZowwBhqD0Dk3bRPKF/Oc8=
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ=
github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
Expand Down Expand Up @@ -863,8 +861,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
Expand Down Expand Up @@ -940,7 +938,6 @@ golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -1341,6 +1338,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v0.0.0-20190624233834-05ebafbffc79/go.mod h1:R//lfYlUuTOTfblYI3lGoAAAebUdzjvbmQsuB7Ykd90=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
Expand Down
4 changes: 1 addition & 3 deletions pkg/crc/machine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ type Client interface {

type client struct {
name string
debug bool
networkMode network.Mode
monitoringEnabled bool
}

func NewClient(name string, debug bool, networkMode network.Mode, monitoringEnabled bool) Client {
func NewClient(name string, networkMode network.Mode, monitoringEnabled bool) Client {
return &client{
name: name,
debug: debug,
networkMode: networkMode,
monitoringEnabled: monitoringEnabled,
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ func (client *client) GetConsoleURL() (*ConsoleResult, error) {
// Here we are only checking if the VM exist and not the status of the VM.
// We might need to improve and use crc status logic, only
// return if the Openshift is running as part of status.
libMachineAPIClient, cleanup, err := createLibMachineClient(client.debug)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return nil, errors.Wrap(err, "Cannot initialize libmachine")
}
host, err := libMachineAPIClient.Load(client.name)
if err != nil {
return nil, errors.Wrap(err, "Cannot load machine")
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import (
)

func (client *client) Delete() error {
libMachineAPIClient, cleanup, err := createLibMachineClient(false)
libMachineAPIClient, cleanup := createLibMachineClient()
defer logging.BackupLogFile()
defer cleanup()
if err != nil {
return errors.Wrap(err, "Cannot initialize libmachine")
}
host, err := libMachineAPIClient.Load(client.name)

if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package machine
import "fmt"

func (client *client) Exists() (bool, error) {
libMachineAPIClient, cleanup, err := createLibMachineClient(client.debug)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return false, err
}
exists, err := libMachineAPIClient.Exists(client.name)
if err != nil {
return false, fmt.Errorf("Error checking if the host exists: %s", err)
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package machine
import "github.com/pkg/errors"

func (client *client) IP() (string, error) {
libMachineAPIClient, cleanup, err := createLibMachineClient(client.debug)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return "", errors.Wrap(err, "Cannot initialize libmachine")
}
host, err := libMachineAPIClient.Load(client.name)

if err != nil {
Expand Down
29 changes: 2 additions & 27 deletions pkg/crc/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package machine
import (
"encoding/base64"
"fmt"
"os"

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/pkg/crc/machine/bundle"
"github.com/code-ready/crc/pkg/crc/network"
"github.com/code-ready/crc/pkg/libmachine"
"github.com/code-ready/crc/pkg/libmachine/host"
"github.com/code-ready/machine/libmachine/drivers"
"github.com/code-ready/machine/libmachine/log"
)

func getClusterConfig(bundleInfo *bundle.CrcBundleInfo) (*ClusterConfig, error) {
Expand Down Expand Up @@ -52,18 +49,11 @@ func getBundleMetadataFromDriver(driver drivers.Driver) (string, *bundle.CrcBund
return bundleName, metadata, err
}

func createLibMachineClient(debug bool) (*libmachine.Client, func(), error) {
logfile, err := setMachineLogging(debug)
if err != nil {
return nil, func() {}, err
}
func createLibMachineClient() (*libmachine.Client, func()) {
client := libmachine.NewClient(constants.MachineBaseDir)
return client, func() {
client.Close()
if logfile != nil {
logfile.Close()
}
}, nil
}
}

func getSSHPort(vsockNetwork bool) int {
Expand All @@ -80,21 +70,6 @@ func getIP(h *host.Host, vsockNetwork bool) (string, error) {
return h.Driver.GetIP()
}

func setMachineLogging(logs bool) (*os.File, error) {
if !logs {
log.SetDebug(true)
logfile, err := logging.OpenLogFile(constants.LogFilePath)
if err != nil {
return nil, err
}
log.SetOutWriter(logfile)
log.SetErrWriter(logfile)
return logfile, nil
}
log.SetDebug(true)
return nil, nil
}

func getProxyConfig(baseDomainName string) (*network.ProxyConfig, error) {
proxy, err := network.NewProxyConfig()
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/poweroff.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package machine
import "github.com/pkg/errors"

func (client *client) PowerOff() error {
libMachineAPIClient, cleanup, err := createLibMachineClient(false)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return errors.Wrap(err, "Cannot initialize libmachine")
}

host, err := libMachineAPIClient.Load(client.name)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ func (client *client) Start(startConfig StartConfig) (*StartResult, error) {

var crcBundleMetadata *bundle.CrcBundleInfo

libMachineAPIClient, cleanup, err := createLibMachineClient(client.debug)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return nil, errors.Wrap(err, "Cannot initialize libmachine")
}

// Pre-VM start
var host *host.Host
Expand Down
7 changes: 2 additions & 5 deletions pkg/crc/machine/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import (
)

func (client *client) Status() (*ClusterStatusResult, error) {
libMachineAPIClient, cleanup, err := createLibMachineClient(false)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return nil, errors.Wrap(err, "Cannot initialize libmachine")
}

_, err = libMachineAPIClient.Exists(client.name)
_, err := libMachineAPIClient.Exists(client.name)
if err != nil {
return nil, errors.Wrap(err, "Cannot check if machine exists")
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import (
)

func (client *client) Stop() (state.State, error) {
libMachineAPIClient, cleanup, err := createLibMachineClient(client.debug)
libMachineAPIClient, cleanup := createLibMachineClient()
defer cleanup()
if err != nil {
return state.None, errors.Wrap(err, "Cannot initialize libmachine")
}
host, err := libMachineAPIClient.Load(client.name)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/crcsuite/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type VMCommandCollector struct {
}

func (collector *VMCommandCollector) Collect(w Writer) error {
client := machine.NewClient(constants.DefaultName, true, network.DefaultMode, false)
client := machine.NewClient(constants.DefaultName, network.DefaultMode, false)
ip, err := client.IP()
if err != nil {
return err
Expand All @@ -198,7 +198,7 @@ type ContainerLogCollector struct {
}

func (collector *ContainerLogCollector) Collect(w Writer) error {
client := machine.NewClient(constants.DefaultName, true, network.DefaultMode, false)
client := machine.NewClient(constants.DefaultName, network.DefaultMode, false)
ip, err := client.IP()
if err != nil {
return err
Expand Down

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

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

Loading

0 comments on commit 162e13a

Please sign in to comment.