Skip to content

Commit e8338fb

Browse files
committed
OCPBUGS-34416: Validate OnHostMaintenance and ConfidentialCompute
** The OnHostMaintenance and ConfidentialCompute values were not validated. ** The OnHostMaintenance value should be set to Terminate when ConfidentialCompute is Enabled, otherwise the value can be Terminate or Migrate. ** Added default values to the MachinePool for both fields.
1 parent acd8593 commit e8338fb

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ spec:
474474
GCP
475475
properties:
476476
confidentialCompute:
477+
default: Disabled
477478
description: ConfidentialCompute Defines whether the instance
478479
should have confidential compute enabled. If enabled OnHostMaintenance
479480
is required to be set to "Terminate". If omitted, the
@@ -484,6 +485,7 @@ spec:
484485
- Disabled
485486
type: string
486487
onHostMaintenance:
488+
default: Migrate
487489
description: OnHostMaintenance determines the behavior when
488490
a maintenance event occurs that might cause the instance
489491
to reboot. Allowed values are "Migrate" and "Terminate".
@@ -1385,6 +1387,7 @@ spec:
13851387
GCP
13861388
properties:
13871389
confidentialCompute:
1390+
default: Disabled
13881391
description: ConfidentialCompute Defines whether the instance
13891392
should have confidential compute enabled. If enabled OnHostMaintenance
13901393
is required to be set to "Terminate". If omitted, the platform
@@ -1395,6 +1398,7 @@ spec:
13951398
- Disabled
13961399
type: string
13971400
onHostMaintenance:
1401+
default: Migrate
13981402
description: OnHostMaintenance determines the behavior when
13991403
a maintenance event occurs that might cause the instance
14001404
to reboot. Allowed values are "Migrate" and "Terminate".
@@ -3012,6 +3016,7 @@ spec:
30123016
their own platform configuration.
30133017
properties:
30143018
confidentialCompute:
3019+
default: Disabled
30153020
description: ConfidentialCompute Defines whether the instance
30163021
should have confidential compute enabled. If enabled OnHostMaintenance
30173022
is required to be set to "Terminate". If omitted, the platform
@@ -3022,6 +3027,7 @@ spec:
30223027
- Disabled
30233028
type: string
30243029
onHostMaintenance:
3030+
default: Migrate
30253031
description: OnHostMaintenance determines the behavior when
30263032
a maintenance event occurs that might cause the instance
30273033
to reboot. Allowed values are "Migrate" and "Terminate".

pkg/types/gcp/machinepools.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
package gcp
22

3+
// FeatureSwitch indicates whether the feature is enabled or disabled.
4+
type FeatureSwitch string
5+
6+
// OnHostMaintenanceType indicates the setting for the OnHostMaintenance feature, but this is only
7+
// applicable when ConfidentialCompute is Enabled.
8+
type OnHostMaintenanceType string
9+
10+
const (
11+
// EnabledFeature indicates that the feature is configured as enabled.
12+
EnabledFeature FeatureSwitch = "Enabled"
13+
14+
// DisabledFeature indicates that the feature is configured as disabled.
15+
DisabledFeature FeatureSwitch = "Disabled"
16+
17+
// OnHostMaintenanceMigrate is the default, and it indicates that the OnHostMaintenance feature is set to Migrate.
18+
OnHostMaintenanceMigrate OnHostMaintenanceType = "Migrate"
19+
20+
// OnHostMaintenanceTerminate indicates that the OnHostMaintenance feature is set to Terminate.
21+
OnHostMaintenanceTerminate OnHostMaintenanceType = "Terminate"
22+
)
23+
324
// MachinePool stores the configuration for a machine pool installed on GCP.
425
type MachinePool struct {
526
// Zones is list of availability zones that can be used.
@@ -38,13 +59,17 @@ type MachinePool struct {
3859
// OnHostMaintenance determines the behavior when a maintenance event occurs that might cause the instance to reboot.
3960
// Allowed values are "Migrate" and "Terminate".
4061
// If omitted, the platform chooses a default, which is subject to change over time, currently that default is "Migrate".
62+
// +kubebuilder:default="Migrate"
63+
// +default="Migrate"
4164
// +kubebuilder:validation:Enum=Migrate;Terminate;
4265
// +optional
4366
OnHostMaintenance string `json:"onHostMaintenance,omitempty"`
4467

4568
// ConfidentialCompute Defines whether the instance should have confidential compute enabled.
4669
// If enabled OnHostMaintenance is required to be set to "Terminate".
4770
// If omitted, the platform chooses a default, which is subject to change over time, currently that default is false.
71+
// +kubebuilder:default="Disabled"
72+
// +default="Disabled"
4873
// +kubebuilder:validation:Enum=Enabled;Disabled
4974
// +optional
5075
ConfidentialCompute string `json:"confidentialCompute,omitempty"`

pkg/types/gcp/validation/machinepool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func ValidateMachinePool(platform *gcp.Platform, p *gcp.MachinePool, fldPath *fi
3636
}
3737
}
3838

39+
if p.ConfidentialCompute == string(gcp.EnabledFeature) && p.OnHostMaintenance != string(gcp.OnHostMaintenanceTerminate) {
40+
allErrs = append(allErrs, field.Invalid(fldPath.Child("OnHostMaintenance"), p.OnHostMaintenance, "OnHostMaintenace must be set to Terminate when ConfidentialCompute is Enabled"))
41+
}
42+
3943
for i, tag := range p.Tags {
4044
if tag == "" {
4145
allErrs = append(allErrs, field.Invalid(fldPath.Child("tags").Index(i), tag, fmt.Sprintf("tag can not be empty")))

pkg/types/gcp/validation/machinepool_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ func TestValidateMachinePool(t *testing.T) {
8585
},
8686
expected: `^test-path\.diskSizeGB: Invalid value: 66000: exceeding maximum GCP disk size limit, must be below 65536$`,
8787
},
88+
{
89+
name: "enable confidential compute with correct on host maintenance",
90+
pool: &gcp.MachinePool{
91+
ConfidentialCompute: string(gcp.EnabledFeature),
92+
OnHostMaintenance: string(gcp.OnHostMaintenanceTerminate),
93+
},
94+
},
95+
{
96+
name: "enable confidential compute with incorrect on host maintenance",
97+
pool: &gcp.MachinePool{
98+
ConfidentialCompute: string(gcp.EnabledFeature),
99+
OnHostMaintenance: string(gcp.OnHostMaintenanceMigrate),
100+
},
101+
expected: `test-path.OnHostMaintenance: Invalid value: "Migrate": OnHostMaintenace must be set to Terminate when ConfidentialCompute is Enabled`,
102+
},
88103
}
89104
for _, tc := range cases {
90105
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)