Skip to content

Commit

Permalink
Add DownwardMetrics feature gate (#2837)
Browse files Browse the repository at this point in the history
It adds the `DownwardMetrics` feature gate to HCO. It allows users to
disable this feature in KubeVirt.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
Co-authored-by: Javier Cano Cano <jcanocan@redhat.com>
  • Loading branch information
kubevirt-bot and jcanocan authored Mar 12, 2024
1 parent 6989ba9 commit 08fb7f4
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 20 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/hyperconverged_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ type VirtualMachineOptions struct {
// by default yet.
// +k8s:openapi-gen=true
type HyperConvergedFeatureGates struct {
// Allow to expose a limited set of host metrics to guests.
// +optional
DownwardMetrics *bool `json:"downwardMetrics,omitempty"`

// Allow migrating a virtual machine with CPU host-passthrough mode. This should be
// enabled only when the Cluster is homogeneous from CPU HW perspective doc here
// +optional
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.

4 changes: 4 additions & 0 deletions config/crd/bases/hco.kubevirt.io_hyperconvergeds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ spec:
default: false
description: Disable mediated devices handling on KubeVirt
type: boolean
downwardMetrics:
description: Allow to expose a limited set of host metrics to
guests.
type: boolean
enableApplicationAwareQuota:
default: false
description: EnableApplicationAwareQuota if true, enables the
Expand Down
12 changes: 8 additions & 4 deletions controllers/operands/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ const (
// Allow assigning host devices to virtual machines
kvHostDevicesGate = "HostDevices"

// Add downwardMetrics volume to expose a limited set of host metrics to guests
kvDownwardMetricsGate = "DownwardMetrics"

// Expand disks to the largest size
kvExpandDisksGate = "ExpandDisks"

Expand Down Expand Up @@ -129,7 +126,6 @@ var (
kvExpandDisksGate,
kvGPUGate,
kvHostDevicesGate,
kvDownwardMetricsGate,
kvNUMA,
kvVMExportGate,
kvDisableCustomSELinuxPolicyGate,
Expand Down Expand Up @@ -162,6 +158,7 @@ var (

// KubeVirt feature gates that are exposed in HCO API
const (
kvDownwardMetrics = "DownwardMetrics"
kvWithHostPassthroughCPU = "WithHostPassthroughCPU"
kvRoot = "Root"
kvDisableMDevConfig = "DisableMDEVConfiguration"
Expand Down Expand Up @@ -751,6 +748,10 @@ func hcoConfig2KvConfig(hcoConfig hcov1beta1.HyperConvergedConfig, infrastructur
func getFeatureGateChecks(featureGates *hcov1beta1.HyperConvergedFeatureGates) []string {
fgs := make([]string, 0, 2)

if featureGates.DownwardMetrics == nil || *featureGates.DownwardMetrics {
fgs = append(fgs, kvDownwardMetrics)
}

if featureGates.WithHostPassthroughCPU != nil && *featureGates.WithHostPassthroughCPU {
fgs = append(fgs, kvWithHostPassthroughCPU)
}
Expand Down Expand Up @@ -880,8 +881,11 @@ func getMandatoryKvFeatureGates(isKVMEmulation bool) []string {
// get list of feature gates or KV FG list
func getKvFeatureGateList(fgs *hcov1beta1.HyperConvergedFeatureGates) []string {
checks := getFeatureGateChecks(fgs)

res := make([]string, 0, len(checks)+len(mandatoryKvFeatureGates)+1)

res = append(res, mandatoryKvFeatureGates...)

res = append(res, checks...)

return res
Expand Down
75 changes: 59 additions & 16 deletions controllers/operands/kubevirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
)

var _ = Describe("KubeVirt Operand", func() {
// DownwardMetrics FG is not listed on any of these lists, but it is enabled by default
const enabledByDefaultFeatureGates = 1

var (
basicNumFgOnOpenshift = len(hardCodeKvFgs) + len(sspConditionKvFgs)
)
Expand Down Expand Up @@ -217,7 +220,7 @@ Version: 1.2.3`)
Expect(foundResource.Namespace).To(Equal(expectedResource.Namespace))

Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(basicNumFgOnOpenshift + 1))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(basicNumFgOnOpenshift + 1 + enabledByDefaultFeatureGates))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(
hardCodeKvFgs,
))
Expand Down Expand Up @@ -427,7 +430,7 @@ Version: 1.2.3`)
foundResource),
).ToNot(HaveOccurred())
Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(basicNumFgOnOpenshift + 1))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(basicNumFgOnOpenshift + 1 + enabledByDefaultFeatureGates))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(
hardCodeKvFgs,
))
Expand Down Expand Up @@ -1797,10 +1800,49 @@ Version: 1.2.3`)

Expect(existingResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
fgList := getKvFeatureGateList(&hco.Spec.FeatureGates)
Expect(fgList).To(HaveLen(basicNumFgOnOpenshift))
Expect(fgList).To(HaveLen(basicNumFgOnOpenshift + enabledByDefaultFeatureGates))
Expect(fgList).Should(ContainElements(hardCodeKvFgs))
Expect(fgList).Should(ContainElements(sspConditionKvFgs))
})

It("should add the DownwardMetrics if feature gate DownwardMetrics is true in HyperConverged CR", func() {
hco.Spec.FeatureGates = hcov1beta1.HyperConvergedFeatureGates{
DownwardMetrics: ptr.To(true),
}

existingResource, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())
By("KV CR should contain the DownwardMetrics feature gate", func() {
Expect(existingResource.Spec.Configuration.DeveloperConfiguration).NotTo(BeNil())
Expect(existingResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElement(kvDownwardMetrics))
})
})

It("should add the DownwardMetrics if feature gate DownwardMetrics is not in HyperConverged CR", func() {
hco.Spec.FeatureGates = hcov1beta1.HyperConvergedFeatureGates{
DownwardMetrics: nil,
}

existingResource, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())
By("KV CR should contain the DownwardMetrics feature gate", func() {
Expect(existingResource.Spec.Configuration.DeveloperConfiguration).NotTo(BeNil())
Expect(existingResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElement(kvDownwardMetrics))
})
})

It("should not add the DownwardMetrics if feature gate DownwardMetrics is set to false in HyperConverged CR", func() {
hco.Spec.FeatureGates = hcov1beta1.HyperConvergedFeatureGates{
DownwardMetrics: ptr.To(false),
}

existingResource, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())
By("KV CR should not contain the DownwardMetrics feature gate", func() {
Expect(existingResource.Spec.Configuration.DeveloperConfiguration).NotTo(BeNil())
Expect(existingResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).ToNot(ContainElement(kvDownwardMetrics))
})
})
})

Context("test feature gates in KV handler", func() {
Expand Down Expand Up @@ -1876,7 +1918,7 @@ Version: 1.2.3`)
mandatoryKvFeatureGates = getMandatoryKvFeatureGates(false)
Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
fgList := getKvFeatureGateList(&hco.Spec.FeatureGates)
Expect(fgList).To(HaveLen(basicNumFgOnOpenshift))
Expect(fgList).To(HaveLen(basicNumFgOnOpenshift + enabledByDefaultFeatureGates))
Expect(fgList).Should(ContainElements(hardCodeKvFgs))
Expect(fgList).Should(ContainElements(sspConditionKvFgs))
})
Expand Down Expand Up @@ -1907,15 +1949,16 @@ Version: 1.2.3`)
mandatoryKvFeatureGates = getMandatoryKvFeatureGates(false)
Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
fgList := getKvFeatureGateList(&hco.Spec.FeatureGates)
Expect(fgList).To(HaveLen(basicNumFgOnOpenshift))
Expect(fgList).To(HaveLen(len(getKvFeatureGateList(&hco.Spec.FeatureGates))))
Expect(fgList).Should(ContainElements(hardCodeKvFgs))
Expect(fgList).Should(ContainElements(sspConditionKvFgs))
})
})

It("should keep FG if already exist", func() {
mandatoryKvFeatureGates = getMandatoryKvFeatureGates(true)
fgs := append(hardCodeKvFgs, kvWithHostPassthroughCPU)
fgs := getKvFeatureGateList(&hco.Spec.FeatureGates)
fgs = append(fgs, kvWithHostPassthroughCPU)
existingResource, err := NewKubeVirt(hco)
Expect(err).ToNot(HaveOccurred())
existingResource.Spec.Configuration.DeveloperConfiguration.FeatureGates = fgs
Expand Down Expand Up @@ -1985,7 +2028,7 @@ Version: 1.2.3`)
).ToNot(HaveOccurred())

Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(basicNumFgOnOpenshift))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(len(getKvFeatureGateList(&hco.Spec.FeatureGates))))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(hardCodeKvFgs))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(sspConditionKvFgs))
})
Expand Down Expand Up @@ -2022,7 +2065,7 @@ Version: 1.2.3`)
).ToNot(HaveOccurred())

Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(basicNumFgOnOpenshift))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(len(getKvFeatureGateList(&hco.Spec.FeatureGates))))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(hardCodeKvFgs))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(sspConditionKvFgs))
})
Expand Down Expand Up @@ -2059,7 +2102,7 @@ Version: 1.2.3`)
).ToNot(HaveOccurred())

Expect(foundResource.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(len(hardCodeKvFgs)))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(len(hardCodeKvFgs) + enabledByDefaultFeatureGates))
Expect(foundResource.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(hardCodeKvFgs))
})
})
Expand Down Expand Up @@ -2090,37 +2133,37 @@ Version: 1.2.3`)
Entry("When not using kvm-emulation and FG is empty",
false,
&hcov1beta1.HyperConvergedFeatureGates{},
basicNumFgOnOpenshift,
basicNumFgOnOpenshift+enabledByDefaultFeatureGates,
[][]string{hardCodeKvFgs, sspConditionKvFgs},
),
Entry("When using kvm-emulation and FG is empty",
true,
&hcov1beta1.HyperConvergedFeatureGates{},
len(hardCodeKvFgs),
len(hardCodeKvFgs)+enabledByDefaultFeatureGates,
[][]string{hardCodeKvFgs},
),
Entry("When not using kvm-emulation and all FGs are disabled",
false,
&hcov1beta1.HyperConvergedFeatureGates{WithHostPassthroughCPU: ptr.To(false)},
basicNumFgOnOpenshift,
basicNumFgOnOpenshift+enabledByDefaultFeatureGates,
[][]string{hardCodeKvFgs, sspConditionKvFgs},
),
Entry("When using kvm-emulation all FGs are disabled",
true,
&hcov1beta1.HyperConvergedFeatureGates{WithHostPassthroughCPU: ptr.To(false)},
len(hardCodeKvFgs),
len(hardCodeKvFgs)+enabledByDefaultFeatureGates,
[][]string{hardCodeKvFgs},
),
Entry("When not using kvm-emulation and all FGs are enabled",
false,
&hcov1beta1.HyperConvergedFeatureGates{WithHostPassthroughCPU: ptr.To(true)},
basicNumFgOnOpenshift+1,
basicNumFgOnOpenshift+1+enabledByDefaultFeatureGates,
[][]string{hardCodeKvFgs, sspConditionKvFgs, {kvWithHostPassthroughCPU}},
),
Entry("When using kvm-emulation all FGs are enabled",
true,
&hcov1beta1.HyperConvergedFeatureGates{WithHostPassthroughCPU: ptr.To(true)},
len(hardCodeKvFgs)+1,
len(hardCodeKvFgs)+1+enabledByDefaultFeatureGates,
[][]string{hardCodeKvFgs, {kvWithHostPassthroughCPU}},
))
})
Expand Down Expand Up @@ -3645,7 +3688,7 @@ Version: 1.2.3`)
).ToNot(HaveOccurred())

Expect(kv.Spec.Configuration.DeveloperConfiguration).ToNot(BeNil())
Expect(kv.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(len(mandatoryKvFeatureGates)))
Expect(kv.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(HaveLen(len(getKvFeatureGateList(&hco.Spec.FeatureGates))))
Expect(kv.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElements(hardCodeKvFgs))
Expect(kv.Spec.Configuration.DeveloperConfiguration.FeatureGates).To(ContainElement(kvSRIOVGate))
Expect(kv.Spec.Configuration.CPURequest).To(BeNil())
Expand Down
4 changes: 4 additions & 0 deletions deploy/crds/hco00.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ spec:
default: false
description: Disable mediated devices handling on KubeVirt
type: boolean
downwardMetrics:
description: Allow to expose a limited set of host metrics to
guests.
type: boolean
enableApplicationAwareQuota:
default: false
description: EnableApplicationAwareQuota if true, enables the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ spec:
default: false
description: Disable mediated devices handling on KubeVirt
type: boolean
downwardMetrics:
description: Allow to expose a limited set of host metrics to
guests.
type: boolean
enableApplicationAwareQuota:
default: false
description: EnableApplicationAwareQuota if true, enables the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ spec:
default: false
description: Disable mediated devices handling on KubeVirt
type: boolean
downwardMetrics:
description: Allow to expose a limited set of host metrics to
guests.
type: boolean
enableApplicationAwareQuota:
default: false
description: EnableApplicationAwareQuota if true, enables the
Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ HyperConvergedFeatureGates is a set of optional feature gates to enable or disab

| Field | Description | Scheme | Default | Required |
| ----- | ----------- | ------ | -------- |-------- |
| downwardMetrics | Allow to expose a limited set of host metrics to guests. | *bool | | false |
| withHostPassthroughCPU | Allow migrating a virtual machine with CPU host-passthrough mode. This should be enabled only when the Cluster is homogeneous from CPU HW perspective doc here | *bool | false | false |
| enableCommonBootImageImport | Opt-in to automatic delivery/updates of the common data import cron templates. There are two sources for the data import cron templates: hard coded list of common templates, and custom templates that can be added to the dataImportCronTemplates field. This feature gates only control the common templates. It is possible to use custom templates by adding them to the dataImportCronTemplates field. | *bool | true | false |
| deployTektonTaskResources | deploy resources (kubevirt tekton tasks and example pipelines) in SSP operator | *bool | false | false |
Expand Down
11 changes: 11 additions & 0 deletions docs/cluster-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ or new features that are not enabled by default.
To enable a feature, add its name to the `featureGates` list and set it to `true`. Missing or `false` feature gates
disables the feature.

### downwardMetrics Feature Gate
Set the `downwardMetrics` feature gate in order to allow exposing a limited set of VM and host metrics to the guest.
The format is compatible with [vhostmd](https://github.com/vhostmd/vhostmd).
These metrics allow third-parties diagnosing issues.
DownwardMetrics may be exposed to the guest through a `volume` or a `virtio-serial port`.

By default, if the `downwardMetrics` is not set to `false`, the metrics will be available to the guests.
This means that updates from previous versions will not require any special configuration.

**Note**: In future versions, the feature gate will be disabled by default.

### withHostPassthroughCPU Feature Gate
Set the `withHostPassthroughCPU` feature gate in order to allow migrating a virtual machine with CPU host-passthrough
mode. This can provide slightly better CPU performance, but should be enabled only when the Cluster is homogeneous from
Expand Down

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

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

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

0 comments on commit 08fb7f4

Please sign in to comment.