Commit 9621bdf5 authored by ddavison's avatar ddavison

Refactor KubernetesCluster to base and project

Current usages of KubernetesClusters do not
differentiate between group/instance and
project clusters
parent 799d0e3b
......@@ -75,7 +75,6 @@ module QA
autoload :CiVariable, 'qa/resource/ci_variable'
autoload :Runner, 'qa/resource/runner'
autoload :PersonalAccessToken, 'qa/resource/personal_access_token'
autoload :KubernetesCluster, 'qa/resource/kubernetes_cluster'
autoload :User, 'qa/resource/user'
autoload :ProjectMilestone, 'qa/resource/project_milestone'
autoload :Members, 'qa/resource/members'
......@@ -89,6 +88,11 @@ module QA
autoload :UserGPG, 'qa/resource/user_gpg'
autoload :Visibility, 'qa/resource/visibility'
module KubernetesCluster
autoload :Base, 'qa/resource/kubernetes_cluster/base'
autoload :ProjectCluster, 'qa/resource/kubernetes_cluster/project_cluster'
end
module Events
autoload :Base, 'qa/resource/events/base'
autoload :Project, 'qa/resource/events/project'
......
# frozen_string_literal: true
require 'securerandom'
module QA
module Resource
class KubernetesCluster < Base
attr_writer :project, :cluster,
:install_helm_tiller, :install_ingress, :install_prometheus, :install_runner, :domain
attribute :ingress_ip do
Page::Project::Operations::Kubernetes::Show.perform(&:ingress_ip)
end
def fabricate!
@project.visit!
Page::Project::Menu.perform(
&:go_to_operations_kubernetes)
Page::Project::Operations::Kubernetes::Index.perform(
&:add_kubernetes_cluster)
Page::Project::Operations::Kubernetes::Add.perform(
&:add_existing_cluster)
Page::Project::Operations::Kubernetes::AddExisting.perform do |cluster_page|
cluster_page.set_cluster_name(@cluster.cluster_name)
cluster_page.set_api_url(@cluster.api_url)
cluster_page.set_ca_certificate(@cluster.ca_certificate)
cluster_page.set_token(@cluster.token)
cluster_page.uncheck_rbac! unless @cluster.rbac
cluster_page.add_cluster!
end
if @install_helm_tiller
Page::Project::Operations::Kubernetes::Show.perform do |show|
# We must wait a few seconds for permissions to be set up correctly for new cluster
sleep 10
# Open applications tab
show.open_applications
# Helm must be installed before everything else
show.install!(:helm)
show.await_installed(:helm)
show.install!(:ingress) if @install_ingress
show.install!(:prometheus) if @install_prometheus
show.install!(:runner) if @install_runner
show.await_installed(:ingress) if @install_ingress
show.await_installed(:prometheus) if @install_prometheus
show.await_installed(:runner) if @install_runner
if @install_ingress
populate(:ingress_ip)
show.open_details
show.set_domain("#{ingress_ip}.nip.io")
show.save_domain
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'securerandom'
module QA
module Resource
module KubernetesCluster
class Base < Resource::Base
attr_writer :add_name_uuid
attribute :id
attribute :name
attribute :domain
attribute :enabled
attribute :managed
attribute :management_project_id
attribute :api_url
attribute :token
attribute :ca_cert
attribute :namespace
attribute :authorization_type
attribute :environment_scope
def initialize
@add_name_uuid = true
@enabled = true
@managed = true
@authorization_type = :rbac
@environment_scope = :*
end
def name=(new_name)
@name = @add_name_uuid ? "#{new_name}-#{SecureRandom.hex(5)}" : new_name
end
end
end
end
end
# frozen_string_literal: true
module QA
module Resource
module KubernetesCluster
class ProjectCluster < Base
attr_writer :cluster,
:install_helm_tiller, :install_ingress, :install_prometheus, :install_runner, :domain
attribute :project do
Resource::Project.fabricate!
end
attribute :ingress_ip do
Page::Project::Operations::Kubernetes::Show.perform(&:ingress_ip)
end
def fabricate!
project.visit!
Page::Project::Menu.perform(
&:go_to_operations_kubernetes)
Page::Project::Operations::Kubernetes::Index.perform(
&:add_kubernetes_cluster)
Page::Project::Operations::Kubernetes::Add.perform(
&:add_existing_cluster)
Page::Project::Operations::Kubernetes::AddExisting.perform do |cluster_page|
cluster_page.set_cluster_name(@cluster.cluster_name)
cluster_page.set_api_url(@cluster.api_url)
cluster_page.set_ca_certificate(@cluster.ca_certificate)
cluster_page.set_token(@cluster.token)
cluster_page.uncheck_rbac! unless @cluster.rbac
cluster_page.add_cluster!
end
if @install_helm_tiller
Page::Project::Operations::Kubernetes::Show.perform do |show|
# We must wait a few seconds for permissions to be set up correctly for new cluster
sleep 10
# Open applications tab
show.open_applications
# Helm must be installed before everything else
show.install!(:helm)
show.await_installed(:helm)
show.install!(:ingress) if @install_ingress
show.install!(:prometheus) if @install_prometheus
show.install!(:runner) if @install_runner
show.await_installed(:ingress) if @install_ingress
show.await_installed(:prometheus) if @install_prometheus
show.await_installed(:runner) if @install_runner
if @install_ingress
populate(:ingress_ip)
show.open_details
show.set_domain("#{ingress_ip}.nip.io")
show.save_domain
end
end
end
end
end
end
end
end
......@@ -35,7 +35,7 @@ module QA
end
# Connect K8s cluster
Resource::KubernetesCluster.fabricate! do |k8s_cluster|
Resource::KubernetesCluster::ProjectCluster.fabricate! do |k8s_cluster|
k8s_cluster.project = project
k8s_cluster.cluster = cluster
k8s_cluster.install_helm_tiller = true
......
......@@ -21,12 +21,10 @@ module QA
end
it 'can create and associate a project cluster', :smoke do
Resource::KubernetesCluster.fabricate_via_browser_ui! do |k8s_cluster|
Resource::KubernetesCluster::ProjectCluster.fabricate_via_browser_ui! do |k8s_cluster|
k8s_cluster.project = project
k8s_cluster.cluster = cluster
end
project.visit!
end.project.visit!
Page::Project::Menu.perform(&:go_to_operations_kubernetes)
......
......@@ -69,7 +69,7 @@ module QA
project.description = 'Cluster with Prometheus'
end
@cluster_props = Resource::KubernetesCluster.fabricate_via_browser_ui! do |cluster_settings|
@cluster_props = Resource::KubernetesCluster::ProjectCluster.fabricate_via_browser_ui! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_helm_tiller = true
......
......@@ -40,7 +40,7 @@ module QA
p.description = 'Cluster with Prometheus'
end
@cluster_props = Resource::KubernetesCluster.fabricate_via_browser_ui! do |c|
@cluster_props = Resource::KubernetesCluster::ProjectCluster.fabricate_via_browser_ui! do |c|
c.project = @project
c.cluster = @cluster
c.install_helm_tiller = true
......
......@@ -37,7 +37,7 @@ module QA
end
def create_kubernetes_cluster(project, cluster)
Resource::KubernetesCluster.fabricate_via_browser_ui! do |c|
Resource::KubernetesCluster::ProjectCluster.fabricate_via_browser_ui! do |c|
c.project = project
c.cluster = cluster
c.install_helm_tiller = true
......
......@@ -31,7 +31,7 @@ module QA
end
def create_kubernetes_cluster
Resource::KubernetesCluster.fabricate_via_browser_ui! do |c|
Resource::KubernetesCluster::ProjectCluster.fabricate_via_browser_ui! do |c|
c.project = @project
c.cluster = @cluster
c.install_helm_tiller = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment