Files
ubicloud/helpers/kubernetes_cluster.rb
Burak Yucesoy 2986594195 Use lambda instead of block for option filtering
Return statements in blocks return from not only the block but also from the
method that contains the block. This means returns cannot be used for exiting
early from option filtering blocks. Using lambdas instead allows us to use
return statements to exit early from the filtering logic without affecting
the surrounding method.
2025-06-03 05:36:51 +03:00

55 lines
2.0 KiB
Ruby

# frozen_string_literal: true
class Clover
def kubernetes_cluster_post(name)
authorize("KubernetesCluster:create", @project.id)
fail Validation::ValidationFailed.new({billing_info: "Project doesn't have valid billing information"}) unless @project.has_valid_payment_method?
version, target_node_size = typecast_params.nonempty_str!(["version", "worker_size"])
cp_node_count, node_count = typecast_params.pos_int!(["cp_nodes", "worker_nodes"])
DB.transaction do
kc = Prog::Kubernetes::KubernetesClusterNexus.assemble(
name:,
project_id: @project.id,
location_id: @location.id,
cp_node_count:,
version:
).subject
Prog::Kubernetes::KubernetesNodepoolNexus.assemble(
name: name + "-np",
node_count:,
kubernetes_cluster_id: kc.id,
target_node_size:
)
audit_log(kc, "create")
flash["notice"] = "'#{name}' will be ready in a few minutes"
request.redirect "#{@project.path}#{kc.path}"
end
end
def kubernetes_cluster_list
@kcs = dataset_authorize(@project.kubernetes_clusters_dataset, "KubernetesCluster:view").all
view "kubernetes-cluster/index"
end
def generate_kubernetes_cluster_options
options = OptionTreeGenerator.new
options.add_option(name: "name")
options.add_option(name: "location", values: Option.kubernetes_locations)
options.add_option(name: "version", values: Option.kubernetes_versions)
options.add_option(name: "cp_nodes", values: Option::KubernetesCPOptions.map(&:cp_node_count), parent: "location")
options.add_option(name: "worker_size", values: Option::VmSizes.select { it.visible && it.vcpus <= 16 }.map { it.display_name }, parent: "location", check: ->(location, size) {
vm_size = Option::VmSizes.find { it.display_name == size && it.arch == "x64" }
vm_size.family == "standard"
})
options.add_option(name: "worker_nodes", values: (1..10).map { {value: it, display_name: "#{it} Node#{(it == 1) ? "" : "s"}"} }, parent: "worker_size")
options.serialize
end
end