Commit 1f6eb863 authored by Sofia Vistas's avatar Sofia Vistas Committed by Andrejs Cunskis

Unquarantine kubernetes tests

parent 44f1a288
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
.top-area.adjust .top-area.adjust
.gl-display-block.gl-text-right.gl-my-4.gl-w-full .gl-display-block.gl-text-right.gl-my-4.gl-w-full
- if clusterable.can_add_cluster? - if clusterable.can_add_cluster?
= link_to s_('ClusterIntegration|Connect cluster with certificate'), clusterable.new_path, class: 'btn gl-button btn-confirm js-add-cluster gl-py-2', qa_selector: :integrate_kubernetes_cluster_button = link_to s_('ClusterIntegration|Connect cluster with certificate'), clusterable.new_path, class: 'btn gl-button btn-confirm js-add-cluster gl-py-2', data: { qa_selector: 'integrate_kubernetes_cluster_button' }
- else - else
%span.btn.gl-button.btn-confirm.js-add-cluster.disabled.gl-py-2 %span.btn.gl-button.btn-confirm.js-add-cluster.disabled.gl-py-2
= s_("ClusterIntegration|Connect cluster with certificate") = s_("ClusterIntegration|Connect cluster with certificate")
......
...@@ -24,8 +24,7 @@ spec: ...@@ -24,8 +24,7 @@ spec:
args: args:
- --token-file=/config/token - --token-file=/config/token
- --kas-address - --kas-address
- "<%= kas_wss_address %>" # Use this for GitLab chart deployments - "<%= kas_wss_address %>"
# - "<%= kas_grpc_address %>" # Use this for GDK
volumeMounts: volumeMounts:
- name: token-volume - name: token-volume
mountPath: /config mountPath: /config
......
...@@ -11,7 +11,7 @@ module QA ...@@ -11,7 +11,7 @@ module QA
end end
def add_existing_cluster def add_existing_cluster
click_element(:add_existing_cluster_tab) page.find('.gl-tab-nav-item', text: 'Connect existing cluster').click
end end
end end
end end
......
...@@ -6,12 +6,12 @@ module QA ...@@ -6,12 +6,12 @@ module QA
module Infrastructure module Infrastructure
module Kubernetes module Kubernetes
class Index < Page::Base class Index < Page::Base
view 'app/assets/javascripts/clusters_list/components/clusters_empty_state.vue' do view 'app/views/clusters/clusters/_cluster_list.html.haml' do
element :add_kubernetes_cluster_link element :integrate_kubernetes_cluster_button
end end
def add_kubernetes_cluster def connect_cluster_with_certificate
click_element :add_kubernetes_cluster_link find('.js-add-cluster').click
end end
def has_cluster?(cluster) def has_cluster?(cluster)
......
...@@ -7,26 +7,9 @@ module QA ...@@ -7,26 +7,9 @@ module QA
module Kubernetes module Kubernetes
class Show < Page::Base class Show < Page::Base
view 'app/assets/javascripts/clusters/forms/components/integration_form.vue' do view 'app/assets/javascripts/clusters/forms/components/integration_form.vue' do
element :integration_status_toggle, required: true element :integration_status_toggle
element :base_domain_field, required: true element :base_domain_field
element :save_changes_button, required: true element :save_changes_button
end
view 'app/views/clusters/clusters/_details_tab.html.haml' do
element :details, required: true
end
view 'app/views/clusters/clusters/_health.html.haml' do
element :cluster_health_section
end
view 'app/views/clusters/clusters/_health_tab.html.haml' do
element :health, required: true
end
def open_details
has_element?(:details, wait: 30)
click_element :details
end end
def set_domain(domain) def set_domain(domain)
...@@ -36,29 +19,6 @@ module QA ...@@ -36,29 +19,6 @@ module QA
def save_domain def save_domain
click_element :save_changes_button, Page::Project::Infrastructure::Kubernetes::Show click_element :save_changes_button, Page::Project::Infrastructure::Kubernetes::Show
end end
def wait_for_cluster_health
wait_until(max_duration: 120, sleep_interval: 3, reload: true) do
has_cluster_health_graphs?
end
end
def open_health
has_element?(:health, wait: 30)
click_element :health
end
def has_cluster_health_graphs?
within_cluster_health_section do
has_text?('CPU Usage')
end
end
def within_cluster_health_section
within_element :cluster_health_section do
yield
end
end
end end
end end
end end
......
...@@ -19,13 +19,12 @@ module QA ...@@ -19,13 +19,12 @@ module QA
def fabricate! def fabricate!
puts 'TODO: FABRICATE VIA UI' puts 'TODO: FABRICATE VIA UI'
end end
# TODO
# def resource_web_url(resource)
# The UI for this model is not yet implemented. So far it can only be super
# created through the GraphQL API rescue ResourceURLMissingError
# def fabricate # this particular resource does not expose a web_url property
# end
# end
def api_get_path def api_get_path
"gid://gitlab/Clusters::Agent/#{id}" "gid://gitlab/Clusters::Agent/#{id}"
......
...@@ -13,13 +13,12 @@ module QA ...@@ -13,13 +13,12 @@ module QA
def fabricate! def fabricate!
puts 'TODO: FABRICATE VIA UI' puts 'TODO: FABRICATE VIA UI'
end end
# TODO
# def resource_web_url(resource)
# The UI for this model is not yet implemented. So far it can only be super
# created through the GraphQL API rescue ResourceURLMissingError
# def fabricate # this particular resource does not expose a web_url property
# end
# end
def api_get_path def api_get_path
"gid://gitlab/Clusters::AgentToken/#{id}" "gid://gitlab/Clusters::AgentToken/#{id}"
......
...@@ -13,8 +13,8 @@ module QA ...@@ -13,8 +13,8 @@ module QA
Resource::Project.fabricate! Resource::Project.fabricate!
end end
def ingress_ip attribute :ingress_ip do
@ingress_ip ||= @cluster.fetch_external_ip_for_ingress @cluster.fetch_external_ip_for_ingress
end end
def fabricate! def fabricate!
...@@ -24,7 +24,7 @@ module QA ...@@ -24,7 +24,7 @@ module QA
&:go_to_infrastructure_kubernetes) &:go_to_infrastructure_kubernetes)
Page::Project::Infrastructure::Kubernetes::Index.perform( Page::Project::Infrastructure::Kubernetes::Index.perform(
&:add_kubernetes_cluster) &:connect_cluster_with_certificate)
Page::Project::Infrastructure::Kubernetes::Add.perform( Page::Project::Infrastructure::Kubernetes::Add.perform(
&:add_existing_cluster) &:add_existing_cluster)
...@@ -39,14 +39,10 @@ module QA ...@@ -39,14 +39,10 @@ module QA
end end
Page::Project::Infrastructure::Kubernetes::Show.perform do |show| Page::Project::Infrastructure::Kubernetes::Show.perform do |show|
# We must wait a few seconds for permissions to be set up correctly for new cluster
sleep 25
if @install_ingress if @install_ingress
populate(:ingress_ip) ingress_ip
show.open_details show.set_domain("#{@ingress_ip}.nip.io")
show.set_domain("#{ingress_ip}.nip.io")
show.save_domain show.save_domain
end end
end end
......
...@@ -398,7 +398,7 @@ module QA ...@@ -398,7 +398,7 @@ module QA
end end
def gitlab_agentk_version def gitlab_agentk_version
ENV.fetch('GITLAB_AGENTK_VERSION', 'v13.7.0') ENV.fetch('GITLAB_AGENTK_VERSION', 'v14.4.0')
end end
def transient_trials def transient_trials
......
...@@ -24,16 +24,6 @@ module QA ...@@ -24,16 +24,6 @@ module QA
) )
end end
def set_credentials(admin_user)
master_auth = JSON.parse(`gcloud container clusters describe #{cluster_name} --region #{@region} --format 'json(masterAuth.username, masterAuth.password)'`)
shell <<~CMD.tr("\n", ' ')
kubectl config set-credentials #{admin_user}
--username #{master_auth['masterAuth']['username']}
--password #{master_auth['masterAuth']['password']}
CMD
end
def setup def setup
login_if_not_already_logged_in login_if_not_already_logged_in
create_cluster create_cluster
...@@ -43,6 +33,12 @@ module QA ...@@ -43,6 +33,12 @@ module QA
delete_cluster delete_cluster
end end
def install_ingress
QA::Runtime::Logger.info "Attempting to install Ingress on cluster #{cluster_name}"
shell 'kubectl create -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-0.31.0/deploy/static/provider/cloud/deploy.yaml'
wait_for_ingress
end
private private
def login_if_not_already_logged_in def login_if_not_already_logged_in
...@@ -59,7 +55,7 @@ module QA ...@@ -59,7 +55,7 @@ module QA
end end
def attempt_login_with_env_vars def attempt_login_with_env_vars
puts "No gcloud account. Attempting to login from env vars GCLOUD_ACCOUNT_EMAIL and GCLOUD_ACCOUNT_KEY." QA::Runtime::Logger.debug("Logging in with GCLOUD_ACCOUNT_EMAIL and GCLOUD_ACCOUNT_KEY.")
gcloud_account_key = Tempfile.new('gcloud-account-key') gcloud_account_key = Tempfile.new('gcloud-account-key')
gcloud_account_key.write(Runtime::Env.gcloud_account_key) gcloud_account_key.write(Runtime::Env.gcloud_account_key)
gcloud_account_key.close gcloud_account_key.close
...@@ -80,7 +76,6 @@ module QA ...@@ -80,7 +76,6 @@ module QA
gcloud container clusters gcloud container clusters
create #{cluster_name} create #{cluster_name}
#{auth_options} #{auth_options}
--enable-basic-auth
--region #{@region} --region #{@region}
--disk-size 10GB --disk-size 10GB
--num-nodes #{Runtime::Env.gcloud_num_nodes} --num-nodes #{Runtime::Env.gcloud_num_nodes}
...@@ -109,6 +104,18 @@ module QA ...@@ -109,6 +104,18 @@ module QA
def get_region def get_region
Runtime::Env.gcloud_region || @available_regions.delete(@available_regions.sample) Runtime::Env.gcloud_region || @available_regions.delete(@available_regions.sample)
end end
def wait_for_ingress
QA::Runtime::Logger.info 'Waiting for Ingress controller pod to be initialized'
Support::Retrier.retry_until(max_attempts: 60, sleep_interval: 1) do
service_available?('kubectl get pods --all-namespaces -l app.kubernetes.io/component=controller | grep -o "ingress-nginx-controller.*1/1"')
end
end
def service_available?(command)
system("#{command} > /dev/null 2>&1")
end
end end
end end
end end
......
...@@ -41,6 +41,10 @@ module QA ...@@ -41,6 +41,10 @@ module QA
cluster_name cluster_name
end end
def install_ingress
@provider.install_ingress
end
def create_secret(secret, secret_name) def create_secret(secret, secret_name)
shell("kubectl create secret generic #{secret_name} --from-literal=token='#{secret}'") shell("kubectl create secret generic #{secret_name} --from-literal=token='#{secret}'")
end end
...@@ -70,7 +74,13 @@ module QA ...@@ -70,7 +74,13 @@ module QA
end end
def fetch_external_ip_for_ingress def fetch_external_ip_for_ingress
`kubectl get svc --all-namespaces --no-headers=true -l app.kubernetes.io/name=ingress-nginx -o custom-columns=:'status.loadBalancer.ingress[0].ip' | grep -v 'none'` install_ingress
# need to wait since the ingress-nginx service has an initial delay set of 10 seconds
sleep 10
ingress_ip = `kubectl get svc --all-namespaces --no-headers=true -l app.kubernetes.io/name=ingress-nginx -o custom-columns=:'status.loadBalancer.ingress[0].ip' | grep -v 'none'`
QA::Runtime::Logger.debug "Has ingress address set to: #{ingress_ip}"
ingress_ip
end end
private private
...@@ -82,7 +92,6 @@ module QA ...@@ -82,7 +92,6 @@ module QA
def fetch_credentials def fetch_credentials
return global_credentials unless rbac return global_credentials unless rbac
@provider.set_credentials(admin_user)
create_service_account(admin_user) create_service_account(admin_user)
account_credentials account_credentials
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module QA module QA
RSpec.describe 'Configure' do RSpec.describe 'Configure', only: { subdomain: :staging } do
let(:project) do let(:project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = Runtime::Env.auto_devops_project_name || 'autodevops-project' project.name = 'autodevops-project'
project.auto_devops_enabled = true project.auto_devops_enabled = true
end end
end end
...@@ -13,35 +13,24 @@ module QA ...@@ -13,35 +13,24 @@ module QA
disable_optional_jobs(project) disable_optional_jobs(project)
end end
describe 'Auto DevOps support', :orchestrated, :kubernetes, quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/251090', type: :stale } do describe 'Auto DevOps support' do
context 'when rbac is enabled' do context 'when rbac is enabled' do
let(:cluster) { Service::KubernetesCluster.new.create! } let(:cluster) { Service::KubernetesCluster.new.create! }
after do after do
cluster&.remove! cluster&.remove!
project.remove_via_api!
end end
it 'runs auto devops', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1422' do it 'runs auto devops', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1422' do
Flow::Login.sign_in Flow::Login.sign_in
# Set an application secret CI variable (prefixed with K8S_SECRET_)
Resource::CiVariable.fabricate! do |resource|
resource.project = project
resource.key = 'K8S_SECRET_OPTIONAL_MESSAGE'
resource.value = 'you_can_see_this_variable'
resource.masked = false
end
# Connect K8s cluster
Resource::KubernetesCluster::ProjectCluster.fabricate! do |k8s_cluster| Resource::KubernetesCluster::ProjectCluster.fabricate! do |k8s_cluster|
k8s_cluster.project = project k8s_cluster.project = project
k8s_cluster.cluster = cluster k8s_cluster.cluster = cluster
k8s_cluster.install_ingress = true k8s_cluster.install_ingress = true
k8s_cluster.install_prometheus = true
k8s_cluster.install_runner = true
end end
# Create Auto DevOps compatible repo
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project push.project = project
push.directory = Pathname push.directory = Pathname
...@@ -78,46 +67,6 @@ module QA ...@@ -78,46 +67,6 @@ module QA
job.click_element(:pipeline_path) job.click_element(:pipeline_path)
end end
Page::Project::Menu.perform(&:go_to_deployments_environments)
Page::Project::Deployments::Environments::Index.perform do |index|
index.click_environment_link('production')
end
Page::Project::Deployments::Environments::Show.perform do |show|
show.view_deployment do
expect(page).to have_content('Hello World!')
expect(page).to have_content('you_can_see_this_variable')
end
end
end
end
end
describe 'Auto DevOps', :smoke do
before do
Flow::Login.sign_in
project.visit!
Page::Project::Menu.perform(&:go_to_ci_cd_settings)
Page::Project::Settings::CiCd.perform(&:expand_auto_devops)
Page::Project::Settings::AutoDevops.perform(&:enable_autodevops)
# Create AutoDevOps repo
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project
push.directory = Pathname
.new(__dir__)
.join('../../../../../fixtures/auto_devops_rack')
push.commit_message = 'Create AutoDevOps compatible Project'
end
end
it 'runs an AutoDevOps pipeline', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1564' do
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
expect(pipeline).to have_tag('Auto DevOps')
end end
end end
end end
...@@ -128,7 +77,8 @@ module QA ...@@ -128,7 +77,8 @@ module QA
%w[ %w[
CODE_QUALITY_DISABLED LICENSE_MANAGEMENT_DISABLED CODE_QUALITY_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED CONTAINER_SCANNING_DISABLED BROWSER_PERFORMANCE_DISABLED
SECRET_DETECTION_DISABLED
].each do |key| ].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource| Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = project resource.project = project
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
require 'erb' require 'erb'
module QA module QA
RSpec.describe 'Configure' do RSpec.describe 'Configure', only: { subdomain: :staging } do
include Service::Shellout include Service::Shellout
describe 'Kubernetes Agent', :orchestrated, :kubernetes, :requires_admin, quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/294177', type: :waiting_on } do describe 'Kubernetes Agent' do
let!(:cluster) { Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create! } let!(:cluster) { Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::Gcloud).create! }
let(:agent_token) do let(:agent_token) do
Resource::Clusters::AgentToken.fabricate_via_api! Resource::Clusters::AgentToken.fabricate_via_api!
...@@ -23,7 +23,7 @@ module QA ...@@ -23,7 +23,7 @@ module QA
end end
after do after do
cluster.remove! cluster&.remove!
project.group.remove_via_api! project.group.remove_via_api!
end end
...@@ -43,10 +43,7 @@ module QA ...@@ -43,10 +43,7 @@ module QA
def install_agentk(cluster, agent_token) def install_agentk(cluster, agent_token)
cluster.create_secret(agent_token.secret, 'gitlab-agent-token') cluster.create_secret(agent_token.secret, 'gitlab-agent-token')
uri = URI.parse(Runtime::Scenario.gitlab_address) kas_wss_address = "wss://kas.staging.gitlab.com"
kas_grpc_address = "grpc://#{uri.host}:8150"
kas_wss_address = "wss://kas.#{uri.host}:#{uri.port}"
agent_manifest_template = read_agent_fixture('agentk-manifest.yaml.erb') agent_manifest_template = read_agent_fixture('agentk-manifest.yaml.erb')
agent_manifest_yaml = ERB.new(agent_manifest_template).result(binding) agent_manifest_yaml = ERB.new(agent_manifest_template).result(binding)
......
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