Class: Kube::Helm::Repo
- Inherits:
-
Object
- Object
- Kube::Helm::Repo
- Defined in:
- lib/kube/helm/repo.rb
Overview
Models a Helm chart repository (traditional or OCI).
Wraps the lifecycle commands (‘helm repo add`, `helm repo update`, `helm repo remove`) and fetches charts for rendering.
When a cluster is provided, all Helm commands are scoped to that cluster’s kubeconfig.
repo = Kube::Helm::Repo.new("bitnami", url: "https://charts.bitnami.com/bitnami")
chart = repo.fetch("nginx", version: "18.1.0")
manifest = chart.apply_values({ "replicaCount" => 3 })
# One-liner
manifest = Kube::Helm::Repo
.new("bitnami", url: "https://charts.bitnami.com/bitnami")
.fetch("nginx", version: "18.1.0")
.apply_values({ "replicaCount" => 3 })
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#add ⇒ self
Register this repo with the local Helm client.
-
#fetch(chart_name, version: nil) ⇒ Chart
Fetch a chart from this repo.
-
#initialize(name, url:, cluster: nil) ⇒ Repo
constructor
A new instance of Repo.
-
#oci? ⇒ Boolean
Is this an OCI-backed repo?.
-
#remove ⇒ self
Remove this repo from the local Helm client.
- #to_s ⇒ Object
-
#update ⇒ self
Update the local chart index for this repo.
Constructor Details
#initialize(name, url:, cluster: nil) ⇒ Repo
Returns a new instance of Repo.
32 33 34 35 36 37 38 39 40 |
# File 'lib/kube/helm/repo.rb', line 32 def initialize(name, url:, cluster: nil) unless name.is_a?(String) && !name.strip.empty? raise ArgumentError, "name must be a non-empty String" end @name = name @endpoint = Endpoint.new(url) @cluster = cluster end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
27 28 29 |
# File 'lib/kube/helm/repo.rb', line 27 def cluster @cluster end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
27 28 29 |
# File 'lib/kube/helm/repo.rb', line 27 def endpoint @endpoint end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/kube/helm/repo.rb', line 27 def name @name end |
Instance Method Details
#add ⇒ self
Register this repo with the local Helm client. No-op for OCI registries.
46 47 48 49 50 51 52 53 54 |
# File 'lib/kube/helm/repo.rb', line 46 def add if endpoint.requires_add? repo_name = @name repo_url = endpoint.url cmd = helm.call { repo.add.(repo_name).(repo_url) } helm.run(cmd.to_s) end self end |
#fetch(chart_name, version: nil) ⇒ Chart
Fetch a chart from this repo.
Adds and updates the repo, retrieves the Chart.yaml metadata via ‘helm show chart`, and returns a Chart object with the ref set for subsequent helm commands.
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/kube/helm/repo.rb', line 91 def fetch(chart_name, version: nil) add update ref = endpoint.chart_ref(chart_name, repo_name: @name) cmd = helm.call { show.chart.(ref) } cmd = cmd.version(version) if version yaml_output = helm.run(cmd.to_s) data = YAML.safe_load(yaml_output, permitted_classes: [Symbol]) || {} Chart.new(data, ref: ref, cluster: @cluster) end |
#oci? ⇒ Boolean
Is this an OCI-backed repo?
106 107 108 |
# File 'lib/kube/helm/repo.rb', line 106 def oci? endpoint.oci? end |
#remove ⇒ self
Remove this repo from the local Helm client. No-op for OCI registries.
73 74 75 76 77 78 79 80 |
# File 'lib/kube/helm/repo.rb', line 73 def remove if endpoint.requires_add? repo_name = @name cmd = helm.call { repo.remove.(repo_name) } helm.run(cmd.to_s) end self end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/kube/helm/repo.rb', line 110 def to_s "#{@name} (#{endpoint.url})" end |
#update ⇒ self
Update the local chart index for this repo. No-op for OCI registries.
60 61 62 63 64 65 66 67 |
# File 'lib/kube/helm/repo.rb', line 60 def update if endpoint.requires_add? repo_name = @name cmd = helm.call { repo.update.(repo_name) } helm.run(cmd.to_s) end self end |