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

clusters_util.js « clusters_list « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 25a8426500e46441d4eba6b58ed8451cf443e33d (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
import { ACTIVE_CONNECTION_TIME, NAME_MAX_LENGTH } from './constants';

function getTruncatedName(name) {
  return name.substring(0, NAME_MAX_LENGTH);
}

export function generateAgentRegistrationCommand({ name, token, version, address }) {
  return `helm repo add gitlab https://charts.gitlab.io
helm repo update
helm upgrade --install ${name} gitlab/gitlab-agent \\
    --namespace gitlab-agent-${getTruncatedName(name)} \\
    --create-namespace \\
    --set image.tag=v${version} \\
    --set config.token=${token} \\
    --set config.kasAddress=${address}`;
}

export function getAgentConfigPath(clusterAgentName) {
  return `.gitlab/agents/${clusterAgentName}`;
}

export function getAgentLastContact(tokens = []) {
  let lastContact = null;
  tokens.forEach((token) => {
    const lastContactToDate = new Date(token.lastUsedAt).getTime();
    if (lastContactToDate > lastContact) {
      lastContact = lastContactToDate;
    }
  });
  return lastContact;
}

export function getAgentStatus(lastContact) {
  if (lastContact) {
    const now = new Date().getTime();
    const diff = now - lastContact;

    return diff >= ACTIVE_CONNECTION_TIME ? 'inactive' : 'active';
  }
  return 'unused';
}