Skip to content

Commit

Permalink
chore: try to use virt-artifact-classic-go
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita korolev <[email protected]>
  • Loading branch information
universal-itengineer committed Oct 2, 2024
1 parent c66cd24 commit fcc491e
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 162 deletions.
5 changes: 5 additions & 0 deletions base-images/alt_image_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# REGISTRY_PATH is a special key which is concatenated with other base images
REGISTRY_PATH: "registry.altlinux.org/"

# Virtualization images
DISTROLESS_ALT_P11: "alt/distroless-base:p11@sha256:256886b532513294e84688f63ba06b380b5160aac30f45cb7c7542ae4365bf29"
21 changes: 19 additions & 2 deletions images/virt-artifact/werf.inc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,35 @@ shell:
- export CGO_ENABLED=0
- export GOARCH=amd64

- echo ============== Build container-disk ====================
- echo ============== Build container-disk ===================
- gcc -static cmd/container-disk-v2alpha/main.c -o /kubevirt-binaries/container-disk

- echo ============== Build virt-launcher ====================
- CGO_ENABLED=1 go build -o /kubevirt-binaries/virt-launcher ./cmd/virt-launcher/

- echo "Create group file"
- |
GROUP_FILE=./cmd/virt-launcher/group
echo "qemu:x:107:" > $GROUP_FILE
echo "root:x:0:" >> $GROUP_FILE
chmod 0644 $GROUP_FILE
- echo "Create passwd file"
- |
PASSWD_FILE=./cmd/virt-launcher/passwd
echo "qemu:x:107:107:user:/home/qemu:/bin/bash" > $PASSWD_FILE
echo "root:x:0:0:root:/root:/bin/bash" >> $PASSWD_FILE
chmod 0644 $PASSWD_FILE
- echo ============== Build virt-handler =====================
- CGO_ENABLED=1 go build -o /kubevirt-binaries/virt-handler ./cmd/virt-handler/

- echo ============== Build virt-launcher-monitor ============
- go build -o /kubevirt-binaries/virt-launcher-monitor ./cmd/virt-launcher-monitor/

- echo ============== Build virt-tail ========================
- go build -o /kubevirt-binaries/virt-tail ./cmd/virt-tail/

- echo ============== Build virt-freezer =====================
- go build -o /kubevirt-binaries/virt-freezer ./cmd/virt-freezer/

Expand All @@ -152,7 +169,7 @@ shell:
- echo ============== Build virt-operator ====================
- go build -o /kubevirt-binaries/virt-operator ./cmd/virt-operator/

- echo ============== Build sidecars ====================
- echo ============== Build sidecars =========================
- go build -o /kubevirt-binaries/sidecars ./cmd/sidecars/

- echo ============== Build virtctl ==========================
Expand Down
33 changes: 25 additions & 8 deletions images/virt-launcher/werf.inc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,48 @@ import:
after: install
includePaths:
- .version
- image: virt-artifact
add: /images/kubevirt/{{ $.ImageName }}:latest/etc/libvirt
- image: virt-artifact-classic-go
add: /kubevirt/cmd/{{ $.ImageName }}
to: /etc/libvirt
after: install
includePaths:
- qemu.conf
- virtqemud.conf
# - image: virt-artifact
# add: /images/kubevirt/{{ $.ImageName }}:latest/etc/libvirt
# to: /etc/libvirt
# after: install
# includePaths:
# - qemu.conf
# - virtqemud.conf
- image: virt-artifact
add: /images/kubevirt/{{ $.ImageName }}:latest/etc
to: /etc
after: install
includePaths:
- nsswitch.conf
- image: virt-artifact
add: /images/kubevirt/{{ $.ImageName }}:latest/usr/bin
# - image: virt-artifact
# add: /images/kubevirt/{{ $.ImageName }}:latest/usr/bin
- image: virt-artifact-classic-go
add: /kubevirt-binaries/
to: /usr/bin
before: setup
includePaths:
- container-disk
- node-labeller.sh
- virt-freezer
- virt-launcher
- virt-launcher-monitor
- virt-probe
- virt-tail
# - kubevirt/cmd/virt-launcher/node-labeller
- image: virt-artifact-classic-go
add: /kubevirt-binaries/
to: /kubevirt-binaries
after: install
add: /kubevirt/cmd/virt-launcher/node-labeller/
to: /usr/bin
before: setup
# - image: virt-artifact-classic-go
# add: /kubevirt-binaries/
# to: /kubevirt-binaries
# after: install
git:
- add: /images/{{ $.ImageName }}
to: /
Expand Down Expand Up @@ -312,3 +325,7 @@ shell:
echo "Build RPMs from:" /home/builder/*.rpm
echo "Note: time consuming operation, be patient ..."
su - builder -c 'trap "echo Build log tail: ; tail -n 1024 /tmp/build.log" EXIT ; rpm -ba /home/builder/RPM/SPECS/edk2.spec > /tmp/build.log 2>&1'
# ---
# image: {{ $.ImageName }}-dir-sctruct
# final: false
# from: {{ .Images.DISTROLESS_ALT_P11 }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ limitations under the License.
package service

import (
"context"
"errors"
"fmt"
"strconv"
"strings"

"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/deckhouse/virtualization/api/core/v1alpha2"
)
Expand All @@ -36,23 +33,13 @@ const (
greater = 1
)

type SizePolicyService struct {
client client.Client
}
type SizePolicyService struct{}

func NewSizePolicyService(client client.Client) *SizePolicyService {
return &SizePolicyService{client: client}
func NewSizePolicyService() *SizePolicyService {
return &SizePolicyService{}
}

func (s *SizePolicyService) CheckVMMatchedSizePolicy(ctx context.Context, vm *v1alpha2.VirtualMachine) error {
vmClass := &v1alpha2.VirtualMachineClass{}
err := s.client.Get(ctx, types.NamespacedName{
Name: vm.Spec.VirtualMachineClassName,
}, vmClass)
if err != nil {
return err
}

func (s *SizePolicyService) CheckVMMatchedSizePolicy(vm *v1alpha2.VirtualMachine, vmClass *v1alpha2.VirtualMachineClass) error {
sizePolicy := getVMSizePolicy(vm, vmClass)
if sizePolicy == nil {
return fmt.Errorf(
Expand Down Expand Up @@ -148,9 +135,9 @@ func validatePerCoreMemory(vm *v1alpha2.VirtualMachine, sp *v1alpha2.SizingPolic
return
}

// not have a default dividing :(
// dirty, I know
// wash your hands after read this
// Calculate memory portion per CPU core
// to compare it later with min and max
// limits in the sizing policy.
vmPerCore := vm.Spec.Memory.Size.Value() / int64(vm.Spec.CPU.Cores)
perCoreMemory := resource.NewQuantity(vmPerCore, resource.BinarySI)

Expand Down
Loading

0 comments on commit fcc491e

Please sign in to comment.