diff --git a/app/assets/javascripts/boards/stores/boards_store.js b/app/assets/javascripts/boards/stores/boards_store.js index 010eda9b6c538e82dcfa2b88073facca616e9107..2a5571543fb71d0592091c7982d6e283b939208b 100644 --- a/app/assets/javascripts/boards/stores/boards_store.js +++ b/app/assets/javascripts/boards/stores/boards_store.js @@ -337,7 +337,8 @@ const boardsStore = { return ( (listTo.type !== 'label' && listFrom.type === 'assignee') || (listTo.type !== 'assignee' && listFrom.type === 'label') || - listFrom.type === 'backlog' + listFrom.type === 'backlog' || + listFrom.type === 'closed' ); }, moveIssueInList(list, issue, oldIndex, newIndex, idArray) { diff --git a/app/helpers/system_note_helper.rb b/app/helpers/system_note_helper.rb index 05d698a6d9915c833cdd3c0abc2feeb24246e26c..c982b48a94e73398a1b01b0b33a49417f360cb91 100644 --- a/app/helpers/system_note_helper.rb +++ b/app/helpers/system_note_helper.rb @@ -2,7 +2,7 @@ module SystemNoteHelper ICON_NAMES_BY_ACTION = { - 'cherry_pick' => 'link', + 'cherry_pick' => 'cherry-pick-commit', 'commit' => 'commit', 'description' => 'pencil-square', 'merge' => 'git-merge', diff --git a/app/models/clusters/applications/knative.rb b/app/models/clusters/applications/knative.rb index eebcbcba2d39490ce830257f1614ab1bade71145..1f90318f845578c762cc92bc7577e40a05318d91 100644 --- a/app/models/clusters/applications/knative.rb +++ b/app/models/clusters/applications/knative.rb @@ -33,6 +33,12 @@ def set_initial_status FETCH_IP_ADDRESS_DELAY, application.name, application.id) end end + + after_transition any => [:installed, :updated] do |application| + application.run_after_commit do + ClusterConfigureIstioWorker.perform_async(application.cluster_id) + end + end end default_value_for :version, VERSION @@ -41,6 +47,8 @@ def set_initial_status scope :for_cluster, -> (cluster) { where(cluster: cluster) } + has_one :pages_domain, through: :serverless_domain_cluster + def chart 'knative/knative' end @@ -49,6 +57,14 @@ def values { "domain" => hostname }.to_yaml end + def available_domains + PagesDomain.instance_serverless + end + + def find_available_domain(pages_domain_id) + available_domains.find_by(id: pages_domain_id) + end + def allowed_to_uninstall? !pre_installed? end diff --git a/app/serializers/cluster_application_entity.rb b/app/serializers/cluster_application_entity.rb index 632718df780b3b08c94d55f0d1db5dbc8b2f24b3..ac59a9df9e56b5186108ea3d928ba243237f2a14 100644 --- a/app/serializers/cluster_application_entity.rb +++ b/app/serializers/cluster_application_entity.rb @@ -13,4 +13,6 @@ class ClusterApplicationEntity < Grape::Entity expose :modsecurity_enabled, if: -> (e, _) { e.respond_to?(:modsecurity_enabled) } expose :update_available?, as: :update_available, if: -> (e, _) { e.respond_to?(:update_available?) } expose :can_uninstall?, as: :can_uninstall + expose :available_domains, using: Serverless::DomainEntity, if: -> (e, _) { e.respond_to?(:available_domains) } + expose :pages_domain, using: Serverless::DomainEntity, if: -> (e, _) { e.respond_to?(:pages_domain) } end diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index c48e60064ed60f493e3c631ea37d5f3f9f2c0a22..6df26de529de5ebda94f736f9e681f3e7bf53414 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -94,7 +94,8 @@ def can_add_ci_config_path?(merge_request) merge_request.source_project&.uses_default_ci_config? && merge_request.all_pipelines.none? && merge_request.commits_count.positive? && - can?(current_user, :push_code, merge_request.source_project) + can?(current_user, :read_build, merge_request.source_project) && + can?(current_user, :create_pipeline, merge_request.source_project) end end diff --git a/app/serializers/serverless/domain_entity.rb b/app/serializers/serverless/domain_entity.rb new file mode 100644 index 0000000000000000000000000000000000000000..556e3c99eee244d9fb0779d53d24c1eb3762ba56 --- /dev/null +++ b/app/serializers/serverless/domain_entity.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Serverless + class DomainEntity < Grape::Entity + expose :id + expose :domain + end +end diff --git a/app/services/clusters/applications/base_service.rb b/app/services/clusters/applications/base_service.rb index 2585d815e073d8b7d2158b2c363cbb248cc853c3..a3b39f0994d4eea0e4c7944aaae97ff5ab4b4264 100644 --- a/app/services/clusters/applications/base_service.rb +++ b/app/services/clusters/applications/base_service.rb @@ -35,6 +35,12 @@ def execute(request) application.oauth_application = create_oauth_application(application, request) end + if application.instance_of?(Knative) + Serverless::AssociateDomainService + .new(application, pages_domain_id: params[:pages_domain_id], creator: current_user) + .execute + end + worker = worker_class(application) application.make_scheduled! diff --git a/app/services/clusters/kubernetes/configure_istio_ingress_service.rb b/app/services/clusters/kubernetes/configure_istio_ingress_service.rb index fe577beaa8aea7072d5ebdddc3c5c4c0f2ab8e01..a81014d99ffe8ae58de54f18bb778061e4347544 100644 --- a/app/services/clusters/kubernetes/configure_istio_ingress_service.rb +++ b/app/services/clusters/kubernetes/configure_istio_ingress_service.rb @@ -27,6 +27,10 @@ def execute return configure_certificates if serverless_domain_cluster configure_passthrough + rescue Kubeclient::HttpError => e + knative.make_errored!(_('Kubernetes error: %{error_code}') % { error_code: e.error_code }) + rescue StandardError + knative.make_errored!(_('Failed to update.')) end private diff --git a/app/services/serverless/associate_domain_service.rb b/app/services/serverless/associate_domain_service.rb new file mode 100644 index 0000000000000000000000000000000000000000..673f1f8326011eadab45486654bc86ef90354035 --- /dev/null +++ b/app/services/serverless/associate_domain_service.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Serverless + class AssociateDomainService + PLACEHOLDER_HOSTNAME = 'example.com'.freeze + + def initialize(knative, pages_domain_id:, creator:) + @knative = knative + @pages_domain_id = pages_domain_id + @creator = creator + end + + def execute + return if unchanged? + + knative.hostname ||= PLACEHOLDER_HOSTNAME + + knative.pages_domain = knative.find_available_domain(pages_domain_id) + knative.serverless_domain_cluster.update(creator: creator) if knative.pages_domain + end + + private + + attr_reader :knative, :pages_domain_id, :creator + + def unchanged? + knative.pages_domain&.id == pages_domain_id + end + end +end diff --git a/changelogs/unreleased/25550-there-is-a-drag-and-drop-bug-in-boards.yml b/changelogs/unreleased/25550-there-is-a-drag-and-drop-bug-in-boards.yml new file mode 100644 index 0000000000000000000000000000000000000000..e4777065f078b506e648d4cf643ec698835dc18d --- /dev/null +++ b/changelogs/unreleased/25550-there-is-a-drag-and-drop-bug-in-boards.yml @@ -0,0 +1,5 @@ +--- +title: Resolves the disappearance of a ticket when it was moved from the closed list. +merge_request: +author: Gwen_ +type: fixed diff --git a/changelogs/unreleased/27300-add-filepath-to-release-links-api.yml b/changelogs/unreleased/27300-add-filepath-to-release-links-api.yml new file mode 100644 index 0000000000000000000000000000000000000000..2616aa2cc5b3c2f82a24e1d2d79a9c88db5f8c28 --- /dev/null +++ b/changelogs/unreleased/27300-add-filepath-to-release-links-api.yml @@ -0,0 +1,5 @@ +--- +title: Add filepath to release links API +merge_request: 25533 +author: +type: added diff --git a/doc/user/project/clusters/serverless/aws.md b/doc/user/project/clusters/serverless/aws.md index 95c0b7f143691e96feadb146651c9e56c53f00c9..758ab528fa603c9bbe9b4448d1a861119a5eedbf 100644 --- a/doc/user/project/clusters/serverless/aws.md +++ b/doc/user/project/clusters/serverless/aws.md @@ -4,13 +4,17 @@ GitLab allows users to easily deploy AWS Lambda functions and create rich server GitLab supports deployment of functions to AWS Lambda using a combination of: -- [Serverless Framework with AWS](https://serverless.com/framework/docs/providers/aws/) +- [Serverless Framework with AWS](#serverless-framework) +- [AWS' Serverless Application Model (SAM)](#aws-serverless-application-model) - GitLab CI/CD +## Serverless Framework + +The [Serverless Framework can deploy to AWS](https://serverless.com/framework/docs/providers/aws/). + We have prepared an example with a step-by-step guide to create a simple function and deploy it on AWS. -Additionally, in the [How To section](#how-to), you can read about different use cases, -like: +Additionally, in the [How To section](#how-to), you can read about different use cases like: - Running a function locally. - Working with secrets. @@ -18,27 +22,27 @@ like: Alternatively, you can quickly [create a new project with a template](../../../../gitlab-basics/create-project.md#project-templates). The [`Serverless Framework/JS` template](https://gitlab.com/gitlab-org/project-templates/serverless-framework/) already includes all parts described below. -## Example +### Example In the following example, you will: 1. Create a basic AWS Lambda Node.js function. 1. Link the function to an API Gateway `GET` endpoint. -### Steps +#### Steps The example consists of the following steps: -1. Creating a Lambda handler function -1. Creating a `serverless.yml` file -1. Crafting the `.gitlab-ci.yml` file -1. Setting up your AWS credentials with your GitLab account -1. Deploying your function -1. Testing the deployed function +1. Creating a Lambda handler function. +1. Creating a `serverless.yml` file. +1. Crafting the `.gitlab-ci.yml` file. +1. Setting up your AWS credentials with your GitLab account. +1. Deploying your function. +1. Testing the deployed function. Lets take it step by step. -### Creating a Lambda handler function +#### Creating a Lambda handler function Your Lambda function will be the primary handler of requests. In this case we will create a very simple Node.js `hello` function: @@ -67,7 +71,7 @@ In our case, `module.exports.hello` defines the `hello` handler that will be ref You can learn more about the AWS Lambda Node.js function handler and all its various options here: -### Creating a `serverless.yml` file +#### Creating a `serverless.yml` file In the root of your project, create a `serverless.yml` file that will contain configuration specifics for the Serverless Framework. @@ -94,7 +98,7 @@ The `events` declaration will create a AWS API Gateway `GET` endpoint to receive You can read more about the available properties and additional configuration possibilities of the Serverless Framework here: -### Crafting the `.gitlab-ci.yml` file +#### Crafting the `.gitlab-ci.yml` file In a `.gitlab-ci.yml` file in the root of your project, place the following code: @@ -122,7 +126,7 @@ This example code does the following: - Deploys the serverless function to your AWS account using the AWS credentials defined above. -### Setting up your AWS credentials with your GitLab account +#### Setting up your AWS credentials with your GitLab account In order to interact with your AWS account, the GitLab CI/CD pipelines require both `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` to be defined in your GitLab settings under **Settings > CI/CD > Variables**. For more information please see: @@ -130,7 +134,7 @@ For more information please see: { For more information, see the [Your CORS and API Gateway survival guide](https://serverless.com/blog/cors-api-gateway-survival-guide/) blog post written by the Serverless Framework team. -### Writing automated tests +#### Writing automated tests The [Serverless Framework](https://gitlab.com/gitlab-org/project-templates/serverless-framework/) example project shows how to use Jest, Axios, and `serverless-offline` plugin to do automated testing of both local and deployed serverless function. -## Examples and template +### Examples and template The example code is available: @@ -285,3 +289,212 @@ The example code is available: You can also use a [template](../../../../gitlab-basics/create-project.md#project-templates) (based on the version with tests and secret variables) from within the GitLab UI (see the `Serverless Framework/JS` template). + +## AWS Serverless Application Model + +AWS Serverless Application Model is an open source framework for building serverless applications. It makes it easier to build and deploy serverless applications. For more details please take a look at AWS documentation on AWS Serverless Application Model + +### Deploying AWS Lambda function using AWS SAM and GitLab CI/CD + +GitLab allows developers to build and deploy serverless applications using the combination of: + +- [AWS Serverless Application Model (AWS SAM)](https://aws.amazon.com/serverless/sam/) +- GitLab CI/CD + +### Example + +In the following example, you will: + +- Install SAM CLI. +- Create a sample SAM application including a Lambda function and API Gateway. +- Build and deploy the application to your AWS account using GitLab CI/CD. + +### Steps + +The example consists of the following steps: + +1. Install SAM CLI. +1. Creating an AWS SAM application using SAM CLI. +1. Crafting the `.gitlab-ci.yml` file. +1. Setting up your AWS credentials with your GitLab account. +1. Deploying your application. +1. Testing the deployed function. + +### Installing SAM CLI + +AWS SAM provides a CLI called AWS SAM CLI to make it easier to create and manage +applications. + +Some steps in this documentation use SAM CLI. Follow the instructions for +[installing SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) +to install and configure SAM CLI. + +If you use [AWS Cloud9](https://aws.amazon.com/cloud9/) as your integrated development +environment (IDE), the following are installed for you: + +- [AWS Command Line Interface](https://docs.aws.amazon.com/en_pv/cli/latest/userguide/cli-chap-install.html) +- [SAM CLI](https://docs.aws.amazon.com/en_pv/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) +- [Docker](https://docs.docker.com/install/) and necessary Docker images. + +### Creating an AWS SAM application using SAM CLI + +Create a new project on GitLab. Once created, `git clone` the project into your local development environment. + +Change to the newly cloned repo and create a new SAM app using the following command: + +```shell +sam init -r python3.8 -n gitlabpoc --app-template "hello-world" +``` + +This creates a SAM app named `gitlabpoc` using the default configuration, a single +Python 3.8 function invoked by an [Amazon API Gateway](https://aws.amazon.com/api-gateway/) +endpoint. To see additional runtimes supported by SAM and options for `sam init`, run: + +```shell +sam init -h +``` + +Push this project to a new project in GitLab. + +### Setting up your AWS credentials with your GitLab account + +In order to interact with your AWS account, the GitLab CI/CD pipelines require both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be defined in your GitLab settings under **Settings > CI/CD > Variables**. For more information please see [link](../../../../ci/variables/README.html#via-the-ui) Please ensure you mask the credentials so they do not show in logs. + +**Note:** +The AWS credentials you provide must include IAM policies that provision correct access +control to AWS Lambda, API Gateway, CloudFormation, and IAM resources. + +### Crafting the `.gitlab-ci.yml` file + +In a [`.gitlab-ci.yml`](../../../../ci/yaml/README.md) file in the root of your project, +add the following and replace with an S3 bucket name where you want to +store your package: + +```yaml +image: python:latest + +stages: + + - deploy + +production: + + stage: deploy + + before_script: + + - pip3 install awscli --upgrade + + - pip3 install aws-sam-cli --upgrade + + script: + + - sam build + + - sam package --output-template-file packaged.yaml --s3-bucket + + - sam deploy --template-file packaged.yaml --stack-name gitlabpoc --s3-bucket --capabilities CAPABILITY_IAM --region us-east-1 + + environment: production + ``` + +Let’s examine the config file more closely: + +- `image` specifies the Docker image to use for this build. This is the latest Python + image since the sample application is written in Python. +- AWS CLI and AWS SAM CLI are installed in the `before_script` section. +- SAM build, package, and deploy commands are used to build, package, and deploy the + application. + +### Deploying your application + +Push changes to your GitLab repository and the GitLab build pipeline will automatically +deploy your application. If your: + +- Build and deploy are successful, [test your deployed application](#testing-the-deployed-application). +- Build fails, look at the build log to see why the build failed. Some common reasons + the build might fail are: + + - Incompatible versions of software. For example, Python runtime version might be + different from the Python on the build machine. Address this by installing the + required versions of the software. + - You may not be able to access your AWS account from GitLab. Check the environment + variables you set up with AWS credentials. + - You may not have permission to deploy a serverless application. Make sure you + provide all required permissions to deploy a serverless application. + +### Testing the deployed application + +To test the application you deployed, please go to the build log and follow the following steps: + +1. Click on “Show complete raw” on the upper right-hand corner: + + ![sam-complete-raw](img/sam-complete-raw.png) + +1. Look for HelloWorldApi – API Gateway endpoint similar to shown below: + + ![sam-api-endpoint](img/sam-api-endpoint.png) + +1. Use curl to test the API. For example: + + ```shell + curl https://py4rg7qtlg.execute-api.us-east-1.amazonaws.com/Prod/hello/ + ``` + +Output should be: + +```json +{"message": "hello world"} +``` + +### Testing Locally + +AWS SAM provides functionality to test your applications locally. You must have AWS SAM +CLI installed locally for you to test locally. + +First, test the function. + +SAM provides a default event in `events/event.json` that includes a message body of: + +```json +{\“message\”: \“hello world\”} +``` + +If you pass that event into the `HelloWorldFunction`, it should respond with the same +body. + +Invoke the function by running: + +```shell +sam local invoke HelloWorldFunction -e events/event.json +``` + +Output should be: + +```json +{"message": "hello world"} +``` + +After you confirm that Lambda function is working as expected, test the API Gateway +using following steps. + +Start the API locally by running: + +```shell +sam local start-api +``` + +SAM again launches a Docker container, this time with a mocked Amazon API Gateway +listening on `localhost:3000`. + +Call the `hello` API by running: + +```shell +curl http://127.0.0.1:3000/hello +``` + +Output again should be: + +```json +{"message": "hello world"} +``` diff --git a/doc/user/project/clusters/serverless/img/sam-api-endpoint.png b/doc/user/project/clusters/serverless/img/sam-api-endpoint.png new file mode 100644 index 0000000000000000000000000000000000000000..695d975387ff284585eaea2f758706a0f1547fd5 Binary files /dev/null and b/doc/user/project/clusters/serverless/img/sam-api-endpoint.png differ diff --git a/doc/user/project/clusters/serverless/img/sam-complete-raw.png b/doc/user/project/clusters/serverless/img/sam-complete-raw.png new file mode 100644 index 0000000000000000000000000000000000000000..1098c1bb93fde2b399af1d9d4136068cbdc47fe6 Binary files /dev/null and b/doc/user/project/clusters/serverless/img/sam-complete-raw.png differ diff --git a/ee/app/controllers/ee/admin/dashboard_controller.rb b/ee/app/controllers/ee/admin/dashboard_controller.rb index 5ac223f80743c07d29f51e50569b693c94d2bcd9..77d2bf9333f96d2f0ca3d003aa47ce77343619a2 100644 --- a/ee/app/controllers/ee/admin/dashboard_controller.rb +++ b/ee/app/controllers/ee/admin/dashboard_controller.rb @@ -17,7 +17,6 @@ def index end def stats - @admin_count = ::User.admins.count @roles_count = ::ProjectAuthorization.roles_stats end diff --git a/ee/app/views/admin/dashboard/stats.html.haml b/ee/app/views/admin/dashboard/stats.html.haml index 3f9abfdb02ff08fa895f7dbaad8b3d6d8d284ac9..96c37ec53198a5a4804a954b03056c178cad04da 100644 --- a/ee/app/views/admin/dashboard/stats.html.haml +++ b/ee/app/views/admin/dashboard/stats.html.haml @@ -7,12 +7,6 @@ %td = User.count - - if @admin_count - %tr - %td Admin users - %td - = @admin_count - - if @roles_count - @roles_count.each do |row| %tr diff --git a/ee/changelogs/unreleased/remove_admin_count_from_users_statistics.yml b/ee/changelogs/unreleased/remove_admin_count_from_users_statistics.yml new file mode 100644 index 0000000000000000000000000000000000000000..94defa6bd652d2044c0e2b80a9659b67b1e0a8cf --- /dev/null +++ b/ee/changelogs/unreleased/remove_admin_count_from_users_statistics.yml @@ -0,0 +1,5 @@ +--- +title: Remove admin user count from Users statistics +merge_request: 25337 +author: +type: changed diff --git a/ee/spec/features/admin/admin_dashboard_spec.rb b/ee/spec/features/admin/admin_dashboard_spec.rb index f7dc5917f279ee99143ae5f5155cf22fbac3fa99..492fe3c5de5505e33027f1300517ed4f7de9d412 100644 --- a/ee/spec/features/admin/admin_dashboard_spec.rb +++ b/ee/spec/features/admin/admin_dashboard_spec.rb @@ -24,7 +24,6 @@ it 'show correct amount of users per role' do visit admin_dashboard_stats_path - expect(page).to have_content('Admin users 1') expect(page).to have_content('Users with highest role developer 2') expect(page).to have_content('Users with highest role reporter 1') end diff --git a/lib/api/entities/releases/link.rb b/lib/api/entities/releases/link.rb index 6cc01e0e981870761c8a09738c7d808442cfd364..f4edb83bd585a84c2c95006b4d266b3f7302a415 100644 --- a/lib/api/entities/releases/link.rb +++ b/lib/api/entities/releases/link.rb @@ -7,7 +7,17 @@ class Link < Grape::Entity expose :id expose :name expose :url + expose :direct_asset_url expose :external?, as: :external + + def direct_asset_url + return object.url unless object.filepath + + release = object.release + project = release.project + + Gitlab::Routing.url_helpers.project_release_url(project, release) << object.filepath + end end end end diff --git a/lib/api/release/links.rb b/lib/api/release/links.rb index def36dc8529891f716a7dec73a8d877b9b59ecb0..f72230c084c5beee8c6afa98aa714f60f000b13e 100644 --- a/lib/api/release/links.rb +++ b/lib/api/release/links.rb @@ -39,6 +39,7 @@ class Links < Grape::API params do requires :name, type: String, desc: 'The name of the link' requires :url, type: String, desc: 'The URL of the link' + optional :filepath, type: String, desc: 'The filepath of the link' end post 'links' do authorize! :create_release, release @@ -73,6 +74,7 @@ class Links < Grape::API params do optional :name, type: String, desc: 'The name of the link' optional :url, type: String, desc: 'The URL of the link' + optional :filepath, type: String, desc: 'The filepath of the link' at_least_one_of :name, :url end put do diff --git a/spec/fixtures/api/schemas/cluster_status.json b/spec/fixtures/api/schemas/cluster_status.json index 29c56b5c820d4dc488c7ee25fa8b23f08e86d9a0..6017ca9e2d532c0bef56ff6455764e0c0ded53ae 100644 --- a/spec/fixtures/api/schemas/cluster_status.json +++ b/spec/fixtures/api/schemas/cluster_status.json @@ -39,9 +39,15 @@ "stack": { "type": ["string", "null"] }, "modsecurity_enabled": { "type": ["boolean", "null"] }, "update_available": { "type": ["boolean", "null"] }, - "can_uninstall": { "type": "boolean" } + "can_uninstall": { "type": "boolean" }, + "available_domains": { + "type": "array", + "items": { "$ref": "#/definitions/domain" } + }, + "pages_domain": { "type": [ { "$ref": "#/definitions/domain" }, "null"] } }, "required" : [ "name", "status" ] - } + }, + "domain": { "id": "integer", "domain": "string" } } } diff --git a/spec/fixtures/api/schemas/release/link.json b/spec/fixtures/api/schemas/release/link.json index 97347cb91ccdc916fc2f64c330c75556df4b3290..bf175be2bc08f60a274d86538cc0dbbce8e6e093 100644 --- a/spec/fixtures/api/schemas/release/link.json +++ b/spec/fixtures/api/schemas/release/link.json @@ -4,7 +4,9 @@ "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, + "filepath": { "type": "string" }, "url": { "type": "string" }, + "direct_asset_url": { "type": "string" }, "external": { "type": "boolean" } }, "additionalProperties": false diff --git a/spec/models/clusters/applications/knative_spec.rb b/spec/models/clusters/applications/knative_spec.rb index 993cc7d0203d6234c071833f235f3e97c0b883a1..7ff7644e7033d1c149a54145b4d27adb9cb39cc7 100644 --- a/spec/models/clusters/applications/knative_spec.rb +++ b/spec/models/clusters/applications/knative_spec.rb @@ -14,6 +14,7 @@ before do allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in) allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async) + allow(ClusterConfigureIstioWorker).to receive(:perform_async) end describe 'associations' do @@ -47,6 +48,32 @@ end end + describe 'configuring istio ingress gateway' do + context 'after installed' do + let(:application) { create(:clusters_applications_knative, :installing) } + + before do + application.make_installed! + end + + it 'schedules a ClusterConfigureIstioWorker' do + expect(ClusterConfigureIstioWorker).to have_received(:perform_async).with(application.cluster_id) + end + end + + context 'after updated' do + let(:application) { create(:clusters_applications_knative, :updating) } + + before do + application.make_installed! + end + + it 'schedules a ClusterConfigureIstioWorker' do + expect(ClusterConfigureIstioWorker).to have_received(:perform_async).with(application.cluster_id) + end + end + end + describe '#can_uninstall?' do subject { knative.can_uninstall? } @@ -196,4 +223,34 @@ describe 'validations' do it { is_expected.to validate_presence_of(:hostname) } end + + describe '#available_domains' do + let!(:domain) { create(:pages_domain, :instance_serverless) } + + it 'returns all instance serverless domains' do + expect(PagesDomain).to receive(:instance_serverless).and_call_original + + domains = subject.available_domains + + expect(domains.length).to eq(1) + expect(domains).to include(domain) + end + end + + describe '#find_available_domain' do + let!(:domain) { create(:pages_domain, :instance_serverless) } + + it 'returns the domain scoped to available domains' do + expect(subject).to receive(:available_domains).and_call_original + expect(subject.find_available_domain(domain.id)).to eq(domain) + end + end + + describe '#pages_domain' do + let!(:sdc) { create(:serverless_domain_cluster, knative: knative) } + + it 'returns the the associated pages domain' do + expect(knative.reload.pages_domain).to eq(sdc.pages_domain) + end + end end diff --git a/spec/requests/api/release/links_spec.rb b/spec/requests/api/release/links_spec.rb index 3a59052bb2923a8693a83ee81f9e07c4dc9fbfae..cf2043ecc7456fb437c035641e99705ea5737703 100644 --- a/spec/requests/api/release/links_spec.rb +++ b/spec/requests/api/release/links_spec.rb @@ -135,16 +135,44 @@ end end end + + describe '#direct_asset_url' do + let!(:link) { create(:release_link, release: release, url: url, filepath: filepath) } + let(:url) { 'https://google.com/-/jobs/140463678/artifacts/download' } + + context 'when filepath is provided' do + let(:filepath) { '/bin/bigfile.exe' } + + specify do + get api("/projects/#{project.id}/releases/v0.1/assets/links/#{link.id}", maintainer) + + expect(json_response['direct_asset_url']).to eq("http://localhost/#{project.namespace.path}/#{project.name}/-/releases/#{release.tag}/bin/bigfile.exe") + end + end + + context 'when filepath is not provided' do + let(:filepath) { nil } + + specify do + get api("/projects/#{project.id}/releases/v0.1/assets/links/#{link.id}", maintainer) + + expect(json_response['direct_asset_url']).to eq(url) + end + end + end end describe 'POST /projects/:id/releases/:tag_name/assets/links' do let(:params) do { name: 'awesome-app.dmg', + filepath: '/binaries/awesome-app.dmg', url: 'https://example.com/download/awesome-app.dmg' } end + let(:last_release_link) { release.links.last } + it 'accepts the request' do post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), params: params @@ -157,8 +185,9 @@ end.to change { Releases::Link.count }.by(1) release.reload - expect(release.links.last.name).to eq('awesome-app.dmg') - expect(release.links.last.url).to eq('https://example.com/download/awesome-app.dmg') + expect(last_release_link.name).to eq('awesome-app.dmg') + expect(last_release_link.filepath).to eq('/binaries/awesome-app.dmg') + expect(last_release_link.url).to eq('https://example.com/download/awesome-app.dmg') end it 'matches response schema' do diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb index c700c150461c632b85d67ebe018e606b2c0d1732..873fbf812ccfdc52c2730446c5e4d5780cb317c7 100644 --- a/spec/serializers/cluster_application_entity_spec.rb +++ b/spec/serializers/cluster_application_entity_spec.rb @@ -59,5 +59,23 @@ expect(subject[:external_ip]).to eq('111.222.111.222') end end + + context 'for knative application' do + let(:pages_domain) { create(:pages_domain, :instance_serverless) } + let(:application) { build(:clusters_applications_knative, :installed) } + + before do + create(:serverless_domain_cluster, knative: application, pages_domain: pages_domain) + end + + it 'includes available domains' do + expect(subject[:available_domains].length).to eq(1) + expect(subject[:available_domains].first).to eq(id: pages_domain.id, domain: pages_domain.domain) + end + + it 'includes pages_domain' do + expect(subject[:pages_domain]).to eq(id: pages_domain.id, domain: pages_domain.domain) + end + end end end diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 597dae81cfb10cfc8b17cba0d9bea71e23dc9391..beb6a0de0f6ba0a45da47297c7c1d489c3987933 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -123,6 +123,26 @@ expect(subject[:merge_request_add_ci_config_path]).not_to be_nil end end + + context 'when build feature is disabled' do + before do + project.project_feature.update(builds_access_level: ProjectFeature::DISABLED) + end + + it 'has no path' do + expect(subject[:merge_request_add_ci_config_path]).to be_nil + end + end + + context 'when creating the pipeline is not allowed' do + before do + user.state = 'blocked' + end + + it 'has no path' do + expect(subject[:merge_request_add_ci_config_path]).to be_nil + end + end end context 'when user does not have permissions' do diff --git a/spec/serializers/serverless/domain_entity_spec.rb b/spec/serializers/serverless/domain_entity_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..bdf0ccb176c1e16d50e4c6110081aa64e5270a0b --- /dev/null +++ b/spec/serializers/serverless/domain_entity_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Serverless::DomainEntity do + describe '#as_json' do + let(:domain) { create(:pages_domain, :instance_serverless) } + + subject { described_class.new(domain).as_json } + + it 'has an id' do + expect(subject[:id]).to eq(domain.id) + end + + it 'has a domain' do + expect(subject[:domain]).to eq(domain.domain) + end + end +end diff --git a/spec/services/clusters/applications/create_service_spec.rb b/spec/services/clusters/applications/create_service_spec.rb index f62af86f1bf179c868f4fe7ace5b73ad4750cdde..0b48af408e1da139f7f02a08e05d6732f579ec8b 100644 --- a/spec/services/clusters/applications/create_service_spec.rb +++ b/spec/services/clusters/applications/create_service_spec.rb @@ -137,10 +137,14 @@ let(:params) do { application: 'knative', - hostname: 'example.com' + hostname: 'example.com', + pages_domain_id: domain.id } end + let(:domain) { create(:pages_domain, :instance_serverless) } + let(:associate_domain_service) { double('AssociateDomainService') } + before do expect_any_instance_of(Clusters::Applications::Knative) .to receive(:make_scheduled!) @@ -158,6 +162,20 @@ it 'sets the hostname' do expect(subject.hostname).to eq('example.com') end + + it 'executes AssociateDomainService' do + expect(Serverless::AssociateDomainService).to receive(:new) do |knative, args| + expect(knative).to be_a(Clusters::Applications::Knative) + expect(args[:pages_domain_id]).to eq(params[:pages_domain_id]) + expect(args[:creator]).to eq(user) + + associate_domain_service + end + + expect(associate_domain_service).to receive(:execute) + + subject + end end context 'elastic stack application' do diff --git a/spec/services/clusters/applications/update_service_spec.rb b/spec/services/clusters/applications/update_service_spec.rb index 2d299882af0f4a5b00388525478d4d7fdd67ed5e..4676951faff123768a7c6bb43d1aa9dffffb6283 100644 --- a/spec/services/clusters/applications/update_service_spec.rb +++ b/spec/services/clusters/applications/update_service_spec.rb @@ -7,8 +7,9 @@ let(:cluster) { create(:cluster, :project, :provided_by_gcp) } let(:user) { create(:user) } - let(:params) { { application: 'knative', hostname: 'udpate.example.com' } } + let(:params) { { application: 'knative', hostname: 'update.example.com', pages_domain_id: domain.id } } let(:service) { described_class.new(cluster, user, params) } + let(:domain) { create(:pages_domain, :instance_serverless) } subject { service.execute(test_request) } @@ -51,6 +52,24 @@ subject end + + context 'knative application' do + let(:associate_domain_service) { double('AssociateDomainService') } + + it 'executes AssociateDomainService' do + expect(Serverless::AssociateDomainService).to receive(:new) do |knative, args| + expect(knative.id).to eq(application.id) + expect(args[:pages_domain_id]).to eq(params[:pages_domain_id]) + expect(args[:creator]).to eq(user) + + associate_domain_service + end + + expect(associate_domain_service).to receive(:execute) + + subject + end + end end context 'application is not schedulable' do diff --git a/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb b/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb index 572e2b911871171e451c536a4143e72fd96fca9b..9238f7debd0a89cbf10bf7ea47c5da72c2892d67 100644 --- a/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb +++ b/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb @@ -194,4 +194,36 @@ ) end end + + context 'when there is an error' do + before do + cluster.application_knative = create(:clusters_applications_knative) + + allow_next_instance_of(described_class) do |instance| + allow(instance).to receive(:configure_passthrough).and_raise(error) + end + end + + context 'Kubeclient::HttpError' do + let(:error) { Kubeclient::HttpError.new(404, nil, nil) } + + it 'puts Knative into an errored state' do + subject + + expect(cluster.application_knative).to be_errored + expect(cluster.application_knative.status_reason).to eq('Kubernetes error: 404') + end + end + + context 'StandardError' do + let(:error) { RuntimeError.new('something went wrong') } + + it 'puts Knative into an errored state' do + subject + + expect(cluster.application_knative).to be_errored + expect(cluster.application_knative.status_reason).to eq('Failed to update.') + end + end + end end diff --git a/spec/services/serverless/associate_domain_service_spec.rb b/spec/services/serverless/associate_domain_service_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..3d1a878bcf582ea2cbed3ff602ff7eba0344d894 --- /dev/null +++ b/spec/services/serverless/associate_domain_service_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Serverless::AssociateDomainService do + subject { described_class.new(knative, pages_domain_id: pages_domain_id, creator: creator) } + + let(:sdc) { create(:serverless_domain_cluster, pages_domain: create(:pages_domain, :instance_serverless)) } + let(:knative) { sdc.knative } + let(:creator) { sdc.creator } + let(:pages_domain_id) { sdc.pages_domain_id } + + context 'when the domain is unchanged' do + let(:creator) { create(:user) } + + it 'does not update creator' do + expect { subject.execute }.not_to change { sdc.reload.creator } + end + end + + context 'when domain is changed to nil' do + let(:pages_domain_id) { nil } + let(:creator) { create(:user) } + + it 'removes the association between knative and the domain' do + expect { subject.execute }.to change { knative.reload.pages_domain }.from(sdc.pages_domain).to(nil) + end + + it 'does not attempt to update creator' do + expect { subject.execute }.not_to raise_error + end + end + + context 'when a new domain is associated' do + let(:pages_domain_id) { create(:pages_domain, :instance_serverless).id } + let(:creator) { create(:user) } + + it 'creates an association with the domain' do + expect { subject.execute }.to change { knative.pages_domain.id }.from(sdc.pages_domain.id).to(pages_domain_id) + end + + it 'updates creator' do + expect { subject.execute }.to change { sdc.reload.creator }.from(sdc.creator).to(creator) + end + end + + context 'when knative is not authorized to use the pages domain' do + let(:pages_domain_id) { create(:pages_domain).id } + + before do + expect(knative).to receive(:available_domains).and_return(PagesDomain.none) + end + + it 'sets pages_domain_id to nil' do + expect { subject.execute }.to change { knative.reload.pages_domain }.from(sdc.pages_domain).to(nil) + end + end + + context 'when knative hostname is nil' do + let(:knative) { build(:clusters_applications_knative, hostname: nil) } + + it 'sets hostname to a placeholder value' do + expect { subject.execute }.to change { knative.hostname }.to('example.com') + end + end + + context 'when knative hostname exists' do + let(:knative) { build(:clusters_applications_knative, hostname: 'hostname.com') } + + it 'does not change hostname' do + expect { subject.execute }.not_to change { knative.hostname } + end + end +end