|
| 1 | +/* |
| 2 | +Copyright 2022 The Kubernetes Authors All rights reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package host |
| 18 | + |
| 19 | +import ( |
| 20 | + "k8s.io/minikube/pkg/libmachine/auth" |
| 21 | + "k8s.io/minikube/pkg/libmachine/engine" |
| 22 | + "k8s.io/minikube/pkg/libmachine/swarm" |
| 23 | +) |
| 24 | + |
| 25 | +// In the 0.1.0 => 0.2.0 transition, the JSON representation of |
| 26 | +// machines changed from a "flat" to a more "nested" structure |
| 27 | +// for various options and configuration settings. To preserve |
| 28 | +// compatibility with existing machines, these migration functions |
| 29 | +// have been introduced. They preserve backwards compat at the expense |
| 30 | +// of some duplicated information. |
| 31 | + |
| 32 | +// MigrateHostV0ToHostV1 validates host config and modifies if needed |
| 33 | +// this is used for configuration updates |
| 34 | +func MigrateHostV0ToHostV1(hostV0 *V0) *V1 { |
| 35 | + hostV1 := &V1{ |
| 36 | + Driver: hostV0.Driver, |
| 37 | + DriverName: hostV0.DriverName, |
| 38 | + } |
| 39 | + |
| 40 | + hostV1.HostOptions = &OptionsV1{} |
| 41 | + hostV1.HostOptions.EngineOptions = &engine.Options{ |
| 42 | + TLSVerify: true, |
| 43 | + InstallURL: "https://get.docker.com", |
| 44 | + } |
| 45 | + hostV1.HostOptions.SwarmOptions = &swarm.Options{ |
| 46 | + Address: "", |
| 47 | + Discovery: hostV0.SwarmDiscovery, |
| 48 | + Host: hostV0.SwarmHost, |
| 49 | + Master: hostV0.SwarmMaster, |
| 50 | + } |
| 51 | + hostV1.HostOptions.AuthOptions = &AuthOptionsV1{ |
| 52 | + StorePath: hostV0.StorePath, |
| 53 | + CaCertPath: hostV0.CaCertPath, |
| 54 | + CaCertRemotePath: "", |
| 55 | + ServerCertPath: hostV0.ServerCertPath, |
| 56 | + ServerKeyPath: hostV0.ServerKeyPath, |
| 57 | + ClientKeyPath: hostV0.ClientKeyPath, |
| 58 | + ServerCertRemotePath: "", |
| 59 | + ServerKeyRemotePath: "", |
| 60 | + PrivateKeyPath: hostV0.PrivateKeyPath, |
| 61 | + ClientCertPath: hostV0.ClientCertPath, |
| 62 | + } |
| 63 | + |
| 64 | + return hostV1 |
| 65 | +} |
| 66 | + |
| 67 | +// MigrateHostMetadataV0ToHostMetadataV1 fills nested host metadata and modifies if needed |
| 68 | +// this is used for configuration updates |
| 69 | +func MigrateHostMetadataV0ToHostMetadataV1(m *MetadataV0) *Metadata { |
| 70 | + hostMetadata := &Metadata{} |
| 71 | + hostMetadata.DriverName = m.DriverName |
| 72 | + hostMetadata.HostOptions.EngineOptions = &engine.Options{} |
| 73 | + hostMetadata.HostOptions.AuthOptions = &auth.Options{ |
| 74 | + StorePath: m.StorePath, |
| 75 | + CaCertPath: m.CaCertPath, |
| 76 | + CaCertRemotePath: "", |
| 77 | + ServerCertPath: m.ServerCertPath, |
| 78 | + ServerKeyPath: m.ServerKeyPath, |
| 79 | + ClientKeyPath: "", |
| 80 | + ServerCertRemotePath: "", |
| 81 | + ServerKeyRemotePath: "", |
| 82 | + CaPrivateKeyPath: m.PrivateKeyPath, |
| 83 | + ClientCertPath: m.ClientCertPath, |
| 84 | + } |
| 85 | + |
| 86 | + hostMetadata.ConfigVersion = m.ConfigVersion |
| 87 | + |
| 88 | + return hostMetadata |
| 89 | +} |
0 commit comments