-
Notifications
You must be signed in to change notification settings - Fork 39
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 PVC controller #662
Conversation
|
if cap == relciamSpaceOp { | ||
driverAnnotation = rsCSIAddonsDriverAnnotation | ||
} | ||
|
||
ok := r.supportsReclaimSpace(driver) | ||
if reclaimSpaceSupportedByDriver && !ok { | ||
logger.Info("Driver supports spacereclamation but driver is not registered in the connection pool, Reqeueing request", "DriverName", driver) | ||
return true, false | ||
if cap == keyRotationOp { | ||
driverAnnotation = krCSIAddonsDriverAnnotation |
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.
Move this to switch case
var driverAnnotation string
switch cap {
case relciamSpaceOp:
driverAnnotation = rsCSIAddonsDriverAnnotation
case keyRotationOp:
driverAnnotation = krCSIAddonsDriverAnnotation
default:
logger.Info(fmt.Sprintf("Invalid capability: %s", cap))
return false, false
}
logger *logr.Logger, | ||
annotations map[string]string, | ||
driverName string, | ||
cap string) (bool, 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.
define a type for cap and pass it
// Define a custom type for capabilities
type Capability string
// Define constants for the different capabilities
const (
ReclaimSpaceOp Capability = "ReclaimSpace"
KeyRotationOp Capability = "KeyRotation"
)
RetryDeadlineSeconds: defaultRetryDeadlineSeconds, | ||
|
||
switch jobtype { | ||
case relciamSpaceOp: |
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.
define Type for it and use it
internal/controller/util/common.go
Outdated
limitations under the License. | ||
*/ | ||
|
||
package util |
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 dont need a helper file for it, this are common to PVC controller and not used outside by others, add this as functions to PVC controller only
14d9cd9
to
40e9d2f
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.
LGTM, can you please do test this out and see nothing breaks
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.
Left 2 comments.
@iPraveenParihar can you check the indexer and eventhandler parts.
if annotationKey == krcJobScheduleTimeAnnotation { | ||
requeue, keyRotationSupported := r.checkDriverSupportsEncryptionKeyRotate(logger, ns.Annotations, driverName) | ||
requeue, keyRotationSupported := r.checkDriverSupportCapability(logger, ns.Annotations, driverName, keyRotationOp) | ||
if keyRotationSupported { | ||
return schedule, nil | ||
} | ||
if requeue { | ||
return "", ErrConnNotFoundRequeueNeeded | ||
} | ||
} else if annotationKey == rsCronJobScheduleTimeAnnotation { |
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.
Can you use switch case for annotationKey
?
@@ -521,35 +492,63 @@ func getScheduleFromAnnotation( | |||
return schedule, true | |||
} | |||
|
|||
// constructRSCronJob constructs and returns ReclaimSpaceCronJob. | |||
func constructRSCronJob(name, namespace, schedule, pvcName string) *csiaddonsv1alpha1.ReclaimSpaceCronJob { | |||
func constructCronJob(jobtype Operation, name, namespace, schedule, pvcName string) client.Object { |
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 write two different contruct[KR|RS]CronJob
functions.
It's better to avoid unsafe typecasting.
90d0946
to
a3c90ba
Compare
a3c90ba
to
b43a913
Compare
case keyRotationOp: | ||
driverAnnotation = krCSIAddonsDriverAnnotation | ||
default: | ||
logger.Info("Unknown capability", "Capability", cap) |
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 it be Unknown operation?
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 check for capability inside this function. The reason constants are called Operation
and not Capability
is to avoid ambiguity with CSI's Capability
struct.
TestingLogs (annotating PVC)
Note: The relcaim-space error is related to Logs (annotating SC)
|
I have updated the PR with logs. |
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.
LGTM, has the testing done for all scenarios?
I’ll be updating above comment with logs for other scenarios shortly. |
@Rakshith-R PTAL at this one again when you can? |
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.
one more change.
if capFound { | ||
return false, 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.
you don't need to check capFound in below lines.
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.
Done. Here's a diff of the latest change for ease of review:
- if driverSupportsCap && !capFound {
- logger.Info(fmt.Sprintf("Driver supports %s but driver is not registered in the connection pool, Reqeueing request", cap), "DriverName", driverName)
+ // If the driver supports the capability but the capability is not found in connection pool,
+ if driverSupportsCap {
+ logger.Info(fmt.Sprintf("Driver supports %s but driver is not registered in the connection pool, Requeuing request", cap), "DriverName", driverName)
return true, false
}
- if !capFound {
- logger.Info(fmt.Sprintf("Driver does not support %s, skip Requeue", cap), "DriverName", driverName)
- return false, false
- }
-
- // Do not reque, cap is supported
- return false, true
-
+ // If the driver does not support the capability, skip requeue
+ logger.Info(fmt.Sprintf("Driver does not support %s, skip Requeue", cap), "DriverName", driverName)
+ return false, false
}
b43a913
to
2507163
Compare
Pull request has been modified.
This PR refactors the PVC controller to reduce code duplication by extracting common logic into its own functions/packages Signed-off-by: Niraj Yadav <[email protected]>
2507163
to
d58422b
Compare
… ) (#5423) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [kubernetes-csi-addons](https://redirect.github.com/csi-addons/kubernetes-csi-addons) | minor | `v0.9.1` -> `v0.10.0` | --- ### Release Notes <details> <summary>csi-addons/kubernetes-csi-addons (kubernetes-csi-addons)</summary> ### [`v0.10.0`](https://redirect.github.com/csi-addons/kubernetes-csi-addons/releases/tag/v0.10.0) [Compare Source](https://redirect.github.com/csi-addons/kubernetes-csi-addons/compare/v0.9.1...v0.10.0) #### What's Changed - Add proto and sidecar code for volumegroup by [@​Nikhil-Ladha](https://redirect.github.com/Nikhil-Ladha) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/652](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/652) - vendor: Bump google.golang.org/grpc from 1.65.0 to 1.66.0 in the golang-dependencies group by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/656](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/656) - vendor: Bump sigs.k8s.io/controller-tools from 0.16.1 to 0.16.2 in /tools in the k8s-dependencies group by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/658](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/658) - vendor: Bump the github-dependencies group across 1 directory with 3 updates by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/657](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/657) - replication: add new Validated condition by [@​Rakshith-R](https://redirect.github.com/Rakshith-R) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/664](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/664) - bundle: Update CSV capability to Seamless Upgrades by [@​black-dragon74](https://redirect.github.com/black-dragon74) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/668](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/668) - Refactor PVC controller by [@​black-dragon74](https://redirect.github.com/black-dragon74) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/662](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/662) - bundle: Add missing CRDs to bundle CSV by [@​black-dragon74](https://redirect.github.com/black-dragon74) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/669](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/669) - vendor: bump the k8s-dependencies group with 3 updates by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/673](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/673) #### New Contributors - [@​Nikhil-Ladha](https://redirect.github.com/Nikhil-Ladha) made their first contribution in [https://github.com/csi-addons/kubernetes-csi-addons/pull/652](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/652) **Full Changelog**: csi-addons/kubernetes-csi-addons@v0.9.1...v0.10.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://redirect.github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44NS4wIiwidXBkYXRlZEluVmVyIjoiMzguODUuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicmVub3ZhdGUvZ2l0aHViLXJlbGVhc2UiLCJ0eXBlL21pbm9yIl19--> Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [kubernetes-csi-addons](https://redirect.github.com/csi-addons/kubernetes-csi-addons) | minor | `v0.9.1` -> `v0.10.0` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>csi-addons/kubernetes-csi-addons (kubernetes-csi-addons)</summary> ### [`v0.10.0`](https://redirect.github.com/csi-addons/kubernetes-csi-addons/releases/tag/v0.10.0) [Compare Source](https://redirect.github.com/csi-addons/kubernetes-csi-addons/compare/v0.9.1...v0.10.0) #### What's Changed - Add proto and sidecar code for volumegroup by [@​Nikhil-Ladha](https://redirect.github.com/Nikhil-Ladha) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/652](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/652) - vendor: Bump google.golang.org/grpc from 1.65.0 to 1.66.0 in the golang-dependencies group by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/656](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/656) - vendor: Bump sigs.k8s.io/controller-tools from 0.16.1 to 0.16.2 in /tools in the k8s-dependencies group by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/658](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/658) - vendor: Bump the github-dependencies group across 1 directory with 3 updates by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/657](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/657) - replication: add new Validated condition by [@​Rakshith-R](https://redirect.github.com/Rakshith-R) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/664](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/664) - bundle: Update CSV capability to Seamless Upgrades by [@​black-dragon74](https://redirect.github.com/black-dragon74) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/668](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/668) - Refactor PVC controller by [@​black-dragon74](https://redirect.github.com/black-dragon74) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/662](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/662) - bundle: Add missing CRDs to bundle CSV by [@​black-dragon74](https://redirect.github.com/black-dragon74) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/669](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/669) - vendor: bump the k8s-dependencies group with 3 updates by [@​dependabot](https://redirect.github.com/dependabot) in [https://github.com/csi-addons/kubernetes-csi-addons/pull/673](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/673) #### New Contributors - [@​Nikhil-Ladha](https://redirect.github.com/Nikhil-Ladha) made their first contribution in [https://github.com/csi-addons/kubernetes-csi-addons/pull/652](https://redirect.github.com/csi-addons/kubernetes-csi-addons/pull/652) **Full Changelog**: csi-addons/kubernetes-csi-addons@v0.9.1...v0.10.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://redirect.github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44NS4wIiwidXBkYXRlZEluVmVyIjoiMzguODUuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicmVub3ZhdGUvZ2l0aHViLXJlbGVhc2UiLCJ0eXBlL21pbm9yIl19-->
This PR refactors the PVC controller to reduce
code duplication by extracting common logic
into its own functions/packages