UNPKG

@atomist/sdm

Version:

Atomist Software Delivery Machine SDK

203 lines • 9.36 kB
import * as k8s from "@kubernetes/client-node"; import { K8sObjectApi } from "./api"; /** Kubernetes resource type specifier. */ export interface KubernetesResourceKind { /** Kubernetes API version, e.g., "v1" or "apps/v1". */ apiVersion: string; /** Kubernetes resource, e.g., "Service" or "Deployment". */ kind: string; } /** * Various ways to select Kubernetes resources. All means provided * are logically ANDed together. */ export interface KubernetesResourceSelector { /** * Whether this selector is for inclusion or exclusion. * If not provided, the rule will be used for inclusion. */ action?: "include" | "exclude"; /** * If provided, only resources of a kind provided will be * considered a match. Only the "kind" is considered when * matching, since the same kind can appear under multiple * "apiVersion"s. See [[populateResourceSelectorDefaults]] for * rules on how it is populated if it is not set. */ kinds?: KubernetesResourceKind[]; /** * If provided, only resources with names matching either the * entire string or regular expression will be considered a match. * If not provided, the resource name is not considered when * matching. */ name?: string | RegExp; /** * If provided, only resources in namespaces matching either the * entire strings or regular expression will be considered a * match. If not provided, the resource namespace is not * considered when matching. */ namespace?: string | RegExp; /** * Kubernetes-style label selectors. If provided, only resources * matching the selectors are considered a match. If not * provided, the resource labels are not considered when matching. */ labelSelector?: k8s.V1LabelSelector; /** * If provided, resources will be considered a match if their * filter function returns `true`. If not provided, this property * has no effect on matching. */ filter?: (r: k8s.KubernetesObject) => boolean; } /** * Useful default set of kinds of Kubernetes resources. */ export declare const defaultKubernetesResourceSelectorKinds: KubernetesResourceKind[]; /** * Kubernetes fetch options specifying which resources to fetch. */ export interface KubernetesFetchOptions { /** * Array of Kubernetes resource selectors. The selectors are * applied in order to each resource and the action of the first * matching selector is applied. */ selectors?: KubernetesResourceSelector[]; } /** * The default options used when fetching resource from a Kubernetes * cluster. By default it fetches resources whose kind is in the * [[defaultKubernetesResourceSelectorKinds]] array, excluding the * resources that look like Kubernetes managed resources like the * `kubernetes` service in the `default` namespace, resources in * namespaces that starts with "kube-", and system- and cloud-related * cluster roles and cluster role bindings. */ export declare const defaultKubernetesFetchOptions: KubernetesFetchOptions; /** * Fetch resource specs from a Kubernetes cluster as directed by the * fetch options, removing read-only properties filled by the * Kubernetes system. * * The inclusion selectors are processed to determine which resources * in the Kubernetes cluster to query. * * @param options Kubernetes fetch options * @return Kubernetes resources matching the fetch options */ export declare function kubernetesFetch(options?: KubernetesFetchOptions): Promise<k8s.KubernetesObject[]>; /** * Make sure Kubernetes resource selectors have appropriate properties * populated with default values. If the selector does not have an * `action` set, it is set to "include". If the selector does not have * `kinds` set and `action` is "include", `kinds` is set to * [[defaultKubernetesResourceSelectorKinds]]. Rules with `action` set * to "exclude" and have no selectors are discarded. * * @param selectors Kubernetes resource selectors to ensure have default values * @return Properly defaulted Kubernetes resource selectors */ export declare function populateResourceSelectorDefaults(selectors: KubernetesResourceSelector[]): KubernetesResourceSelector[]; /** * Determine all Kuberenetes resources that we should query based on * all the selectors and return an array with each Kubernetes resource * type appearing no more than once. Note that uniqueness of a * Kubernetes resource type is determined solely by the `kind` * property, `apiVersion` is not considered since the same resource * can be found with the same kind and different API versions. * * @param selectors All the resource selectors * @return A deduplicated array of Kubernetes resource kinds among the inclusion rules */ export declare function includedResourceKinds(selectors: KubernetesResourceSelector[]): KubernetesResourceKind[]; /** * Determine all Kuberenetes cluster, i.e., not namespaced, resources * that we should query based on all the selectors and return an array * with each Kubernetes cluster resource type appearing no more than * once. Note that uniqueness of a Kubernetes resource type is * determined solely by the `kind` property, `apiVersion` is not * considered since the same resource can be found with the same kind * and different API versions. * * @param selectors All the resource selectors * @return A deduplicated array of Kubernetes cluster resource kinds among the inclusion rules */ export declare function clusterResourceKinds(selectors: KubernetesResourceSelector[], client: K8sObjectApi): Promise<KubernetesResourceKind[]>; /** * For the provided set of selectors, return a deduplicated array of * resource kinds that match the provided namespace. * * @param ns Namespace to check * @param selectors Selectors to evaluate * @return A deduplicated array of Kubernetes resource kinds among the inclusion rules for namespace `ns` */ export declare function namespaceResourceKinds(ns: string, selectors: KubernetesResourceSelector[], client: K8sObjectApi): Promise<KubernetesResourceKind[]>; /** * Remove read-only type properties not useful to retain in a resource * specification used for upserting resources. This is probably not * perfect. Add the `apiVersion` and `kind` properties since the they * are not included in the items returned by the list endpoint, * https://github.com/kubernetes/kubernetes/issues/3030 . * * @param obj Kubernetes spec to clean * @return Kubernetes spec with status-like properties removed */ export declare function cleanKubernetesSpec(obj: k8s.KubernetesObject, apiKind: KubernetesResourceKind): k8s.KubernetesObject; /** * Filter provided Kubernetes resources according to the provides * selectors. Each selector is applied in turn to each spec. The * action of the first selector that matches a resource is applied to * that resource. If no selector matches a resource, it is not * returned, i.e., the default is to exclude. * * @param specs Kubernetes resources to filter * @param selectors Filtering rules * @return Filtered array of Kubernetes resources */ export declare function selectKubernetesResources(specs: k8s.KubernetesObject[], selectors: KubernetesResourceSelector[]): k8s.KubernetesObject[]; /** * Reduce a Kubernetes resource to its uniquely identifying * properties. Note that `apiVersion` is not among them as identical * resources can be access via different API versions, e.g., * Deployment via app/v1 and extensions/v1beta1. * * @param obj Kubernetes resource * @return Stripped down resource for unique identification */ export declare function kubernetesResourceIdentity(obj: k8s.KubernetesObject): string; /** * Determine if Kubernetes resource is a match against the selector. * If there is a match, return the action of the selector. If there * is not a match, return `undefined`. * * @param spec Kubernetes resource to check * @param selector Selector to use for checking * @return Selector action if there is a match, `undefined` otherwise */ export declare function selectorMatch(spec: k8s.KubernetesObject, selector: KubernetesResourceSelector): "include" | "exclude" | undefined; /** * Determine if Kubernetes resource `kind` property is among the kinds * provided. If no kinds are provided, it is considered matching. * Only the resource's `kind` property is considered when matching, * `apiVersion` is ignored. * * @param spec Kubernetes resource to check * @param kinds Kubernetes resource selector `kinds` property to use for checking * @return Return `true` if it is a match, `false` otherwise */ export declare function kindMatch(spec: k8s.KubernetesObject, kinds: KubernetesResourceKind[]): boolean; /** * Determine if Kubernetes resource `kind` property is among the kinds * provided. If no kinds are provided, it is considered matching. * Only the resource's `kind` property is considered when matching, * `apiVersion` is ignored. * * @param spec Kubernetes resource to check * @param kinds Kubernetes resource selector `kinds` property to use for checking * @return Return `true` if it is a match, `false` otherwise */ export declare function filterMatch(spec: k8s.KubernetesObject, filter: (r: k8s.KubernetesObject) => boolean): boolean; //# sourceMappingURL=fetch.d.ts.map