Skip to content

Commit 7400a77

Browse files
Add some small support for forward compatible configuration mistakes
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
1 parent 43543d1 commit 7400a77

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

libmachine/host/migrate.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func getMigratedHostMetadata(data []byte) (*HostMetadata, error) {
3838

3939
func MigrateHost(h *Host, data []byte) (*Host, bool, error) {
4040
var (
41+
migrationNeeded = false
4142
migrationPerformed = false
4243
hostV1 *HostV1
4344
hostV2 *HostV2
@@ -61,7 +62,29 @@ func MigrateHost(h *Host, data []byte) (*Host, bool, error) {
6162
if err := json.Unmarshal(data, &h); err != nil {
6263
return nil, migrationPerformed, fmt.Errorf("Error unmarshalling most recent host version: %s", err)
6364
}
65+
66+
// We are config version 3, so we definitely should have a
67+
// RawDriver field. However, it's possible some might use
68+
// older clients after already migrating, so check if it exists
69+
// and create one if not. The following code is an (admittedly
70+
// fragile) attempt to account for the fact that the above code
71+
// to forbid loading from future clients was not introduced
72+
// sooner.
73+
if h.RawDriver == nil {
74+
log.Warn("It looks like you have used an older Docker Machine binary to interact with hosts after using a 0.5.0 binary.")
75+
log.Warn("Please be advised that doing so can result in erratic behavior due to migrated configuration settings.")
76+
log.Warn("Machine will attempt to re-migrate the configuration settings, but safety is not guaranteed.")
77+
migrationNeeded = true
78+
79+
// Treat the data as config version 1, even though it
80+
// says "latest".
81+
migratedHostMetadata.ConfigVersion = 1
82+
}
6483
} else {
84+
migrationNeeded = true
85+
}
86+
87+
if migrationNeeded {
6588
migrationPerformed = true
6689
for h.ConfigVersion = migratedHostMetadata.ConfigVersion; h.ConfigVersion < version.ConfigVersion; h.ConfigVersion++ {
6790
log.Debug("Migrating to config v%d", h.ConfigVersion)
@@ -96,9 +119,6 @@ func MigrateHost(h *Host, data []byte) (*Host, bool, error) {
96119
h = MigrateHostV2ToHostV3(hostV2, data, globalStorePath)
97120
h.Driver = RawDataDriver{driver, nil}
98121
case 3:
99-
// Everything for migration to plugin model is
100-
// already set up in previous block, so no need
101-
// to do anything here.
102122
}
103123
}
104124
}

0 commit comments

Comments
 (0)