Skip to content

Commit

Permalink
Run crystal-lang autoformatter on rest of the repo
Browse files Browse the repository at this point in the history
- Do other formatting operations as breaking long lines etc
- Update according to changes in Helm module

Signed-off-by: Rafal Lal <[email protected]>
  • Loading branch information
rafal-lal committed Feb 5, 2025
1 parent 334d1b6 commit 9010245
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 86 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
on:
push:
paths:
- '**'
- '!**.md'
- "**"
- "!**.md"
pull_request:
paths:
- '**'
- '!**.md'
- "**"
- "!**.md"
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Download source
uses: actions/checkout@v2

- name: Install Crystal
uses: crystal-lang/install-crystal@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Create k8s Kind Cluster
uses: helm/[email protected]

- name: Global Helm Binary
uses: azure/setup-helm@v3

- name: Run tests
run: |
shards install
crystal spec
crystal spec
4 changes: 2 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.0
shards:
docker_client:
git: https://github.com/cnf-testsuite/docker_client.git
version: 0.1.0+git.commit.32dacefbc3dfcf98c8126ff793c97a3038e9b122
version: 1.0.0

find:
git: https://github.com/cnf-testsuite/find.git
Expand All @@ -14,7 +14,7 @@ shards:

kubectl_client:
git: https://github.com/cnf-testsuite/kubectl_client.git
version: 0.1.0+git.commit.12cad24a372469e34e0f64019b10e1b3dc82a124
version: 1.0.7

popcorn:
git: https://github.com/icyleaf/popcorn.git
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "spec"
require "colorize"

ENV["CRYSTAL_ENV"] = "TEST"
ENV["CRYSTAL_ENV"] = "TEST"
38 changes: 19 additions & 19 deletions spec/utils/system_information_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ describe "Helm" do
(Helm::SystemInfo.helm_installation_info(true)).should contain("helm found")
end

it "'Helm::SystemInfo.global_helm_installed?' should return the information about the helm installation", tags: ["helm-utils"] do
it "'Helm::SystemInfo.global_helm_installed?' should return the information about the helm installation", tags: ["helm-utils"] do
(Helm::SystemInfo.global_helm_installed?).should be_true
end

it "local helm should not be detected", tags: ["helm-utils"] do
it "local helm should not be detected", tags: ["helm-utils"] do
(Helm::BinarySingleton.local_helm_installed?).should be_false
end
it "'Helm::BinarySingleton.installation_found?' should find installation", tags: ["helm-utils"] do

it "'Helm::BinarySingleton.installation_found?' should find installation", tags: ["helm-utils"] do
(Helm::BinarySingleton.installation_found?).should be_true
end
it "'helm_global_response()' should return the information about the helm installation", tags: ["helm-utils"] do

it "'helm_global_response()' should return the information about the helm installation", tags: ["helm-utils"] do
(helm_global_response(true)).should contain("\"v3.")
end

it "'helm_installations()' should return the information about the helm installation", tags: ["helm-utils"] do
it "'helm_installations()' should return the information about the helm installation", tags: ["helm-utils"] do
(helm_installation(true)).should contain("helm found")
end
end
Expand All @@ -39,31 +39,31 @@ describe "Helm" do
before_all do
install_local_helm
end

it "'helm_installation_info()' should return the information about the helm installation", tags: ["kubectl-utils"] do
(Helm::SystemInfo.helm_installation_info(true)).should contain("helm found")
end
it "'Helm::SystemInfo.local_helm_installed?' should return the information about the helm installation", tags: ["helm-utils"] do

it "'Helm::SystemInfo.local_helm_installed?' should return the information about the helm installation", tags: ["helm-utils"] do
(Helm::SystemInfo.local_helm_installed?).should be_true
end
it "'Helm::BinarySingleton.installation_found?' should find installation", tags: ["helm-utils"] do

it "'Helm::BinarySingleton.installation_found?' should find installation", tags: ["helm-utils"] do
(Helm::BinarySingleton.installation_found?).should be_true
end

it "'helm_local_response()' should return the information about the helm installation", tags: ["helm-utils"] do
Helm::ShellCmd.run("ls -R tools/helm", "helm_dir_check", force_output: true)
it "'helm_local_response()' should return the information about the helm installation", tags: ["helm-utils"] do
Helm::ShellCMD.run("ls -R tools/helm", Helm::Log.for("helm_dir_check"), force_output: true)
(helm_local_response(true)).should contain("\"v3.")
end
it "'helm_version()' should return the information about the helm version", tags: ["helm-utils"] do
Helm::ShellCmd.run("ls -R tools/helm", "helm_dir_check", force_output: true)

it "'helm_version()' should return the information about the helm version", tags: ["helm-utils"] do
Helm::ShellCMD.run("ls -R tools/helm", Helm::Log.for("helm_dir_check"), force_output: true)
(helm_version(helm_local_response)).should contain("v3.")
end

it "local helm should be detected", tags: ["helm-utils"] do
it "local helm should be detected", tags: ["helm-utils"] do
(Helm::BinarySingleton.local_helm_installed?).should be_true
end
end
end
end
8 changes: 4 additions & 4 deletions src/constants.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Helm
DEFAULT_ARCH = "linux-amd64"
DEFAULT_LOCAL_BINARY_PATH = "tools/helm"
BASE_CONFIG = "./config.yml"
end
DEFAULT_ARCH = "linux-amd64"
DEFAULT_LOCAL_BINARY_PATH = "tools/helm"
BASE_CONFIG = "./config.yml"
end
76 changes: 37 additions & 39 deletions src/utils/binary_reference.cr
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
require "./utils.cr"
require "./system_information.cr"

class BinaryReference
class BinaryReference
@helm : String?


def global_helm_installed?
Helm::SystemInfo.global_helm_installed?
end

def helm_global_response(verbose=false)
Process.run("helm version", shell: true, output: stdout = IO::Memory.new, error: stderr = IO::Memory.new)
stdout.to_s
end

def helm_v3_version(helm_response)
# version.BuildInfo{Version:"v3.1.1", GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}
helm_v3 = helm_response.match /BuildInfo{Version:\"(v([0-9]{1,3}[\.]){1,2}[0-9]{1,3}).+"/
helm_v3 && helm_v3.not_nil![1]
end

def global_helm
"helm"
end

def local_helm_installed?
Helm::SystemInfo.local_helm_installed?
end


def installation_found?
global_helm_installed? || local_helm_installed?
end

def local_helm
local_helm_full_path
end

# Get helm directory
def helm
@helm ||= global_helm_installed? ? global_helm : local_helm
end
end
def global_helm_installed?
Helm::SystemInfo.global_helm_installed?
end

def helm_global_response(verbose = false)
Process.run("helm version", shell: true, output: stdout = IO::Memory.new, error: stderr = IO::Memory.new)
stdout.to_s
end

def helm_v3_version(helm_response)
# version.BuildInfo{Version:"v3.1.1", GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}
helm_v3 = helm_response.match /BuildInfo{Version:\"(v([0-9]{1,3}[\.]){1,2}[0-9]{1,3}).+"/
helm_v3 && helm_v3.not_nil![1]
end

def global_helm
"helm"
end

def local_helm_installed?
Helm::SystemInfo.local_helm_installed?
end

def installation_found?
global_helm_installed? || local_helm_installed?
end

def local_helm
local_helm_full_path
end

# Get helm directory
def helm
@helm ||= global_helm_installed? ? global_helm : local_helm
end
end
28 changes: 15 additions & 13 deletions src/utils/system_information.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ require "kubectl_client"
require "./utils.cr"
require "../../helm.cr"

def helm_installation(verbose=false)
# TODO (rafal-lal): move stdout_ to main cnti testsuite
def helm_installation(verbose = false)
gmsg = "No Global helm version found"
lmsg = "No Local helm version found"
ghelm = helm_global_response
Expand All @@ -28,7 +29,6 @@ def helm_installation(verbose=false)
if local_helm_version && !local_helm_version.empty?
lmsg = "Local helm found. Version: #{local_helm_version}"
stdout_success lmsg

else
stdout_warning lmsg
end
Expand All @@ -45,29 +45,30 @@ def helm_installation(verbose=false)
"#{lmsg} #{gmsg}"
end

def helm_global_response(verbose=false)
def helm_global_response(verbose = false)
helm_response = `helm version 2>/dev/null`
Log.info { helm_response } if verbose
helm_response
end

def helm_local_response(verbose=false)
result = Helm::ShellCmd.run("#{local_helm_full_path} version", "helm_local_version", force_output: verbose)
def helm_local_response(verbose = false)
result = Helm::ShellCMD.run(
"#{local_helm_full_path} version", Helm::Log.for("helm_local_response"), force_output: verbose
)
result[:output]
end

def helm_version(helm_response, verbose=false)
def helm_version(helm_response, verbose = false)
resp = "#{helm_v2_version(helm_response) || helm_v3_version(helm_response)}"
Log.info { resp } if verbose
resp
end


def helm_v2_version(helm_response)
# example
# Client: &version.Version{SemVer:\"v2.14.3\", GitCommit:\"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085\", GitTreeState:\"clean\"}\nServer: &version.Version{SemVer:\"v2.16.1\", GitCommit:\"bbdfe5e7803a12bbdf97e94cd847859890cf4050\", GitTreeState:\"clean\"}
helm_v2 = helm_response.match /Client: &version.Version{SemVer:\"(v([0-9]{1,3}[\.]){1,2}[0-9]{1,3}).+"/
Log.debug {"helm_v2?: #{helm_v2}"}
Log.debug { "helm_v2?: #{helm_v2}" }
helm_v2 && helm_v2.not_nil![1]
end

Expand All @@ -79,15 +80,16 @@ def helm_v3_version(helm_response)
helm_v3 && helm_v3.not_nil![1]
end

#TODO Get global response for helm
#TODO Get version number of global response for helm
#TODO If version of helm not 3 or greater, act as if helm is not installed
#TODO If version of helm is 3, return helm installed
# TODO Get global response for helm
# TODO Get version number of global response for helm
# TODO If version of helm not 3 or greater, act as if helm is not installed
# TODO If version of helm is 3, return helm installed
module Helm
class SystemInfo
def self.helm_installation_info(verbose=false)
def self.helm_installation_info(verbose = false)
helm_installation(verbose)
end

def self.global_helm_installed?
ghelm = helm_global_response
global_helm_version = helm_v3_version(ghelm)
Expand Down
8 changes: 5 additions & 3 deletions src/utils/utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def install_local_helm
Log.for("verbose").debug { "full path?: #{local_helm_full_path}" }

stdout = IO::Memory.new
status = Process.run("wget -P #{binary_directory} https://get.helm.sh/helm-v3.8.2-#{Helm::DEFAULT_ARCH}.tar.gz", shell: true, output: stdout, error: stdout)
status = Process.run("wget -P #{binary_directory} https://get.helm.sh/helm-v3.8.2-#{Helm::DEFAULT_ARCH}.tar.gz",
shell: true, output: stdout, error: stdout
)

unless status.success?
Log.for("verbose").debug { stdout }
Expand All @@ -71,7 +73,7 @@ def install_local_helm
)

helm = Helm::BinarySingleton.local_helm

status = Process.run("#{helm} version", shell: true, output: stdout, error: stdout)

Log.for("verbose").debug { stdout }
Expand All @@ -82,7 +84,7 @@ def install_local_helm
end

def helm_local_cleanup
current_dir = FileUtils.pwd
current_dir = FileUtils.pwd
path = "#{current_dir}/#{local_helm_path}"
Log.for("verbose").info { "helm_local_cleanup path: #{path}" }
FileUtils.rm_rf(path)
Expand Down

0 comments on commit 9010245

Please sign in to comment.