mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
feat: log more info
This commit is contained in:
@@ -119,22 +119,26 @@ func (d *Options) Main(ctx context.Context, tempContainerConfig *containerConfig
|
||||
|
||||
env, err := util.GetEnv(ctx, d.Factory, d.Namespace, pod)
|
||||
if err != nil {
|
||||
log.Errorf("get env from k8s: %v", err)
|
||||
return err
|
||||
}
|
||||
volume, err := GetVolume(ctx, d.Factory, d.Namespace, pod)
|
||||
if err != nil {
|
||||
log.Errorf("get volume from k8s: %v", err)
|
||||
return err
|
||||
}
|
||||
dns, err := GetDNS(ctx, d.Factory, d.Namespace, pod)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can not get dns conf from pod: %s, err: %v", pod, err)
|
||||
log.Errorf("get dns from k8s: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
mesh.RemoveContainers(templateSpec)
|
||||
runConfigList := ConvertKubeResourceToContainer(d.Namespace, *templateSpec, env, volume, dns)
|
||||
err = mergeDockerOptions(runConfigList, d, tempContainerConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can not fill docker options, err: %v", err)
|
||||
log.Errorf("can not fill docker options, err: %v", err)
|
||||
return err
|
||||
}
|
||||
// check resource
|
||||
var outOfMemory bool
|
||||
@@ -164,6 +168,7 @@ func (d *Options) Main(ctx context.Context, tempContainerConfig *containerConfig
|
||||
var networkID string
|
||||
networkID, err = createKubevpnNetwork(ctx, d.Cli)
|
||||
if err != nil {
|
||||
log.Errorf("create network for %s: %v", d.Workload, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -245,6 +250,7 @@ func (l ConfigList) Run(ctx context.Context, volume map[string][]mount.Mount, cl
|
||||
if index == 0 {
|
||||
_, err := runFirst(ctx, runConfig, cli, dockerCli)
|
||||
if err != nil {
|
||||
log.Errorf("run main container container failed: %v", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -272,20 +278,23 @@ func (l ConfigList) copyToContainer(ctx context.Context, volume []mount.Mount, c
|
||||
for _, v := range volume {
|
||||
target, err := createFolder(ctx, cli, id, v.Source, v.Target)
|
||||
if err != nil {
|
||||
log.Debugf("create folder %s previoully faied, err: %v", target, err)
|
||||
log.Debugf("create folder %s previoully failed, err: %v", target, err)
|
||||
}
|
||||
log.Debugf("from %s to %s", v.Source, v.Target)
|
||||
srcInfo, err := archive.CopyInfoSourcePath(v.Source, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("copy info source path, err: %v", err)
|
||||
log.Errorf("copy info source path, err: %v", err)
|
||||
return err
|
||||
}
|
||||
srcArchive, err := archive.TarResource(srcInfo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tar resource failed, err: %v", err)
|
||||
log.Errorf("tar resource failed, err: %v", err)
|
||||
return err
|
||||
}
|
||||
dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: v.Target})
|
||||
if err != nil {
|
||||
return fmt.Errorf("can not prepare archive copy, err: %v", err)
|
||||
log.Errorf("can not prepare archive copy, err: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = cli.CopyToContainer(ctx, id, dstDir, preparedArchive, types.CopyToContainerOptions{
|
||||
@@ -293,7 +302,7 @@ func (l ConfigList) copyToContainer(ctx context.Context, volume []mount.Mount, c
|
||||
CopyUIDGID: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Info(fmt.Errorf("can not copy %s to container %s:%s, err: %v", v.Source, id, v.Target, err))
|
||||
log.Infof("can not copy %s to container %s:%s, err: %v", v.Source, id, v.Target, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -315,16 +324,20 @@ func createFolder(ctx context.Context, cli *client.Client, id string, src string
|
||||
Cmd: []string{"mkdir", "-p", target},
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("create folder %s previoully failed, err: %v", target, err)
|
||||
return "", err
|
||||
}
|
||||
err = cli.ContainerExecStart(ctx, create.ID, types.ExecStartCheck{})
|
||||
if err != nil {
|
||||
log.Errorf("create folder %s previoully failed, err: %v", target, err)
|
||||
return "", err
|
||||
}
|
||||
log.Infof("wait create folder %s in container %s to be done...", target, id)
|
||||
chanStop := make(chan struct{})
|
||||
wait.Until(func() {
|
||||
inspect, err := cli.ContainerExecInspect(ctx, create.ID)
|
||||
if err != nil {
|
||||
log.Warningf("can not inspect container %s, err: %v", id, err)
|
||||
return
|
||||
}
|
||||
if !inspect.Running {
|
||||
|
||||
@@ -49,6 +49,7 @@ func run(ctx context.Context, runConfig *RunConfig, cli *client.Client, c *comma
|
||||
if needPull {
|
||||
err = util.PullImage(ctx, runConfig.platform, cli, c, config.Image, nil)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to pull image: %s, err: %s", config.Image, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -56,7 +57,7 @@ func run(ctx context.Context, runConfig *RunConfig, cli *client.Client, c *comma
|
||||
var create typescommand.CreateResponse
|
||||
create, err = cli.ContainerCreate(ctx, config, hostConfig, networkConfig, platform, name)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to create container %s, err: %s", name, err)
|
||||
log.Errorf("Failed to create container: %s, err: %s", name, err)
|
||||
return
|
||||
}
|
||||
id = create.ID
|
||||
@@ -69,7 +70,7 @@ func run(ctx context.Context, runConfig *RunConfig, cli *client.Client, c *comma
|
||||
|
||||
err = cli.ContainerStart(ctx, create.ID, types.ContainerStartOptions{})
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to startup container %s: %v", name, err)
|
||||
log.Errorf("failed to startup container %s: %v", name, err)
|
||||
return
|
||||
}
|
||||
log.Infof("Wait container %s to be running...", name)
|
||||
@@ -96,7 +97,7 @@ func run(ctx context.Context, runConfig *RunConfig, cli *client.Client, c *comma
|
||||
}
|
||||
}, time.Second, chanStop)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to wait container to be ready: %v", err)
|
||||
log.Errorf("failed to wait container to be ready: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -167,6 +168,7 @@ func runFirst(ctx context.Context, runConfig *RunConfig, cli *apiclient.Client,
|
||||
NetworkingConfig: runConfig.networkingConfig,
|
||||
}, &runConfig.Options.createOptions)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to create container: %s", err)
|
||||
return "", err
|
||||
}
|
||||
log.Infof("Created container: %s", runConfig.containerName)
|
||||
@@ -251,6 +253,7 @@ func runFirst(ctx context.Context, runConfig *RunConfig, cli *apiclient.Client,
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("Error inspect container: %s", err)
|
||||
return
|
||||
}
|
||||
if inspect.State != nil && (inspect.State.Status == "exited" || inspect.State.Status == "dead" || inspect.State.Dead) {
|
||||
@@ -264,6 +267,7 @@ func runFirst(ctx context.Context, runConfig *RunConfig, cli *apiclient.Client,
|
||||
}
|
||||
}, time.Second, chanStop)
|
||||
if err != nil {
|
||||
log.Errorf("wait container to be ready: %v", err)
|
||||
err = fmt.Errorf("failed to wait container to be ready: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user