Skip to content

Commit

Permalink
Merge pull request #1201 from nestoracunablanco/refactor/templateArch…
Browse files Browse the repository at this point in the history
…WithLabel

refactor: use the template architecture label
  • Loading branch information
kubevirt-bot authored Jan 15, 2025
2 parents 262b35d + ca7357e commit 9403b6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 3 additions & 14 deletions internal/template-bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package template_bundle

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -22,16 +21,6 @@ type Bundle struct {
DataSources []cdiv1beta1.DataSource
}

type templateArchitecture struct {
Spec struct {
Template struct {
Spec struct {
Architecture string `json:"architecture"`
} `json:"spec"`
} `json:"template"`
} `json:"spec"`
}

func ReadBundle(filename string) (Bundle, error) {
templates, err := readTemplates(filename)
if err != nil {
Expand Down Expand Up @@ -80,14 +69,14 @@ func readTemplates(filename string) ([]templatev1.Template, error) {
if template.Name == "" {
continue
}
templateArchitecture := templateArchitecture{}
if err = json.Unmarshal(template.Objects[0].Raw, &templateArchitecture); err != nil {
templateArch, ok := template.Labels["template.kubevirt.io/architecture"]
if !ok {
return nil, err
}
// DISCLAIMER: This is a temporary solution for delivering templates related to the host architecture.
// Once the common templates are released based on architecture, this change will no longer be necessary.
// Instead, a modification will be required in setup.go to specify the bundle to read from.
if templateArchitecture.Spec.Template.Spec.Architecture == runtime.GOARCH {
if templateArch == runtime.GOARCH {
bundle = append(bundle, template)
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/template-bundle/template-bundle-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ metadata:
flavor.template.kubevirt.io/medium: "true"
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.19.0"
template.kubevirt.io/architecture: "amd64"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -166,6 +167,7 @@ metadata:
flavor.template.kubevirt.io/large: "true"
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.19.1"
template.kubevirt.io/architecture: "amd64"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -303,6 +305,7 @@ metadata:
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.17.0"
template.kubevirt.io/default-os-variant: "true"
template.kubevirt.io/architecture: "amd64"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -466,6 +469,7 @@ metadata:
flavor.template.kubevirt.io/tiny: "true"
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.18.1"
template.kubevirt.io/architecture: "amd64"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -681,6 +685,7 @@ metadata:
flavor.template.kubevirt.io/medium: "true"
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.19.0"
template.kubevirt.io/architecture: "s390x"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -814,6 +819,7 @@ metadata:
flavor.template.kubevirt.io/large: "true"
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.19.1"
template.kubevirt.io/architecture: "s390x"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -951,6 +957,7 @@ metadata:
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.17.0"
template.kubevirt.io/default-os-variant: "true"
template.kubevirt.io/architecture: "s390x"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down Expand Up @@ -1114,6 +1121,7 @@ metadata:
flavor.template.kubevirt.io/tiny: "true"
template.kubevirt.io/type: "base"
template.kubevirt.io/version: "v0.18.1"
template.kubevirt.io/architecture: "s390x"
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
Expand Down

0 comments on commit 9403b6c

Please sign in to comment.