Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 00:07:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 00:07:54 +0300
commit2fd92f2dc784ade9cb4e1c33dd60cbfad7b86818 (patch)
tree7779f36689db97a46e0268a4aec1d49f283eb0c8 /qa
parent42ca24aa5bbab7a2d43bc866d9bee9876941cea2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r--qa/qa.rb2
-rw-r--r--qa/qa/page/project/operations/kubernetes/add_existing.rb4
-rw-r--r--qa/qa/page/project/operations/kubernetes/show.rb16
-rw-r--r--qa/qa/service/cluster_provider/k3s.rb94
-rw-r--r--qa/qa/service/docker_run/base.rb4
-rw-r--r--qa/qa/service/docker_run/k3s.rb46
-rw-r--r--qa/qa/specs/features/browser_ui/7_configure/kubernetes/kubernetes_integration_spec.rb17
-rw-r--r--qa/spec/service/docker_run/k3s_spec.rb32
8 files changed, 193 insertions, 22 deletions
diff --git a/qa/qa.rb b/qa/qa.rb
index ac5569bfad8..57b622c7d93 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -429,6 +429,7 @@ module QA
autoload :Gcloud, 'qa/service/cluster_provider/gcloud'
autoload :Minikube, 'qa/service/cluster_provider/minikube'
autoload :K3d, 'qa/service/cluster_provider/k3d'
+ autoload :K3s, 'qa/service/cluster_provider/k3s'
end
module DockerRun
@@ -440,6 +441,7 @@ module QA
autoload :GitlabRunner, 'qa/service/docker_run/gitlab_runner'
autoload :MailHog, 'qa/service/docker_run/mail_hog'
autoload :SamlIdp, 'qa/service/docker_run/saml_idp'
+ autoload :K3s, 'qa/service/docker_run/k3s'
end
end
diff --git a/qa/qa/page/project/operations/kubernetes/add_existing.rb b/qa/qa/page/project/operations/kubernetes/add_existing.rb
index 9f47841366e..c143b55d057 100644
--- a/qa/qa/page/project/operations/kubernetes/add_existing.rb
+++ b/qa/qa/page/project/operations/kubernetes/add_existing.rb
@@ -11,7 +11,7 @@ module QA
element :api_url, 'url_field :api_url' # rubocop:disable QA/ElementWithPattern
element :ca_certificate, 'text_area :ca_cert' # rubocop:disable QA/ElementWithPattern
element :token, 'text_field :token' # rubocop:disable QA/ElementWithPattern
- element :add_cluster_button, "submit s_('ClusterIntegration|Add Kubernetes cluster')" # rubocop:disable QA/ElementWithPattern
+ element :add_kubernetes_cluster_button
element :rbac_checkbox
end
@@ -32,7 +32,7 @@ module QA
end
def add_cluster!
- click_on 'Add Kubernetes cluster'
+ click_element :add_kubernetes_cluster_button, Page::Project::Operations::Kubernetes::Show
end
def uncheck_rbac!
diff --git a/qa/qa/page/project/operations/kubernetes/show.rb b/qa/qa/page/project/operations/kubernetes/show.rb
index 3d3eebdbec9..b639f867593 100644
--- a/qa/qa/page/project/operations/kubernetes/show.rb
+++ b/qa/qa/page/project/operations/kubernetes/show.rb
@@ -11,14 +11,20 @@ module QA
end
view 'app/views/clusters/clusters/_form.html.haml' do
- element :base_domain
- element :save_domain
+ element :integration_status_toggle, required: true
+ element :base_domain_field, required: true
+ element :save_changes_button, required: true
+ end
+
+ view 'app/assets/javascripts/clusters/components/application_row.vue' do
+ element :install_button
+ element :uninstall_button
end
def install!(application_name)
within_element(application_name) do
has_element?(:install_button, application: application_name, wait: 30)
- click_on 'Install' # TODO replace with click_element
+ click_element :install_button
end
end
@@ -41,11 +47,11 @@ module QA
end
def set_domain(domain)
- fill_element :base_domain, domain
+ fill_element :base_domain_field, domain
end
def save_domain
- click_element :save_domain
+ click_element :save_changes_button, Page::Project::Operations::Kubernetes::Show
end
end
end
diff --git a/qa/qa/service/cluster_provider/k3s.rb b/qa/qa/service/cluster_provider/k3s.rb
new file mode 100644
index 00000000000..165de795683
--- /dev/null
+++ b/qa/qa/service/cluster_provider/k3s.rb
@@ -0,0 +1,94 @@
+# frozen_string_literal: true
+
+module QA
+ module Service
+ module ClusterProvider
+ class K3s < Base
+ def validate_dependencies
+ Runtime::ApplicationSettings.set_application_settings(allow_local_requests_from_web_hooks_and_services: true)
+ end
+
+ def setup
+ @k3s = Service::DockerRun::K3s.new.tap do |k3s|
+ k3s.register!
+
+ shell "kubectl config set-cluster k3s --server https://#{k3s.host_name}:6443 --insecure-skip-tls-verify"
+ shell 'kubectl config set-credentials default --username=node --password=some-secret'
+ shell 'kubectl config set-context k3s --cluster=k3s --user=default'
+ shell 'kubectl config use-context k3s'
+
+ wait_for_server(k3s.host_name) do
+ shell 'kubectl version'
+
+ wait_for_namespaces do
+ # install local storage
+ shell 'kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml'
+
+ # patch local storage
+ shell %(kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}')
+ end
+ end
+ end
+ end
+
+ def teardown
+ Runtime::ApplicationSettings.set_application_settings(allow_local_requests_from_web_hooks_and_services: false)
+
+ @k3s&.remove!
+ end
+
+ def set_credentials(admin_user)
+ end
+
+ # Fetch "real" certificate
+ # See https://github.com/rancher/k3s/issues/27
+ def filter_credentials(credentials)
+ kubeconfig = YAML.safe_load(@k3s.kubeconfig)
+ ca_certificate = kubeconfig.dig('clusters', 0, 'cluster', 'certificate-authority-data')
+
+ credentials.merge('data' => credentials['data'].merge('ca.crt' => ca_certificate))
+ end
+
+ private
+
+ def wait_for_server(host_name)
+ print "Waiting for K3s server at `https://#{host_name}:6443` to become available "
+
+ 60.times do
+ if service_available?('kubectl version')
+ return yield if block_given?
+
+ return true
+ end
+
+ sleep 1
+ print '.'
+ end
+
+ raise 'K3s server never came up'
+ end
+
+ def wait_for_namespaces
+ print 'Waiting for k8s namespaces to populate'
+
+ 60.times do
+ if service_available?('kubectl get pods --all-namespaces | grep --silent "Running"')
+ return yield if block_given?
+
+ return true
+ end
+
+ sleep 1
+ print '.'
+ end
+
+ raise 'K8s namespaces didnt populate correctly'
+ end
+
+ def service_available?(command)
+ system("#{command} > /dev/null 2>&1")
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/service/docker_run/base.rb b/qa/qa/service/docker_run/base.rb
index 3f42c09ad2c..b02bbea8ff5 100644
--- a/qa/qa/service/docker_run/base.rb
+++ b/qa/qa/service/docker_run/base.rb
@@ -37,6 +37,10 @@ module QA
def running?
`docker ps -f name=#{@name}`.include?(@name)
end
+
+ def read_file(file_path)
+ `docker exec #{@name} /bin/cat #{file_path}`
+ end
end
end
end
diff --git a/qa/qa/service/docker_run/k3s.rb b/qa/qa/service/docker_run/k3s.rb
new file mode 100644
index 00000000000..da254497ff0
--- /dev/null
+++ b/qa/qa/service/docker_run/k3s.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module QA
+ module Service
+ module DockerRun
+ class K3s < Base
+ def initialize
+ @image = 'registry.gitlab.com/gitlab-org/cluster-integration/test-utils/k3s-gitlab-ci/releases/v0.6.1'
+ @name = 'k3s'
+ super
+ end
+
+ def register!
+ pull
+ start_k3s
+ end
+
+ def host_name
+ return 'localhost' unless Runtime::Env.running_in_ci?
+
+ super
+ end
+
+ def kubeconfig
+ read_file('/etc/rancher/k3s/k3s.yaml').chomp
+ end
+
+ def start_k3s
+ command = <<~CMD.tr("\n", ' ')
+ docker run -d --rm
+ --network #{network}
+ --hostname #{host_name}
+ --name #{@name}
+ --publish 6443:6443
+ --privileged
+ #{@image} server --cluster-secret some-secret
+ CMD
+
+ command.gsub!("--network #{network} ", '') unless QA::Runtime::Env.running_in_ci?
+
+ shell command
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/specs/features/browser_ui/7_configure/kubernetes/kubernetes_integration_spec.rb b/qa/qa/specs/features/browser_ui/7_configure/kubernetes/kubernetes_integration_spec.rb
index 73b5a579e08..728f22aed89 100644
--- a/qa/qa/specs/features/browser_ui/7_configure/kubernetes/kubernetes_integration_spec.rb
+++ b/qa/qa/specs/features/browser_ui/7_configure/kubernetes/kubernetes_integration_spec.rb
@@ -2,10 +2,9 @@
module QA
context 'Configure' do
- # This test requires GITLAB_QA_ADMIN_ACCESS_TOKEN to be specified
- describe 'Kubernetes Cluster Integration', :orchestrated, :kubernetes, :requires_admin, :skip do
+ describe 'Kubernetes Cluster Integration', :orchestrated, :kubernetes, :requires_admin do
context 'Project Clusters' do
- let(:cluster) { Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3d).create! }
+ let(:cluster) { Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create! }
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'project-with-k8s'
@@ -35,18 +34,6 @@ module QA
expect(index).to have_cluster(cluster)
end
end
-
- it 'installs helm and tiller on a gitlab managed app' do
- Resource::KubernetesCluster.fabricate_via_browser_ui! do |k8s_cluster|
- k8s_cluster.project = project
- k8s_cluster.cluster = cluster
- k8s_cluster.install_helm_tiller = true
- end
-
- Page::Project::Operations::Kubernetes::Show.perform do |show|
- expect(show).to have_application_installed(:helm)
- end
- end
end
end
end
diff --git a/qa/spec/service/docker_run/k3s_spec.rb b/qa/spec/service/docker_run/k3s_spec.rb
new file mode 100644
index 00000000000..0224b7d6704
--- /dev/null
+++ b/qa/spec/service/docker_run/k3s_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module QA
+ describe Service::DockerRun::K3s do
+ describe '#host_name' do
+ context 'in CI' do
+ let(:name) { 'k3s-12345' }
+ let(:network) { 'thenet' }
+
+ before do
+ allow(Runtime::Env).to receive(:running_in_ci?).and_return(true)
+ allow(subject).to receive(:network).and_return(network)
+ subject.instance_variable_set(:@name, name)
+ end
+
+ it 'returns name.network' do
+ expect(subject.host_name).to eq("#{name}.#{network}")
+ end
+ end
+
+ context 'not in CI' do
+ before do
+ allow(Runtime::Env).to receive(:running_in_ci?).and_return(false)
+ end
+
+ it 'returns localhost if not running in a CI environment' do
+ expect(subject.host_name).to eq('localhost')
+ end
+ end
+ end
+ end
+end