-
Notifications
You must be signed in to change notification settings - Fork 131
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
add http source for kubevirt VM Disk Image #1470
add http source for kubevirt VM Disk Image #1470
Conversation
d7a7115
to
4d5ebfb
Compare
/retest |
4d5ebfb
to
8db73b3
Compare
8db73b3
to
c8f3062
Compare
e40b7d3
to
b61138f
Compare
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a first review round. I will repeat after new changes.
@@ -93,7 +98,7 @@ type Config struct { | |||
CPUs string | |||
Memory string | |||
Namespace string | |||
OsImage OSImage | |||
OsImage *OSImage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be OSImage on the left side as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw why it has to be a pointer now?
@@ -149,8 +154,18 @@ type SecondaryDisks struct { | |||
} | |||
|
|||
type OSImage struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comments to each structure with explanation of the structutre itself and fields
|
||
type HTTPSource struct { | ||
URL string | ||
PreAllocatedDataVolume bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe let's rename to CacheImage
DataVolumeName string | ||
NameSpace string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be named Namespace
} | ||
|
||
var parsedOSImage *OSImage | ||
// If PrimaryDiskOSSource is specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would extend this comment and say that if source is specified then that means we deal with new API
parsedOSImage = &OSImage{PVCClone: &PVCSource{DataVolumeName: osImage, NameSpace: nameSpace}} | ||
} | ||
} | ||
// If PrimaryDiskOSSource is not specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to extend that comment and say that we are dealing here with older API and it's a matter of backward compatibility
if !exist { | ||
return sigClient.Create(ctx, newDataVolume(c, dvName, machine.Name)) | ||
} | ||
// annotate existing DataVolume with VM-name, if already exist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is not needed, the code is quite clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same with the below comment
return sigClient.Create(ctx, newDataVolume(c, dvName, machine.Name)) | ||
} | ||
// annotate existing DataVolume with VM-name, if already exist. | ||
updatedDV := existingDV.DeepCopy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for doing a DeepCopy
in here? Controller runtime get function will return already a deep copy.
func (p *provider) Cleanup(ctx context.Context, machine *clusterv1alpha1.Machine, _ *cloudprovidertypes.ProviderData) (bool, error) { | ||
func (p *provider) createPreAllocatedDataVolume(ctx context.Context, c *Config, machine *clusterv1alpha1.Machine, sigClient client.Client, dvName string) error { | ||
existingDV := &cdiv1beta1.DataVolume{} | ||
exist := true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get rid of this flag, it's not required. You can check if the object is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean here is that you can return an error from Get and implement a check that if err is not found then create a new data volume.
} | ||
|
||
// Source. | ||
type Source struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need better comments with explanation about the fields.
b61138f
to
ea080db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another review round.
@@ -66,6 +69,8 @@ const ( | |||
// machineDeploymentLabelKey defines the label key used to contains as value the MachineDeployment name | |||
// which machine comes from. | |||
machineDeploymentLabelKey = "md" | |||
// preAllocatedDVAnnotation defines the annotation for preAllocated DataVolume for cloning. | |||
preAllocatedDVAnnotation = "datavolume.clone.kubevirt.io/machine" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's change to disk-clone.machines.cluster.k8s.io/machine-%s
@@ -679,9 +759,39 @@ func (p *provider) Cleanup(ctx context.Context, machine *clusterv1alpha1.Machine | |||
return true, nil | |||
} | |||
|
|||
// cleanup preAllocated DataVolume |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed comment
annotationKey := fmt.Sprintf("%s-%s", preAllocatedDVAnnotation, machine.Name) | ||
if dv.Annotations[annotationKey] == "true" { | ||
// If the Machine-Deployment is scaled to zero or deleted or preAllocateDataVolume is disabled, remove preAllocated DataVolume. | ||
if len(dv.Annotations) == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep it safe and change to <= 1
return sigClient.Delete(ctx, dv) | ||
} | ||
// Remove annotation of corresponding VM from preAllocated DataVolume. | ||
updatedDv := dv.DeepCopy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need deep copy
@@ -93,7 +98,7 @@ type Config struct { | |||
CPUs string | |||
Memory string | |||
Namespace string | |||
OsImage OSImage | |||
OSImage *OSImage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it has to be a pointer now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notting specific, just parseOSImage()
return pointer so I can directly assign it to config.OSImage
It does not affect the old API.
var machineDeploymentName string | ||
if mdName, err := machineDeploymentNameAndRevisionForMachineGetter(ctx, machine, data.Client)(); err == nil { | ||
machineDeploymentName = mdName | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if I follow this logic.
Why it cannot be:
mdName, err := machineDeploymentNameAndRevisionForMachineGetter(ctx, machine, data.Client)()
if err != nil {
return nil, err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this change, we used to create VMs even if getting the MD-name returned error.
So continue with earlier behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if MD-name returns an error then we have a problem. Based on that you create a data volume.
if !kerrors.IsNotFound(err) { | ||
return err | ||
} | ||
// create DV if it doesn't exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need comments like that, code is self explanatory
ed2fb43
to
3721aa8
Compare
/retest |
PVCClone *PVCCloneSource `json:"pvcClone,omitempty"` | ||
} | ||
|
||
// HTTPSource. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need better comments with explanation about the fields.
The same for all sources (HTTP and PVCClone)
3721aa8
to
842b0cb
Compare
I am sorry @sankalp-r I have to block this PR, we have to do another brainstorming session /hold |
|
||
// PVCSource represents pvc source for cloning VMImage. | ||
type PVCSource struct { | ||
// DataVolumeName represent name of source pvc for cloning. | ||
DataVolumeName string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's change DataVolumeName
to Name
ea253d9
to
5293085
Compare
/retest |
2 similar comments
/retest |
/retest |
@@ -66,6 +66,10 @@ const ( | |||
// machineDeploymentLabelKey defines the label key used to contains as value the MachineDeployment name | |||
// which machine comes from. | |||
machineDeploymentLabelKey = "md" | |||
// httpSource defines the http source type for VM Disk Image. | |||
httpSource = "http" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to introduce imageSource
type.
type imageSource string
const (
...
httpSource imageSource = "http"
pvcSource imageSource = "pvc"
)
and later in the switch statement you would have
switch imageSource(osImageSource) ...
case httpSource: | ||
return &cdiv1beta1.DataVolumeSource{HTTP: &cdiv1beta1.DataVolumeSourceHTTP{URL: osImage}}, nil | ||
case pvcSource: | ||
if nameSpaceAndName := strings.Split(osImage, "/"); len(nameSpaceAndName) >= 2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please name it namespaceAndName
(namespace is one word)
419ff5d
to
970c3b0
Compare
Signed-off-by: Sankalp Rangare <sankalprangare786@gmail.com>
970c3b0
to
9dc2b69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/unhold
/approve
/lgtm
LGTM label has been added. Git tree hash: 908bfa286cec24942d7608b937967988b36079f9
|
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve ⚡
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmedwaleedmalik, mfranczy, sankalp-r 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 |
@@ -167,7 +168,12 @@ func (k kubevirtProviderSpecConf) rawProviderSpec(t *testing.T) []byte { | |||
"osImage": "http://x.y.z.t/ubuntu.img", | |||
{{- end }} | |||
"size": "10Gi", | |||
{{- if .OsImageSource }} | |||
"storageClassName": "longhorn", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As storageClassName
is set to "longhorn" in the if and the else, it could go out of the if/else condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be just one if to add OsImageSource
true, but the current state doesn't break the behaviour.
What this PR does / why we need it:
This PR introduces
PrimarDiskImageSource
for the KubeVirt provider. The source can beHTTP
orPVC-Clone
.If the source is
HTTP
withpreAllocatedDataVolume
as false, the VM disk-image will be downloaded from the HTTP source.If the source is
HTTP
withpreAllocatedDataVolume
as true, the VM disk-image will be downloaded just once to create PreAllocatedDataVolume and VM Disks will be created by cloning over PreAllocatedDataVolume.If the source is
PVC-Clone
, VM Disks will be created by cloning over custom-local-disks.Which issue(s) this PR fixes:
Fixes #kubermatic/kubermatic#11234
What type of PR is this?
/kind feature
Special notes for your reviewer:
Does this PR introduce a user-facing change? Then add your Release Note here:
Documentation:
Signed-off-by: Sankalp Rangare sankalprangare786@gmail.com