-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic Custom Resource Deployments (#376)
- Loading branch information
1 parent
a3d2f05
commit a591e52
Showing
19 changed files
with
890 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
lib/kubernetes-deploy/kubernetes_resource/custom_resource.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# frozen_string_literal: true | ||
require 'jsonpath' | ||
|
||
module KubernetesDeploy | ||
class CustomResource < KubernetesResource | ||
TIMEOUT_MESSAGE_DIFFERENT_GENERATIONS = <<~MSG | ||
This resource's status could not be used to determine rollout success because it is not up-to-date | ||
(.metadata.generation != .status.observedGeneration). | ||
MSG | ||
|
||
def initialize(namespace:, context:, definition:, logger:, statsd_tags: [], crd:) | ||
super(namespace: namespace, context: context, definition: definition, | ||
logger: logger, statsd_tags: statsd_tags) | ||
@crd = crd | ||
end | ||
|
||
def timeout | ||
timeout_override || @crd.timeout_for_instance || TIMEOUT | ||
end | ||
|
||
def deploy_succeeded? | ||
return super unless rollout_conditions | ||
return false unless observed_generation == current_generation | ||
|
||
rollout_conditions.rollout_successful?(@instance_data) | ||
end | ||
|
||
def deploy_failed? | ||
return super unless rollout_conditions | ||
return false unless observed_generation == current_generation | ||
|
||
rollout_conditions.rollout_failed?(@instance_data) | ||
end | ||
|
||
def failure_message | ||
return super unless rollout_conditions | ||
messages = rollout_conditions.failure_messages(@instance_data) | ||
messages.join("\n") if messages.present? | ||
end | ||
|
||
def timeout_message | ||
if rollout_conditions && current_generation != observed_generation | ||
TIMEOUT_MESSAGE_DIFFERENT_GENERATIONS | ||
else | ||
super | ||
end | ||
end | ||
|
||
def status | ||
if !exists? || rollout_conditions.nil? | ||
super | ||
elsif deploy_succeeded? | ||
"Healthy" | ||
elsif deploy_failed? | ||
"Unhealthy" | ||
else | ||
"Unknown" | ||
end | ||
end | ||
|
||
def type | ||
kind | ||
end | ||
|
||
def validate_definition(kubectl) | ||
super | ||
|
||
@crd.validate_rollout_conditions | ||
rescue RolloutConditionsError => e | ||
@validation_errors << "The CRD that specifies this resource is using invalid rollout conditions. " \ | ||
"Kubernetes-deploy will not be able to continue until those rollout conditions are fixed.\n" \ | ||
"Rollout conditions can be found on the CRD that defines this resource (#{@crd.name}), " \ | ||
"under the annotation #{CustomResourceDefinition::ROLLOUT_CONDITIONS_ANNOTATION}.\n" \ | ||
"Validation failed with: #{e}" | ||
end | ||
|
||
private | ||
|
||
def kind | ||
@definition["kind"] | ||
end | ||
|
||
def rollout_conditions | ||
@crd.rollout_conditions | ||
end | ||
end | ||
end |
Oops, something went wrong.