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

Wait for rollout #260

Merged
merged 11 commits into from
Mar 22, 2025
Merged

Wait for rollout #260

merged 11 commits into from
Mar 22, 2025

Conversation

Starefossen
Copy link
Member

@Starefossen Starefossen commented Dec 11, 2023

This pull request introduces several enhancements and fixes to the UnleashReconciler in the controllers/unleash_controller.go file. The most significant changes include adding a deployment readiness check, refactoring error handling, and updating the test suite to cover new functionalities.

Enhancements and Fixes:

Deployment Readiness Check:

  • Introduced a new constant deploymentTimeout and a function waitForDeployment to ensure the deployment rollout is complete before proceeding. (controllers/unleash_controller.go) [1] [2] [3]
  • Added utility functions getDeployment, setDeploymentStatusFailed, and setDeploymentStatusAvailable to facilitate deployment status checks in tests. (controllers/unleash_controller_test.go) [1] [2] [3]

Error Handling:

  • Refactored error handling in the Reconcile function to use a more consistent variable name statusErr for status update errors. (controllers/unleash_controller.go) [1] [2] [3] [4]

Test Suite Updates:

  • Added new test cases to ensure proper handling of deployment status and readiness checks. (controllers/unleash_controller_test.go) [1] [2]
  • Implemented the TestDeploymentIsReady function to validate the deployment readiness utility. (pkg/utils/k8s_test.go)

Utility Enhancements:

  • Added the DeploymentIsReady function to the utils package for checking deployment readiness. (pkg/utils/k8s.go)

Imports:

  • Added necessary imports for new functionalities in controllers/unleash_controller.go and pkg/utils/k8s.go. [1] [2] [3] [4]

Close #193

@Starefossen Starefossen marked this pull request as ready for review December 30, 2023 16:04
@Starefossen Starefossen requested a review from a team as a code owner December 30, 2023 16:04
Copy link
Contributor

@Reasonable-Solutions Reasonable-Solutions left a comment

Choose a reason for hiding this comment

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

lgtm.

@Starefossen Starefossen mentioned this pull request Jul 13, 2024
2 tasks
@Starefossen Starefossen requested a review from Copilot March 10, 2025 08:27

Choose a reason for hiding this comment

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

PR Overview

This pull request enhances the Unleash controllers by adding a deployment readiness check, refactoring error and status handling, and updating the test suite to cover new functionalities.

  • Introduces a waitForDeployment function and associated tests for deployment rollout readiness.
  • Refactors error handling in the Reconcile function with more descriptive error variable names.
  • Consolidates code changes across controllers and utilities to support the enhanced deployment and network policy management.

Reviewed Changes

File Description
pkg/utils/k8s_test.go Added tests for the new DeploymentIsReady utility function.
controllers/unleash_controller_test.go Introduced helper functions and test cases for faking deployment statuses.
pkg/utils/k8s.go Added the DeploymentIsReady utility function.
controllers/unleash_controller.go Updated the reconcile loop to include a deployment rollout wait and refined error handling.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

controllers/unleash_controller.go:213

  • The variable 'statsusErr' appears to be a typo; consider renaming it to 'statusErr' for clarity and consistency with its intended meaning.
if statsusErr := r.updateStatusReconcileFailed(ctx, unleash, err, "Failed to reconcile Secrets"); statsusErr != nil {
@Starefossen Starefossen force-pushed the deploy-rollout-wait branch 2 times, most recently from bdd98e5 to a17c7d8 Compare March 19, 2025 20:34
@Starefossen Starefossen requested a review from Copilot March 19, 2025 20:36

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds a deployment readiness check to the Unleash controller along with error handling refactors and new test cases for deployment status. Key changes include:

  • Introducing a waitForDeployment function with a new timeout and requeueAfter constant.
  • Refactoring the reconcile flow to log and update error messages consistently.
  • Expanding the test suite with new deployment readiness scenarios.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/utils/k8s.go Added/updated DeploymentIsReady function with added documentation comment.
pkg/utils/k8s_test.go Added tests validating the behavior of DeploymentIsReady under different conditions.
controllers/unleash_controller.go Reordered and enhanced reconcile steps by introducing waitForDeployment and updating errors.
controllers/unleash_controller_test.go Added utility functions and test cases to simulate deployment status and readiness changes.
Comments suppressed due to low confidence (3)

controllers/unleash_controller.go:235

  • [nitpick] Ensure that the span event messages and the corresponding error update messages remain consistent as the reconcile order has changed. This will improve traceability and debugging clarity.
span.AddEvent("Reconciling NetworkPolicy")

controllers/unleash_controller.go:312

  • [nitpick] The error handling block for waitForDeployment repeats the status update call and error return, leading to potential redundancy. Consider refactoring to call updateStatusReconcileFailed once and then return the error.
if err = r.waitForDeployment(ctx, deploymentTimeout, req.NamespacedName); err != nil {

controllers/unleash_controller_test.go:198

  • [nitpick] Similar blocks of code for simulating deployment status (failed/available) appear multiple times. Consider extracting a helper function to reduce duplication and improve maintainability in tests.
setDeploymentStatusFailed(createdDeployment)
@Starefossen Starefossen force-pushed the deploy-rollout-wait branch 2 times, most recently from 8a7a3f2 to d3fb90c Compare March 20, 2025 13:50
@Starefossen Starefossen force-pushed the deploy-rollout-wait branch from efd3dd5 to 9f15805 Compare March 22, 2025 19:57
@Starefossen Starefossen requested a review from Copilot March 22, 2025 20:02

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances the Unleash reconciler by adding a deployment readiness check, refactoring error handling, and updating associated tests and configuration files. Key changes include:

  • Introducing a rollout wait mechanism with a new waitForDeployment function.
  • Refactoring reconciliation order and error handling in the controller.
  • Updating test suites, YAML charts, and utilities for deployment and ApiToken status.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
charts/unleasherator/templates/tests/test-unleash-v5.yaml New YAML test manifest for Unleash instance connection validation
charts/unleasherator/ci/k3s-values.yaml Updated configuration values including network policy and OTLP endpoint settings
pkg/utils/k8s_test.go Added tests for Deployment readiness utility
controllers/unleash_controller_test.go Added helper functions for faking Deployment status in tests
controllers/unleash_controller.go Refactored reconciliation order; introduced rollout waiting via waitForDeployment
charts/unleasherator/ci/gcp-values.yaml Adjusted API server CIDR and allowed namespaces
pkg/utils/k8s.go Added DeploymentIsReady utility function
.github/workflows/chart.yaml Updated helm command with extended timeout arguments
config/samples/unleash_v1_apitoken.yaml Fixed typo in the sample ApiToken manifest
controllers/apitoken_controller.go Renamed constant for requeue duration and updated status handling
Comments suppressed due to low confidence (4)

charts/unleasherator/ci/k3s-values.yaml:18

  • Review the indentation and structure of the 'otlpServiceEndpoint' configuration to ensure it adheres to valid YAML schema.
otlpServiceEndpoint:

controllers/unleash_controller_test.go:74

  • [nitpick] Consider increasing the deploymentTimeout duration in tests to avoid potential flakiness in environments with slower response times.
deploymentTimeout = time.Second * 1

controllers/unleash_controller.go:235

  • [nitpick] Ensure that the reordering of reconciliation steps (NetworkPolicy before Deployment) is intentional, as it differs from the previous sequence.
span.AddEvent("Reconciling NetworkPolicy")

config/samples/unleash_v1_apitoken.yaml:11

  • Correct the spelling of 'unleasshInstance' to 'unleashInstance'.
unleasshInstance:
@Starefossen Starefossen enabled auto-merge (squash) March 22, 2025 20:39
@Starefossen Starefossen merged commit 45edbe0 into main Mar 22, 2025
10 checks passed
@Starefossen Starefossen deleted the deploy-rollout-wait branch March 22, 2025 20:49
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.

Connection tests does not wait for rollout to complete
2 participants