forked from openshift/installer
/
installconfig.go
55 lines (46 loc) · 1.58 KB
/
installconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package conversion
import (
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types"
"github.com/pkg/errors"
)
// ConvertInstallConfig is modeled after the k8s conversion schemes, which is
// how deprecated values are upconverted.
// This updates the APIVersion to reflect the fact that we've internally
// upconverted.
func ConvertInstallConfig(config *types.InstallConfig) error {
// check that the version is convertible
switch config.APIVersion {
case types.InstallConfigVersion, "v1beta3":
// works
default:
return errors.Errorf("cannot upconvert from version %s", config.APIVersion)
}
ConvertNetworking(config)
config.APIVersion = types.InstallConfigVersion
return nil
}
// ConvertNetworking upconverts deprecated fields in networking
func ConvertNetworking(config *types.InstallConfig) {
if config.Networking == nil {
return
}
netconf := config.Networking
if len(netconf.ClusterNetwork) == 0 {
netconf.ClusterNetwork = netconf.DeprecatedClusterNetworks
}
if len(netconf.ServiceNetwork) == 0 && netconf.DeprecatedServiceCIDR != nil {
netconf.ServiceNetwork = []ipnet.IPNet{*netconf.DeprecatedServiceCIDR}
}
// Convert type to networkType if the latter is missing
if netconf.NetworkType == "" {
netconf.NetworkType = netconf.DeprecatedType
}
// Convert hostSubnetLength to hostPrefix
for i, entry := range netconf.ClusterNetwork {
if entry.HostPrefix == 0 && entry.DeprecatedHostSubnetLength != 0 {
_, size := entry.CIDR.Mask.Size()
netconf.ClusterNetwork[i].HostPrefix = int32(size) - entry.DeprecatedHostSubnetLength
}
}
}