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

implemented adaptive scaling #5

Merged
merged 8 commits into from
Dec 2, 2023
Merged

implemented adaptive scaling #5

merged 8 commits into from
Dec 2, 2023

Conversation

sinamna
Copy link
Collaborator

@sinamna sinamna commented Nov 27, 2023

adaptively scale based on target deployment

Summary by CodeRabbit

  • New Features

    • Added a search functionality to the app.
  • Style

    • Added styles for the search bar.
  • Refactor

    • Introduced a new Search class with methods for fetching and displaying results.
    • Added a search bar to the Hero component and a Search component to the App component.

Copy link

coderabbitai bot commented Nov 27, 2023

Walkthrough

The changes involve enhancing a Kubernetes controller for a Basic Authenticator service. New functionalities include watching for externally managed deployments, adaptive scaling based on specific fields, and utility functions for service name extraction and Nginx configuration. There's also the introduction of a random generator package for creating random strings and names, and refactoring to improve the handling of custom configurations and Kubernetes client interactions.

Changes

File Path Change Summary
internal/controller/basic_authenticator/.../basicauthenticator_controller.go Added new imports, RBAC rules, a method to find externally managed deployments, and modified setup to watch for Deployment objects.
internal/controller/basic_authenticator/const.go Updated the basicAuthenticatorFinalizer constant and introduced ExternallyManaged constant.
internal/controller/basic_authenticator/provision.go Added imports, new AcquireTargetReplica function, updated CreateDeploymentAuthenticator for adaptive scaling, and refactored function calls.
internal/controller/basic_authenticator/utility.go Added imports and new utility functions for Nginx container configuration.
internal/controller/basic_authenticator/nginx.go Renamed functions, added new parameters for custom configuration, and introduced import for random generator.
pkg/random_generator/random_generator.go Introduced a new package with functions to generate random strings and names.

"In the warren of code, where the logic hops,
A rabbit refactored, and the clutter drops. 🐇💻
With each function and file, neatly in place,
The authenticator scales, with newfound grace."


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d01bb67 and 7a9cc1a.
Files ignored due to filter (6)
  • tests/e2e/adaptive-scaling/00-assert.yaml
  • tests/e2e/adaptive-scaling/00-install.yaml
  • tests/e2e/adaptive-scaling/01-assert.yaml
  • tests/e2e/adaptive-scaling/01-increase-deploy-replicas.yaml
  • tests/e2e/adaptive-scaling/02-assert.yaml
  • tests/e2e/adaptive-scaling/02-decrease-deploy-replicas.yaml
Files selected for processing (4)
  • internal/controller/basic_authenticator/basicauthenticator_controller.go (2 hunks)
  • internal/controller/basic_authenticator/const.go (1 hunks)
  • internal/controller/basic_authenticator/provision.go (4 hunks)
  • internal/controller/basic_authenticator/utility.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • internal/controller/basic_authenticator/const.go
Additional comments: 5
internal/controller/basic_authenticator/basicauthenticator_controller.go (3)
  • 23-33: The import statements are correctly added to support the new features in the reconciler.

  • 70-88: The findExternallyManagedDeployments method is correctly implemented to filter deployments based on the ExternallyManaged annotation.

  • 60-67: The SetupWithManager method is correctly updated to include a new watch for appv1.Deployment objects and to enqueue reconcile requests using findExternallyManagedDeployments.

internal/controller/basic_authenticator/provision.go (2)
  • 263-263: Updating the ReadyReplicas in the BasicAuthenticator status is a good practice as it reflects the current state of the deployment. Ensure that this status update is tested thoroughly to confirm that it behaves as expected during various deployment states.

  • 226-263: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [196-291]

The error handling and logic for creating or updating the deployment in the ensureDeployment function appear to be correct. However, ensure that the error messages are clear and provide enough context for debugging any issues that may arise during the creation or update process.

internal/controller/basic_authenticator/utility.go Outdated Show resolved Hide resolved
internal/controller/basic_authenticator/provision.go Outdated Show resolved Hide resolved
internal/controller/basic_authenticator/provision.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7a9cc1a and ccff276.
Files selected for processing (1)
  • internal/controller/basic_authenticator/basicauthenticator_controller.go (3 hunks)
Additional comments: 2
internal/controller/basic_authenticator/basicauthenticator_controller.go (2)
  • 23-32: The import statements are correctly added to support the new functionality.

  • 45-48: The RBAC rule for services has been correctly added to the reconciler.

@sinamna sinamna self-assigned this Nov 27, 2023
@sinamna sinamna requested a review from hoptical November 27, 2023 15:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ccff276 and 0245920.
Files selected for processing (3)
  • internal/controller/basic_authenticator/basicauthenticator_controller.go (3 hunks)
  • internal/controller/basic_authenticator/provision.go (4 hunks)
  • internal/controller/basic_authenticator/utility.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • internal/controller/basic_authenticator/utility.go
Additional comments: 7
internal/controller/basic_authenticator/basicauthenticator_controller.go (4)
  • 23-32: The import statements are correctly added and formatted.

  • 45-48: The RBAC rule for "services" has been correctly added to allow the reconciler to manage services.

  • 71-88: The findExternallyManagedDeployments function is correctly implemented to identify and enqueue reconcile requests for deployments managed externally.

  • 61-68: The SetupWithManager function is correctly updated to include a watch for appv1.Deployment objects and to enqueue reconcile requests using the findExternallyManagedDeployments function.

internal/controller/basic_authenticator/provision.go (3)
  • 196-221: The changes in the CreateDeploymentAuthenticator method to incorporate adaptive scaling logic by using the AcquireTargetReplica method are consistent with the summary and the user's feedback. The method correctly acquires the target replica count when the AdaptiveScale flag is set and updates the deployment's replicas accordingly.

  • 288-322: The AcquireTargetReplica method's logic for updating the target deployment's annotations and replica count is consistent with the summary and the user's feedback. The method correctly annotates the deployment with ExternallyManaged and calculates the target replica count based on the existing replicas. Additionally, the method logs debug information, which aids in monitoring and troubleshooting.

  • 226-257: The changes in the CreateDeploymentAuthenticator method to update the BasicAuthenticator status with the number of ready replicas after updating the deployment are correct and follow the expected behavior.

@hoptical
Copy link
Collaborator

hoptical commented Dec 2, 2023

CreateCredentials in nginx.go is not needed to be a method of BasicAuthenticatorReconciler.
Additionally, all functions in nginx.go can be private.

@hoptical
Copy link
Collaborator

hoptical commented Dec 2, 2023

@sinamna
The created secret needs a controller reference.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0245920 and 5d406b0.
Files selected for processing (2)
  • internal/controller/basic_authenticator/nginx.go (5 hunks)
  • internal/controller/basic_authenticator/provision.go (7 hunks)
Additional comments: 11
internal/controller/basic_authenticator/nginx.go (6)
  • 6-12: The import statement for github.com/snapp-incubator/simple-authenticator/internal/config has been correctly added.

  • 39-51: The function CreateNginxDeployment has been correctly renamed to createNginxDeployment and the new parameter customConfig *config.CustomConfig has been added as per the summary.

  • 122-125: The function CreateNginxConfigmap has been correctly renamed to createNginxConfigmap.

  • 142-145: The function CreateCredentials has been correctly renamed to createCredentials.

  • 158-170: The function Injector has been correctly renamed to injector and the new parameters customConfig *config.CustomConfig and k8Client client.Client have been added as per the summary.

  • 155-173: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [39-170]

No additional changes impacting dependents were found beyond those mentioned in the summary.

internal/controller/basic_authenticator/provision.go (5)
  • 9-17: The imports have been correctly updated to include the "math" and "sigs.k8s.io/controller-runtime/pkg/client" packages, aligning with the PR's objective to implement adaptive scaling and manage Kubernetes resources.

  • 59-65: The function calls have been correctly updated to use the unexported versions of createCredentials, createNginxConfigmap, and createNginxDeployment, following the refactoring and renaming conventions outlined in the PR's objective.

  • 188-206: The CreateDeploymentAuthenticator function has been updated to include adaptive scaling logic, which is in line with the PR's objective to implement adaptive scaling capabilities.

  • 288-322: The AcquireTargetReplica function has been added and includes logic to calculate and return a target replica count, which is a key part of the new adaptive scaling feature.

  • 301-305: As per the previous learning, the user has indicated that they will clarify in the documentation that the AcquireTargetReplica function expects only one deployment to match the appService label selector. Ensure that this documentation update is completed to prevent confusion or unintended behavior.

@hoptical
Copy link
Collaborator

hoptical commented Dec 2, 2023

@sinamna
These lines in injector function are common with createNginxDeployment function. Can be moved out to another function.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5d406b0 and 655d089.
Files selected for processing (4)
  • internal/controller/basic_authenticator/nginx.go (6 hunks)
  • internal/controller/basic_authenticator/provision.go (9 hunks)
  • internal/controller/basic_authenticator/utility.go (1 hunks)
  • pkg/random_generator/random_generator.go (1 hunks)
Additional comments: 17
internal/controller/basic_authenticator/nginx.go (7)
  • 8-8: The import statement for random_generator is correctly added to support the new functionality.

  • 38-38: The function createNginxDeployment has been correctly renamed and updated to accept a new parameter for custom configuration.

  • 120-120: The function createNginxConfigmap has been correctly renamed without any changes to its signature.

  • 140-140: The function createCredentials has been correctly renamed without any changes to its signature.

  • 156-156: The function injector has been correctly renamed and updated to accept new parameters for custom configuration and Kubernetes client.

  • 120-120: The summary correctly reflects the changes in the hunks for createNginxConfigmap and createCredentials, which align with the PR objective of refactoring for clarity and consistency.

Also applies to: 140-140

  • 220-226: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [223-236]

The summary does not mention the changes to the fillTemplate function, which has been modified to handle the new authenticator structure. This should be included in the summary for completeness.

internal/controller/basic_authenticator/provision.go (7)
  • 9-17: The addition of the "math" and "sigs.k8s.io/controller-runtime/pkg/client" imports is consistent with the PR objective of implementing adaptive scaling and managing deployments.

  • 37-40: The function getLatestBasicAuthenticator is used appropriately to fetch the latest state of a BasicAuthenticator object, which is a common pattern in Kubernetes controllers.

  • 52-65: The ensureSecret function correctly handles both the retrieval of an existing secret and the creation of a new one if it does not exist, updating the BasicAuthenticator accordingly.

  • 106-116: The ensureConfigmap function mirrors the logic of ensureSecret, properly handling the retrieval or creation of a configmap and updating the BasicAuthenticator.

  • 160-166: The ensureDeployment function correctly checks for the presence of required annotations before proceeding, which is a good practice to ensure that necessary information is available.

  • 188-206: The createDeploymentAuthenticator function includes conditional logic for adaptive scaling, which aligns with the PR objective of implementing automatic scaling based on specific conditions.

  • 288-321: The acquireTargetReplica function is responsible for calculating the target replica count for adaptive scaling, utilizing the "math" package as expected based on the earlier import.

internal/controller/basic_authenticator/utility.go (2)
  • 3-6: The import statements have been grouped correctly, which aligns with best practices in Go.

  • 15-26: The implementation of getNginxContainerImage and getNginxContainerName functions is correct and follows the expected logic as per the summary.

pkg/random_generator/random_generator.go (1)
  • 22-27: The implementation of GenerateRandomName appears to be correct and follows best practices for generating a hash-based name.

pkg/random_generator/random_generator.go Outdated Show resolved Hide resolved
@sinamna
Copy link
Collaborator Author

sinamna commented Dec 2, 2023

These lines in injector function are common with createNginxDeployment function. Can be moved out to another function.

done

@sinamna
Copy link
Collaborator Author

sinamna commented Dec 2, 2023

The created secret needs a controller reference.

done

@sinamna
Copy link
Collaborator Author

sinamna commented Dec 2, 2023

CreateCredentials in nginx.go is not needed to be a method of BasicAuthenticatorReconciler. Additionally, all functions in nginx.go can be private.

done

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 655d089 and e513ad3.
Files selected for processing (2)
  • internal/controller/basic_authenticator/nginx.go (6 hunks)
  • internal/controller/basic_authenticator/provision.go (9 hunks)
Additional comments: 15
internal/controller/basic_authenticator/nginx.go (6)
  • 2-11: The import statement for github.com/snapp-incubator/simple-authenticator/pkg/random_generator has been correctly added to support the new functionality.

  • 38-54: The function createNginxDeployment has been correctly renamed and the new parameter customConfig *config.CustomConfig has been added as per the summary.

  • 113-130: The function createNginxConfigmap has been correctly renamed and no changes to the signature have been made, which is consistent with the summary.

  • 110-139: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [133-147]

The function createCredentials has been correctly renamed and no changes to the signature have been made, which is consistent with the summary.

  • 146-158: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [149-213]

The function injector has been correctly renamed and the new parameters customConfig *config.CustomConfig and k8Client client.Client have been added as per the summary.

  • 213-219: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [216-229]

The function fillTemplate is present in the code but not mentioned in the summary. It's important to ensure that all changes are documented, especially if this function has been modified or is new.

internal/controller/basic_authenticator/provision.go (9)
  • 9-17: The added imports align with the PR objective of implementing adaptive scaling and enhancing Kubernetes client operations.

  • 52-70: The function calls have been updated to use the new function names, which is consistent with the PR summary.

  • 195-195: The function signature for createNginxDeployment has been updated to include the r.CustomConfig parameter, aligning with the PR summary.

  • 40-40: The error handling and logging improvements are consistent with the PR objective.

  • 183-225: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [9-325]

No direct modifications to global variables are present in the provided hunks.

  • 203-209: The logic for adaptive scaling in the createDeploymentAuthenticator function is consistent with the PR objective.

  • 292-325: The acquireTargetReplica function is implemented and aligns with the PR summary.

  • 273-273: The injector function is used in the createSidecarAuthenticator function, which is consistent with the PR summary.

  • 183-225: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [9-325]

No issues with the logic or implementation are apparent in the provided hunks.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e513ad3 and 3fd2813.
Files selected for processing (3)
  • internal/controller/basic_authenticator/nginx.go (6 hunks)
  • internal/controller/basic_authenticator/provision.go (9 hunks)
  • pkg/random_generator/random_generator.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/random_generator/random_generator.go
Additional comments: 15
internal/controller/basic_authenticator/nginx.go (6)
  • 9-9: The import statement for github.com/snapp-incubator/simple-authenticator/pkg/random_generator has been correctly added to support the new utility functions.

  • 39-39: The function CreateNginxDeployment has been correctly renamed to createNginxDeployment and the new parameter customConfig *config.CustomConfig has been added as per the summary.

  • 114-114: The function CreateNginxConfigmap has been correctly renamed to createNginxConfigmap without any changes to the signature.

  • 134-134: The function CreateCredentials has been correctly renamed to createCredentials and the return type has been modified to include an error, aligning with the summary.

  • 161-161: The function Injector has been correctly renamed to injector and the new parameters customConfig *config.CustomConfig and k8Client client.Client have been added as per the summary.

  • 111-151: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [2-241]

The changes in the provided hunks align with the PR objective and the summary, enhancing the BasicAuthenticator's ability to manage Nginx deployments with adaptive scaling, improved error handling, logging, and code organization.

internal/controller/basic_authenticator/provision.go (9)
  • 9-17: The added imports for "math" and "sigs.k8s.io/controller-runtime/pkg/client" align with the PR objectives of implementing adaptive scaling and handling Kubernetes client interactions.

  • 52-74: The function calls have been updated to use the new function names, which is consistent with the PR objectives of refactoring for consistent naming conventions.

  • 296-330: The function acquireTargetReplica is implemented to calculate and return a target replica count, which aligns with the PR objectives. However, the function name in the code is in camelCase, which is inconsistent with the summary that refers to it as AcquireTargetReplica. Please verify if the naming convention is intended to be camelCase or PascalCase for consistency across the codebase.

  • 39-40: The error handling and logging have been enhanced with more descriptive messages and appropriate requeue patterns, which aligns with the PR objectives.

  • 9-17: No direct modifications to global variables are observed, and the new dependencies introduced by the imports are consistent with the PR objectives.

  • 196-213: The function signature changes, including the addition of r.CustomConfig to the createNginxDeployment call and the conditional logic based on basicAuthenticator.Spec.AdaptiveScale, are consistent with the PR objectives.

  • 187-229: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-330]

The PR summary mentions a new package random_generator, but its usage is not visible in the provided code. Please verify if the package is used elsewhere in the codebase or if its mention in the summary is an oversight.

  • 187-229: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-330]

The PR objectives mention updates to documentation, but the provided code does not include comments or documentation updates. Please verify if the documentation updates are included in other parts of the codebase.

  • 187-229: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-330]

The logic and implementation in the provided code are consistent with the PR objectives, and there are no apparent issues with the changes.

@hoptical hoptical added the enhancement New feature or request label Dec 2, 2023
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3fd2813 and 0d461ac.
Files selected for processing (2)
  • internal/controller/basic_authenticator/basicauthenticator_controller.go (3 hunks)
  • internal/controller/basic_authenticator/provision.go (6 hunks)
Additional comments: 6
internal/controller/basic_authenticator/basicauthenticator_controller.go (3)
  • 18-42: The addition of the logger field to the BasicAuthenticatorReconciler struct is consistent with the PR objective and the generated summaries. This change will enhance logging capabilities within the reconciler.

  • 52-57: The Reconcile method has been modified to use the new logger field for logging, which aligns with the PR objective and the generated summaries. This change will improve the logging of reconciliation events.

  • 73-91: The new findExternallyManagedDeployments method has been added to watch for changes in deployments and enqueue reconcile requests. This method is consistent with the PR objective and the generated summaries. Ensure that the ExternallyManaged constant is defined and used consistently throughout the codebase.

internal/controller/basic_authenticator/provision.go (3)
  • 9-15: The imports have been correctly updated to include "math" and "sigs.k8s.io/controller-runtime/pkg/client" which aligns with the PR objective and summary.

  • 191-267: The function createDeploymentAuthenticator has been updated to support adaptive scaling, which is in line with the PR objective. The function now correctly uses the acquireTargetReplica method to set the replica count when AdaptiveScale is true.

  • 289-321: The new function acquireTargetReplica has been added to calculate the target replica count for adaptive scaling, which aligns with the PR objective and summary.

@sinamna sinamna merged commit 6474243 into main Dec 2, 2023
1 check passed
@sinamna sinamna deleted the adaptive-scale branch December 11, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants