提交 6c08fedf 编写于 作者: M Medya Gh

remove cyclic depdenecy and make cluster pkg smaller

上级 72b17439
......@@ -163,7 +163,7 @@ func DeleteProfiles(profiles []*pkg_config.Profile) []error {
err := deleteProfile(profile)
if err != nil {
mm, loadErr := cluster.LoadMachine(profile.Name)
mm, loadErr := machine.LoadMachine(profile.Name)
if !profile.IsValid() || (loadErr != nil || !mm.IsValid()) {
invalidProfileDeletionErrs := deleteInvalidProfile(profile)
......@@ -263,7 +263,7 @@ func deleteInvalidProfile(profile *pkg_config.Profile) []error {
}
}
pathToMachine := cluster.MachinePath(profile.Name, localpath.MiniPath())
pathToMachine := machine.MachinePath(profile.Name, localpath.MiniPath())
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
err := os.RemoveAll(pathToMachine)
if err != nil {
......
......@@ -26,9 +26,9 @@ import (
"github.com/otiai10/copy"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
)
// except returns a list of strings, minus the excluded ones
......@@ -117,7 +117,7 @@ func TestDeleteProfile(t *testing.T) {
t.Errorf("Profile folder of profile \"%s\" was not deleted", profile.Name)
}
pathToMachine := cluster.MachinePath(profile.Name, localpath.MiniPath())
pathToMachine := machine.MachinePath(profile.Name, localpath.MiniPath())
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
t.Errorf("Profile folder of profile \"%s\" was not deleted", profile.Name)
}
......
......@@ -27,6 +27,7 @@ import (
"sync"
"time"
"github.com/docker/machine/libmachine/state"
"github.com/golang/glog"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
......@@ -38,6 +39,7 @@ import (
"golang.org/x/sync/errgroup"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
......@@ -95,7 +97,6 @@ func CacheImages(images []string, cacheDir string) error {
func LoadImages(cmd command.Runner, images []string, cacheDir string) error {
glog.Infof("LoadImages start: %s", images)
defer glog.Infof("LoadImages end")
var g errgroup.Group
// Load profile cluster config from file
cc, err := config.Load()
......@@ -121,7 +122,7 @@ func LoadImages(cmd command.Runner, images []string, cacheDir string) error {
return nil
}
// CacheAndLoadImages caches and loads images
// CacheAndLoadImages caches and loads images to all profiles
func CacheAndLoadImages(images []string) error {
if err := CacheImages(images, constants.ImageCacheDir); err != nil {
return err
......@@ -131,20 +132,34 @@ func CacheAndLoadImages(images []string) error {
return err
}
defer api.Close()
cc, err := config.Load()
profiles, _, err := config.ListProfiles() // need to load image to all profiles
if err != nil {
return err
return errors.Wrap(err, "list profiles")
}
h, err := api.Load(cc.Name)
if err != nil {
return err
}
runner, err := CommandRunner(h)
if err != nil {
return err
for _, p := range profiles { // adding images to all the profiles
pName := p.Name // capture the loop variable
status, err := cluster.GetHostStatus(api, pName)
if err != nil {
glog.Warningf("skipping loading cache for profile %s", pName)
glog.Errorf("error getting status for %s: %v", pName, err)
continue // try next machine
}
if status == state.Running.String() { // the not running hosts will load on next start
h, err := api.Load(pName)
if err != nil {
return err
}
cr, err := CommandRunner(h)
if err != nil {
return err
}
err = LoadImages(cr, images, constants.ImageCacheDir)
if err != nil {
glog.Warningf("Failed to load cached images for profile %s. make sure the profile is running. %v", pName, err)
}
}
}
return LoadImages(runner, images, constants.ImageCacheDir)
return err
}
// # ParseReference cannot have a : in the directory path
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
package machine
import (
"io/ioutil"
......@@ -23,8 +23,8 @@ import (
"github.com/docker/machine/libmachine/host"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
)
// Machine contains information about a machine
......@@ -85,12 +85,12 @@ func ListMachines(miniHome ...string) (validMachines []*Machine, inValidMachines
// LoadMachine loads a machine or throws an error if the machine could not be loadedG
func LoadMachine(name string) (*Machine, error) {
api, err := machine.NewAPIClient()
api, err := NewAPIClient()
if err != nil {
return nil, err
}
h, err := CheckIfHostExistsAndLoad(api, name)
h, err := cluster.CheckIfHostExistsAndLoad(api, name)
if err != nil {
return nil, err
}
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
package machine
import (
"io/ioutil"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册