Skip to content

Commit

Permalink
feat: list k8s daemon and stateful sets (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 7, 2019
1 parent 80a5b0e commit 5e012d6
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/controller/kubernetes/AppsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { KubernetesBaseController, KubernetesBaseControllerData } from 'src/cont
import { Command, CommandVerb } from 'src/entity/Command';
import { mustExist } from 'src/utils';

export const NOUN_DAEMONSET = 'kubernetes-daemonset';
export const NOUN_DEPLOYMENT = 'kubernetes-deployment';
export const NOUN_STATEFULSET = 'kubernetes-statefulset';

export interface AppsControllerData extends KubernetesBaseControllerData {
default: {
Expand All @@ -22,7 +24,11 @@ export class KubernetesAppsController extends KubernetesBaseController<AppsContr
protected client?: k8s.Apps_v1Api;

constructor(options: AppsControllerOptions) {
super(options, 'isolex#/definitions/service-controller-kubernetes-apps', [NOUN_DEPLOYMENT]);
super(options, 'isolex#/definitions/service-controller-kubernetes-apps', [
NOUN_DAEMONSET,
NOUN_DEPLOYMENT,
NOUN_STATEFULSET,
]);
}

public async start() {
Expand All @@ -32,15 +38,36 @@ export class KubernetesAppsController extends KubernetesBaseController<AppsContr
this.client = config.makeApiClient(k8s.Apps_v1Api);
}

@Handler(NOUN_DAEMONSET, CommandVerb.List)
@CheckRBAC()
public async listDaemons(cmd: Command): Promise<void> {
const client = mustExist(this.client);
const ns = cmd.getHeadOrDefault('ns', this.data.default.namespace);
this.logger.debug({ cmd, ns }, 'listing k8s daemon sets');

const response = await client.listNamespacedDaemonSet(ns);
return this.transformJSON(cmd, response.body.items);
}

@Handler(NOUN_DEPLOYMENT, CommandVerb.List)
@CheckRBAC()
public async listDeployments(cmd: Command): Promise<void> {
public async listDeploys(cmd: Command): Promise<void> {
const client = mustExist(this.client);
const ns = cmd.getHeadOrDefault('ns', this.data.default.namespace);
this.logger.debug({ cmd, ns }, 'listing k8s deployments');

const response = await client.listNamespacedDeployment(ns);
this.logger.debug({ deployments: response.body }, 'found deployments');
return this.transformJSON(cmd, response.body.items);
}

@Handler(NOUN_STATEFULSET, CommandVerb.List)
@CheckRBAC()
public async listStatefuls(cmd: Command): Promise<void> {
const client = mustExist(this.client);
const ns = cmd.getHeadOrDefault('ns', this.data.default.namespace);
this.logger.debug({ cmd, ns }, 'listing k8s stateful sets');

const response = await client.listNamespacedStatefulSet(ns);
return this.transformJSON(cmd, response.body.items);
}
}

0 comments on commit 5e012d6

Please sign in to comment.