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

Use nocloud when specified #212

Closed
wants to merge 16 commits into from

Conversation

BobyMCbobs
Copy link
Member

What this PR does / why we need it:

Allows for CloudInitNoCloud volume type to be used and filled in when a volume is specified with the given type and the name "cloudinitvolume" and doesn't insert a CloudInitConfigDrive volume and disk.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #200

Special notes for your reviewer:

Release notes:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 29, 2022
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 29, 2022
@coveralls
Copy link

coveralls commented Nov 29, 2022

Pull Request Test Coverage Report for Build 3654098425

  • 43 of 69 (62.32%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.3%) to 51.163%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/kubevirt/machine.go 2 4 50.0%
pkg/kubevirt/utils.go 41 65 63.08%
Files with Coverage Reduction New Missed Lines %
pkg/kubevirt/utils.go 2 70.78%
Totals Coverage Status
Change from base Build 3565380590: -0.3%
Covered Lines: 968
Relevant Lines: 1892

💛 - Coveralls

@davidvossel
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Nov 29, 2022
Comment on lines 199 to 205
CDRom: &kubevirtv1.CDRomTarget{
Bus: kubevirtv1.DiskBusSATA,
ReadOnly: func() *bool {
b := true
return &b
}(),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why noCloud should use a cdrom instead of a disk with virtio?

Copy link
Member Author

Choose a reason for hiding this comment

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

To some tests the CDROM type appears to work better with Talos

Copy link
Contributor

Choose a reason for hiding this comment

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

How about we default to the disk approach that we already have today, but only create that disk if there's not already a disk with the name cloudinitvolume

So this would allow you to create a disk however you want and our controllers won't touch it. But if the cloudinit disk doesn't exist, our controllers will give one as a default.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried it with Disk again and it appears to work fine.
I like the flow of providing a disk/volume with a given name and it fills in the rest using your changes on top.

Made it so it adds to if it doesn't already exist 57d40f5

Bus: "virtio",
},
},
cloudInitType, index := noCloudVolume(template)
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of calling this function noCloudVolume, could it instead be something like, detectCloudInitVolume

cloudInitType, index := noCloudVolume(template)
cloudInitVolume := cloudinitVolume(template, ctx, cloudInitType)
cloudInitDisk := cloudinitDisk(template, cloudInitType)
if cloudInitType == "CloudInitNoCloud" {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of keying off the "CloudInitNoCloud" type here, could we instead detect if a previous cloudinit volume existed and use that index... So maybe have the detectCloudInitVolume function return either an index >= 0 if a volume already exists, or maybe -1 if no previous volume exists. Then with this if/def we'd just have if index >= 0 {

Copy link
Member Author

Choose a reason for hiding this comment

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

I think while that would make it less, I believe that would require extra explaining and documentation.
It might be clearer with outputs like exists and index.

Copy link
Member Author

Choose a reason for hiding this comment

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

In any case, the goal is to have it default to CloudInitConfigDrive, unless there's an non-nil CloudInitNoCloud volume named cloudinitvolume

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, an exists bool with an index makes sense as well.

I think i'd rather avoid detection logic that keys for the CloudInitNoCloud type directly, and instead have one that simply returns the cloud init type found in the volume. Right now we only have CloudInitNoCloud, and ConfigDrive, but in the future there might be more options. It would be nice if this logic naturally worked if the cloud init types are added to in the future

Copy link
Member Author

Choose a reason for hiding this comment

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

Using a different method based on the type detected, such as CloudInitNoCloud or CloudInitConfigDrive, will future proof it more than detecting only CloudInitNoCloud.

I'm sure there's some way to add more support another way

Copy link
Contributor

@davidvossel davidvossel left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BobyMCbobs, davidvossel

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2022
@davidvossel
Copy link
Contributor

/lgtm cancel

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2022
@davidvossel
Copy link
Contributor

@BobyMCbobs the PR looks good now, but can you check why the go-linter unit test is failing?

if err != nil {
panic(err)
}
break
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove. Not needed on golang. It will aldo solve the linter warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in e58acaa

break
case "CloudInitConfigDrive":
template.Spec.Volumes = append(template.Spec.Volumes, cloudInitVolume)
break
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in e58acaa

case "CloudInitNoCloud":
err := mergo.Merge(&template.Spec.Volumes[index], cloudInitVolume)
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Panic will kill the whole process. Are uou sure this is the behaviour we want here?

Copy link
Member Author

Choose a reason for hiding this comment

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

buildVirtualMachineInstanceTemplate doesn't return an error.
Which behaviour would you suggest here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm unsure how the behaviour would be if it were unhandled, like

		_ = mergo.Merge(&template.Spec.Volumes[index], cloudInitVolume)

but perhaps that's an option?

Copy link
Contributor

Choose a reason for hiding this comment

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

After reading the code of mergo.Merge, I think it's too risky to ignore the error. I'm afraid there is no other option but change the signature of the buildVirtualMachineInstanceTemplate function, to add an error return value, and to do the same for the calling function, newVirtualMachineFromKubevirtMachine, then check this error in the Machine::Create methods (that does return error). These functions are also called from unit tests, so there is no choice but fixing these test as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair evaluation!
Updated in bb66a2d

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 5, 2022
@BobyMCbobs
Copy link
Member Author

@davidvossel, @nunnatsa looking for lgtm

Copy link
Contributor

@nunnatsa nunnatsa left a comment

Choose a reason for hiding this comment

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

Thank for the fixes. I added few more comments...

Also, a general comment for the whole PR: the "CloudInitConfigDrive" and "CloudInitNoCloud" strings are only used to get logic decisions. Not sure string is the best option for that. Please consider using integer constants with iota. For example:

type cloudInitType int

const (
	cloudInitConfigDrive cloudInitType = iota
	cloudInitNoCloud
)

@@ -309,7 +309,8 @@ var _ = Describe("util functions", func() {
machineContext.KubevirtMachine.Spec.VirtualMachineTemplate.Spec.DataVolumeTemplates = dataVolumeTemplates
machineContext.KubevirtMachine.Spec.VirtualMachineTemplate.Spec.Template.Spec.Volumes = volumes

newVM := newVirtualMachineFromKubevirtMachine(machineContext, "default")
newVM, err := newVirtualMachineFromKubevirtMachine(machineContext, "default")
Expect(err).To(BeNil())
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please consider using the dedicated gomega error assertion.

Suggested change
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in 6a8fd2b

@@ -453,7 +454,8 @@ var _ = Describe("util functions", func() {
machineContext.KubevirtMachine.Spec.VirtualMachineTemplate.Spec.DataVolumeTemplates = dataVolumeTemplates
machineContext.KubevirtMachine.Spec.VirtualMachineTemplate.Spec.Template.Spec.Volumes = volumes

newVM := newVirtualMachineFromKubevirtMachine(machineContext, "default")
newVM, err := newVirtualMachineFromKubevirtMachine(machineContext, "default")
Expect(err).To(BeNil())
Copy link
Contributor

@nunnatsa nunnatsa Dec 6, 2022

Choose a reason for hiding this comment

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

Nit: Please consider using the dedicated gomega error assertion.

Suggested change
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in 6a8fd2b

Comment on lines 212 to 222
func detectCloudInitVolumeType(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec) (preferredType string, index int) {
preferredType = "CloudInitConfigDrive"
for i, v := range vmi.Spec.Volumes {
if v.CloudInitNoCloud != nil && v.Name == cloudInitVolumeName {
preferredType, index = "CloudInitNoCloud", i
break
}
}
return preferredType, index
}

Copy link
Contributor

@nunnatsa nunnatsa Dec 6, 2022

Choose a reason for hiding this comment

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

Personally, I don't like named return values and I find them confusing. If there is no reason to use them, please consider to drop them.

Also, I think we could write a shorter, simpler version of this function. How do you feel about this suggestion?

Suggested change
func detectCloudInitVolumeType(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec) (preferredType string, index int) {
preferredType = "CloudInitConfigDrive"
for i, v := range vmi.Spec.Volumes {
if v.CloudInitNoCloud != nil && v.Name == cloudInitVolumeName {
preferredType, index = "CloudInitNoCloud", i
break
}
}
return preferredType, index
}
func detectCloudInitVolumeType(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec) (string, int) {
for i, v := range vmi.Spec.Volumes {
if v.CloudInitNoCloud != nil && v.Name == cloudInitVolumeName {
return "CloudInitNoCloud", i
}
}
return "CloudInitConfigDrive", 0
}

Copy link
Member Author

@BobyMCbobs BobyMCbobs Dec 7, 2022

Choose a reason for hiding this comment

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

The suggested function does look tidier, I've updated it to that in a621d12

Personally, I don't like named return values and I find them confusing. If there is no reason to use them, please consider to drop them.

The named return values make it clearing what is expected to be returned and I think are useful.
However, if you mean that the specific names are not helpful I would suggest preferredCloudInitVolumeType and existingCloudInitVolumeIndex

Copy link
Contributor

@nunnatsa nunnatsa Dec 7, 2022

Choose a reason for hiding this comment

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

As I wrote, it's a personal preference. I'm not a fan of the named return values feature. But I'll won't block the PR for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in dc49cec

Comment on lines 223 to 230
func detectCloudInitDisk(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec) (found bool, index int) {
for i, v := range vmi.Spec.Domain.Devices.Disks {
if v.Disk != nil && v.Name == cloudInitVolumeName {
found, index = true, i
break
}
}
return constants.WorkerNodeRoleValue
return found, index
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider removing the named return values. Also, the index return value is not in use and can be dropped. This function can be simplified a bit; for example:

Suggested change
func detectCloudInitDisk(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec) (found bool, index int) {
for i, v := range vmi.Spec.Domain.Devices.Disks {
if v.Disk != nil && v.Name == cloudInitVolumeName {
found, index = true, i
break
}
}
return constants.WorkerNodeRoleValue
return found, index
func detectCloudInitDisk(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec) bool {
for _, v := range vmi.Spec.Domain.Devices.Disks {
if v.Disk != nil && v.Name == cloudInitVolumeName {
return true
}
}
return false
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in acd5d10.

The named return values in the signature will be useful when reading documentation and for maintaining the functions in the future

Comment on lines 174 to 197
func cloudinitVolume(vmi *kubevirtv1.VirtualMachineInstanceTemplateSpec, ctx *context.MachineContext, preferredType string) kubevirtv1.Volume {
switch preferredType {
case "CloudInitNoCloud":
return kubevirtv1.Volume{
Name: cloudInitVolumeName,
VolumeSource: kubevirtv1.VolumeSource{
CloudInitNoCloud: &kubevirtv1.CloudInitNoCloudSource{
UserDataSecretRef: &corev1.LocalObjectReference{
Name: *ctx.Machine.Spec.Bootstrap.DataSecretName + "-userdata",
},
},
},
},
}
default:
return kubevirtv1.Volume{
Name: cloudInitVolumeName,
VolumeSource: kubevirtv1.VolumeSource{
CloudInitConfigDrive: &kubevirtv1.CloudInitConfigDriveSource{
UserDataSecretRef: &corev1.LocalObjectReference{
Name: *ctx.Machine.Spec.Bootstrap.DataSecretName + "-userdata",
},
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about this function. Another way to implement this logic will be to split it to two functions, each generating one version of cloud init volume. Then use each one of them in the matching case in the switch sentence in the buildVirtualMachineInstanceTemplate function above, where we already know the volume type.

The reason I'm not comfortable with the current implementation is that we ask the same question again and again (what is the volume type?), while we already know the answer.

@BobyMCbobs
Copy link
Member Author

Thank for the fixes. I added few more comments...

@nunnatsa, thanks for your review.

Also, a general comment for the whole PR: the "CloudInitConfigDrive" and "CloudInitNoCloud" strings are only used to get logic decisions. Not sure string is the best option for that. Please consider using integer constants with iota. For example:

type cloudInitType int

const (
	cloudInitConfigDrive cloudInitType = iota
	cloudInitNoCloud
)

I'm not sure why integer constants are preferred when strings provide immediate readability of what we're checking for.
Please help me to understand why integers are better.

@nunnatsa
Copy link
Contributor

nunnatsa commented Dec 7, 2022

Please help me to understand why integers are better.

Integer constants are as readable as strings, I think. But comparing ints is much more efficient than comparing strings. Since the only usage of this values is for branches (if/switch), and there is no use at the actual value (e.g. print it out), then we can use the golang iota feature - this is why it exist for.

return "CloudInitNoCloud", i
}
}
return "CloudInitConfigDrive", 0
Copy link
Contributor

@nunnatsa nunnatsa Dec 8, 2022

Choose a reason for hiding this comment

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

After thinking about it again, 0 is a valid slice index, and returning it is misleading, even if we don't actually using it in the case of CloudInitConfigDrive. Let's change it to -1, to be more clear about not finding the volume in the slice. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good thought! Updated in c2123db

@BobyMCbobs
Copy link
Member Author

Please help me to understand why integers are better.

Integer constants are as readable as strings, I think. But comparing ints is much more efficient than comparing strings. Since the only usage of this values is for branches (if/switch), and there is no use at the actual value (e.g. print it out), then we can use the golang iota feature - this is why it exist for.

I must admit I haven't used this feature before, but it seems to work fine just tested it.
Updated in dc49cec

@BobyMCbobs
Copy link
Member Author

BobyMCbobs commented Dec 9, 2022

Currently experiencing a runtime panic, no experienced before recent changes

I1209 02:08:45.979323       1 machine.go:156] controller/kubevirtmachine/coder-workspaces/talos66-cp-scfrf "msg"="Creating VM with role 'control-plane'..." "name"="talos66-cp-scfrf" "namespace"="coder-workspaces" "reconciler group"="infrastructure.cluster.x-k8s.io" "reconciler kind"="KubevirtMachine"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x2d8 pc=0x153bf8c]

goroutine 579 [running]:
sigs.k8s.io/cluster-api-provider-kubevirt/pkg/kubevirt.prefixDataVolumeTemplates(0xc000436200, {0xc000a1a920, 0x10})
        /workspace/pkg/kubevirt/utils.go:65 +0x26c
sigs.k8s.io/cluster-api-provider-kubevirt/pkg/kubevirt.newVirtualMachineFromKubevirtMachine(0xc000620730, {0xc000a1a990, 0x10})
        /workspace/pkg/kubevirt/utils.go:118 +0x60f
sigs.k8s.io/cluster-api-provider-kubevirt/pkg/kubevirt.(*Machine).Create(0xc0000a9630, {0x1d00cd8, 0xc000701b60})
        /workspace/pkg/kubevirt/machine.go:158 +0x106
sigs.k8s.io/cluster-api-provider-kubevirt/controllers.(*KubevirtMachineReconciler).reconcileNormal(0xc000730000, 0xc000620730)
        /workspace/controllers/kubevirtmachine_controller.go:268 +0x486
sigs.k8s.io/cluster-api-provider-kubevirt/controllers.(*KubevirtMachineReconciler).Reconcile(0xc000730000, {0x1d00cd8?, 0xc000701b60}, {{{0xc000a1a930?, 0x19a3560?}, {0xc000a1a920?, 0x30?}}})
        /workspace/controllers/kubevirtmachine_controller.go:177 +0xebb
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0xc0000e22c0, {0x1d00cd8, 0xc000701b30}, {{{0xc000a1a930?, 0x19a3560?}, {0xc000a1a920?, 0x4041f4?}}})
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.0-beta.0.0.20211110210527-619e6b92dab9/pkg/internal/controller/controller.go:114 +0x27e
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc0000e22c0, {0x1d00c30, 0xc0003ec080}, {0x18b2620?, 0xc00009ca60?})
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.0-beta.0.0.20211110210527-619e6b92dab9/pkg/internal/controller/controller.go:311 +0x349
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc0000e22c0, {0x1d00c30, 0xc0003ec080})
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.0-beta.0.0.20211110210527-619e6b92dab9/pkg/internal/controller/controller.go:266 +0x1d9
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.0-beta.0.0.20211110210527-619e6b92dab9/pkg/internal/controller/controller.go:227 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.0-beta.0.0.20211110210527-619e6b92dab9/pkg/internal/controller/controller.go:223 +0x31c

Update

  • e5b4bbb has appeared to have resolved

Copy link
Contributor

@davidvossel davidvossel left a comment

Choose a reason for hiding this comment

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

Looks great to me. I made one more comment inline, and my only other comment is to please squash the commits down to a single commit, or at most two commits, one for logic and one for the tests. We don't always require that, but 16 commits for this pr is a little excessive.

Comment on lines +161 to +165
err := mergo.Merge(&template.Spec.Volumes[index], cloudInitVolume)
if err != nil {
return nil, err
}
return template, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is any value in the mergo logic here. There's only one possible solution for how the CloudIniitNoCloud volume source can be configured. All we need to do is preserve the volume name, and override whatever is in the CloudInitNoCloud volume source. Anything else can result in an unusable configuration.

This also removes the need to perform any error checking in this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

@davidvossel, this is the simpler method than doing a manual three-way merge.
The logic right now is, if there is a volume called "cloudinitvolume" with a non-nil cloudInitNoCloud volume source it will merge the existing one, which has whatever properties configured, with the one setting the same for the bootstrap secret name.

I'm happy to update if you are really sure. The team is requiring this feature as soon as it's possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be all we need.

if index >= 0 {
    template.Spec.Volumes[index] = cloudInitVolume
} else {
    template.Spec.Domain.Devices.Disks = append(template.Spec.Domain.Devices.Disks, cloudInitDisk)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm unsure whether that would work, the logic is stating to have either a volume added or a disk.

The current way things work means that

  • you can bring your custom cloudInitNoCloud and we'll provide the secret, so that current behaviour is preserved but you can optionally use cloudInitNoCloud
    • e.g: providing custom noCloud networkData
  • a cloudInit disk will be only added if one doesn't already exist, so that you can specify the type of disk that it is (if I wanted CDROM instead)

and i think that is useful

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not following how the mergo usage is necessary to achieve what you previously replied with. I just recommending that the volume be overwritten if the index is known, or appended otherwise.

Comment on lines +161 to +165
err := mergo.Merge(&template.Spec.Volumes[index], cloudInitVolume)
if err != nil {
return nil, err
}
return template, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be all we need.

if index >= 0 {
    template.Spec.Volumes[index] = cloudInitVolume
} else {
    template.Spec.Domain.Devices.Disks = append(template.Spec.Domain.Devices.Disks, cloudInitDisk)
}

Comment on lines +223 to +228
for i, v := range vmi.Spec.Volumes {
if v.CloudInitNoCloud != nil && v.Name == cloudInitVolumeName {
return cloudInitNoCloud, i
}
}
return cloudInitConfigDrive, -1
Copy link
Contributor

Choose a reason for hiding this comment

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

someone could theoretically set a CloudInitConfigDrive volume too. I don't like that this logic is assuming that only a CloudInitNoCloud volume get's the special behavior.

making the default cloudInitConfigDrive is good though

Copy link
Member Author

Choose a reason for hiding this comment

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

this was the way to provide difference, since there's only two types implement currently.
the logic is extend able to show that other cloudInit types are found. it can be adapted when those are implement

@davidvossel
Copy link
Contributor

I'm comfortable merging this once the mergo logic is replaced.

@BobyMCbobs
Copy link
Member Author

I'm comfortable merging this once the mergo logic is replaced.

Thank you @davidvossel.
I'm no longer contributing to the project which this relates to, so I'll close it for now.
It may be picked up at a later date by someone else.

@BobyMCbobs BobyMCbobs closed this Jan 11, 2023
@hh hh mentioned this pull request Feb 10, 2023
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to specific cloudInitNoCloud volumes, currently hardcoded to configInitCloudDrive
5 participants