Skip to content

Conversation

@jonathankingfc
Copy link
Contributor

@jonathankingfc jonathankingfc commented May 30, 2024

  • Swap Postgres and Clair Postgres Deployments to StatefulSets

Summary by Sourcery

Convert Postgres deployments for Quay and Clair from Deployments to StatefulSets to improve database management and persistence

Enhancements:

  • Migrate Postgres and Clair Postgres configurations from Deployments to StatefulSets to provide better stateful application management

CI:

  • Update CI workflow to simplify test command
  • Remove manual Kubebuilder installation step

Chores:

  • Update Kustomize configurations and patches to reflect StatefulSet changes
  • Modify Kubernetes resource management to use StatefulSet kind

@jonathankingfc jonathankingfc force-pushed the PROJQUAY-6672 branch 10 times, most recently from 7e3cab8 to fb9e6ba Compare June 5, 2024 19:09
@@ -1,5 +1,5 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
Copy link
Collaborator

Choose a reason for hiding this comment

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

how will this work with existing deployments? On upgrade will it replace the deployment with a statefulset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will replace the deployment with a stateful set. This is so that we do not have issues with overlapping deployments that would cause issues on the upgrade job.

replicas: 1
strategy:
type: Recreate
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will switch the deployment to a rolling upgrade, which could cause the old and new pod to run at the same time. Will that cause issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it is a stateful set, it will only run one pod at a time

Copy link

Choose a reason for hiding this comment

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

In theory, issues can occur where Quay is operating on a Clair that has a split-brain during a deployment (i.e. the security worker requests the indexing state from a new pod, sees it has changed then makes an indexing request but it goes to an old pod). In practice, this is how it works in production and we've never seen problems so I think it's probably fine but something to document.

@@ -1,5 +1,5 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
Copy link
Collaborator

Choose a reason for hiding this comment

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

The original issue seems to be caused by the old and the new db pods being matched by the same service, making the requests against the db go to either or randomly. Does switching to stateful sets fix this issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since their will be only one underlying pod attached to the service

@jonathankingfc
Copy link
Contributor Author

/retest

1 similar comment
@bcaton85
Copy link
Collaborator

bcaton85 commented Sep 9, 2024

/retest

- Swap Postgres and Clair Postgres Deployments to StatefulSets
@openshift-ci
Copy link

openshift-ci bot commented Oct 15, 2024

@jonathankingfc: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ocp-latest-e2e 0ba46ee link true /test ocp-latest-e2e

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@HammerMeetNail
Copy link
Collaborator

@sourcery-ai summary

@openshift-merge-robot
Copy link
Collaborator

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@HammerMeetNail
Copy link
Collaborator

@sourcery-ai review

@deshpandevlab
Copy link
Contributor

@sourcery-ai guide

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 3, 2025

Reviewer's Guide by Sourcery

This pull request migrates the Postgres and Clair Postgres deployments to StatefulSets for improved database management and persistence. The Kustomize configurations and patches have been updated to reflect these changes. The test command in the Makefile has been simplified, and the Kubebuilder installation process in the CI workflow has been updated. Finally, the StatefulSet kind was added to the kustomize package.

Updated class diagram for Kustomize ModelFor function

classDiagram
  class client.Object {
  }
  class apps.StatefulSet {
  }
  client.Object <|-- apps.StatefulSet
  note for apps.StatefulSet "Added StatefulSet type to ModelFor function"
Loading

File-Level Changes

Change Details Files
Migrated Postgres and Clair Postgres configurations from Deployments to StatefulSets.
  • Changed the kind of the Postgres and Clair Postgres resources from Deployment to StatefulSet.
  • Added serviceName to the specifications of the StatefulSets.
  • Removed the strategy field from the specifications of the StatefulSets.
  • Added volumeClaimTemplates to the specifications of the StatefulSets.
kustomize/components/clairpostgres/postgres.statefulset.yaml
kustomize/components/postgres/postgres.statefulset.yaml
kustomize/components/clairpostgres/kustomization.yaml
kustomize/components/clairpgupgrade/base/clair-pg.statefulset.patch.yaml
kustomize/components/clairpgupgrade/base/kustomization.yaml
kustomize/components/pgupgrade/kustomization.yaml
kustomize/components/pgupgrade/quay-pg.statefulset.patch.yaml
kustomize/components/postgres/kustomization.yaml
Updated the Kustomize configurations and patches to reflect the StatefulSet changes.
  • Updated the Kustomize files to reference the new StatefulSet resources.
  • Updated patches to be compatible with StatefulSets.
kustomize/components/clairpostgres/kustomization.yaml
kustomize/components/clairpgupgrade/base/kustomization.yaml
kustomize/components/pgupgrade/kustomization.yaml
kustomize/components/postgres/kustomization.yaml
Simplified the test command in the Makefile and updated Kubebuilder installation in CI workflow.
  • Replaced the explicit go test command with make test in the Makefile.
  • Removed the Kubebuilder installation steps from the CI workflow.
.github/workflows/ci.yaml
Makefile
Added StatefulSet to the list of known Kinds in the kustomize package.
  • Added a case for StatefulSet to the ModelFor function to return a apps.StatefulSet object.
pkg/kustomize/kustomize.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jonathankingfc - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding podManagementPolicy: Parallel to the StatefulSet spec to speed up deployments.
  • Consider adding updateStrategy to the StatefulSet spec to control the update process.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@HammerMeetNail
Copy link
Collaborator

Hey @jonathankingfc - I've reviewed your changes - here's some feedback:

Overall Comments:

* Consider adding podManagementPolicy: Parallel to the StatefulSet spec to speed up deployments.

* Consider adding updateStrategy to the StatefulSet spec to control the update process.

Here's what I looked at during the review
Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Can you provide an example of the proposed changes?

@deshpandevlab
Copy link
Contributor

Hey @jonathankingfc - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding podManagementPolicy: Parallel to the StatefulSet spec to speed up deployments.
  • Consider adding updateStrategy to the StatefulSet spec to control the update process.

Here's what I looked at during the review
Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sourcery-ai how did you evaluate tests?

@deshpandevlab
Copy link
Contributor

@sourcery-ai plan

@deshpandevlab
Copy link
Contributor

@sourcery-ai review

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 3, 2025

Sure! I'm generating a new review now.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jonathankingfc - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why the Kubebuilder installation was removed from the CI workflow.
  • Ensure that the volumeClaimTemplates are properly configured for the StatefulSets to manage persistent storage.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jonathankingfc - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why the Kubebuilder installation was removed from the CI workflow.
  • Ensure that the volumeClaimTemplates are properly configured for the StatefulSets to manage persistent storage.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 3, 2025

Hey @deshpandevlab, I've posted a new review for you!

@HammerMeetNail
Copy link
Collaborator

@sourcery-ai help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants