Skip to content

Commit

Permalink
Expose a knob to let the user tune default CPU model (#2005)
Browse files Browse the repository at this point in the history
Expose a knob to let the user tune the cluster-wide
default CPU model.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=2096287

Signed-off-by: Simone Tiraboschi <stirabos@redhat.com>

Co-authored-by: Simone Tiraboschi <stirabos@redhat.com>
  • Loading branch information
kubevirt-bot and tiraboschi committed Jun 15, 2022
1 parent 41abeeb commit a059026
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/v1beta1/hyperconverged_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ type HyperConvergedSpec struct {
// +optional
VddkInitImage *string `json:"vddkInitImage,omitempty"`

// DefaultCPUModel defines a cluster default for CPU model: default CPU model is set when vmi doesn't have any cpu model.
// When vmi has cpu model set, then vmi's cpu model is preferred.
// When default cpu model is not set and vmi's cpu model is not set too, host-model will be set.
// Default cpu model can be changed when kubevirt is running.
// +optional
DefaultCPUModel *string `json:"defaulCPUModel,omitempty"`

// ObsoleteCPUs allows avoiding scheduling of VMs for obsolete CPU models
// +optional
ObsoleteCPUs *HyperConvergedObsoleteCPUs `json:"obsoleteCPUs,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/v1beta1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/hco.kubevirt.io_hyperconvergeds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
defaulCPUModel:
description: 'DefaultCPUModel defines a cluster default for CPU model:
default CPU model is set when vmi doesn''t have any cpu model. When
vmi has cpu model set, then vmi''s cpu model is preferred. When
default cpu model is not set and vmi''s cpu model is not set too,
host-model will be set. Default cpu model can be changed when kubevirt
is running.'
type: string
featureGates:
default:
deployTektonTaskResources: false
Expand Down
4 changes: 4 additions & 0 deletions controllers/operands/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ func getKVConfig(hc *hcov1beta1.HyperConverged) (*kubevirtcorev1.KubeVirtConfigu
}
}

if hc.Spec.DefaultCPUModel != nil {
config.CPUModel = *hc.Spec.DefaultCPUModel
}

return config, nil
}

Expand Down
114 changes: 114 additions & 0 deletions controllers/operands/kubevirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"time"

"k8s.io/utils/pointer"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1032,6 +1034,118 @@ Version: 1.2.3`)
})
})

Context("test CPUModel", func() {

It("should propagate the CPUModel from the HC if set", func() {
existKv, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())

testCPUModel := "testValue"
hco.Spec.DefaultCPUModel = pointer.String(testCPUModel)

cl := commonTestUtils.InitClient([]runtime.Object{hco, existKv})
handler := (*genericOperand)(newKubevirtHandler(cl, commonTestUtils.GetScheme()))
res := handler.ensure(req)

Expect(res.UpgradeDone).To(BeFalse())
Expect(res.Updated).To(BeTrue())
Expect(res.Err).ToNot(HaveOccurred())

foundResource := &kubevirtcorev1.KubeVirt{}
Expect(
cl.Get(context.TODO(),
types.NamespacedName{Name: existKv.Name, Namespace: existKv.Namespace},
foundResource),
).ToNot(HaveOccurred())

kvCPUModel := foundResource.Spec.Configuration.CPUModel
Expect(kvCPUModel).ToNot(BeEmpty())
Expect(kvCPUModel).To(Equal(testCPUModel))

})

It("should not propagate the CPUModel from the HC if not set", func() {
existKv, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())

hco.Spec.DefaultCPUModel = nil

cl := commonTestUtils.InitClient([]runtime.Object{hco, existKv})
handler := (*genericOperand)(newKubevirtHandler(cl, commonTestUtils.GetScheme()))
res := handler.ensure(req)

Expect(res.UpgradeDone).To(BeFalse())
Expect(res.Updated).To(BeFalse())
Expect(res.Err).ToNot(HaveOccurred())

foundResource := &kubevirtcorev1.KubeVirt{}
Expect(
cl.Get(context.TODO(),
types.NamespacedName{Name: existKv.Name, Namespace: existKv.Namespace},
foundResource),
).ToNot(HaveOccurred())

kvCPUModel := foundResource.Spec.Configuration.CPUModel
Expect(kvCPUModel).To(BeEmpty())

})

It("should update the CPUModel from the HC", func() {
existKv, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())

oldKVCPUmodel := "oldKVCPUmodel"
existKv.Spec.Configuration.CPUModel = oldKVCPUmodel

testCPUModel := "testValue"
hco.Spec.DefaultCPUModel = &testCPUModel

cl := commonTestUtils.InitClient([]runtime.Object{hco, existKv})

By("Check before reconciling", func() {
foundResource := &kubevirtcorev1.KubeVirt{}
Expect(
cl.Get(context.TODO(),
types.NamespacedName{Name: existKv.Name, Namespace: existKv.Namespace},
foundResource),
).To(BeNil())

kvCPUModel := foundResource.Spec.Configuration.CPUModel
Expect(kvCPUModel).ToNot(BeNil())
Expect(kvCPUModel).To(Equal(oldKVCPUmodel))
})

handler := (*genericOperand)(newKubevirtHandler(cl, commonTestUtils.GetScheme()))
res := handler.ensure(req)

Expect(res.UpgradeDone).To(BeFalse())
Expect(res.Updated).To(BeTrue())
Expect(res.Err).ToNot(HaveOccurred())

foundResource := &kubevirtcorev1.KubeVirt{}
Expect(
cl.Get(context.TODO(),
types.NamespacedName{Name: existKv.Name, Namespace: existKv.Namespace},
foundResource),
).ToNot(HaveOccurred())

By("Check after reconciling", func() {
foundResource := &kubevirtcorev1.KubeVirt{}
Expect(
cl.Get(context.TODO(),
types.NamespacedName{Name: existKv.Name, Namespace: existKv.Namespace},
foundResource),
).To(BeNil())

kvCPUModel := foundResource.Spec.Configuration.CPUModel
Expect(kvCPUModel).ToNot(BeNil())
Expect(kvCPUModel).To(Equal(testCPUModel))
})

})

})

Context("Test node placement", func() {

getClusterInfo := hcoutil.GetClusterInfo
Expand Down
8 changes: 8 additions & 0 deletions deploy/crds/hco00.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
defaulCPUModel:
description: 'DefaultCPUModel defines a cluster default for CPU model:
default CPU model is set when vmi doesn''t have any cpu model. When
vmi has cpu model set, then vmi''s cpu model is preferred. When
default cpu model is not set and vmi''s cpu model is not set too,
host-model will be set. Default cpu model can be changed when kubevirt
is running.'
type: string
featureGates:
default:
deployTektonTaskResources: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
defaulCPUModel:
description: 'DefaultCPUModel defines a cluster default for CPU model:
default CPU model is set when vmi doesn''t have any cpu model. When
vmi has cpu model set, then vmi''s cpu model is preferred. When
default cpu model is not set and vmi''s cpu model is not set too,
host-model will be set. Default cpu model can be changed when kubevirt
is running.'
type: string
featureGates:
default:
deployTektonTaskResources: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
defaulCPUModel:
description: 'DefaultCPUModel defines a cluster default for CPU model:
default CPU model is set when vmi doesn''t have any cpu model. When
vmi has cpu model set, then vmi''s cpu model is preferred. When
default cpu model is not set and vmi''s cpu model is not set too,
host-model will be set. Default cpu model can be changed when kubevirt
is running.'
type: string
featureGates:
default:
deployTektonTaskResources: false
Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ HyperConvergedSpec defines the desired state of HyperConverged
| resourceRequirements | ResourceRequirements describes the resource requirements for the operand workloads. | *[OperandResourceRequirements](#operandresourcerequirements) | | false |
| scratchSpaceStorageClass | Override the storage class used for scratch space during transfer operations. The scratch space storage class is determined in the following order: value of scratchSpaceStorageClass, if that doesn't exist, use the default storage class, if there is no default storage class, use the storage class of the DataVolume, if no storage class specified, use no storage class for scratch space | *string | | false |
| vddkInitImage | VDDK Init Image eventually used to import VMs from external providers | *string | | false |
| defaulCPUModel | DefaultCPUModel defines a cluster default for CPU model: default CPU model is set when vmi doesn't have any cpu model. When vmi has cpu model set, then vmi's cpu model is preferred. When default cpu model is not set and vmi's cpu model is not set too, host-model will be set. Default cpu model can be changed when kubevirt is running. | *string | | false |
| obsoleteCPUs | ObsoleteCPUs allows avoiding scheduling of VMs for obsolete CPU models | *[HyperConvergedObsoleteCPUs](#hyperconvergedobsoletecpus) | | false |
| commonTemplatesNamespace | CommonTemplatesNamespace defines namespace in which common templates will be deployed. It overrides the default openshift namespace. | *string | | false |
| storageImport | StorageImport contains configuration for importing containerized data | *[StorageImportConfig](#storageimportconfig) | | false |
Expand Down
13 changes: 13 additions & 0 deletions docs/cluster-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,19 @@ spec:
minCPUModel: "Penryn"
```

## Default CPU model configuration
User can specify a cluster-wide default CPU model: default CPU model is set when vmi doesn't have any cpu model.
When vmi has cpu model set, then vmi's cpu model is preferred. When default cpu model is not set and vmi's cpu model is not set too, host-model will be set.
Default cpu model can be changed when kubevirt is running.
```yaml
apiVersion: hco.kubevirt.io/v1beta1
kind: HyperConverged
metadata:
name: kubevirt-hyperconverged
spec:
defaultCPUModel: "EPYC"
```

## Common templates namespace
User can specify namespace in which common templates will be deployed. This will override default `openshift` namespace.
```yaml
Expand Down

0 comments on commit a059026

Please sign in to comment.