[WIP] more kubernetes impl
This commit is contained in:
@@ -76,7 +76,7 @@ func (im *InstanceManager) GetImage(ctx context.Context, imageId string) (*insta
|
||||
}
|
||||
|
||||
if imageLabels.Type != Game {
|
||||
return nil, fmt.Errorf("Image not found")
|
||||
return nil, fmt.Errorf("image not found")
|
||||
}
|
||||
|
||||
image := convertImageInspectToInstanceImage(imageInspect)
|
||||
@@ -93,6 +93,9 @@ func (im *InstanceManager) ListImages(ctx context.Context) ([]instancemanager.Im
|
||||
rawImages, err := im.client.ImageList(ctx, image.ListOptions{
|
||||
Filters: *imageFilters,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
images := make([]instancemanager.Image, len(rawImages))
|
||||
|
||||
@@ -177,6 +180,9 @@ func (im *InstanceManager) ListServers(ctx context.Context) ([]instancemanager.S
|
||||
}
|
||||
|
||||
containers, err := im.containerList(ctx, ContainerLabels{Type: Game}, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, container := range containers {
|
||||
rawLabels, err := json.Marshal(container.Labels)
|
||||
@@ -226,7 +232,7 @@ func (im *InstanceManager) StartServer(ctx context.Context,
|
||||
}
|
||||
|
||||
if server.Running {
|
||||
return fmt.Errorf("Server %s already running", serverId)
|
||||
return fmt.Errorf("server %s already running", serverId)
|
||||
}
|
||||
|
||||
containerLabels := ContainerLabels{
|
||||
@@ -236,7 +242,7 @@ func (im *InstanceManager) StartServer(ctx context.Context,
|
||||
|
||||
volumes := make(map[string]struct{})
|
||||
|
||||
var portMapping nat.PortMap = make(nat.PortMap)
|
||||
portMapping := make(nat.PortMap)
|
||||
image, err := im.GetImage(ctx, imageId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -319,6 +325,9 @@ func (im *InstanceManager) StartServer(ctx context.Context,
|
||||
|
||||
func (im *InstanceManager) StopServer(ctx context.Context, serverId string) error {
|
||||
runningContainers, err := im.containerList(ctx, ContainerLabels{VolumeId: serverId, Type: Game}, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rawContainer := range runningContainers {
|
||||
err = im.client.ContainerStop(ctx, rawContainer.ID, container.StopOptions{})
|
||||
@@ -393,7 +402,7 @@ func (im *InstanceManager) InteractiveTerminal(ctx context.Context, serverId str
|
||||
}
|
||||
|
||||
if !server.Running {
|
||||
return nil, fmt.Errorf("Server %s not running", server.Id)
|
||||
return nil, fmt.Errorf("server %s not running", server.Id)
|
||||
}
|
||||
|
||||
rawContainers, err := im.containerList(ctx, ContainerLabels{VolumeId: serverId, Type: Game}, false)
|
||||
@@ -402,7 +411,7 @@ func (im *InstanceManager) InteractiveTerminal(ctx context.Context, serverId str
|
||||
}
|
||||
|
||||
if len(rawContainers) == 0 {
|
||||
return nil, fmt.Errorf("Server %s not running and wasn't caught", server.Id)
|
||||
return nil, fmt.Errorf("server %s not running and wasn't caught", server.Id)
|
||||
}
|
||||
|
||||
rawContainer := rawContainers[0]
|
||||
@@ -431,7 +440,7 @@ func (im *InstanceManager) ResizeTerminal(ctx context.Context, serverId string,
|
||||
}
|
||||
|
||||
if len(containers) == 0 {
|
||||
return fmt.Errorf("Server %s not running", serverId)
|
||||
return fmt.Errorf("server %s not running", serverId)
|
||||
}
|
||||
|
||||
err = im.client.ContainerResize(context.TODO(), containers[0].ID, container.ResizeOptions{Height: height, Width: width})
|
||||
@@ -449,7 +458,7 @@ func (im *InstanceManager) GetFileBrowser(ctx context.Context, serverId string)
|
||||
}
|
||||
|
||||
if len(containers) == 0 {
|
||||
return nil, fmt.Errorf("File Browser for server %s is not running", serverId)
|
||||
return nil, fmt.Errorf("file Browser for server %s is not running", serverId)
|
||||
}
|
||||
|
||||
rawContainer := containers[0]
|
||||
|
Reference in New Issue
Block a user