Skip to content

Commit

Permalink
Add downwardmetrics feature gate
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <rmohr@redhat.com>
  • Loading branch information
rmohr committed May 14, 2021
1 parent f57bffc commit 31e347b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,14 @@ func validateVolumes(field *k8sfield.Path, volumes []v1.Volume, config *virtconf
}
}

if volume.DownwardMetrics != nil && !config.DownwardMetricsEnabled() {
causes = append(causes, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueInvalid,
Message: "downwardMetrics disks are not allowed: DownwardMetrics feature gate is not enabled.",
Field: field.Index(idx).String(),
})
}

// validate HostDisk data
if hostDisk := volume.HostDisk; hostDisk != nil {
if !config.HostDiskEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3038,6 +3038,56 @@ var _ = Describe("Validating VMICreate Admitter", func() {
})

Context("with volume", func() {
It("should accept a single downwardmetrics volume", func() {
enableFeatureGate(virtconfig.DownwardMetricsFeatureGate)
vmi := v1.NewMinimalVMI("testvmi")

vmi.Spec.Volumes = append(vmi.Spec.Volumes, v1.Volume{
Name: "testDownwardMetrics",
VolumeSource: v1.VolumeSource{
DownwardMetrics: &v1.DownwardMetricsVolumeSource{},
},
})

causes := validateVolumes(k8sfield.NewPath("fake"), vmi.Spec.Volumes, config)
Expect(causes).To(BeEmpty())
})
It("should reject downwardMetrics volumes if the feature gate is not enabled", func() {
vmi := v1.NewMinimalVMI("testvmi")

vmi.Spec.Volumes = append(vmi.Spec.Volumes, v1.Volume{
Name: "testDownwardMetrics",
VolumeSource: v1.VolumeSource{
DownwardMetrics: &v1.DownwardMetricsVolumeSource{},
},
})

causes := validateVolumes(k8sfield.NewPath("fake"), vmi.Spec.Volumes, config)
Expect(causes).To(HaveLen(1))
Expect(causes[0].Message).To(ContainSubstring("downwardMetrics disks are not allowed: DownwardMetrics feature gate is not enabled."))
})
It("should reject downwardMetrics volumes if more than one exist", func() {
enableFeatureGate(virtconfig.DownwardMetricsFeatureGate)
vmi := v1.NewMinimalVMI("testvmi")

vmi.Spec.Volumes = append(vmi.Spec.Volumes,
v1.Volume{
Name: "testDownwardMetrics",
VolumeSource: v1.VolumeSource{
DownwardMetrics: &v1.DownwardMetricsVolumeSource{},
},
},
v1.Volume{
Name: "testDownwardMetrics1",
VolumeSource: v1.VolumeSource{
DownwardMetrics: &v1.DownwardMetricsVolumeSource{},
},
},
)
causes := validateVolumes(k8sfield.NewPath("fake"), vmi.Spec.Volumes, config)
Expect(causes).To(HaveLen(1))
Expect(causes[0].Message).To(ContainSubstring("fake must have max one downwardMetric volume set"))
})
It("should reject hostDisk volumes if the feature gate is not enabled", func() {
vmi := v1.NewMinimalVMI("testvmi")

Expand Down
27 changes: 16 additions & 11 deletions pkg/virt-config/feature-gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ const (
IgnitionGate = "ExperimentalIgnitionSupport"
LiveMigrationGate = "LiveMigration"
// SRIOVLiveMigrationGate enable's Live Migration for VM's with SRIOV interfaces.
SRIOVLiveMigrationGate = "SRIOVLiveMigration"
CPUNodeDiscoveryGate = "CPUNodeDiscovery"
HypervStrictCheckGate = "HypervStrictCheck"
SidecarGate = "Sidecar"
GPUGate = "GPU"
HostDevicesGate = "HostDevices"
SnapshotGate = "Snapshot"
HotplugVolumesGate = "HotplugVolumes"
HostDiskGate = "HostDisk"
VirtIOFSGate = "ExperimentalVirtiofsSupport"
MacvtapGate = "Macvtap"
SRIOVLiveMigrationGate = "SRIOVLiveMigration"
CPUNodeDiscoveryGate = "CPUNodeDiscovery"
HypervStrictCheckGate = "HypervStrictCheck"
SidecarGate = "Sidecar"
GPUGate = "GPU"
HostDevicesGate = "HostDevices"
SnapshotGate = "Snapshot"
HotplugVolumesGate = "HotplugVolumes"
HostDiskGate = "HostDisk"
VirtIOFSGate = "ExperimentalVirtiofsSupport"
MacvtapGate = "Macvtap"
DownwardMetricsFeatureGate = "DownwardMetrics"
)

func (c *ClusterConfig) isFeatureGateEnabled(featureGate string) bool {
Expand All @@ -54,6 +55,10 @@ func (config *ClusterConfig) CPUManagerEnabled() bool {
return config.isFeatureGateEnabled(CPUManager)
}

func (config *ClusterConfig) DownwardMetricsEnabled() bool {
return config.isFeatureGateEnabled(DownwardMetricsFeatureGate)
}

func (config *ClusterConfig) IgnitionEnabled() bool {
return config.isFeatureGateEnabled(IgnitionGate)
}
Expand Down
1 change: 1 addition & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ func AdjustKubeVirtResource() {
virtconfig.HostDiskGate,
virtconfig.VirtIOFSGate,
virtconfig.HotplugVolumesGate,
virtconfig.DownwardMetricsFeatureGate,
)
kv.Spec.Configuration.SELinuxLauncherType = "virt_launcher.process"

Expand Down

0 comments on commit 31e347b

Please sign in to comment.