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

Allow more resources to be predeployed #969

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

c-gerke
Copy link

@c-gerke c-gerke commented Dec 4, 2024

What are you trying to accomplish with this PR?

This PR aims to allow operators of the Krane gem to designate more types of resources as being able to be "predeployed" than just CRs and CRDs, as was the previous behavior of the "predeployed" logic.

How is this accomplished?

There are a few changes that have been made to facilitate this:

Documentation Updates:

  • CONTRIBUTING.md: Added instructions for implementing the predeployed? method in custom Kubernetes resource classes and updated the references for adding new resources
  • README.md: Expanded the description of the krane.shopify.io/predeployed annotation to include more resource types and clarified its default behavior

Code Enhancements:

  • lib/krane/kubernetes_resource.rb: Introduced a PREDEPLOYED_RESOURCE_TYPES constant to hold all of the resources that were previously statically predeployed, and a predeployed? method to determine if a resource should be predeployed based on its type or annotation, which is inherited by all lib/krane/kubernetes_resource files
  • lib/krane/kubernetes_resource/custom_resource.rb: Added a predeployed? method to handle custom resources, defaulting to true, similar to that in custom_resource_definition.rb
  • lib/krane/deploy_task.rb: Updated the predeploy_sequence method to include additional resource types in the predeploy sequence

Deployment Process:

  • lib/krane/resource_deployer.rb: Modified the predeploy_priority_resources method to filter resources based on the predeployed? method (see questions section below for a clarification request)
  • lib/krane/resource_deployer.rb: Added a StatsD measurement for the sync duration in the deploy_resources method

Tests:

  • test/helpers/mock_resource.rb: Modified to allow the test MockResource to be able to be predeployed
  • test/integration-serial/serial_deploy_test.rb: Added multiple tests to verify that resources with the krane.shopify.io/predeployed annotation are correctly predeployed
  • test/unit/krane/resource_deployer_test.rb: Modified unit tests to ensure the predeploy_priority_resources method respects the predeploy list and the predeployed? annotation, and that the unit tests know how to operate in a universe where the krane.shopify.io/predeployed annotation can be deployed to almost any resource

What could go wrong?

This could allow operators of Krane to deploy resources out of sequence, causing deployments to fail and requiring troubleshooting.

An example of this failure mode would be adding the annotation to a Service, causing it to be predeployed before a Deployment that the Service would target. In this case where the krane.shopify.io/predeployed: "true" annotation is set on the Service without something like the krane.shopify.io/skip-endpoint-validation: "true" annotation, the Service will fail citing there are no endpoints for the Service and the deployment is likely invalid.

In essence, most of the observed "cons" are giving operators of Krane a gun that could be used to shoot themselves in the foot.

Additional comments and questions

lib/krane/resource_deployer.rb and lib/krane/deploy_task.rb

In lib/krane/resource_deployer.rb, we are getting all of the resources and filtering afterwards for those with the predeployed annotation. 1 This is a different behavior than that for CRs in lib/krane/deploy_task.rb because we don't have access in lib/krane/deploy_task.rb at that point in the process to read the files and determine if they need to be predeployed.

This causes us to always hit 'phase 3 - predeploy' of the deployment process (thus the change in line 347 of test/integration-serial/serial_deploy_test.rb), which seems a little inefficient. Is there a better way that we should do this so we can skip hitting 'phase 3 - predeploy' if there aren't any resources that will need to be predeployed?

oct8l and others added 29 commits November 23, 2024 16:33
- Updated `predeploy_sequence` to specify resource groups for better clarity.
- Modified `predeployed?` method logic to allow for default behavior based on resource type.
- Introduced `default_to_predeployed?` method in multiple resource classes to standardize predeployment behavior.
- Removed redundant `predeployed?` methods from `Deployment`, `Job`, and `Service` classes.
- Added debug logging in integration tests for better traceability of resource groups during deployment.
This will be fixed later on, but getting a proposed version up in a PR to Shopify's Krane is the priority
- Introduced a constant `PREDEPLOYED_RESOURCE_TYPES` to manage predeployed resource types.
- Updated `predeployed?` method to utilize the new constant for Role and RoleBinding checks.
- Removed redundant `predeployed?` methods from ConfigMap, NetworkPolicy, PersistentVolumeClaim, ResourceQuota, Role, RoleBinding, Secret, and ServiceAccount classes, simplifying their implementation.
- Set `default_to_predeployed?` to always return true in CustomResourceDefinition.
… on this PR

Also add CRDs and CRs to their previous functionality, not using the `default_to_predeployed` functionality
… annotation is correctly deployed in phase 3
Multiple test cases in `serial_deploy_test.rb` to verify that various Kubernetes resources (Service, Ingress, Job, DaemonSet, PodDisruptionBudget, PodTemplate, ReplicaSet, StatefulSet) with the `krane.shopify.io/predeployed` annotation are correctly predeployed and logged in the expected phases.
Remove a pedantic documentation change that increases the number of changes in this fork for little benefit

Fix link that points to the Power fork instead of Krane fork
@timothysmith0609
Copy link
Contributor

Hi @c-gerke is this PR ready for a proper review? Thanks for the contribution!

@c-gerke
Copy link
Author

c-gerke commented Jan 15, 2025

Hi @c-gerke is this PR ready for a proper review? Thanks for the contribution!

Hi there @timothysmith0609! I do believe this PR is ready for a proper review. I appreciate having such an awesome and useful project to contribute to and I look forward to learning how I can make it better and hopefully get the changes accepted!

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.

3 participants