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

Insure that any resource that is prunable can be pruned #326

Merged
merged 5 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/kubernetes-deploy/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def prune_whitelist
extensions/v1beta1/Ingress
apps/v1beta1/StatefulSet
autoscaling/v1/HorizontalPodAutoscaler
policy/v1beta1/PodDisruptionBudget
)
if server_version >= Gem::Version.new('1.8.0')
wl << "batch/v1beta1/CronJob"
Expand Down Expand Up @@ -359,6 +360,9 @@ def deploy_resources(resources, prune: false, verify:, record_summary: true)

# Apply can be done in one large batch, the rest have to be done individually
applyables, individuals = resources.partition { |r| r.deploy_method == :apply }
# Prunable resources should also applied so that they can be pruned
pruneable_types = prune_whitelist.map { |t| t.split("/").last }
applyables += individuals.select { |r| pruneable_types.include?(r.type) }

individuals.each do |r|
@logger.info("- #{r.id} (#{r.pretty_timeout_type})") if resources.length > 1
Expand Down
4 changes: 0 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ def status
def deploy_failed?
false
end

def deploy_method
:replace
end
end
end
4 changes: 0 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def deploy_failed?
false
end

def deploy_method
:replace
end

private

def proxy_deployment_ready?
Expand Down
4 changes: 0 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ def deploy_succeeded?
def deploy_failed?
false
end

def deploy_method
:replace
end
end
end
4 changes: 0 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/memcached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def deploy_failed?
false
end

def deploy_method
:replace
end

private

def deployment_ready?
Expand Down
4 changes: 0 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def deploy_failed?
false
end

def deploy_method
:replace
end

private

def deployment_ready?
Expand Down
4 changes: 0 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ def deploy_succeeded?
def deploy_failed?
false
end

def deploy_method
:replace
end
end
end
2 changes: 2 additions & 0 deletions test/fixtures/crd/mail_cr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ apiVersion: "stable.example.io/v1"
kind: Mail
metadata:
name: my-first-mail
spec:
something: 7
12 changes: 12 additions & 0 deletions test/integration-serial/run_serial_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ def test_multiple_configuration_files
ENV['KUBECONFIG'] = old_config
end

def test_cr_merging
assert_deploy_success(deploy_fixtures("crd", subset: %w(mail.yml)))
assert_deploy_success(deploy_fixtures("crd", subset: %w(mail_cr.yml)))
result = deploy_fixtures("crd", subset: %w(mail_cr.yml)) do |f|
mail = f.dig("mail_cr.yml", "Mail").first
mail["spec"]["something"] = 5
end
assert_deploy_success(result)
ensure
apiextensions_v1beta1_kubeclient.delete_custom_resource_definition("mail.stable.example.io")
end

def test_crd_can_fail
result = deploy_fixtures("crd", subset: %w(mail.yml)) do |f|
crd = f.dig("mail.yml", "CustomResourceDefinition").first
Expand Down
9 changes: 8 additions & 1 deletion test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def test_pruning_works
'daemonset(\.extensions)? "ds-app"',
'statefulset(\.apps)? "stateful-busybox"',
'job(\.batch)? "hello-job"',
'poddisruptionbudget(.policy)? "test"',
] # not necessarily listed in this order
expected_msgs = [/Pruned 9 resources and successfully deployed 6 resources/]
expected_msgs = [/Pruned 10 resources and successfully deployed 6 resources/]
expected_pruned.map do |resource|
expected_msgs << /The following resources were pruned:.*#{resource}/
end
Expand Down Expand Up @@ -1070,4 +1071,10 @@ def test_hpa_can_be_pruned
assert_deploy_success(deploy_fixtures("hpa", subset: ["deployment.yml"]))
assert_logs_match_all([/The following resources were pruned: horizontalpodautoscaler(.autoscaling)? "hello-hpa"/])
end

def test_not_apply_resource_can_be_pruned
assert_deploy_success(deploy_fixtures("hello-cloud", subset: %w(disruption-budgets.yml configmap-data.yml)))
assert_deploy_success(deploy_fixtures("hello-cloud", subset: %w(configmap-data.yml)))
assert_logs_match_all([/The following resources were pruned: poddisruptionbudget(.policy)? "test"/])
end
end