Class: Kube::Helm::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/kube/helm/endpoint.rb

Overview

Abstracts the differences between Helm chart sources.

Traditional Helm repos require ‘helm repo add` before charts can be referenced, and charts are addressed as “repo-name/chart-name”.

OCI registries need no ‘repo add` step, and charts are addressed as the full OCI URI: “oci://host/path/chart-name”.

endpoint = Kube::Helm::Endpoint.new("https://charts.bitnami.com/bitnami")
endpoint.oci?           #=> false
endpoint.requires_add?  #=> true
endpoint.chart_ref("nginx", repo_name: "bitnami")
#=> "bitnami/nginx"

endpoint = Kube::Helm::Endpoint.new("oci://ghcr.io/my-org/charts")
endpoint.oci?           #=> true
endpoint.requires_add?  #=> false
endpoint.chart_ref("nginx")
#=> "oci://ghcr.io/my-org/charts/nginx"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Endpoint

Returns a new instance of Endpoint.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File 'lib/kube/helm/endpoint.rb', line 28

def initialize(url)
  raise ArgumentError, "url must be a String" unless url.is_a?(String)
  raise ArgumentError, "url must not be empty" if url.strip.empty?

  @url = url.chomp("/")
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



26
27
28
# File 'lib/kube/helm/endpoint.rb', line 26

def url
  @url
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
# File 'lib/kube/helm/endpoint.rb', line 70

def ==(other)
  other.is_a?(Endpoint) && other.url == @url
end

#chart_ref(chart_name, repo_name: nil) ⇒ String

Build the chart reference string Helm expects.

For OCI: “oci://host/path/chart-name” For traditional: “repo-name/chart-name”

Parameters:

  • chart_name (String)

    the chart name (e.g. “nginx”)

  • repo_name (String, nil) (defaults to: nil)

    the local repo alias (required for non-OCI)

Returns:

  • (String)


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kube/helm/endpoint.rb', line 53

def chart_ref(chart_name, repo_name: nil)
  if oci?
    "#{@url}/#{chart_name}"
  else
    if repo_name.nil?
      raise ArgumentError,
        "repo_name is required for non-OCI endpoints"
    end

    "#{repo_name}/#{chart_name}"
  end
end

#oci?Boolean

Is this an OCI registry endpoint?

Returns:

  • (Boolean)


36
37
38
# File 'lib/kube/helm/endpoint.rb', line 36

def oci?
  @url.start_with?("oci://")
end

#requires_add?Boolean

Traditional Helm repos require ‘helm repo add`; OCI registries do not.

Returns:

  • (Boolean)


41
42
43
# File 'lib/kube/helm/endpoint.rb', line 41

def requires_add?
  !oci?
end

#to_sObject



66
67
68
# File 'lib/kube/helm/endpoint.rb', line 66

def to_s
  @url
end