feat(region): support change container configuration

This commit is contained in:
Zexi Li
2024-03-27 11:25:40 +08:00
parent a7cfc8168b
commit 77ead6271b
6 changed files with 42 additions and 16 deletions
+5
View File
@@ -92,6 +92,11 @@ type ContainerCreateInput struct {
SkipTask bool `json:"skip_task"`
}
type ContainerUpdateInput struct {
apis.VirtualResourceBaseUpdateInput
Spec ContainerSpec `json:"spec"`
}
type ContainerListInput struct {
apis.VirtualResourceListInput
}
+4 -10
View File
@@ -429,16 +429,6 @@ func (p *SPodDriver) OnDeleteGuestFinalCleanup(ctx context.Context, guest *model
return guest.DeleteAllDisksInDB(ctx, userCred)
}
func (p *SPodDriver) RequestSyncConfigOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
// do nothing, call next stage
task.ScheduleRun(nil)
return nil
}
func (p *SPodDriver) RequestChangeVmConfig(ctx context.Context, guest *models.SGuest, task taskman.ITask, instanceType string, vcpuCount, cpuSockets, vmemSize int64) error {
return p.newUnsupportOperationError("change config")
}
func (p *SPodDriver) RequestRebuildRootDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
// do nothing, call next stage
return p.newUnsupportOperationError("rebuild root")
@@ -463,3 +453,7 @@ func (p *SPodDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
func (p *SPodDriver) IsSupportFloppy(guest *models.SGuest) (bool, error) {
return false, nil
}
func (p *SPodDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
return []string{api.VM_READY}, nil
}
+19 -1
View File
@@ -62,7 +62,7 @@ type SContainer struct {
// GuestId is also the pod id
GuestId string `width:"36" charset:"ascii" create:"required" list:"user" index:"true"`
// Spec stores all container running options
Spec *api.ContainerSpec `length:"long" create:"required" list:"user"`
Spec *api.ContainerSpec `length:"long" create:"required" list:"user" update:"user"`
}
func (m *SContainerManager) CreateOnPod(
@@ -253,6 +253,24 @@ func (c *SContainer) StartCreateTask(ctx context.Context, userCred mcclient.Toke
return task.ScheduleRun(nil)
}
func (c *SContainer) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.ContainerUpdateInput) (*api.ContainerUpdateInput, error) {
if c.GetStatus() != api.CONTAINER_STATUS_EXITED {
return nil, httperrors.NewInvalidStatusError("current status %s is not %s", c.GetStatus(), api.CONTAINER_STATUS_EXITED)
}
baseInput, err := c.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, input.VirtualResourceBaseUpdateInput)
if err != nil {
return input, errors.Wrap(err, "SVirtualResourceBase.ValidateUpdateData")
}
input.VirtualResourceBaseUpdateInput = baseInput
if err := GetContainerManager().ValidateSpec(ctx, userCred, &input.Spec, c.GetPod()); err != nil {
return nil, errors.Wrap(err, "validate spec")
}
return input, nil
}
func (c *SContainer) GetPod() *SGuest {
return GuestManager.FetchGuestById(c.GuestId)
}
+1 -1
View File
@@ -923,7 +923,7 @@ func (m *SGuestManager) GuestSync(ctx context.Context, params interface{}) (json
if !ok {
return nil, hostutils.ParamsError
}
guest, _ := m.GetKVMServer(syncParams.Sid)
guest, _ := m.GetServer(syncParams.Sid)
if syncParams.Body.Contains("desc") {
guestDesc := new(desc.SGuestDesc)
if err := syncParams.Body.Unmarshal(guestDesc, "desc"); err != nil {
+12 -4
View File
@@ -342,7 +342,7 @@ func (s *sPodGuestInstance) getPortMapping(pm *computeapi.PodPortMapping) (*runt
usedPorts, ok := otherPorts[pm.Protocol]
if ok {
if usedPorts.Has(*pm.HostPort) {
return nil, errors.Wrapf(err, "%s host_port %d is already used", pm.Protocol, *pm.HostPort)
return nil, errors.Errorf("%s host_port %d is already used", pm.Protocol, *pm.HostPort)
}
}
return runtimePm, nil
@@ -367,7 +367,6 @@ func (s *sPodGuestInstance) getPortMapping(pm *computeapi.PodPortMapping) (*runt
}
func (s *sPodGuestInstance) getCgroupParent() string {
// return fmt.Sprintf("/cloudpods/%s", s.GetId())
return "/cloudpods"
}
@@ -455,7 +454,7 @@ func (s *sPodGuestInstance) stopPod(ctx context.Context, timeout int64) error {
return errors.Wrapf(err, "umount pod volumes")
}
if timeout == 0 {
timeout = 15
timeout = 5
}
ctx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second)
@@ -511,6 +510,16 @@ func (s *sPodGuestInstance) PostLoad(m *SGuestManager) error {
return nil
}
func (s *sPodGuestInstance) SyncConfig(ctx context.Context, guestDesc *desc.SGuestDesc, fwOnly bool) (jsonutils.JSONObject, error) {
if err := SaveDesc(s, guestDesc); err != nil {
return nil, errors.Wrap(err, "SaveDesc")
}
if err := SaveLiveDesc(s, s.Desc); err != nil {
return nil, errors.Wrap(err, "SaveLiveDesc")
}
return nil, nil
}
func (s *sPodGuestInstance) getContainerCRIId(ctrId string) (string, error) {
ctr := s.getContainer(ctrId)
if ctr == nil {
@@ -790,7 +799,6 @@ func (s *sPodGuestInstance) getDefaultCPUPeriod() int64 {
}
func (s *sPodGuestInstance) createContainer(ctx context.Context, userCred mcclient.TokenCredential, ctrId string, input *hostapi.ContainerCreateInput) (string, error) {
log.Infof("=====container input: %s", jsonutils.Marshal(input).PrettyString())
podCfg, err := s.getPodSandboxConfig()
if err != nil {
return "", errors.Wrap(err, "getPodSandboxConfig")
+1
View File
@@ -48,6 +48,7 @@ type GuestRuntimeInstance interface {
LoadDesc() error
PostLoad(m *SGuestManager) error
SyncConfig(ctx context.Context, guestDesc *desc.SGuestDesc, fwOnly bool) (jsonutils.JSONObject, error)
}
type sBaseGuestInstance struct {