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

actions.js « store « eks_cluster « create_cluster « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b182d4dff132bca8ecb90f97f843533b6ed06da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import * as types from './mutation_types';
import { DEFAULT_REGION } from '../constants';
import { setAWSConfig } from '../services/aws_services_facade';
import axios from '~/lib/utils/axios_utils';
import { deprecatedCreateFlash as createFlash } from '~/flash';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';

const getErrorMessage = data => {
  const errorKey = Object.keys(data)[0];

  return data[errorKey][0];
};

export const setClusterName = ({ commit }, payload) => {
  commit(types.SET_CLUSTER_NAME, payload);
};

export const setEnvironmentScope = ({ commit }, payload) => {
  commit(types.SET_ENVIRONMENT_SCOPE, payload);
};

export const setKubernetesVersion = ({ commit }, payload) => {
  commit(types.SET_KUBERNETES_VERSION, payload);
};

export const createRole = ({ dispatch, state: { createRolePath } }, payload) => {
  dispatch('requestCreateRole');

  const region = payload.selectedRegion || DEFAULT_REGION;

  return axios
    .post(createRolePath, {
      role_arn: payload.roleArn,
      role_external_id: payload.externalId,
      region,
    })
    .then(({ data }) => {
      const awsData = {
        ...convertObjectPropsToCamelCase(data),
        region,
      };

      dispatch('createRoleSuccess', awsData);
    })
    .catch(error => {
      let message = error;
      if (error?.response?.data?.message) {
        message = error.response.data.message;
      }
      dispatch('createRoleError', { error: message });
    });
};

export const requestCreateRole = ({ commit }) => {
  commit(types.REQUEST_CREATE_ROLE);
};

export const createRoleSuccess = ({ dispatch, commit }, awsCredentials) => {
  dispatch('setRegion', { region: awsCredentials.region });
  setAWSConfig({ awsCredentials });
  commit(types.CREATE_ROLE_SUCCESS);
};

export const createRoleError = ({ commit }, payload) => {
  commit(types.CREATE_ROLE_ERROR, payload);
};

export const createCluster = ({ dispatch, state }) => {
  dispatch('requestCreateCluster');

  return axios
    .post(state.createClusterPath, {
      name: state.clusterName,
      environment_scope: state.environmentScope,
      managed: state.gitlabManagedCluster,
      namespace_per_environment: state.namespacePerEnvironment,
      provider_aws_attributes: {
        kubernetes_version: state.kubernetesVersion,
        region: state.selectedRegion,
        vpc_id: state.selectedVpc,
        subnet_ids: state.selectedSubnet,
        role_arn: state.selectedRole,
        key_name: state.selectedKeyPair,
        security_group_id: state.selectedSecurityGroup,
        instance_type: state.selectedInstanceType,
        num_nodes: state.nodeCount,
      },
    })
    .then(({ headers: { location } }) => dispatch('createClusterSuccess', location))
    .catch(({ response: { data } }) => {
      dispatch('createClusterError', data);
    });
};

export const requestCreateCluster = ({ commit }) => {
  commit(types.REQUEST_CREATE_CLUSTER);
};

export const createClusterSuccess = (_, location) => {
  window.location.assign(location);
};

export const createClusterError = ({ commit }, error) => {
  commit(types.CREATE_CLUSTER_ERROR, error);
  createFlash(getErrorMessage(error));
};

export const setRegion = ({ commit }, payload) => {
  commit(types.SET_REGION, payload);
};

export const setKeyPair = ({ commit }, payload) => {
  commit(types.SET_KEY_PAIR, payload);
};

export const setVpc = ({ commit }, payload) => {
  commit(types.SET_VPC, payload);
};

export const setSubnet = ({ commit }, payload) => {
  commit(types.SET_SUBNET, payload);
};

export const setRole = ({ commit }, payload) => {
  commit(types.SET_ROLE, payload);
};

export const setSecurityGroup = ({ commit }, payload) => {
  commit(types.SET_SECURITY_GROUP, payload);
};

export const setGitlabManagedCluster = ({ commit }, payload) => {
  commit(types.SET_GITLAB_MANAGED_CLUSTER, payload);
};

export const setNamespacePerEnvironment = ({ commit }, payload) => {
  commit(types.SET_NAMESPACE_PER_ENVIRONMENT, payload);
};

export const setInstanceType = ({ commit }, payload) => {
  commit(types.SET_INSTANCE_TYPE, payload);
};

export const setNodeCount = ({ commit }, payload) => {
  commit(types.SET_NODE_COUNT, payload);
};