-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 Add flag to reserve memory #3130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ spec: | |
Defaults to the eponymous property value in the template from which the | ||
virtual machine is cloned. | ||
format: int64 | ||
type: integer | ||
type: integer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra space |
||
network: | ||
description: Network is the network configuration for this machine's | ||
VM. | ||
|
@@ -1042,6 +1042,14 @@ spec: | |
virtual machine is cloned. | ||
format: int64 | ||
type: integer | ||
memoryReservationLockedToMax: | ||
description: |- | ||
MemoryReservationLockedToMax is a flag that indicates | ||
whether or not the memory resource reservation for this virtual | ||
machine will always be equal to the virtual machine's memory size. | ||
Defaults to the eponymous property value in the template from which | ||
the virtual machine is cloned. | ||
type: boolean | ||
network: | ||
description: Network is the network configuration for this machine's | ||
VM. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- ../base | ||
patches: | ||
- target: | ||
kind: VSphereMachineTemplate | ||
patch: |- | ||
- op: add | ||
path: /spec/template/spec/memoryReservationLockedToMax | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be enough to add this to an existing test to not increase the runtime There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it then make sense to add default variable in env package:
or directly set value in generators:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's just add it to one test, not to all :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reviewed the code, and it seems that if I want to integrate this with an existing test, like the |
||
value: true | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,115 @@ | ||||||
/* | ||||||
Copyright 2022 The Kubernetes Authors. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
new file |
||||||
|
||||||
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 e2e | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
"fmt" | ||||||
|
||||||
. "github.com/onsi/ginkgo/v2" | ||||||
. "github.com/onsi/gomega" | ||||||
"github.com/vmware/govmomi/object" | ||||||
"github.com/vmware/govmomi/vim25/mo" | ||||||
corev1 "k8s.io/api/core/v1" | ||||||
"sigs.k8s.io/cluster-api/test/framework" | ||||||
"sigs.k8s.io/cluster-api/test/framework/clusterctl" | ||||||
. "sigs.k8s.io/cluster-api/test/framework/ginkgoextensions" | ||||||
"sigs.k8s.io/cluster-api/util" | ||||||
) | ||||||
|
||||||
type MemoryReservationLockedSpecInput struct { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been following the naming conventions from other tests, such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes |
||||||
InfraClients | ||||||
Global GlobalInput | ||||||
SpecName string | ||||||
Namespace *corev1.Namespace | ||||||
// Allows to inject a function to be run after test namespace is created. | ||||||
// If not specified, this is a no-op. | ||||||
PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) | ||||||
} | ||||||
|
||||||
var _ = Describe("Set memory reservation locked to max on VMs", func() { | ||||||
const specName = "memory-reservation-locked" | ||||||
Setup(specName, func(testSpecificSettingsGetter func() testSettings) { | ||||||
var ( | ||||||
namespace *corev1.Namespace | ||||||
) | ||||||
|
||||||
BeforeEach(func() { | ||||||
Expect(bootstrapClusterProxy).NotTo(BeNil(), "BootstrapClusterProxy can't be nil") | ||||||
namespace = setupSpecNamespace(specName, testSpecificSettingsGetter().PostNamespaceCreatedFunc) | ||||||
}) | ||||||
|
||||||
AfterEach(func() { | ||||||
cleanupSpecNamespace(namespace) | ||||||
}) | ||||||
|
||||||
It("Creates a workload cluster whose VMs have memory reservation locked set to true", func() { | ||||||
VerfiyMemoryReservationLockToMax(ctx, MemoryReservationLockedSpecInput{ | ||||||
SpecName: specName, | ||||||
Namespace: namespace, | ||||||
InfraClients: InfraClients{ | ||||||
Client: vsphereClient, | ||||||
RestClient: restClient, | ||||||
Finder: vsphereFinder, | ||||||
}, | ||||||
Global: GlobalInput{ | ||||||
BootstrapClusterProxy: bootstrapClusterProxy, | ||||||
ClusterctlConfigPath: testSpecificSettingsGetter().ClusterctlConfigPath, | ||||||
E2EConfig: e2eConfig, | ||||||
ArtifactFolder: artifactFolder, | ||||||
}, | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
func VerfiyMemoryReservationLockToMax(ctx context.Context, input MemoryReservationLockedSpecInput) { | ||||||
var ( | ||||||
specName = input.SpecName | ||||||
namespace = input.Namespace | ||||||
clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) | ||||||
) | ||||||
|
||||||
clusterName := fmt.Sprintf("%s-%s", specName, util.RandomString(6)) | ||||||
By("Creating a workload cluster") | ||||||
configCluster := defaultConfigCluster(clusterName, namespace.Name, specName, 1, 1, input.Global) | ||||||
|
||||||
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ | ||||||
ClusterProxy: input.Global.BootstrapClusterProxy, | ||||||
ConfigCluster: configCluster, | ||||||
WaitForClusterIntervals: input.Global.E2EConfig.GetIntervals(specName, "wait-cluster"), | ||||||
WaitForControlPlaneIntervals: input.Global.E2EConfig.GetIntervals(specName, "wait-control-plane"), | ||||||
WaitForMachineDeployments: input.Global.E2EConfig.GetIntervals(specName, "wait-worker-nodes"), | ||||||
}, clusterResources) | ||||||
|
||||||
Byf("Fetching the VSphereVM objects for the cluster %s", clusterName) | ||||||
vms := getVSphereVMsForCluster(clusterName, namespace.Name) | ||||||
|
||||||
By("Verifying memory reservation locked to max is set to true") | ||||||
for _, vm := range vms.Items { | ||||||
vmObj, err := input.Finder.VirtualMachine(ctx, vm.Name) | ||||||
Expect(err).ToNot(HaveOccurred(), "expected to find VM %s", vm.Name) | ||||||
Expect(getMemoryReservationLockedToMaxFromObj(vmObj)).To(Equal(true), "expected memory reservation locked to max to be set to true") | ||||||
Check failure on line 106 in test/e2e/memory_reservation_locked_test.go
|
||||||
} | ||||||
} | ||||||
|
||||||
func getMemoryReservationLockedToMaxFromObj(vmObj *object.VirtualMachine) *bool { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
var virtualMachine mo.VirtualMachine | ||||||
Expect(vmObj.Properties(ctx, vmObj.Reference(), []string{"config.memoryReservationLockedToMax"}, &virtualMachine)).To(Succeed()) | ||||||
Expect(virtualMachine.Config.MemoryReservationLockedToMax).ToNot(BeEmpty()) | ||||||
return virtualMachine.Config.MemoryReservationLockedToMax | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update it everywhere.