From ed9165c2abda1dca048a8d3cb8030d906c0bbb0c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 18 Mar 2020 06:09:38 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/services/pod_logs/kubernetes_service.rb | 2 +- changelogs/unreleased/ak-fix-multi-pod.yml | 5 ++ doc/user/clusters/applications.md | 9 ++ doc/user/clusters/management_project.md | 4 +- .../gke_cluster/stores/actions_spec.js | 76 +++++++++-------- .../gke_cluster/stores/mutations_spec.js | 97 +++++----------------- spec/services/pod_logs/base_service_spec.rb | 6 +- spec/services/pod_logs/kubernetes_service_spec.rb | 10 ++- spec/support/helpers/kubernetes_helpers.rb | 6 +- 9 files changed, 93 insertions(+), 122 deletions(-) create mode 100644 changelogs/unreleased/ak-fix-multi-pod.yml diff --git a/app/services/pod_logs/kubernetes_service.rb b/app/services/pod_logs/kubernetes_service.rb index 92ebb84b877..31e26912c73 100644 --- a/app/services/pod_logs/kubernetes_service.rb +++ b/app/services/pod_logs/kubernetes_service.rb @@ -43,7 +43,7 @@ module PodLogs end def check_container_name(result) - pod_details = result[:raw_pods].first { |p| p.metadata.name == result[:pod_name] } + pod_details = result[:raw_pods].find { |p| p.metadata.name == result[:pod_name] } containers = pod_details.spec.containers.map(&:name) # select first container if not specified diff --git a/changelogs/unreleased/ak-fix-multi-pod.yml b/changelogs/unreleased/ak-fix-multi-pod.yml new file mode 100644 index 00000000000..7f19dfd6875 --- /dev/null +++ b/changelogs/unreleased/ak-fix-multi-pod.yml @@ -0,0 +1,5 @@ +--- +title: Fix access to logs when multiple pods exist +merge_request: 27008 +author: +type: fixed diff --git a/doc/user/clusters/applications.md b/doc/user/clusters/applications.md index 4768fcc2970..822868aeb35 100644 --- a/doc/user/clusters/applications.md +++ b/doc/user/clusters/applications.md @@ -588,6 +588,15 @@ output of the [Helm Tiller](https://v2.helm.sh/docs/install/#running-tiller-locally) binary will be saved as a [CI job artifact](../../ci/pipelines/job_artifacts.md). +### Important notes + +Note the following: + +- When you set the value for `installed` key back to `false`, the application will be + unprovisioned from the cluster. +- If you update `.gitlab/managed-apps//values.yaml` with new values, the + application will be redeployed. + ### Install Ingress using GitLab CI To install Ingress, define the `.gitlab/managed-apps/config.yaml` file diff --git a/doc/user/clusters/management_project.md b/doc/user/clusters/management_project.md index 5a5ab4dce05..562826eba65 100644 --- a/doc/user/clusters/management_project.md +++ b/doc/user/clusters/management_project.md @@ -14,7 +14,7 @@ privileges. This can be useful for: -- Creating pipelines to install cluster-wide applications into your cluster. +- Creating pipelines to install cluster-wide applications into your cluster, see [Install using GitLab CI (alpha)](applications.md#install-using-gitlab-ci-alpha) for details. - Any jobs that require `cluster-admin` privileges. ## Permissions @@ -47,6 +47,8 @@ To select a cluster management project to use: **Operations > Kubernetes** page. - [Group-level cluster](../group/clusters/index.md), navigate to your group's **Kubernetes** page. + - [Instance-level cluster](../instance/clusters/index.md), navigate to Admin Area's **Kubernetes** + page. 1. Select the project using **Cluster management project field** in the **Advanced settings** section. diff --git a/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js b/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js index 8c3525207d6..c1ac3841136 100644 --- a/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js +++ b/spec/frontend/create_cluster/gke_cluster/stores/actions_spec.js @@ -1,16 +1,18 @@ import testAction from 'helpers/vuex_action_helper'; +import createState from '~/create_cluster/gke_cluster/store/state'; +import * as types from '~/create_cluster/gke_cluster/store/mutation_types'; import * as actions from '~/create_cluster/gke_cluster/store/actions'; -import { createStore } from '~/create_cluster/gke_cluster/store'; import gapi from '../helpers'; -import { selectedProjectMock, selectedZoneMock, selectedMachineTypeMock } from '../mock_data'; +import { + selectedProjectMock, + selectedZoneMock, + selectedMachineTypeMock, + gapiProjectsResponseMock, + gapiZonesResponseMock, + gapiMachineTypesResponseMock, +} from '../mock_data'; describe('GCP Cluster Dropdown Store Actions', () => { - let store; - - beforeEach(() => { - store = createStore(); - }); - describe('setProject', () => { it('should set project', done => { testAction( @@ -76,16 +78,16 @@ describe('GCP Cluster Dropdown Store Actions', () => { }); describe('fetchProjects', () => { - it('fetches projects from Google API', done => { - store - .dispatch('fetchProjects') - .then(() => { - expect(store.state.projects[0].projectId).toEqual(selectedProjectMock.projectId); - expect(store.state.projects[0].name).toEqual(selectedProjectMock.name); - - done(); - }) - .catch(done.fail); + it('fetches projects from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchProjects, + null, + state, + [{ type: types.SET_PROJECTS, payload: gapiProjectsResponseMock.projects }], + [], + ); }); }); @@ -112,28 +114,30 @@ describe('GCP Cluster Dropdown Store Actions', () => { }); describe('fetchZones', () => { - it('fetches zones from Google API', done => { - store - .dispatch('fetchZones') - .then(() => { - expect(store.state.zones[0].name).toEqual(selectedZoneMock); - - done(); - }) - .catch(done.fail); + it('fetches zones from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchZones, + null, + state, + [{ type: types.SET_ZONES, payload: gapiZonesResponseMock.items }], + [], + ); }); }); describe('fetchMachineTypes', () => { - it('fetches machine types from Google API', done => { - store - .dispatch('fetchMachineTypes') - .then(() => { - expect(store.state.machineTypes[0].name).toEqual(selectedMachineTypeMock); - - done(); - }) - .catch(done.fail); + it('fetches machine types from Google API', () => { + const state = createState(); + + return testAction( + actions.fetchMachineTypes, + null, + state, + [{ type: types.SET_MACHINE_TYPES, payload: gapiMachineTypesResponseMock.items }], + [], + ); }); }); }); diff --git a/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js b/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js index 7ee6ff436e2..2a742b6ed8f 100644 --- a/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js +++ b/spec/frontend/create_cluster/gke_cluster/stores/mutations_spec.js @@ -1,87 +1,32 @@ -import { createStore } from '~/create_cluster/gke_cluster/store'; +import createState from '~/create_cluster/gke_cluster/store/state'; import * as types from '~/create_cluster/gke_cluster/store/mutation_types'; +import mutations from '~/create_cluster/gke_cluster/store/mutations'; import { - selectedProjectMock, - selectedZoneMock, - selectedMachineTypeMock, gapiProjectsResponseMock, gapiZonesResponseMock, gapiMachineTypesResponseMock, } from '../mock_data'; describe('GCP Cluster Dropdown Store Mutations', () => { - let store; - - beforeEach(() => { - store = createStore(); - }); - - describe('SET_PROJECT', () => { - it('should set GCP project as selectedProject', () => { - const projectToSelect = gapiProjectsResponseMock.projects[0]; - - store.commit(types.SET_PROJECT, projectToSelect); - - expect(store.state.selectedProject.projectId).toEqual(selectedProjectMock.projectId); - expect(store.state.selectedProject.name).toEqual(selectedProjectMock.name); - }); - }); - - describe('SET_PROJECT_BILLING_STATUS', () => { - it('should set project billing status', () => { - store.commit(types.SET_PROJECT_BILLING_STATUS, true); - - expect(store.state.projectHasBillingEnabled).toBeTruthy(); - }); - }); - - describe('SET_ZONE', () => { - it('should set GCP zone as selectedZone', () => { - const zoneToSelect = gapiZonesResponseMock.items[0].name; - - store.commit(types.SET_ZONE, zoneToSelect); - - expect(store.state.selectedZone).toEqual(selectedZoneMock); - }); - }); - - describe('SET_MACHINE_TYPE', () => { - it('should set GCP machine type as selectedMachineType', () => { - const machineTypeToSelect = gapiMachineTypesResponseMock.items[0].name; - - store.commit(types.SET_MACHINE_TYPE, machineTypeToSelect); - - expect(store.state.selectedMachineType).toEqual(selectedMachineTypeMock); - }); - }); - - describe('SET_PROJECTS', () => { - it('should set Google API Projects response as projects', () => { - expect(store.state.projects.length).toEqual(0); - - store.commit(types.SET_PROJECTS, gapiProjectsResponseMock.projects); - - expect(store.state.projects.length).toEqual(gapiProjectsResponseMock.projects.length); - }); - }); - - describe('SET_ZONES', () => { - it('should set Google API Zones response as zones', () => { - expect(store.state.zones.length).toEqual(0); - - store.commit(types.SET_ZONES, gapiZonesResponseMock.items); - - expect(store.state.zones.length).toEqual(gapiZonesResponseMock.items.length); - }); - }); - - describe('SET_MACHINE_TYPES', () => { - it('should set Google API Machine Types response as machineTypes', () => { - expect(store.state.machineTypes.length).toEqual(0); - - store.commit(types.SET_MACHINE_TYPES, gapiMachineTypesResponseMock.items); - - expect(store.state.machineTypes.length).toEqual(gapiMachineTypesResponseMock.items.length); + describe.each` + mutation | stateProperty | mockData + ${types.SET_PROJECTS} | ${'projects'} | ${gapiProjectsResponseMock.projects} + ${types.SET_ZONES} | ${'zones'} | ${gapiZonesResponseMock.items} + ${types.SET_MACHINE_TYPES} | ${'machineTypes'} | ${gapiMachineTypesResponseMock.items} + ${types.SET_MACHINE_TYPE} | ${'selectedMachineType'} | ${gapiMachineTypesResponseMock.items[0].name} + ${types.SET_ZONE} | ${'selectedZone'} | ${gapiZonesResponseMock.items[0].name} + ${types.SET_PROJECT} | ${'selectedProject'} | ${gapiProjectsResponseMock.projects[0]} + ${types.SET_PROJECT_BILLING_STATUS} | ${'projectHasBillingEnabled'} | ${true} + ${types.SET_IS_VALIDATING_PROJECT_BILLING} | ${'isValidatingProjectBilling'} | ${true} + `('$mutation', ({ mutation, stateProperty, mockData }) => { + it(`should set the mutation payload to the ${stateProperty} state property`, () => { + const state = createState(); + + expect(state[stateProperty]).not.toBe(mockData); + + mutations[mutation](state, mockData); + + expect(state[stateProperty]).toBe(mockData); }); }); }); diff --git a/spec/services/pod_logs/base_service_spec.rb b/spec/services/pod_logs/base_service_spec.rb index d93ea51eae1..fb53321352b 100644 --- a/spec/services/pod_logs/base_service_spec.rb +++ b/spec/services/pod_logs/base_service_spec.rb @@ -9,11 +9,13 @@ describe ::PodLogs::BaseService do let(:namespace) { 'autodevops-deploy-9-production' } let(:pod_name) { 'pod-1' } + let(:pod_name_2) { 'pod-2' } let(:container_name) { 'container-0' } let(:params) { {} } let(:raw_pods) do JSON.parse([ - kube_pod(name: pod_name) + kube_pod(name: pod_name), + kube_pod(name: pod_name_2) ].to_json, object_class: OpenStruct) end @@ -115,7 +117,7 @@ describe ::PodLogs::BaseService do result = subject.send(:get_pod_names, raw_pods: raw_pods) expect(result[:status]).to eq(:success) - expect(result[:pods]).to eq([pod_name]) + expect(result[:pods]).to eq([pod_name, pod_name_2]) end end end diff --git a/spec/services/pod_logs/kubernetes_service_spec.rb b/spec/services/pod_logs/kubernetes_service_spec.rb index 8ce79d4c318..ff0554bbe5c 100644 --- a/spec/services/pod_logs/kubernetes_service_spec.rb +++ b/spec/services/pod_logs/kubernetes_service_spec.rb @@ -9,16 +9,20 @@ describe ::PodLogs::KubernetesService do let(:namespace) { 'autodevops-deploy-9-production' } let(:pod_name) { 'pod-1' } + let(:pod_name_2) { 'pod-2' } let(:container_name) { 'container-0' } + let(:container_name_2) { 'foo-0' } let(:params) { {} } let(:raw_logs) do "2019-12-13T14:04:22.123456Z Log 1\n2019-12-13T14:04:23.123456Z Log 2\n" \ "2019-12-13T14:04:24.123456Z Log 3" end + let(:raw_pods) do JSON.parse([ - kube_pod(name: pod_name) + kube_pod(name: pod_name), + kube_pod(name: pod_name_2, container_name: container_name_2) ].to_json, object_class: OpenStruct) end @@ -220,12 +224,12 @@ describe ::PodLogs::KubernetesService do it 'returns success if container_name was not specified and there are containers' do result = subject.send(:check_container_name, - pod_name: pod_name, + pod_name: pod_name_2, raw_pods: raw_pods ) expect(result[:status]).to eq(:success) - expect(result[:container_name]).to eq(container_name) + expect(result[:container_name]).to eq(container_name_2) end it 'returns error if container_name was not specified and there are no containers on the pod' do diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index 427948bda96..ca910e47695 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -489,7 +489,7 @@ module KubernetesHelpers # This is a partial response, it will have many more elements in reality but # these are the ones we care about at the moment - def kube_pod(name: "kube-pod", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil) + def kube_pod(name: "kube-pod", container_name: "container-0", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil) { "metadata" => { "name" => name, @@ -506,8 +506,8 @@ module KubernetesHelpers }, "spec" => { "containers" => [ - { "name" => "container-0" }, - { "name" => "container-1" } + { "name" => "#{container_name}" }, + { "name" => "#{container_name}-1" } ] }, "status" => { "phase" => status } -- cgit v1.2.1