Class: UffizziCore::ControllerService
Defined Under Namespace
Classes: InvalidPublicPort
Class Method Summary
collapse
ci_module, ci_session, controller_settings_service, deployment_memory_module, domain_module, find_build_parser_module, find_ingress_parser_module, find_volume_parser_module, notification_module, password_protection_module, template_memory_module, user_access_module
Class Method Details
.apply_config_file(deployment, config_file) ⇒ Object
15
16
17
18
19
20
21
|
# File 'app/services/uffizzi_core/controller_service.rb', line 15
def apply_config_file(deployment, config_file)
body = {
config_file: UffizziCore::Controller::ApplyConfigFile::ConfigFileSerializer.new(config_file).as_json,
}
controller_client(deployment).apply_config_file(deployment_id: deployment.id, config_file_id: config_file.id, body: body)
end
|
.apply_credential(deployment, credential) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'app/services/uffizzi_core/controller_service.rb', line 23
def apply_credential(deployment, credential)
image = if credential.github_container_registry?
deployment.containers.by_repo_type(UffizziCore::Repo::GithubContainerRegistry.name).first&.image
end
options = { image: image }
body = UffizziCore::Controller::CreateCredential::CredentialSerializer.new(credential, options).as_json
controller_client(deployment).apply_credential(deployment_id: deployment.id, body: body)
end
|
.create_cluster(cluster) ⇒ Object
100
101
102
103
|
# File 'app/services/uffizzi_core/controller_service.rb', line 100
def create_cluster(cluster)
body = UffizziCore::Controller::CreateCluster::ClusterSerializer.new(cluster).as_json
controller_client(cluster).create_cluster(namespace: cluster.namespace, body: body).result
end
|
.create_namespace(deployable) ⇒ Object
91
92
93
94
|
# File 'app/services/uffizzi_core/controller_service.rb', line 91
def create_namespace(deployable)
body = { namespace: deployable.namespace }
controller_client(deployable).create_namespace(body: body).result || nil
end
|
.delete_cluster(cluster) ⇒ Object
109
110
111
|
# File 'app/services/uffizzi_core/controller_service.rb', line 109
def delete_cluster(cluster)
controller_client(cluster).delete_cluster(namespace: cluster.namespace)
end
|
.delete_credential(deployment, credential) ⇒ Object
34
35
36
|
# File 'app/services/uffizzi_core/controller_service.rb', line 34
def delete_credential(deployment, credential)
controller_client(deployment).delete_credential(deployment_id: deployment.id, credential_id: credential.id)
end
|
.delete_namespace(deployable) ⇒ Object
96
97
98
|
# File 'app/services/uffizzi_core/controller_service.rb', line 96
def delete_namespace(deployable)
controller_client(deployable).delete_namespace(namespace: deployable.namespace)
end
|
.deploy_containers(deployment, containers) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/services/uffizzi_core/controller_service.rb', line 38
def deploy_containers(deployment, containers)
check_any_container_has_public_port(containers) do |exists|
UffizziCore::DeploymentService.disable!(deployment) unless exists
end
containers = containers.map do |container|
UffizziCore::Controller::DeployContainers::ContainerSerializer.new(container).as_json(include: '**')
end
credentials = deployment.credentials.deployable.map do |credential|
UffizziCore::Controller::DeployContainers::CredentialSerializer.new(credential).as_json
end
host_volume_files = UffizziCore::HostVolumeFile.by_deployment(deployment).map do |host_volume_file|
UffizziCore::Controller::DeployContainers::HostVolumeFileSerializer.new(host_volume_file).as_json
end
compose_file = if deployment.compose_file.present?
UffizziCore::Controller::DeployContainers::ComposeFileSerializer.new(deployment.compose_file).as_json
end
body = {
containers: containers,
credentials: credentials,
deployment_url: deployment.preview_url,
compose_file: compose_file,
host_volume_files: host_volume_files,
}
if password_protection_module.present?
body = password_protection_module.add_password_configuration(body, deployment.project_id)
end
controller_client(deployment).deploy_containers(deployment_id: deployment.id, body: body)
end
|
.fetch_deployment_events(deployment) ⇒ Object
78
79
80
|
# File 'app/services/uffizzi_core/controller_service.rb', line 78
def fetch_deployment_events(deployment)
request_events(deployment) || []
end
|
.fetch_namespace(deployable) ⇒ Object
87
88
89
|
# File 'app/services/uffizzi_core/controller_service.rb', line 87
def fetch_namespace(deployable)
controller_client(deployable).namespace(namespace: deployable.namespace).result || nil
end
|
.fetch_pods(deployment) ⇒ Object
82
83
84
85
|
# File 'app/services/uffizzi_core/controller_service.rb', line 82
def fetch_pods(deployment)
pods = controller_client(deployment).deployment_containers(deployment_id: deployment.id).result || []
pods.filter { |pod| pod.metadata.name.start_with?(Settings.controller.namespace_prefix) }
end
|
.ingress_hosts(cluster) ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'app/services/uffizzi_core/controller_service.rb', line 120
def ingress_hosts(cluster)
namespace = cluster.namespace
ingresses = controller_client(cluster).ingresses(namespace: namespace).result.items
ingresses.map do |ingress|
ingress.spec.rules.map(&:host)
end.flatten
end
|
.namespace_exists?(deployable) ⇒ Boolean
74
75
76
|
# File 'app/services/uffizzi_core/controller_service.rb', line 74
def namespace_exists?(deployable)
controller_client(deployable).namespace(namespace: deployable.namespace).code == 200
end
|
.patch_cluster(cluster, sleep:) ⇒ Object
113
114
115
116
117
118
|
# File 'app/services/uffizzi_core/controller_service.rb', line 113
def patch_cluster(cluster, sleep:)
body = UffizziCore::Controller::UpdateCluster::ClusterSerializer.new(cluster).as_json
body[:sleep] = sleep
controller_client(cluster).patch_cluster(name: cluster.name, namespace: cluster.namespace, body: body)
end
|
.show_cluster(cluster) ⇒ Object
105
106
107
|
# File 'app/services/uffizzi_core/controller_service.rb', line 105
def show_cluster(cluster)
controller_client(cluster).show_cluster(namespace: cluster.namespace, name: cluster.name).result
end
|