-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add memcached resource * Remove whitespace * Code review * Fix compile error * Fix some issues with predicates * Fetch using labels instead of name. * Code cleanup
- Loading branch information
1 parent
7da5ab3
commit 1645b70
Showing
3 changed files
with
65 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
module KubernetesDeploy | ||
class Memcached < KubernetesResource | ||
TIMEOUT = 5.minutes | ||
SECRET_NAME = "memcached-url" | ||
|
||
def sync | ||
_, _err, st = kubectl.run("get", type, @name) | ||
@found = st.success? | ||
@deployment_exists = memcached_deployment_exists? | ||
@service_exists = memcached_service_exists? | ||
@secret_exists = memcached_secret_exists? | ||
|
||
@status = if @deployment_exists && @service_exists && @secret_exists | ||
"Provisioned" | ||
else | ||
"Unknown" | ||
end | ||
end | ||
|
||
def deploy_succeeded? | ||
@deployment_exists && @service_exists && @secret_exists | ||
end | ||
|
||
def deploy_failed? | ||
false | ||
end | ||
|
||
def exists? | ||
@found | ||
end | ||
|
||
private | ||
|
||
def memcached_deployment_exists? | ||
deployments, _err, st = kubectl.run("get", "deployments", "-l name=#{@name}", "-o=json") | ||
return false unless st.success? | ||
parsed = JSON.parse(deployments) | ||
return false if parsed.fetch("items", []).count == 0 | ||
deployment = parsed.fetch("items", []).first | ||
status = deployment.fetch("status", {}) | ||
status.fetch("availableReplicas", -1) == status.fetch("replicas", 0) | ||
end | ||
|
||
def memcached_service_exists? | ||
services, _err, st = kubectl.run("get", "services", "-l name=#{@name}", "-o=json") | ||
return false unless st.success? | ||
parsed = JSON.parse(services) | ||
return false if parsed.fetch("items", []).count == 0 | ||
service = parsed.fetch("items", []).first | ||
service.dig("spec", "clusterIP").present? | ||
end | ||
|
||
def memcached_secret_exists? | ||
secret, _err, st = kubectl.run("get", "secrets", SECRET_NAME, "-o=json") | ||
return false unless st.success? | ||
parsed = JSON.parse(secret) | ||
parsed.dig("data", @name).present? | ||
end | ||
end | ||
end |
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