mirror of https://github.com/portainer/portainer
				
				
				
			Revert "refactor(docker): strongly type snapshot [EE-3256]"
This reverts commit 0b2217a916.
			
			
				pull/6991/head
			
			
		
							parent
							
								
									0b2217a916
								
							
						
					
					
						commit
						75d854e6ad
					
				| 
						 | 
				
			
			@ -4,7 +4,6 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"github.com/docker/docker/api/types/volume"
 | 
			
		||||
	"github.com/portainer/portainer/api/dataservices/errors"
 | 
			
		||||
 | 
			
		||||
	portainer "github.com/portainer/portainer/api"
 | 
			
		||||
| 
						 | 
				
			
			@ -207,18 +206,18 @@ func (m *Migrator) updateVolumeResourceControlToDB32() error {
 | 
			
		|||
 | 
			
		||||
		endpointDockerID, err := snapshotutils.FetchDockerID(snapshot)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Printf("[WARN] [bolt,migrator,v31] [message: failed fetching environment docker id] [err: %s]", err)
 | 
			
		||||
			log.Printf("[WARN] [database,migrator,v31] [message: failed fetching environment docker id] [err: %s]", err)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		volumesData := snapshot.SnapshotRaw.Volumes
 | 
			
		||||
		if volumesData.Volumes == nil {
 | 
			
		||||
			log.Println("[DEBUG] [volume migration] [message: no volume data found]")
 | 
			
		||||
			continue
 | 
			
		||||
		if volumesData, done := snapshot.SnapshotRaw.Volumes.(map[string]interface{}); done {
 | 
			
		||||
			if volumesData["Volumes"] == nil {
 | 
			
		||||
				log.Println("[DEBUG] [volume migration] [message: no volume data found]")
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			findResourcesToUpdateForDB32(endpointDockerID, volumesData, toUpdate, volumeResourceControls)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		findResourcesToUpdateToDB32(endpointDockerID, volumesData, toUpdate, volumeResourceControls)
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, resourceControl := range volumeResourceControls {
 | 
			
		||||
| 
						 | 
				
			
			@ -241,11 +240,18 @@ func (m *Migrator) updateVolumeResourceControlToDB32() error {
 | 
			
		|||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func findResourcesToUpdateToDB32(dockerID string, volumesData volume.VolumeListOKBody, toUpdate map[portainer.ResourceControlID]string, volumeResourceControls map[string]*portainer.ResourceControl) {
 | 
			
		||||
	volumes := volumesData.Volumes
 | 
			
		||||
	for _, volume := range volumes {
 | 
			
		||||
		volumeName := volume.Name
 | 
			
		||||
		createTime := volume.CreatedAt
 | 
			
		||||
func findResourcesToUpdateForDB32(dockerID string, volumesData map[string]interface{}, toUpdate map[portainer.ResourceControlID]string, volumeResourceControls map[string]*portainer.ResourceControl) {
 | 
			
		||||
	volumes := volumesData["Volumes"].([]interface{})
 | 
			
		||||
	for _, volumeMeta := range volumes {
 | 
			
		||||
		volume := volumeMeta.(map[string]interface{})
 | 
			
		||||
		volumeName, nameExist := volume["Name"].(string)
 | 
			
		||||
		if !nameExist {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		createTime, createTimeExist := volume["CreatedAt"].(string)
 | 
			
		||||
		if !createTimeExist {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		oldResourceID := fmt.Sprintf("%s%s", volumeName, createTime)
 | 
			
		||||
		resourceControl, ok := volumeResourceControls[oldResourceID]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,103 +70,10 @@
 | 
			
		|||
          "DockerSnapshotRaw": {
 | 
			
		||||
            "Containers": null,
 | 
			
		||||
            "Images": null,
 | 
			
		||||
            "Info": {
 | 
			
		||||
              "Architecture": "",
 | 
			
		||||
              "BridgeNfIp6tables": false,
 | 
			
		||||
              "BridgeNfIptables": false,
 | 
			
		||||
              "CPUSet": false,
 | 
			
		||||
              "CPUShares": false,
 | 
			
		||||
              "CgroupDriver": "",
 | 
			
		||||
              "ContainerdCommit": {
 | 
			
		||||
                "Expected": "",
 | 
			
		||||
                "ID": ""
 | 
			
		||||
              },
 | 
			
		||||
              "Containers": 0,
 | 
			
		||||
              "ContainersPaused": 0,
 | 
			
		||||
              "ContainersRunning": 0,
 | 
			
		||||
              "ContainersStopped": 0,
 | 
			
		||||
              "CpuCfsPeriod": false,
 | 
			
		||||
              "CpuCfsQuota": false,
 | 
			
		||||
              "Debug": false,
 | 
			
		||||
              "DefaultRuntime": "",
 | 
			
		||||
              "DockerRootDir": "",
 | 
			
		||||
              "Driver": "",
 | 
			
		||||
              "DriverStatus": null,
 | 
			
		||||
              "ExperimentalBuild": false,
 | 
			
		||||
              "GenericResources": null,
 | 
			
		||||
              "HttpProxy": "",
 | 
			
		||||
              "HttpsProxy": "",
 | 
			
		||||
              "ID": "",
 | 
			
		||||
              "IPv4Forwarding": false,
 | 
			
		||||
              "Images": 0,
 | 
			
		||||
              "IndexServerAddress": "",
 | 
			
		||||
              "InitBinary": "",
 | 
			
		||||
              "InitCommit": {
 | 
			
		||||
                "Expected": "",
 | 
			
		||||
                "ID": ""
 | 
			
		||||
              },
 | 
			
		||||
              "Isolation": "",
 | 
			
		||||
              "KernelMemory": false,
 | 
			
		||||
              "KernelMemoryTCP": false,
 | 
			
		||||
              "KernelVersion": "",
 | 
			
		||||
              "Labels": null,
 | 
			
		||||
              "LiveRestoreEnabled": false,
 | 
			
		||||
              "LoggingDriver": "",
 | 
			
		||||
              "MemTotal": 0,
 | 
			
		||||
              "MemoryLimit": false,
 | 
			
		||||
              "NCPU": 0,
 | 
			
		||||
              "NEventsListener": 0,
 | 
			
		||||
              "NFd": 0,
 | 
			
		||||
              "NGoroutines": 0,
 | 
			
		||||
              "Name": "",
 | 
			
		||||
              "NoProxy": "",
 | 
			
		||||
              "OSType": "",
 | 
			
		||||
              "OSVersion": "",
 | 
			
		||||
              "OomKillDisable": false,
 | 
			
		||||
              "OperatingSystem": "",
 | 
			
		||||
              "PidsLimit": false,
 | 
			
		||||
              "Plugins": {
 | 
			
		||||
                "Authorization": null,
 | 
			
		||||
                "Log": null,
 | 
			
		||||
                "Network": null,
 | 
			
		||||
                "Volume": null
 | 
			
		||||
              },
 | 
			
		||||
              "RegistryConfig": null,
 | 
			
		||||
              "RuncCommit": {
 | 
			
		||||
                "Expected": "",
 | 
			
		||||
                "ID": ""
 | 
			
		||||
              },
 | 
			
		||||
              "Runtimes": null,
 | 
			
		||||
              "SecurityOptions": null,
 | 
			
		||||
              "ServerVersion": "",
 | 
			
		||||
              "SwapLimit": false,
 | 
			
		||||
              "Swarm": {
 | 
			
		||||
                "ControlAvailable": false,
 | 
			
		||||
                "Error": "",
 | 
			
		||||
                "LocalNodeState": "",
 | 
			
		||||
                "NodeAddr": "",
 | 
			
		||||
                "NodeID": "",
 | 
			
		||||
                "RemoteManagers": null
 | 
			
		||||
              },
 | 
			
		||||
              "SystemTime": "",
 | 
			
		||||
              "Warnings": null
 | 
			
		||||
            },
 | 
			
		||||
            "Info": null,
 | 
			
		||||
            "Networks": null,
 | 
			
		||||
            "Version": {
 | 
			
		||||
              "ApiVersion": "",
 | 
			
		||||
              "Arch": "",
 | 
			
		||||
              "GitCommit": "",
 | 
			
		||||
              "GoVersion": "",
 | 
			
		||||
              "Os": "",
 | 
			
		||||
              "Platform": {
 | 
			
		||||
                "Name": ""
 | 
			
		||||
              },
 | 
			
		||||
              "Version": ""
 | 
			
		||||
            },
 | 
			
		||||
            "Volumes": {
 | 
			
		||||
              "Volumes": null,
 | 
			
		||||
              "Warnings": null
 | 
			
		||||
            }
 | 
			
		||||
            "Version": null,
 | 
			
		||||
            "Volumes": null
 | 
			
		||||
          },
 | 
			
		||||
          "DockerVersion": "20.10.13",
 | 
			
		||||
          "HealthyContainerCount": 0,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -188,17 +188,24 @@ func (service *Service) snapshotEndpoints() error {
 | 
			
		|||
 | 
			
		||||
// FetchDockerID fetches info.Swarm.Cluster.ID if environment(endpoint) is swarm and info.ID otherwise
 | 
			
		||||
func FetchDockerID(snapshot portainer.DockerSnapshot) (string, error) {
 | 
			
		||||
	info := snapshot.SnapshotRaw.Info
 | 
			
		||||
 | 
			
		||||
	if !snapshot.Swarm {
 | 
			
		||||
		return info.ID, nil
 | 
			
		||||
	info, done := snapshot.SnapshotRaw.Info.(map[string]interface{})
 | 
			
		||||
	if !done {
 | 
			
		||||
		return "", errors.New("failed getting snapshot info")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	swarmInfo := info.Swarm
 | 
			
		||||
	if swarmInfo.Cluster == nil {
 | 
			
		||||
	if !snapshot.Swarm {
 | 
			
		||||
		return info["ID"].(string), nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if info["Swarm"] == nil {
 | 
			
		||||
		return "", errors.New("swarm environment is missing swarm info snapshot")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	swarmInfo := info["Swarm"].(map[string]interface{})
 | 
			
		||||
	if swarmInfo["Cluster"] == nil {
 | 
			
		||||
		return "", errors.New("swarm environment is missing cluster info snapshot")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	clusterInfo := swarmInfo.Cluster
 | 
			
		||||
	return clusterInfo.ID, nil
 | 
			
		||||
	clusterInfo := swarmInfo["Cluster"].(map[string]interface{})
 | 
			
		||||
	return clusterInfo["ID"].(string), nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,6 @@ import (
 | 
			
		|||
	"io"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/docker/docker/api/types"
 | 
			
		||||
	"github.com/docker/docker/api/types/volume"
 | 
			
		||||
	gittypes "github.com/portainer/portainer/api/git/types"
 | 
			
		||||
	v1 "k8s.io/api/core/v1"
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -193,14 +191,13 @@ type (
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	// DockerSnapshotRaw represents all the information related to a snapshot as returned by the Docker API
 | 
			
		||||
 | 
			
		||||
	DockerSnapshotRaw struct {
 | 
			
		||||
		Containers []types.Container       `json:"Containers"`
 | 
			
		||||
		Volumes    volume.VolumeListOKBody `json:"Volumes"`
 | 
			
		||||
		Networks   []types.NetworkResource `json:"Networks"`
 | 
			
		||||
		Images     []types.ImageSummary    `json:"Images"`
 | 
			
		||||
		Info       types.Info              `json:"Info"`
 | 
			
		||||
		Version    types.Version           `json:"Version"`
 | 
			
		||||
		Containers interface{} `json:"Containers"`
 | 
			
		||||
		Volumes    interface{} `json:"Volumes"`
 | 
			
		||||
		Networks   interface{} `json:"Networks"`
 | 
			
		||||
		Images     interface{} `json:"Images"`
 | 
			
		||||
		Info       interface{} `json:"Info"`
 | 
			
		||||
		Version    interface{} `json:"Version"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// EdgeGroup represents an Edge group
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue