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

Refactor volume mount logic #1264

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open

Refactor volume mount logic #1264

wants to merge 74 commits into from

Conversation

satr
Copy link
Contributor

@satr satr commented Jan 9, 2025

No description provided.

@satr satr requested a review from nilsgstrabo January 14, 2025 11:57
ObjectMeta: metav1.ObjectMeta{
Name: pvName,
Labels: getCsiAzurePvLabels(appName, namespace, componentName, radixVolumeMount),
Annotations: getCsiAzurePvAnnotations(csiVolumeCredSecretName, namespace, useAzureIdentity),
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel we should skip setting these annotations since none of them are documented anywhere. They are probably just for internal use for automatic privisioning from SC

return ""
}

func getCsiAzurePvAnnotations(csiVolumeCredSecretName, namespace string, useAzureIdentity bool) map[string]string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this function after removing call from buildCsiAzurePv func

Comment on lines +23 to +25
CsiAnnotationProvisionedBy = "pv.kubernetes.io/provisioned-by"
CsiAnnotationProvisionerDeletionSecretName = "volume.kubernetes.io/provisioner-deletion-secret-name"
CsiAnnotationProvisionerDeletionSecretNamespace = "volume.kubernetes.io/provisioner-deletion-secret-namespace"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CsiAnnotationProvisionedBy = "pv.kubernetes.io/provisioned-by"
CsiAnnotationProvisionerDeletionSecretName = "volume.kubernetes.io/provisioner-deletion-secret-name"
CsiAnnotationProvisionerDeletionSecretNamespace = "volume.kubernetes.io/provisioner-deletion-secret-namespace"

Can be removed after getCsiAzurePvAnnotations function is deleted

Comment on lines +21 to +23
if !utils.EqualStringMaps(getPvAnnotations(pv1), getPvAnnotations(pv2)) {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !utils.EqualStringMaps(getPvAnnotations(pv1), getPvAnnotations(pv2)) {
return false
}

Remove this comparison since we don't set any annotations

Comment on lines +28 to +30
if !utils.EqualStringMaps(getAnnotations(pvc1), getAnnotations(pvc2)) {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !utils.EqualStringMaps(getAnnotations(pvc1), getAnnotations(pvc2)) {
return false
}

Should probably remove this comparison since we don't set any annotations.

Comment on lines +24 to +28
expectedClonedVolumeAttrs := cloneMap(pv1.Spec.CSI.VolumeAttributes, CsiVolumeMountAttributePvName, CsiVolumeMountAttributePvcName, CsiVolumeMountAttributeProvisionerIdentity)
actualClonedVolumeAttrs := cloneMap(pv2.Spec.CSI.VolumeAttributes, CsiVolumeMountAttributePvName, CsiVolumeMountAttributePvcName, CsiVolumeMountAttributeProvisionerIdentity)
if !utils.EqualStringMaps(expectedClonedVolumeAttrs, actualClonedVolumeAttrs) {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I comment out these lines, all tests still pass. Either we miss some tests, or the tests incorrectly use this function (EqualPersistentVolumes) to compare actual and expected

Comment on lines +33 to +57
if pv1.Spec.Capacity[corev1.ResourceStorage] != pv2.Spec.Capacity[corev1.ResourceStorage] ||
len(pv1.Spec.AccessModes) != len(pv2.Spec.AccessModes) ||
(len(pv1.Spec.AccessModes) != 1 && pv1.Spec.AccessModes[0] != pv2.Spec.AccessModes[0]) ||
pv1.Spec.CSI.Driver != pv2.Spec.CSI.Driver {
return false
}

if pv1.Spec.CSI.NodeStageSecretRef != nil {
if pv2.Spec.CSI.NodeStageSecretRef == nil || pv1.Spec.CSI.NodeStageSecretRef.Name != pv2.Spec.CSI.NodeStageSecretRef.Name {
return false
}
} else if pv2.Spec.CSI.NodeStageSecretRef != nil {
return false
}

if pv1.Spec.ClaimRef != nil {
if pv2.Spec.ClaimRef == nil ||
!internal.EqualTillPostfix(pv1.Spec.ClaimRef.Name, pv2.Spec.ClaimRef.Name, 5) ||
pv1.Spec.ClaimRef.Namespace != pv2.Spec.ClaimRef.Namespace ||
pv1.Spec.ClaimRef.Kind != pv2.Spec.ClaimRef.Kind {
return false
}
} else if pv2.Spec.ClaimRef != nil {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I comment out these lines, all tests still pass. Either we miss some tests, or the tests incorrectly use this function (EqualPersistentVolumes) to compare actual and expected

package internal

// EqualTillPostfix Compares two strings till the postfix
func EqualTillPostfix(value1, value2 string, postfixLength int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move (and make private) this function to the volumemount package since it is only used there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is here because it is used in two files: volumemount and persistentvolume

@@ -0,0 +1,64 @@
package persistentvolume
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move everything here into the volumemount package since this is the only place it is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to volumemount

Copy link
Contributor

@nilsgstrabo nilsgstrabo left a comment

Choose a reason for hiding this comment

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

Added a few comments regarding annotations on PV and PVC. We should probably not set them since they are not documented anywhere, and is probably only used internally by the driver.

Also added some optional suggestions about moving code from internal package to the volumemount package, then as private props/functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants