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

kubernetes_overview.vue « components « environments « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0e52a80c2c5430a1e71225e8430cc254f23a3ba5 (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
<script>
import { GlCollapse, GlButton, GlAlert } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import csrf from '~/lib/utils/csrf';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import KubernetesAgentInfo from './kubernetes_agent_info.vue';
import KubernetesPods from './kubernetes_pods.vue';
import KubernetesTabs from './kubernetes_tabs.vue';
import KubernetesStatusBar from './kubernetes_status_bar.vue';

export default {
  components: {
    GlCollapse,
    GlButton,
    GlAlert,
    KubernetesAgentInfo,
    KubernetesPods,
    KubernetesTabs,
    KubernetesStatusBar,
  },
  inject: ['kasTunnelUrl'],
  props: {
    clusterAgent: {
      required: true,
      type: Object,
    },
    environmentName: {
      required: true,
      type: String,
    },
    namespace: {
      required: false,
      type: String,
      default: '',
    },
    fluxResourcePath: {
      required: false,
      type: String,
      default: '',
    },
  },
  data() {
    return {
      isVisible: false,
      error: '',
      hasFailedState: false,
      podsLoading: false,
      workloadTypesLoading: false,
    };
  },
  computed: {
    chevronIcon() {
      return this.isVisible ? 'chevron-down' : 'chevron-right';
    },
    label() {
      return this.isVisible ? this.$options.i18n.collapse : this.$options.i18n.expand;
    },
    gitlabAgentId() {
      return getIdFromGraphQLId(this.clusterAgent.id).toString();
    },
    k8sAccessConfiguration() {
      return {
        basePath: this.kasTunnelUrl,
        baseOptions: {
          headers: { 'GitLab-Agent-Id': this.gitlabAgentId, ...csrf.headers },
          withCredentials: true,
        },
      };
    },
    clusterHealthStatus() {
      const clusterDataLoading = this.podsLoading || this.workloadTypesLoading;
      if (clusterDataLoading) {
        return '';
      }

      return this.hasFailedState ? 'error' : 'success';
    },
  },
  methods: {
    toggleCollapse() {
      this.isVisible = !this.isVisible;
    },
    onClusterError(message) {
      this.error = message;
    },
  },
  i18n: {
    collapse: __('Collapse'),
    expand: __('Expand'),
    sectionTitle: s__('Environment|Kubernetes overview'),
  },
};
</script>
<template>
  <div class="gl-px-4">
    <p class="gl-font-weight-bold gl-text-gray-500 gl-display-flex gl-mb-0">
      <gl-button
        :icon="chevronIcon"
        :aria-label="label"
        category="tertiary"
        size="small"
        class="gl-mr-3"
        @click="toggleCollapse"
      />{{ $options.i18n.sectionTitle }}
    </p>
    <gl-collapse :visible="isVisible" class="gl-md-pl-7 gl-md-pr-5 gl-mt-4">
      <template v-if="isVisible">
        <kubernetes-status-bar
          :cluster-health-status="clusterHealthStatus"
          :configuration="k8sAccessConfiguration"
          :namespace="namespace"
          :environment-name="environmentName"
          :flux-resource-path="fluxResourcePath"
          class="gl-mb-3" />
        <kubernetes-agent-info :cluster-agent="clusterAgent" class="gl-mb-5" />

        <gl-alert v-if="error" variant="danger" :dismissible="false" class="gl-mb-5">
          {{ error }}
        </gl-alert>

        <kubernetes-pods
          :configuration="k8sAccessConfiguration"
          :namespace="namespace"
          class="gl-mb-5"
          @cluster-error="onClusterError"
          @loading="podsLoading = $event"
          @failed="hasFailedState = true" />
        <kubernetes-tabs
          :configuration="k8sAccessConfiguration"
          :namespace="namespace"
          class="gl-mb-5"
          @cluster-error="onClusterError"
          @loading="workloadTypesLoading = $event"
          @failed="hasFailedState = true"
      /></template>
    </gl-collapse>
  </div>
</template>