Skip to content

Commit

Permalink
Refactor predeployed logic for Kubernetes resources
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
c-gerke committed Dec 3, 2024
1 parent bbc989f commit 6c4c6a9
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 36 deletions.
13 changes: 12 additions & 1 deletion lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,20 @@ def use_generated_name(instance_data)
@file = create_definition_tempfile
end

PREDEPLOYED_RESOURCE_TYPES = [
"ResourceQuota",
"NetworkPolicy",
"ConfigMap",
"PersistentVolumeClaim",
"ServiceAccount",
"Role",
"RoleBinding",
"Secret"
]

def predeployed?
predeployed = krane_annotation_value("predeployed")
if type == "Role" || type == "RoleBinding"
if PREDEPLOYED_RESOURCE_TYPES.include?(type)
true
else
default_to_predeployed? ? (predeployed != "false") : (predeployed == "true")
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/config_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class ConfigMap < KubernetesResource
TIMEOUT = 30.seconds

def predeployed?
true
end

def deploy_succeeded?
exists?
end
Expand Down
5 changes: 2 additions & 3 deletions lib/krane/kubernetes_resource/custom_resource_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ def prunable?
prunable == "true"
end

def predeployed?
predeployed = krane_annotation_value("predeployed")
predeployed.nil? || predeployed == "true"
def default_to_predeployed?
true
end

def rollout_conditions
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/network_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class NetworkPolicy < KubernetesResource
TIMEOUT = 30.seconds

def predeployed?
true
end

def status
exists? ? "Created" : "Not Found"
end
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/persistent_volume_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class PersistentVolumeClaim < KubernetesResource
TIMEOUT = 5.minutes

def predeployed?
true
end

def sync(cache)
super
@storage_classes = cache.get_all("StorageClass").map { |sc| StorageClass.new(sc) }
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/resource_quota.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class ResourceQuota < KubernetesResource
TIMEOUT = 30.seconds

def predeployed?
true
end

def status
exists? ? "In effect" : "Not Found"
end
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class Role < KubernetesResource
TIMEOUT = 30.seconds

def predeployed?
true
end

def status
exists? ? "Created" : "Not Found"
end
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/role_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class RoleBinding < KubernetesResource
TIMEOUT = 30.seconds

def predeployed?
true
end

def status
exists? ? "Created" : "Not Found"
end
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/secret.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ class Secret < KubernetesResource
SENSITIVE_TEMPLATE_CONTENT = true
SERVER_DRY_RUNNABLE = true

def predeployed?
true
end

def status
exists? ? "Available" : "Not Found"
end
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/service_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Krane
class ServiceAccount < KubernetesResource
TIMEOUT = 30.seconds

def predeployed?
true
end

def status
exists? ? "Created" : "Not Found"
end
Expand Down

0 comments on commit 6c4c6a9

Please sign in to comment.