Skip to content

Commit

Permalink
refactor(main): unmount override container
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu committed Oct 29, 2023
1 parent 03a3a3f commit ef76318
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
19 changes: 16 additions & 3 deletions pkg/apply/processor/install.go
Expand Up @@ -140,9 +140,20 @@ func (c *InstallProcessor) PreProcess(cluster *v2.Cluster) error {
imageTypes.Insert(string(v2.AppImage))
}
}
syncMounts := make([]v2.MountImage, 0)
imageIndices := make(map[string]int)
for _, mot := range cluster.Status.Mounts {
if idx, exists := imageIndices[mot.ImageName]; exists {
syncMounts[idx] = *mot.DeepCopy()
} else {
imageIndices[mot.ImageName] = len(syncMounts)
syncMounts = append(syncMounts, mot)
}
}
cluster.Status.Mounts = syncMounts
for _, img := range c.NewImages {
index, mount := cluster.FindImage(img)
var ctrName string
mount := cluster.FindImage(img)
if mount != nil {
if !ForceOverride {
continue
Expand All @@ -168,8 +179,10 @@ func (c *InstallProcessor) PreProcess(cluster *v2.Cluster) error {
return err
}
mount.Env = maps.Merge(mount.Env, c.ExtraEnvs)

cluster.SetMountImage(mount)
if index >= 0 {
cluster.Status.Mounts = append(cluster.Status.Mounts[:index], cluster.Status.Mounts[index+1:]...)
}
cluster.Status.Mounts = append(cluster.Status.Mounts, *mount)
c.NewMounts = append(c.NewMounts, *mount)
}

Expand Down
24 changes: 4 additions & 20 deletions pkg/types/v1beta1/utils.go
Expand Up @@ -117,29 +117,13 @@ func (c *Cluster) GetRootfsImage() *MountImage {
return nil
}

func (c *Cluster) FindImage(name string) *MountImage {
for _, img := range c.Status.Mounts {
func (c *Cluster) FindImage(name string) (int, *MountImage) {
for i, img := range c.Status.Mounts {
if img.ImageName == name {
return &img
}
}
return nil
}

func (c *Cluster) SetMountImage(mount *MountImage) {
if mount == nil {
return
}

if c.Status.Mounts != nil {
for i, img := range c.Status.Mounts {
if img.Name == mount.Name && img.Type == mount.Type {
c.Status.Mounts[i] = *mount.DeepCopy()
return
}
return i, &img
}
c.Status.Mounts = append(c.Status.Mounts, *mount)
}
return -1, nil
}

func (c *Cluster) ReplaceRootfsImage() {
Expand Down

0 comments on commit ef76318

Please sign in to comment.