Skip to content

Commit

Permalink
[346] added k8s version option
Browse files Browse the repository at this point in the history
  • Loading branch information
moklidia committed Oct 9, 2023
1 parent 140cb5c commit a14b278
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
26 changes: 18 additions & 8 deletions lib/uffizzi/cli/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'uffizzi/services/cluster/disconnect_service'

MANUAL = 'manual'
DEFAULT_K8S_VERSION = '1.27'

module Uffizzi
class Cli::Cluster < Thor
Expand All @@ -32,6 +33,7 @@ def list
method_option :'update-current-context', type: :boolean, required: false, default: true
method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'pretty-json']
method_option :'creation-source', required: false, type: :string
method_option :'k8s-version', required: false, type: :string, default: '1.27'
def create(name = nil)
run('create', { name: name })
end
Expand Down Expand Up @@ -116,13 +118,16 @@ def handle_create_command(project_slug, command_args)

cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name
creation_source = options[:"creation-source"] || MANUAL

unless ClusterService.valid_name?(cluster_name)
Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.")
end

manifest_file_path = options[:manifest]
params = cluster_creation_params(cluster_name, creation_source, manifest_file_path)
k8s_version = options[:k8s_version] || DEFAULT_K8S_VERSION
Uffizzi.ui.say_error_and_exit('k8s version should be formatted as [MAJOR].[MINOR].') unless valid_k8s_version?(k8s_version)
Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") unless ClusterService.valid_name?(cluster_name)

params = cluster_creation_params(
name: cluster_name,
creation_source: creation_source,
manifest_file_path: options[:manifest],
k8s_version: k8s_version,
)
response = create_cluster(ConfigFile.read_option(:server), project_slug, params)

return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response)
Expand Down Expand Up @@ -241,7 +246,7 @@ def say_error_update_kubeconfig(cluster_data)
end
end

def cluster_creation_params(name, creation_source, manifest_file_path)
def cluster_creation_params(name:, creation_source:, manifest_file_path:, k8s_version:)
manifest_content = load_manifest_file(manifest_file_path)
oidc_token = Uffizzi::ConfigFile.read_option(:oidc_token)

Expand All @@ -250,6 +255,7 @@ def cluster_creation_params(name, creation_source, manifest_file_path)
name: name,
manifest: manifest_content,
creation_source: creation_source,
k8s_version: k8s_version,
},
token: oidc_token,
}
Expand Down Expand Up @@ -399,5 +405,9 @@ def save_previous_current_context(kubeconfig_path, current_context)
previous_current_contexts = Uffizzi::ConfigHelper.set_previous_current_context_by_path(kubeconfig_path, current_context)
ConfigFile.write_option(:previous_current_contexts, previous_current_contexts)
end

def valid_k8s_version?(version)
['1.28', '1.27', '1.26'].include?(version)
end
end
end
11 changes: 10 additions & 1 deletion man/uffizzi-cluster-create.ronn
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
uffizzi cluster create -h
uffizzi-cluster-create - create a cluster
================================================================

Expand All @@ -12,9 +13,17 @@ uffizzi-cluster-create - create a cluster
https://docs.uffizzi.com/references/cli/

## FLAGS

--name
Option is deprecated and will be removed in the newer versions.
Please use a positional argument instead: uffizzi cluster create my-awesome-name.
Please use a positional argument instead: uffizzi cluster create
my-awesome-name.

--k8s-version=<api-version>
Specify which version of the Kubernetes API to use when creating
the cluster, formatted as [MAJOR].[MINOR]. Defaults to 1.27.
Minor versions point to the latest release of the corresponding k3s
minor version. See https://github.com/k3s-io/k3s/releases

--kubeconfig="/path/to/your/kubeconfig"
Path to kubeconfig file
Expand Down

0 comments on commit a14b278

Please sign in to comment.