1 | /*
|
2 | * Copyright © 2019 Atomist, Inc.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 |
|
17 | import {
|
18 | RepoContext,
|
19 | SdmGoalEvent,
|
20 | ServiceRegistration,
|
21 | } from "@atomist/sdm";
|
22 | import * as k8s from "@kubernetes/client-node";
|
23 | import { DeepPartial } from "ts-essentials";
|
24 |
|
25 | /**
|
26 | * Key of k8s services inside the service structure of goal data
|
27 | */
|
28 | export enum K8sServiceRegistrationType {
|
29 | K8sService = "@atomist/sdm/service/k8s",
|
30 | }
|
31 |
|
32 | /**
|
33 | * K8s specific service spec
|
34 | *
|
35 | * Allows to register additional containers that are being added to the goal job.
|
36 | * Open for future extension to support adding other k8s resource types.
|
37 | */
|
38 | export interface K8sServiceSpec {
|
39 | /** Additional containers to be added into the goal job. */
|
40 | container?: DeepPartial<k8s.V1Container> | Array<DeepPartial<k8s.V1Container>>;
|
41 | /** Additional init containers to be added into the goal job. */
|
42 | initContainer?: DeepPartial<k8s.V1Container> | Array<DeepPartial<k8s.V1Container>>;
|
43 |
|
44 | /** Additional volumes to be added into the goal job. */
|
45 | volume?: DeepPartial<k8s.V1Volume> | Array<DeepPartial<k8s.V1Volume>>;
|
46 | /**
|
47 | * Additional volumeMounts to be added into the goal job. Each
|
48 | * will be added to all containers and initContainers.
|
49 | */
|
50 | volumeMount?: DeepPartial<k8s.V1VolumeMount> | Array<DeepPartial<k8s.V1VolumeMount>>;
|
51 |
|
52 | /** Additional image pull secrets to be added into the goal job. */
|
53 | imagePullSecret?: DeepPartial<k8s.V1LocalObjectReference> | Array<DeepPartial<k8s.V1LocalObjectReference>>;
|
54 | }
|
55 |
|
56 | /**
|
57 | * K8s specific service registration
|
58 | */
|
59 | export interface K8sServiceRegistration extends ServiceRegistration<K8sServiceSpec> {
|
60 | service: (goalEvent: SdmGoalEvent, repo: RepoContext) => Promise<{
|
61 | type: K8sServiceRegistrationType.K8sService;
|
62 | spec: K8sServiceSpec;
|
63 | } | undefined>;
|
64 | }
|