Skip to content

Commit

Permalink
Fix yetus and build issue came from accepting a review suggestion
Browse files Browse the repository at this point in the history
Signed-off-by: Pramodh Pallapothu <pramodh@zededa.com>
  • Loading branch information
Pramodh Pallapothu committed Apr 15, 2024
1 parent 6af0693 commit ddf251d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
35 changes: 19 additions & 16 deletions pkg/pillar/hypervisor/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
type vmiMetaData struct {
vmi *v1.VirtualMachineInstance // Handle to the VM instance
pod *k8sv1.Pod // Handle to the pod container
domainId int // DomainId understood by domainmgr in EVE
domainID int // DomainID understood by domainmgr in EVE
isPod bool // switch on is Pod or is VMI
name string // Display-Name(all lower case) + first 5 bytes of domainName
cputotal uint64 // total CPU in NS so far
Expand Down Expand Up @@ -266,12 +266,12 @@ func (ctx kubevirtContext) CreateVMIConfig(domainName string, config types.Domai
// The concept is same in kubevirt eve too. Kubevirt supports this functionality through feature
// https://kubevirt.io/user-guide/virtual_machines/boot_from_external_source/
// Since disks are virtio disks we assume /dev/vda is the boot disk
kernel_args := "console=tty0 root=/dev/vda dhcp=1 rootfstype=ext4"
scratch_image := "docker.io/lfedge/eve-external-boot-image:latest"
kernel_path := "/kernel"
initrd_path := "/runx-initrd"
kernelArgs := "console=tty0 root=/dev/vda dhcp=1 rootfstype=ext4"
scratchImage := "docker.io/lfedge/eve-external-boot-image:latest"
kernelPath := "/kernel"
initrdPath := "/runx-initrd"

addKernelBootContainer(&vmi.Spec, scratch_image, kernel_args, kernel_path, initrd_path)
addKernelBootContainer(&vmi.Spec, scratchImage, kernelArgs, kernelPath, initrdPath)

// We don't set this disk to vmi spec
ndisks = ndisks - 1
Expand Down Expand Up @@ -382,7 +382,7 @@ func (ctx kubevirtContext) CreateVMIConfig(domainName string, config types.Domai
meta := vmiMetaData{
vmi: vmi,
name: kubeName,
domainId: int(rand.Uint32()),
domainID: int(rand.Uint32()),
}
ctx.vmiList[domainName] = &meta

Expand Down Expand Up @@ -449,9 +449,9 @@ func (ctx kubevirtContext) Start(domainName string) error {

}

// Create is no-op for kubevirt, just return the domainId we already have.
// Create is no-op for kubevirt, just return the domainID we already have.
func (ctx kubevirtContext) Create(domainName string, cfgFilename string, config *types.DomainConfig) (int, error) {
return ctx.vmiList[domainName].domainId, nil
return ctx.vmiList[domainName].domainID, nil
}

// There is no such thing as stop VMI, so delete it.
Expand Down Expand Up @@ -576,7 +576,7 @@ func (ctx kubevirtContext) Info(domainName string) (int, types.SwState, error) {
if _, ok := ctx.vmiList[domainName]; !ok {
return 0, types.HALTED, logError("domain %s is deleted", domainName)
}
return ctx.vmiList[domainName].domainId, effectiveDomainState, nil
return ctx.vmiList[domainName].domainID, effectiveDomainState, nil
}
}

Expand Down Expand Up @@ -864,11 +864,13 @@ func getVMIName(metricStr string) string {
}

func fillMetrics(res map[string]types.DomainMetric, domainName, metricName string, value interface{}) {
if r, ok := res[domainName]; !ok {

if _, ok := res[domainName]; !ok {
logrus.Infof("fillMetrics, vmiName %s not in map", domainName)
return
}

r := res[domainName]
BytesInMegabyte := uint32(1024 * 1024)
switch metricName {
// add all the cpus to be Total, seconds should be from VM startup time
Expand All @@ -883,8 +885,6 @@ func fillMetrics(res map[string]types.DomainMetric, domainName, metricName strin
r.AllocatedMB = uint32(assignToInt64(value)) / BytesInMegabyte
case "kubevirt_vmi_memory_available_bytes": // save this temp for later
r.UsedMemory = uint32(assignToInt64(value)) / BytesInMegabyte
//case "kubevirt_vmi_memory_resident_bytes":
// r.UsedMemory = uint32(assignToInt64(value)) / BytesInMegabyte
default:
}
res[domainName] = r
Expand Down Expand Up @@ -998,7 +998,7 @@ func (ctx kubevirtContext) CreatePodConfig(domainName string, config types.Domai
pod: pod,
isPod: true,
name: kubeName,
domainId: int(rand.Uint32()),
domainID: int(rand.Uint32()),
}
ctx.vmiList[domainName] = &meta

Expand All @@ -1019,6 +1019,7 @@ func encodeSelections(selections []netattdefv1.NetworkSelectionElement) string {
return string(bytes)
}

// StartPodContainer : Starts container as kubernetes pod

Check failure on line 1022 in pkg/pillar/hypervisor/kubevirt.go

View workflow job for this annotation

GitHub Actions / yetus

revive: comment on exported function StartPodContiner should be of the form "StartPodContiner ..." https://revive.run/r#exported
func StartPodContiner(kubeconfig *rest.Config, pod *k8sv1.Pod) error {

clientset, err := kubernetes.NewForConfig(kubeconfig)
Expand Down Expand Up @@ -1077,6 +1078,7 @@ func checkForPod(kubeconfig *rest.Config, podName string) error {
return fmt.Errorf("checkForPod: timed out, statuus %s, err %v", status, err)
}

// StopPodContainer : Stops the running kubernetes pod
func StopPodContainer(kubeconfig *rest.Config, podName string) error {

clientset, err := kubernetes.NewForConfig(kubeconfig)
Expand All @@ -1096,6 +1098,7 @@ func StopPodContainer(kubeconfig *rest.Config, podName string) error {
return nil
}

// InfoPodContainer : Get the pod information
func InfoPodContainer(kubeconfig *rest.Config, podName string) (string, error) {

podclientset, err := kubernetes.NewForConfig(kubeconfig)
Expand Down Expand Up @@ -1170,7 +1173,7 @@ func checkPodMetrics(ctx kubevirtContext, res map[string]types.DomainMetric, emp

cpuTotalNs := metrics.Containers[0].Usage[k8sv1.ResourceCPU]
cpuTotalNsAsFloat64 := cpuTotalNs.AsApproximateFloat64() * float64(time.Second) // get nanoseconds
totalCpu := uint64(cpuTotalNsAsFloat64)
totalCPU := uint64(cpuTotalNsAsFloat64)

//allocatedMemory := metrics.Containers[0].Usage[k8sv1.ResourceMemory]
usedMemory := metrics.Containers[0].Usage[k8sv1.ResourceMemory]
Expand All @@ -1188,7 +1191,7 @@ func checkPodMetrics(ctx kubevirtContext, res map[string]types.DomainMetric, emp
usedMemoryPercent := calculateMemoryUsagePercent(usedMemory.Value(), memoryLimits.Value())
BytesInMegabyte := uint32(1024 * 1024)

realCPUTotal := vmis.cputotal + totalCpu
realCPUTotal := vmis.cputotal + totalCPU
vmis.cputotal = realCPUTotal
dm := types.DomainMetric{
CPUTotalNs: realCPUTotal,
Expand Down
1 change: 1 addition & 0 deletions pkg/pillar/hypervisor/nokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package hypervisor

const (
// KubevirtHypervisorName : Name of the kubevirt hypervisor
KubevirtHypervisorName = "kubevirt"
)

Expand Down

0 comments on commit ddf251d

Please sign in to comment.