Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read architecture specific common templates file #1156

Merged

Conversation

nestoracunablanco
Copy link
Contributor

This change prepares for architecture-specific delivery. The logic will first attempt to locate the architecture-specific common templates bundle. If it is not found, it will then fall back to the generic bundle.

What this PR does / why we need it: s390x enablement

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: no Indicates the PR's author has not DCO signed all their commits. size/M labels Dec 3, 2024
@nestoracunablanco nestoracunablanco force-pushed the feat/selectArchFileIfExists branch from 9b4849c to 50f7390 Compare December 3, 2024 11:59
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Dec 3, 2024
Comment on lines 58 to 59
archDependentFileName := filepath.Join(templateBundleDir, commonTemplatesFilePrefix+runtime.GOARCH+"-"+common_templates.Version+commonTemplatesFileSuffix)
archIndependentFileName := filepath.Join(templateBundleDir, commonTemplatesFilePrefix+common_templates.Version+commonTemplatesFileSuffix)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string concatenation is a little confusing here. Can you use fmt.Sprintf()? The format string could be:

common-templates-%s-%s.yaml`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

func RetrieveCommonTemplatesBundleFile(templateBundleDir string) (string, error) {
archDependentFileName := filepath.Join(templateBundleDir, commonTemplatesFilePrefix+runtime.GOARCH+"-"+common_templates.Version+commonTemplatesFileSuffix)
archIndependentFileName := filepath.Join(templateBundleDir, commonTemplatesFilePrefix+common_templates.Version+commonTemplatesFileSuffix)
commonTemplatesExistingFiles := filterExistingTemplateFiles([]string{archDependentFileName, archIndependentFileName})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you simplify this by not using a filter function? IMHO directly checking if the 2 files exists is more readable.

if _, err := os.Stat(archDependentFileName); err == nil {
    return archDependentFileName, nil
}

if _, err := os.Stat(archIndependentFileName); err == nil {
    return archIndependentFileName, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 34 to 38
_, filename, _, ok := runtime.Caller(0)
Expect(ok).To(BeTrue())
fileAbsolutePath, err := filepath.Abs(filename)
Expect(err).NotTo(HaveOccurred())
testDir = filepath.Dir(fileAbsolutePath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of reading files from the repo, can you create them in a temp directory when the test starts?
Ginkgo can create the directory for you:

tmpDir := GinkgoT().TempDir()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea, thanks for pointing that out

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't commit these empty files into the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nestoracunablanco nestoracunablanco force-pushed the feat/selectArchFileIfExists branch 2 times, most recently from 2cc78b0 to 0532aea Compare December 3, 2024 13:25
@nestoracunablanco
Copy link
Contributor Author

/retest

@nestoracunablanco nestoracunablanco force-pushed the feat/selectArchFileIfExists branch from 0532aea to 10ab46a Compare December 4, 2024 12:39
@akrejcir
Copy link
Collaborator

akrejcir commented Dec 4, 2024

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akrejcir

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 4, 2024
@dominikholler
Copy link
Contributor

dominikholler commented Dec 5, 2024

@nestoracunablanco
Is the assumption that the node, which runs the ssp-operator, has the same architecture as the nodes running the VMs?
Are you aware that this change might limit the usage of templates in clusters with worker nodes of multiple architectures?
Does this mean you prefer to go the volume (instancetypes/preferences) approach for clusters using worker nodes of mixed architectures?

@nestoracunablanco
Copy link
Contributor Author

Hello @dominikholler,

Thank you for reaching out. Regarding your questions:

  1. Are you aware that this change might limit the usage of templates in clusters with worker nodes of multiple architectures?
  • The assumption is not that the node running the same architecture as the SSP operator will have the same architecture as the nodes running the VMs. However, it is true that multi-architecture support is currently not available and would require significant design changes. With the existing design (which works well for amd64), the SSP operator attempts to import the data volumes even if they are not enabled for the host architecture (for example, Windows or OpenSUSE on s390x). To enhance the user experience for s390x, these options are not presented.
    For amd64, this change is completely transparent. In the case of s390x, end users can clone a template and modify it according to their needs (in case they want to run amd64 workloads).
  1. Does this mean you prefer to adopt the volume (instance types/preferences) approach for clusters using worker nodes of mixed architectures?
  • I do not have a personal opinion on this matter. My primary focus is to enable the existing features for the s390x architecture.

Looking ahead, here are some ideas to address the lack of multi-architecture worker node support (though they may not be fully feasible):

  • Load the templates based on the available architectures across all nodes.
  • Import the data volumes selectively.

In my opinion, enabling multi-architecture worker nodes would require a design change that necessitates consensus.

@dominikholler
Copy link
Contributor

dominikholler commented Dec 5, 2024 via email

@nestoracunablanco
Copy link
Contributor Author

nestoracunablanco commented Dec 5, 2024

I do not understand. If the containerdisk imported by a DataImportCron
contains s390x, and the containerdisk is referring to the s390x
preference
(kubevirt/common-instancetypes#290), wouldn't the OpenShift UI create a working VM from the related golden base image?

Are you looking for a way to prevent importing DataImportCrons which
does not support the architecture of the node?

Yes, if the container disk includes s390x, that is not an issue. However, some Linux distributions do not support s390x, and Windows does not either. In my opinion, it could be inconvenient (or even a bug) for users if we present features they cannot utilize, such as starting Windows or openSUSE VMs that are incompatible with s390x.
Another aspect to consider is when a user attempts to run a VM based on a template, such as selecting "Fedora." If this does not work out of the box because the default architecture does not match that of the worker nodes, it does not reflect an ideal user experience.
I am open to achieving these goals through various means, as long as it enhances the user experience and does not disrupt existing functionality. To facilitate this discussion, I suggest we hold a meeting with all involved parties, as lengthy messages in a pull request can be quite time-consuming.

Sounds interesting. What do you mean by "load" here, maybe showing
them in the UI?

For example, as long as the user is not presented with any "misleading" indicators, this can be addressed at the UI level, be filtered by the SSP operator, etc. etc. etc.

@akrejcir
Copy link
Collaborator

akrejcir commented Dec 5, 2024

@0xFelix , can you please take a look?

Comment on lines 41 to 42
archIndependentFile = tmpDir + fmt.Sprintf("/common-templates-%s.yaml", common_templates.Version)
archDependentFile = tmpDir + fmt.Sprintf("/common-templates-%s-%s.yaml", runtime.GOARCH, common_templates.Version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use filepath.Join

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


It("should throw an error retrieving the bundle file", func() {
_, err := RetrieveCommonTemplatesBundleFile(tmpDir)
Expect(err.Error()).To(ContainSubstring("failed to find common-templates bundles, none of the files were found"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(err.Error()).To(ContainSubstring("failed to find common-templates bundles, none of the files were found"))
Expect(err).To(MatchError(ContainSubstring("failed to find common-templates bundles, none of the files were found")))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

This change prepares for architecture-specific delivery. The logic
will first attempt to locate the architecture-specific common
templates bundle. If it is not found, it will then fall back to the
generic bundle.

Signed-off-by: Nestor Acuna Blanco <nestor.acuna@ibm.com>
@nestoracunablanco nestoracunablanco force-pushed the feat/selectArchFileIfExists branch from 10ab46a to ca7e46f Compare December 6, 2024 08:37
Copy link

sonarqubecloud bot commented Dec 6, 2024

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 9, 2024
@kubevirt-bot kubevirt-bot merged commit 5b3a952 into kubevirt:main Dec 9, 2024
11 of 12 checks passed
@nestoracunablanco nestoracunablanco deleted the feat/selectArchFileIfExists branch December 9, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants