Skip to content

Commit

Permalink
Merge pull request #353 from UffizziCloud/feature/346_k8s_version_option
Browse files Browse the repository at this point in the history
[346] added k8s version option
  • Loading branch information
moklidia authored Oct 16, 2023
2 parents 58f13d8 + e3c7673 commit 6b8738b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
21 changes: 13 additions & 8 deletions lib/uffizzi/cli/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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
def create(name = nil)
run('create', { name: name })
end
Expand Down Expand Up @@ -111,13 +112,15 @@ def handle_create_command(project_slug, command_args)

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

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"]
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 @@ -236,7 +239,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 @@ -245,6 +248,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 @@ -300,6 +304,7 @@ def handle_succeed_describe(cluster_data)
status: cluster_data[:state],
created: Time.strptime(cluster_data[:created_at], '%Y-%m-%dT%H:%M:%S.%N').strftime('%a %b %d %H:%M:%S %Y'),
url: cluster_data[:host],
k8s_version: cluster_data[:k8s_version],
}

rendered_cluster_data = if Uffizzi.ui.output_format.nil?
Expand Down
12 changes: 8 additions & 4 deletions lib/uffizzi/cli/dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Cli::Dev < Thor
method_option :quiet, type: :boolean, aliases: :q
method_option :'default-repo', type: :string
method_option :kubeconfig, type: :string
method_option :'k8s-version', required: false, type: :string
def start(config_path = 'skaffold.yaml')
Uffizzi::AuthHelper.check_login(options[:project])
DevService.check_skaffold_existence
Expand Down Expand Up @@ -50,9 +51,11 @@ def stop
private

def start_create_cluster
cluster_name = ClusterService.generate_name
creation_source = ClusterService::MANUAL_CREATION_SOURCE
params = cluster_creation_params(cluster_name, creation_source)
params = cluster_creation_params(
name: ClusterService.generate_name,
creation_source: ClusterService::MANUAL_CREATION_SOURCE,
k8s_version: options[:"k8s-version"],
)
Uffizzi.ui.say('Start creating a cluster')
response = create_cluster(ConfigFile.read_option(:server), project_slug, params)
return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response)
Expand Down Expand Up @@ -105,14 +108,15 @@ def update_clusters_config(id, params)
ConfigFile.write_option(:clusters, clusters_config)
end

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

{
cluster: {
name: name,
manifest: nil,
creation_source: creation_source,
k8s_version: k8s_version,
},
token: oidc_token,
}
Expand Down
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
9 changes: 5 additions & 4 deletions man/uffizzi-dev-start.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ uffizzi-dev-start - start a development environment
Currently supports skaffold.yaml files.

## FLAGS
--build="<local-or-remote>"
This option specifies whether to build images on the
local environment or on the remote Uffizzi cluster.
Possible values are "local" or "remote".
--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

--default-repo="<container-registry-domain>"
A public or private repo used to push/pull build
Expand Down

0 comments on commit 6b8738b

Please sign in to comment.