-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OnHostMaintenance and ConfidentialCompute to GCPMachineSpec
Add manual conversion for ConfidentialCompute and OnHostMaintenance Add webhook to validate that OnHostMaintenance is set to TERMINATE if ConfidentialCompute is Enabled Add webhook to validate that the instanceType belongs to a machine series that support confidentail computing Update machine.go to set instance.ConfidentialCompute and instance.OnHostMaintenance according to GCPMachine.Spec
- Loading branch information
Showing
18 changed files
with
516 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGCPMachine_ValidateCreate(t *testing.T) { | ||
g := NewWithT(t) | ||
confidentialComputeEnabled := ConfidentialComputePolicyEnabled | ||
onHostMaintenanceTerminate := HostMaintenancePolicyTerminate | ||
onHostMaintenanceMigrate := HostMaintenancePolicyMigrate | ||
tests := []struct { | ||
name string | ||
*GCPMachine | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "GCPMachined with OnHostMaintenance set to Terminate - valid", | ||
GCPMachine: &GCPMachine{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
OnHostMaintenance: &onHostMaintenanceTerminate, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "GCPMachined with ConfidentialCompute enabled and OnHostMaintenance set to Terminate - valid", | ||
GCPMachine: &GCPMachine{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
OnHostMaintenance: &onHostMaintenanceTerminate, | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "GCPMachined with ConfidentialCompute enabled and OnHostMaintenance set to Migrate - invalid", | ||
GCPMachine: &GCPMachine{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
OnHostMaintenance: &onHostMaintenanceMigrate, | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "GCPMachined with ConfidentialCompute enabled and default OnHostMaintenance (Migrate) - invalid", | ||
GCPMachine: &GCPMachine{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "GCPMachined with ConfidentialCompute enabled and unsupported instance type - invalid", | ||
GCPMachine: &GCPMachine{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "e2-standard-4", | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
OnHostMaintenance: &onHostMaintenanceTerminate, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
test := test | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
err := test.GCPMachine.ValidateCreate() | ||
if test.wantErr { | ||
g.Expect(err).To(HaveOccurred()) | ||
} else { | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGCPMachineTemplate_ValidateCreate(t *testing.T) { | ||
g := NewWithT(t) | ||
confidentialComputeEnabled := ConfidentialComputePolicyEnabled | ||
onHostMaintenanceTerminate := HostMaintenancePolicyTerminate | ||
onHostMaintenanceMigrate := HostMaintenancePolicyMigrate | ||
tests := []struct { | ||
name string | ||
template *GCPMachineTemplate | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "GCPMachineTemplate with OnHostMaintenance set to Terminate - valid", | ||
template: &GCPMachineTemplate{ | ||
Spec: GCPMachineTemplateSpec{ | ||
Template: GCPMachineTemplateResource{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
OnHostMaintenance: &onHostMaintenanceTerminate, | ||
}}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "GCPMachineTemplate with ConfidentialCompute enabled and OnHostMaintenance set to Terminate - valid", | ||
template: &GCPMachineTemplate{ | ||
Spec: GCPMachineTemplateSpec{ | ||
Template: GCPMachineTemplateResource{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
OnHostMaintenance: &onHostMaintenanceTerminate, | ||
}}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "GCPMachineTemplate with ConfidentialCompute enabled and OnHostMaintenance set to Migrate - invalid", | ||
template: &GCPMachineTemplate{ | ||
Spec: GCPMachineTemplateSpec{ | ||
Template: GCPMachineTemplateResource{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
OnHostMaintenance: &onHostMaintenanceMigrate, | ||
}}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "GCPMachineTemplate with ConfidentialCompute enabled and default OnHostMaintenance (Migrate) - invalid", | ||
template: &GCPMachineTemplate{ | ||
Spec: GCPMachineTemplateSpec{ | ||
Template: GCPMachineTemplateResource{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "n2d-standard-4", | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
}}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "GCPMachineTemplate with ConfidentialCompute enabled and unsupported instance type - invalid", | ||
template: &GCPMachineTemplate{ | ||
Spec: GCPMachineTemplateSpec{ | ||
Template: GCPMachineTemplateResource{ | ||
Spec: GCPMachineSpec{ | ||
InstanceType: "e2-standard-4", | ||
ConfidentialCompute: &confidentialComputeEnabled, | ||
OnHostMaintenance: &onHostMaintenanceTerminate, | ||
}}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
test := test | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
err := test.template.ValidateCreate() | ||
if test.wantErr { | ||
g.Expect(err).To(HaveOccurred()) | ||
} else { | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.