diff options
Diffstat (limited to 'app/assets/javascripts/kubernetes_dashboard/graphql')
6 files changed, 289 insertions, 42 deletions
diff --git a/app/assets/javascripts/kubernetes_dashboard/graphql/client.js b/app/assets/javascripts/kubernetes_dashboard/graphql/client.js index 5894472d83b..9454465df9d 100644 --- a/app/assets/javascripts/kubernetes_dashboard/graphql/client.js +++ b/app/assets/javascripts/kubernetes_dashboard/graphql/client.js @@ -6,6 +6,9 @@ import k8sDeploymentsQuery from './queries/k8s_dashboard_deployments.query.graph import k8sStatefulSetsQuery from './queries/k8s_dashboard_stateful_sets.query.graphql'; import k8sReplicaSetsQuery from './queries/k8s_dashboard_replica_sets.query.graphql'; import k8sDaemonSetsQuery from './queries/k8s_dashboard_daemon_sets.query.graphql'; +import k8sJobsQuery from './queries/k8s_dashboard_jobs.query.graphql'; +import k8sCronJobsQuery from './queries/k8s_dashboard_cron_jobs.query.graphql'; +import k8sServicesQuery from './queries/k8s_dashboard_services.query.graphql'; import { resolvers } from './resolvers'; export const apolloProvider = () => { @@ -14,16 +17,18 @@ export const apolloProvider = () => { }); const { cache } = defaultClient; + const metadata = { + name: null, + namespace: null, + creationTimestamp: null, + labels: null, + annotations: null, + }; + cache.writeQuery({ query: k8sPodsQuery, data: { - metadata: { - name: null, - namespace: null, - creationTimestamp: null, - labels: null, - annotations: null, - }, + metadata, status: { phase: null, }, @@ -33,13 +38,7 @@ export const apolloProvider = () => { cache.writeQuery({ query: k8sDeploymentsQuery, data: { - metadata: { - name: null, - namespace: null, - creationTimestamp: null, - labels: null, - annotations: null, - }, + metadata, status: { conditions: null, }, @@ -49,13 +48,7 @@ export const apolloProvider = () => { cache.writeQuery({ query: k8sStatefulSetsQuery, data: { - metadata: { - name: null, - namespace: null, - creationTimestamp: null, - labels: null, - annotations: null, - }, + metadata, status: { readyReplicas: null, }, @@ -68,13 +61,7 @@ export const apolloProvider = () => { cache.writeQuery({ query: k8sReplicaSetsQuery, data: { - metadata: { - name: null, - namespace: null, - creationTimestamp: null, - labels: null, - annotations: null, - }, + metadata, status: { readyReplicas: null, }, @@ -87,13 +74,7 @@ export const apolloProvider = () => { cache.writeQuery({ query: k8sDaemonSetsQuery, data: { - metadata: { - name: null, - namespace: null, - creationTimestamp: null, - labels: null, - annotations: null, - }, + metadata, status: { numberMisscheduled: null, numberReady: null, @@ -102,6 +83,47 @@ export const apolloProvider = () => { }, }); + cache.writeQuery({ + query: k8sJobsQuery, + data: { + metadata, + status: { + failed: null, + succeeded: null, + }, + spec: { + completions: null, + }, + }, + }); + + cache.writeQuery({ + query: k8sCronJobsQuery, + data: { + metadata, + status: { + active: null, + lastScheduleTime: null, + }, + spec: { + suspend: null, + }, + }, + }); + + cache.writeQuery({ + query: k8sServicesQuery, + data: { + metadata, + spec: { + type: null, + clusterIP: null, + externalIP: null, + ports: null, + }, + }, + }); + return new VueApollo({ defaultClient, }); diff --git a/app/assets/javascripts/kubernetes_dashboard/graphql/helpers/resolver_helpers.js b/app/assets/javascripts/kubernetes_dashboard/graphql/helpers/resolver_helpers.js index 47c2f543357..b9c195d83d0 100644 --- a/app/assets/javascripts/kubernetes_dashboard/graphql/helpers/resolver_helpers.js +++ b/app/assets/javascripts/kubernetes_dashboard/graphql/helpers/resolver_helpers.js @@ -43,6 +43,62 @@ export const mapSetItem = (item) => { return { status, metadata, spec }; }; +export const mapJobItem = (item) => { + const metadata = { + ...item.metadata, + annotations: item.metadata?.annotations || {}, + labels: item.metadata?.labels || {}, + }; + + const status = { + failed: item.status?.failed || 0, + succeeded: item.status?.succeeded || 0, + }; + + return { + status, + metadata, + spec: item.spec, + }; +}; + +export const mapServicesItems = (item) => { + const { type, clusterIP, externalIP, ports } = item.spec; + + return { + metadata: { + ...item.metadata, + annotations: item.metadata?.annotations || {}, + labels: item.metadata?.labels || {}, + }, + spec: { + type, + clusterIP: clusterIP || '-', + externalIP: externalIP || '-', + ports, + }, + }; +}; + +export const mapCronJobItem = (item) => { + const metadata = { + ...item.metadata, + annotations: item.metadata?.annotations || {}, + labels: item.metadata?.labels || {}, + }; + + const status = { + active: item.status?.active || 0, + lastScheduleTime: item.status?.lastScheduleTime || null, + }; + + return { + status, + metadata, + spec: item.spec, + }; +}; + export const watchWorkloadItems = ({ client, query, diff --git a/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_cron_jobs.query.graphql b/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_cron_jobs.query.graphql new file mode 100644 index 00000000000..fe20cd2e70e --- /dev/null +++ b/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_cron_jobs.query.graphql @@ -0,0 +1,18 @@ +query getK8sDashboardCronJobs($configuration: LocalConfiguration) { + k8sCronJobs(configuration: $configuration) @client { + metadata { + name + namespace + creationTimestamp + labels + annotations + } + status { + active + lastScheduleTime + } + spec { + suspend + } + } +} diff --git a/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_jobs.query.graphql b/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_jobs.query.graphql new file mode 100644 index 00000000000..86afb47f2f9 --- /dev/null +++ b/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_jobs.query.graphql @@ -0,0 +1,18 @@ +query getK8sDashboardJobs($configuration: LocalConfiguration) { + k8sJobs(configuration: $configuration) @client { + metadata { + name + namespace + creationTimestamp + labels + annotations + } + status { + failed + succeeded + } + spec { + completions + } + } +} diff --git a/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_services.query.graphql b/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_services.query.graphql new file mode 100644 index 00000000000..7d42d66183e --- /dev/null +++ b/app/assets/javascripts/kubernetes_dashboard/graphql/queries/k8s_dashboard_services.query.graphql @@ -0,0 +1,17 @@ +query getK8sDashboardServices($configuration: LocalConfiguration) { + k8sServices(configuration: $configuration) @client { + metadata { + name + namespace + creationTimestamp + labels + annotations + } + spec { + type + clusterIP + externalIP + ports + } + } +} diff --git a/app/assets/javascripts/kubernetes_dashboard/graphql/resolvers/kubernetes.js b/app/assets/javascripts/kubernetes_dashboard/graphql/resolvers/kubernetes.js index e59bed5581b..75285ad2cca 100644 --- a/app/assets/javascripts/kubernetes_dashboard/graphql/resolvers/kubernetes.js +++ b/app/assets/javascripts/kubernetes_dashboard/graphql/resolvers/kubernetes.js @@ -1,4 +1,4 @@ -import { Configuration, AppsV1Api } from '@gitlab/cluster-client'; +import { Configuration, CoreV1Api, AppsV1Api, BatchV1Api } from '@gitlab/cluster-client'; import { getK8sPods, @@ -7,12 +7,18 @@ import { mapSetItem, buildWatchPath, watchWorkloadItems, + mapJobItem, + mapCronJobItem, + mapServicesItems, } from '../helpers/resolver_helpers'; import k8sDashboardPodsQuery from '../queries/k8s_dashboard_pods.query.graphql'; import k8sDashboardDeploymentsQuery from '../queries/k8s_dashboard_deployments.query.graphql'; import k8sDashboardStatefulSetsQuery from '../queries/k8s_dashboard_stateful_sets.query.graphql'; import k8sDashboardReplicaSetsQuery from '../queries/k8s_dashboard_replica_sets.query.graphql'; import k8sDaemonSetsQuery from '../queries/k8s_dashboard_daemon_sets.query.graphql'; +import k8sJobsQuery from '../queries/k8s_dashboard_jobs.query.graphql'; +import k8sCronJobsQuery from '../queries/k8s_dashboard_cron_jobs.query.graphql'; +import k8sServicesQuery from '../queries/k8s_dashboard_services.query.graphql'; export default { k8sPods(_, { configuration }, { client }) { @@ -61,10 +67,10 @@ export default { const config = new Configuration(configuration); const appsV1api = new AppsV1Api(config); - const deploymentsApi = namespace + const statefulSetsApi = namespace ? appsV1api.listAppsV1NamespacedStatefulSet({ namespace }) : appsV1api.listAppsV1StatefulSetForAllNamespaces(); - return deploymentsApi + return statefulSetsApi .then((res) => { const watchPath = buildWatchPath({ resource: 'statefulsets', @@ -98,10 +104,10 @@ export default { const config = new Configuration(configuration); const appsV1api = new AppsV1Api(config); - const deploymentsApi = namespace + const replicaSetsApi = namespace ? appsV1api.listAppsV1NamespacedReplicaSet({ namespace }) : appsV1api.listAppsV1ReplicaSetForAllNamespaces(); - return deploymentsApi + return replicaSetsApi .then((res) => { const watchPath = buildWatchPath({ resource: 'replicasets', @@ -135,10 +141,10 @@ export default { const config = new Configuration(configuration); const appsV1api = new AppsV1Api(config); - const deploymentsApi = namespace + const daemonSetsApi = namespace ? appsV1api.listAppsV1NamespacedDaemonSet({ namespace }) : appsV1api.listAppsV1DaemonSetForAllNamespaces(); - return deploymentsApi + return daemonSetsApi .then((res) => { const watchPath = buildWatchPath({ resource: 'daemonsets', @@ -166,4 +172,114 @@ export default { } }); }, + + k8sJobs(_, { configuration, namespace = '' }, { client }) { + const config = new Configuration(configuration); + + const batchV1api = new BatchV1Api(config); + const jobsApi = namespace + ? batchV1api.listBatchV1NamespacedJob({ namespace }) + : batchV1api.listBatchV1JobForAllNamespaces(); + return jobsApi + .then((res) => { + const watchPath = buildWatchPath({ + resource: 'jobs', + api: 'apis/batch/v1', + namespace, + }); + watchWorkloadItems({ + client, + query: k8sJobsQuery, + configuration, + namespace, + watchPath, + queryField: 'k8sJobs', + mapFn: mapJobItem, + }); + + const data = res?.items || []; + + return data.map(mapJobItem); + }) + .catch(async (err) => { + try { + await handleClusterError(err); + } catch (error) { + throw new Error(error.message); + } + }); + }, + + k8sCronJobs(_, { configuration, namespace = '' }, { client }) { + const config = new Configuration(configuration); + + const batchV1api = new BatchV1Api(config); + const cronJobsApi = namespace + ? batchV1api.listBatchV1NamespacedCronJob({ namespace }) + : batchV1api.listBatchV1CronJobForAllNamespaces(); + return cronJobsApi + .then((res) => { + const watchPath = buildWatchPath({ + resource: 'cronjobs', + api: 'apis/batch/v1', + namespace, + }); + watchWorkloadItems({ + client, + query: k8sCronJobsQuery, + configuration, + namespace, + watchPath, + queryField: 'k8sCronJobs', + mapFn: mapCronJobItem, + }); + + const data = res?.items || []; + + return data.map(mapCronJobItem); + }) + .catch(async (err) => { + try { + await handleClusterError(err); + } catch (error) { + throw new Error(error.message); + } + }); + }, + + k8sServices(_, { configuration, namespace = '' }, { client }) { + const config = new Configuration(configuration); + + const coreV1Api = new CoreV1Api(config); + const servicesApi = namespace + ? coreV1Api.listCoreV1NamespacedService({ namespace }) + : coreV1Api.listCoreV1ServiceForAllNamespaces(); + return servicesApi + .then((res) => { + const watchPath = buildWatchPath({ + resource: 'services', + namespace, + }); + watchWorkloadItems({ + client, + query: k8sServicesQuery, + configuration, + namespace, + watchPath, + queryField: 'k8sServices', + mapFn: mapServicesItems, + }); + + const data = res?.items || []; + + return data.map(mapServicesItems); + }) + .catch(async (err) => { + try { + await handleClusterError(err); + } catch (error) { + throw new Error(error.message); + } + }); + }, }; |