Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/user/aws/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following options are available when using AWS:
An example `install-config.yaml` is shown below. This configuration has been modified to show the customization that is possible via the install config.

```yaml
apiVersion: v1beta3
apiVersion: v1beta4
baseDomain: example.com
controlPlane:
name: master
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/ignition/machine/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestMasterGenerate(t *testing.T) {
},
BaseDomain: "test-domain",
Networking: &types.Networking{
ServiceCIDR: ipnet.MustParseCIDR("10.0.1.0/24"),
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")},
},
Platform: types.Platform{
AWS: &aws.Platform{
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/ignition/machine/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestWorkerGenerate(t *testing.T) {
installConfig := &installconfig.InstallConfig{
Config: &types.InstallConfig{
Networking: &types.Networking{
ServiceCIDR: ipnet.MustParseCIDR("10.0.1.0/24"),
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")},
},
Platform: types.Platform{
AWS: &aws.Platform{
Expand Down
12 changes: 12 additions & 0 deletions pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/conversion"
"github.com/openshift/installer/pkg/types/defaults"
openstackvalidation "github.com/openshift/installer/pkg/types/openstack/validation"
"github.com/openshift/installer/pkg/types/validation"
Expand Down Expand Up @@ -118,6 +119,11 @@ func (a *InstallConfig) Load(f asset.FileFetcher) (found bool, err error) {
}
a.Config = config

// Upconvert any deprecated fields
if err := a.convert(); err != nil {
return false, errors.Wrap(err, "failed to upconvert install config")
}

if err := a.setDefaults(); err != nil {
return false, errors.Wrap(err, "failed to set defaults for install config")
}
Expand All @@ -142,3 +148,9 @@ func (a *InstallConfig) setDefaults() error {
defaults.SetInstallConfigDefaults(a.Config)
return nil
}

// convert converts possibly older versions of the install config to
// the current version, relocating deprecated fields.
func (a *InstallConfig) convert() error {
return conversion.ConvertInstallConfig(a.Config)
}
78 changes: 65 additions & 13 deletions pkg/asset/installconfig/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func TestInstallConfigGenerate_FillsInDefaults(t *testing.T) {
},
BaseDomain: "test-domain",
Networking: &types.Networking{
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
Type: "OpenShiftSDN",
ServiceCIDR: ipnet.MustParseCIDR("172.30.0.0/16"),
ClusterNetworks: []types.ClusterNetworkEntry{
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
NetworkType: "OpenShiftSDN",
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("172.30.0.0/16")},
ClusterNetwork: []types.ClusterNetworkEntry{
{
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
HostSubnetLength: 9,
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
HostPrefix: 23,
},
},
},
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestInstallConfigLoad(t *testing.T) {
{
name: "valid InstallConfig",
data: `
apiVersion: v1beta3
apiVersion: v1beta4
metadata:
name: test-cluster
baseDomain: test-domain
Expand All @@ -124,13 +124,13 @@ pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"authorization value\"}}}"
},
BaseDomain: "test-domain",
Networking: &types.Networking{
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
Type: "OpenShiftSDN",
ServiceCIDR: ipnet.MustParseCIDR("172.30.0.0/16"),
ClusterNetworks: []types.ClusterNetworkEntry{
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
NetworkType: "OpenShiftSDN",
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("172.30.0.0/16")},
ClusterNetwork: []types.ClusterNetworkEntry{
{
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
HostSubnetLength: 9,
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
HostPrefix: 23,
},
},
},
Expand Down Expand Up @@ -179,6 +179,58 @@ metadata:
fetchError: errors.New("fetch failed"),
expectedError: true,
},
{
name: "old valid InstallConfig",
data: `
apiVersion: v1beta3
metadata:
name: test-cluster
baseDomain: test-domain
platform:
aws:
region: us-east-1
pullSecret: "{\"auths\":{\"example.com\":{\"auth\":\"authorization value\"}}}"
network:
type: OpenShiftSDN
`,
expectedFound: true,
expectedConfig: &types.InstallConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: types.InstallConfigVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
BaseDomain: "test-domain",
Networking: &types.Networking{
MachineCIDR: ipnet.MustParseCIDR("10.0.0.0/16"),
NetworkType: "OpenShiftSDN",
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("172.30.0.0/16")},
ClusterNetwork: []types.ClusterNetworkEntry{
{
CIDR: *ipnet.MustParseCIDR("10.128.0.0/14"),
HostPrefix: 23,
},
},
},
ControlPlane: &types.MachinePool{
Name: "master",
Replicas: pointer.Int64Ptr(3),
},
Compute: []types.MachinePool{
{
Name: "worker",
Replicas: pointer.Int64Ptr(3),
},
},
Platform: types.Platform{
AWS: &aws.Platform{
Region: "us-east-1",
},
},
PullSecret: `{"auths":{"example.com":{"auth":"authorization value"}}}`,
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
16 changes: 10 additions & 6 deletions pkg/asset/manifests/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,22 @@ func (no *Networking) Generate(dependencies asset.Parents) error {
netConfig := installConfig.Config.Networking

clusterNet := []configv1.ClusterNetworkEntry{}
if len(netConfig.ClusterNetworks) > 0 {
for _, net := range netConfig.ClusterNetworks {
_, size := net.CIDR.Mask.Size()
if len(netConfig.ClusterNetwork) > 0 {
for _, net := range netConfig.ClusterNetwork {
clusterNet = append(clusterNet, configv1.ClusterNetworkEntry{
CIDR: net.CIDR.String(),
HostPrefix: uint32(size) - uint32(net.HostSubnetLength),
HostPrefix: uint32(net.HostPrefix),
})
}
} else {
return errors.Errorf("ClusterNetworks must be specified")
}

serviceNet := []string{}
for _, sn := range netConfig.ServiceNetwork {
serviceNet = append(serviceNet, sn.String())
}

no.Config = &configv1.Network{
TypeMeta: metav1.TypeMeta{
APIVersion: configv1.SchemeGroupVersion.String(),
Expand All @@ -84,8 +88,8 @@ func (no *Networking) Generate(dependencies asset.Parents) error {
},
Spec: configv1.NetworkSpec{
ClusterNetwork: clusterNet,
ServiceNetwork: []string{netConfig.ServiceCIDR.String()},
NetworkType: netConfig.Type,
ServiceNetwork: serviceNet,
NetworkType: netConfig.NetworkType,
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/tls/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (a *APIServerCertKey) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
dependencies.Get(kubeCA, installConfig)

apiServerAddress, err := cidrhost(installConfig.Config.Networking.ServiceCIDR.IPNet, 1)
apiServerAddress, err := cidrhost(installConfig.Config.Networking.ServiceNetwork[0].IPNet, 1)
Comment thread
squeed marked this conversation as resolved.
Resolved
if err != nil {
return errors.Wrap(err, "failed to get API Server address from InstallConfig")
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func (a *KubeAPIServerServiceNetworkServerCertKey) Generate(dependencies asset.P
ca := &KubeAPIServerServiceNetworkSignerCertKey{}
installConfig := &installconfig.InstallConfig{}
dependencies.Get(ca, installConfig)
serviceAddress, err := cidrhost(installConfig.Config.Networking.ServiceCIDR.IPNet, 1)
serviceAddress, err := cidrhost(installConfig.Config.Networking.ServiceNetwork[0].IPNet, 1)
if err != nil {
return errors.Wrap(err, "failed to get service address for kube-apiserver from InstallConfig")
}
Expand Down
55 changes: 55 additions & 0 deletions pkg/types/conversion/installconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
}
Loading