Skip to content

Commit ecfdaba

Browse files
committed
Add imagebased install config
Signed-off-by: Michail Resvanis <[email protected]>
1 parent cacb639 commit ecfdaba

File tree

2 files changed

+404
-0
lines changed

2 files changed

+404
-0
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
package configimage
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/sirupsen/logrus"
7+
"k8s.io/apimachinery/pkg/util/validation/field"
8+
9+
configv1 "github.com/openshift/api/config/v1"
10+
"github.com/openshift/installer/pkg/asset"
11+
"github.com/openshift/installer/pkg/asset/installconfig"
12+
"github.com/openshift/installer/pkg/types"
13+
"github.com/openshift/installer/pkg/types/none"
14+
"github.com/openshift/installer/pkg/types/validation"
15+
)
16+
17+
const (
18+
// InstallConfigFilename is the file containing the install-config.
19+
InstallConfigFilename = "install-config.yaml"
20+
)
21+
22+
// InstallConfig is an InstallConfig where the default is empty, rather
23+
// than generated from running the survey.
24+
type InstallConfig struct {
25+
installconfig.AssetBase
26+
}
27+
28+
var _ asset.WritableAsset = (*InstallConfig)(nil)
29+
30+
// Dependencies returns all of the dependencies directly needed by an
31+
// InstallConfig asset.
32+
func (i *InstallConfig) Dependencies() []asset.Asset {
33+
// Return no dependencies for the Agent install config, because it is
34+
// optional. We don't need to run the survey if it doesn't exist, since the
35+
// user may have supplied cluster-manifests that fully define the cluster.
36+
return []asset.Asset{}
37+
}
38+
39+
// Generate generates the install-config.yaml file.
40+
func (i *InstallConfig) Generate(parents asset.Parents) error {
41+
// Just generate an empty install config, since we have no dependencies.
42+
return nil
43+
}
44+
45+
// Load returns the installconfig from disk.
46+
func (i *InstallConfig) Load(f asset.FileFetcher) (bool, error) {
47+
found, err := i.LoadFromFile(f)
48+
if found && err == nil {
49+
if err := i.validateInstallConfig(i.Config).ToAggregate(); err != nil {
50+
return false, fmt.Errorf("invalid install-config configuration: %w", err)
51+
}
52+
if err := i.RecordFile(); err != nil {
53+
return false, err
54+
}
55+
}
56+
return found, err
57+
}
58+
59+
func (i *InstallConfig) validateInstallConfig(installConfig *types.InstallConfig) field.ErrorList {
60+
var allErrs field.ErrorList
61+
if err := validation.ValidateInstallConfig(i.Config, true); err != nil {
62+
allErrs = append(allErrs, err...)
63+
}
64+
65+
if err := i.validateSupportedPlatforms(installConfig); err != nil {
66+
allErrs = append(allErrs, err...)
67+
}
68+
69+
if installConfig.FeatureSet != configv1.Default {
70+
allErrs = append(allErrs, field.NotSupported(field.NewPath("FeatureSet"), installConfig.FeatureSet, []string{string(configv1.Default)}))
71+
}
72+
73+
warnUnusedConfig(installConfig)
74+
75+
if err := i.validateSNOConfiguration(installConfig); err != nil {
76+
allErrs = append(allErrs, err...)
77+
}
78+
79+
return allErrs
80+
}
81+
82+
func (i *InstallConfig) validateSupportedPlatforms(installConfig *types.InstallConfig) field.ErrorList {
83+
var allErrs field.ErrorList
84+
85+
fieldPath := field.NewPath("Platform")
86+
87+
if installConfig.Platform.Name() != "" && installConfig.Platform.Name() != none.Name {
88+
allErrs = append(allErrs, field.NotSupported(fieldPath, installConfig.Platform.Name(), []string{none.Name}))
89+
}
90+
91+
return allErrs
92+
}
93+
94+
func (i *InstallConfig) validateSNOConfiguration(installConfig *types.InstallConfig) field.ErrorList {
95+
var allErrs field.ErrorList
96+
var fieldPath *field.Path
97+
98+
controlPlaneReplicas := *installConfig.ControlPlane.Replicas
99+
if installConfig.ControlPlane != nil && controlPlaneReplicas != 1 {
100+
fieldPath = field.NewPath("ControlPlane", "Replicas")
101+
allErrs = append(allErrs, field.Required(fieldPath, fmt.Sprintf("Only Single Node OpenShift (SNO) is supported, total number of ControlPlane.Replicas must be 1. Found %v", controlPlaneReplicas)))
102+
}
103+
104+
var workers int
105+
for _, worker := range installConfig.Compute {
106+
workers += int(*worker.Replicas)
107+
}
108+
if workers != 0 {
109+
fieldPath = field.NewPath("Compute", "Replicas")
110+
allErrs = append(allErrs, field.Required(fieldPath, fmt.Sprintf("Total number of Compute.Replicas must be 0 when ControlPlane.Replicas is 1 for platform %s. Found %v", none.Name, workers)))
111+
}
112+
113+
if installConfig.Networking.NetworkType != "OVNKubernetes" {
114+
fieldPath = field.NewPath("Networking", "NetworkType")
115+
allErrs = append(allErrs, field.Invalid(fieldPath, installConfig.Networking.NetworkType, "Only OVNKubernetes network type is allowed for Single Node OpenShift (SNO) cluster"))
116+
}
117+
118+
machineNetworksCount := len(installConfig.Networking.MachineNetwork)
119+
if machineNetworksCount != 1 {
120+
fieldPath = field.NewPath("Networking", "MachineNetwork")
121+
allErrs = append(allErrs, field.TooMany(fieldPath, machineNetworksCount, 1))
122+
}
123+
124+
return allErrs
125+
}
126+
127+
// ClusterName returns the name of the cluster, or a default name if no
128+
// InstallConfig is supplied.
129+
func (i *InstallConfig) ClusterName() string {
130+
if i.Config != nil && i.Config.ObjectMeta.Name != "" {
131+
return i.Config.ObjectMeta.Name
132+
}
133+
return "imagebased-sno-cluster"
134+
}
135+
136+
// ClusterNamespace returns the namespace of the cluster.
137+
func (i *InstallConfig) ClusterNamespace() string {
138+
if i.Config != nil && i.Config.ObjectMeta.Namespace != "" {
139+
return i.Config.ObjectMeta.Namespace
140+
}
141+
return ""
142+
}
143+
144+
func warnUnusedConfig(installConfig *types.InstallConfig) {
145+
// "Proxyonly" is the default set from generic install config code
146+
if installConfig.AdditionalTrustBundlePolicy != "Proxyonly" {
147+
fieldPath := field.NewPath("AdditionalTrustBundlePolicy")
148+
logrus.Warnf(fmt.Sprintf("%s: %s is ignored", fieldPath, installConfig.AdditionalTrustBundlePolicy))
149+
}
150+
151+
for i, compute := range installConfig.Compute {
152+
if compute.Hyperthreading != "Enabled" {
153+
fieldPath := field.NewPath(fmt.Sprintf("Compute[%d]", i), "Hyperthreading")
154+
logrus.Warnf(fmt.Sprintf("%s: %s is ignored", fieldPath, compute.Hyperthreading))
155+
}
156+
157+
if compute.Platform != (types.MachinePoolPlatform{}) {
158+
fieldPath := field.NewPath(fmt.Sprintf("Compute[%d]", i), "Platform")
159+
logrus.Warnf(fmt.Sprintf("%s is ignored", fieldPath))
160+
}
161+
}
162+
163+
if installConfig.ControlPlane.Hyperthreading != "Enabled" {
164+
fieldPath := field.NewPath("ControlPlane", "Hyperthreading")
165+
logrus.Warnf(fmt.Sprintf("%s: %s is ignored", fieldPath, installConfig.ControlPlane.Hyperthreading))
166+
}
167+
168+
if installConfig.ControlPlane.Platform != (types.MachinePoolPlatform{}) {
169+
fieldPath := field.NewPath("ControlPlane", "Platform")
170+
logrus.Warnf(fmt.Sprintf("%s is ignored", fieldPath))
171+
}
172+
}

0 commit comments

Comments
 (0)