Merge pull request #8197 from brexhq/k8s-backend-add-cronjobs-and-jobs

add cronjobs and jobs as default objects for the kubernetes-backend
This commit is contained in:
Fredrik Adelöw
2021-11-25 11:32:49 +01:00
committed by GitHub
11 changed files with 108 additions and 7 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-kubernetes-backend': patch
'@backstage/plugin-kubernetes-common': patch
---
Include CronJobs and Jobs as default objects returned by the kubernetes backend and add/update relevant types.
+2
View File
@@ -202,6 +202,8 @@ export type KubernetesObjectTypes =
| 'deployments'
| 'replicasets'
| 'horizontalpodautoscalers'
| 'jobs'
| 'cronjobs'
| 'ingresses'
| 'customresources';
@@ -27,14 +27,15 @@ Add or update `app-config.local.yaml` with the following:
```yaml
kubernetes:
serviceLocatorMethod: 'multiTenant'
serviceLocatorMethod:
type: 'multiTenant'
clusterLocatorMethods:
- 'config'
clusters:
- url: <KUBERNETES MASTER BASE URL FROM STEP 2>
name: minikube
serviceAccountToken: <TOKEN FROM STEP 4>
authProvider: 'serviceAccount'
- type: 'config'
clusters:
- url: <KUBERNETES MASTER BASE URL FROM STEP 2>
name: minikube
serviceAccountToken: <TOKEN FROM STEP 4>
authProvider: 'serviceAccount'
```
### Getting the service account token
@@ -200,6 +200,35 @@ spec:
maxReplicas: 15
targetCPUUtilizationPercentage: 50
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: dice-roller-cronjob
labels:
'backstage.io/kubernetes-id': dice-roller
spec:
schedule: '*/1 * * * *'
jobTemplate:
metadata:
labels:
'backstage.io/kubernetes-id': dice-roller
spec:
template:
metadata:
labels:
'backstage.io/kubernetes-id': dice-roller
spec:
containers:
- name: busybox
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Rolling a die!
restartPolicy: OnFailure
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
+2
View File
@@ -23,6 +23,8 @@ export interface Config {
| 'deployments'
| 'replicasets'
| 'horizontalpodautoscalers'
| 'jobs'
| 'cronjobs'
| 'ingresses'
>;
serviceLocatorMethod: {
@@ -16,6 +16,7 @@
import {
AppsV1Api,
BatchV1Api,
AutoscalingV1Api,
CoreV1Api,
KubeConfig,
@@ -74,6 +75,12 @@ export class KubernetesClientProvider {
return kc.makeApiClient(AutoscalingV1Api);
}
getBatchClientByClusterDetails(clusterDetails: ClusterDetails) {
const kc = this.getKubeConfig(clusterDetails);
return kc.makeApiClient(BatchV1Api);
}
getNetworkingBeta1Client(clusterDetails: ClusterDetails) {
const kc = this.getKubeConfig(clusterDetails);
@@ -68,6 +68,18 @@ export const DEFAULT_OBJECTS: ObjectToFetch[] = [
plural: 'horizontalpodautoscalers',
objectType: 'horizontalpodautoscalers',
},
{
group: 'batch',
apiVersion: 'v1',
plural: 'jobs',
objectType: 'jobs',
},
{
group: 'batch',
apiVersion: 'v1',
plural: 'cronjobs',
objectType: 'cronjobs',
},
{
group: 'networking.k8s.io',
apiVersion: 'v1',
@@ -17,6 +17,7 @@
import {
AppsV1Api,
AutoscalingV1Api,
BatchV1Api,
CoreV1Api,
NetworkingV1beta1Api,
} from '@kubernetes/client-node';
@@ -41,6 +42,7 @@ export interface Clients {
core: CoreV1Api;
apps: AppsV1Api;
autoscaling: AutoscalingV1Api;
batch: BatchV1Api;
networkingBeta1: NetworkingV1beta1Api;
}
@@ -67,6 +67,8 @@ export type KubernetesObjectTypes =
| 'deployments'
| 'replicasets'
| 'horizontalpodautoscalers'
| 'jobs'
| 'cronjobs'
| 'ingresses'
| 'customresources';
+24
View File
@@ -6,8 +6,10 @@
import { Entity } from '@backstage/catalog-model';
import { ExtensionsV1beta1Ingress } from '@kubernetes/client-node';
import { V1ConfigMap } from '@kubernetes/client-node';
import { V1CronJob } from '@kubernetes/client-node';
import { V1Deployment } from '@kubernetes/client-node';
import { V1HorizontalPodAutoscaler } from '@kubernetes/client-node';
import { V1Job } from '@kubernetes/client-node';
import { V1Pod } from '@kubernetes/client-node';
import { V1ReplicaSet } from '@kubernetes/client-node';
import { V1Service } from '@kubernetes/client-node';
@@ -48,6 +50,16 @@ export interface ConfigMapFetchResponse {
type: 'configmaps';
}
// Warning: (ae-missing-release-tag) "CronJobsFetchResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface CronJobsFetchResponse {
// (undocumented)
resources: Array<V1CronJob>;
// (undocumented)
type: 'cronjobs';
}
// Warning: (ae-missing-release-tag) "CustomResourceFetchResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
@@ -78,6 +90,8 @@ export type FetchResponse =
| DeploymentFetchResponse
| ReplicaSetsFetchResponse
| HorizontalPodAutoscalersFetchResponse
| JobsFetchResponse
| CronJobsFetchResponse
| IngressesFetchResponse
| CustomResourceFetchResponse;
@@ -101,6 +115,16 @@ export interface IngressesFetchResponse {
type: 'ingresses';
}
// Warning: (ae-missing-release-tag) "JobsFetchResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface JobsFetchResponse {
// (undocumented)
resources: Array<V1Job>;
// (undocumented)
type: 'jobs';
}
// Warning: (ae-missing-release-tag) "KubernetesErrorTypes" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
+14
View File
@@ -17,8 +17,10 @@
import {
ExtensionsV1beta1Ingress,
V1ConfigMap,
V1CronJob,
V1Deployment,
V1HorizontalPodAutoscaler,
V1Job,
V1Pod,
V1ReplicaSet,
V1Service,
@@ -83,6 +85,8 @@ export type FetchResponse =
| DeploymentFetchResponse
| ReplicaSetsFetchResponse
| HorizontalPodAutoscalersFetchResponse
| JobsFetchResponse
| CronJobsFetchResponse
| IngressesFetchResponse
| CustomResourceFetchResponse;
@@ -116,6 +120,16 @@ export interface HorizontalPodAutoscalersFetchResponse {
resources: Array<V1HorizontalPodAutoscaler>;
}
export interface JobsFetchResponse {
type: 'jobs';
resources: Array<V1Job>;
}
export interface CronJobsFetchResponse {
type: 'cronjobs';
resources: Array<V1CronJob>;
}
export interface IngressesFetchResponse {
type: 'ingresses';
resources: Array<ExtensionsV1beta1Ingress>;