How to use the @kubernetes/client-node.V1ObjectMeta function in @kubernetes/client-node

To help you get started, we’ve selected a few @kubernetes/client-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brigadecore / brigade / brigade-worker / src / k8s.ts View on Github external
function newRunnerPod(
  podname: string,
  brigadeImage: string,
  imageForcePull: boolean,
  serviceAccount: string,
  resourceRequests: jobs.JobResourceRequest,
  resourceLimits: jobs.JobResourceLimit,
  jobAnnotations: { [key: string]: string },
  jobShell: string
): kubernetes.V1Pod {
  let pod = new kubernetes.V1Pod();
  pod.metadata = new kubernetes.V1ObjectMeta();
  pod.metadata.name = podname;
  pod.metadata.labels = {
    heritage: "brigade",
    component: "job"
  };
  pod.metadata.annotations = jobAnnotations;

  let c1 = new kubernetes.V1Container();
  c1.name = "brigaderun";
  c1.image = brigadeImage;

  if (jobShell == "") {
    jobShell = "/bin/sh";
  }
  c1.command = [jobShell, "/hook/main.sh"];
github che-incubator / chectl / src / api / kube.ts View on Github external
async createAdminRoleBinding(name = '', serviceAccount = '', namespace = '') {
    const k8sRbacAuthApi = this.kc.makeApiClient(RbacAuthorizationV1Api)
    let rb = new V1RoleBinding()
    rb.metadata = new V1ObjectMeta()
    rb.metadata.name = name
    rb.metadata.namespace = namespace
    rb.roleRef = new V1RoleRef()
    rb.roleRef.kind = 'ClusterRole'
    rb.roleRef.name = 'admin'
    let subject = new V1Subject()
    subject.kind = 'ServiceAccount'
    subject.name = serviceAccount
    subject.namespace = namespace
    rb.subjects = [subject]
    try {
      return await k8sRbacAuthApi.createNamespacedRoleBinding(namespace, rb)
    } catch (e) {
      throw this.wrapK8sClientError(e)
    }
  }
github brigadecore / brigade / brigade-worker / src / k8s.ts View on Github external
protected buildPVC(size: string): kubernetes.V1PersistentVolumeClaim {
    let s = new kubernetes.V1PersistentVolumeClaim();
    s.metadata = new kubernetes.V1ObjectMeta();
    s.metadata.name = this.name;
    s.metadata.labels = {
      heritage: "brigade",
      component: "buildStorage",
      project: this.proj.id,
      worker: this.name,
      build: this.build
    };

    s.spec = new kubernetes.V1PersistentVolumeClaimSpec();
    s.spec.accessModes = ["ReadWriteMany"];

    let res = new kubernetes.V1ResourceRequirements();
    res.requests = { storage: size };
    s.spec.resources = res;
    if (this.proj.kubernetes.buildStorageClass.length > 0) {
github brigadecore / brigade / brigade-worker / src / k8s.ts View on Github external
function newSecret(name: string): kubernetes.V1Secret {
  let s = new kubernetes.V1Secret();
  s.type = "brigade.sh/job";
  s.metadata = new kubernetes.V1ObjectMeta();
  s.metadata.name = name;
  s.metadata.labels = {
    heritage: "brigade",
    component: "job"
  };
  s.data = {}; //{"main.sh": b64enc("echo hello && echo goodbye")}

  return s;
}
github che-incubator / chectl / src / api / kube.ts View on Github external
async createServiceAccount(name = '', namespace = '') {
    const k8sCoreApi = this.kc.makeApiClient(CoreV1Api)
    let sa = new V1ServiceAccount()
    sa.metadata = new V1ObjectMeta()
    sa.metadata.name = name
    sa.metadata.namespace = namespace
    try {
      return await k8sCoreApi.createNamespacedServiceAccount(namespace, sa)
    } catch (e) {
      throw this.wrapK8sClientError(e)
    }
  }
github che-incubator / chectl / src / api / kube.ts View on Github external
async createDeployment(name: string,
                         image: string,
                         serviceAccount: string,
                         pullPolicy: string,
                         configMapEnvSource: string,
                         namespace: string) {
    const k8sAppsApi = this.kc.makeApiClient(AppsV1Api)
    let deployment = new V1Deployment()
    deployment.metadata = new V1ObjectMeta()
    deployment.metadata.name = name
    deployment.metadata.namespace = namespace
    deployment.spec = new V1DeploymentSpec()
    deployment.spec.selector = new V1LabelSelector()
    deployment.spec.selector.matchLabels = { app: name }
    deployment.spec.template = new V1PodTemplateSpec()
    deployment.spec.template.metadata = new V1ObjectMeta()
    deployment.spec.template.metadata.name = name
    deployment.spec.template.metadata.labels = { app: name }
    deployment.spec.template.spec = new V1PodSpec()
    deployment.spec.template.spec.serviceAccountName = serviceAccount
    let opContainer = new V1Container()
    opContainer.name = name
    opContainer.image = image
    opContainer.imagePullPolicy = pullPolicy
    let envFromSource = new V1EnvFromSource()
    envFromSource.configMapRef = new V1ConfigMapEnvSource()
    envFromSource.configMapRef.name = configMapEnvSource
    opContainer.envFrom = [envFromSource]
    deployment.spec.template.spec.containers = [opContainer]

    try {
      return await k8sAppsApi.createNamespacedDeployment(namespace, deployment)
github che-incubator / chectl / src / commands / devfile / generate.ts View on Github external
k8sDeployList.items.forEach(async item => {
      let deployment = new V1Deployment()
      deployment.apiVersion = 'apps/v1'
      deployment.kind = 'Deployment'
      deployment.metadata = new V1ObjectMeta()
      deployment.metadata.labels = { ...item.metadata!.labels }
      deployment.metadata.name = item.metadata!.name
      deployment.spec = new V1DeploymentSpec()
      deployment.spec.selector = item.spec!.selector
      deployment.spec.template = new V1PodTemplateSpec()
      deployment.spec.template.metadata = new V1ObjectMeta()
      deployment.spec.template.metadata.labels = { ...item.spec!.template.metadata!.labels }
      deployment.spec.template.metadata.name = item.spec!.template.metadata!.name
      deployment.spec.template.spec = item.spec!.template.spec
      await items.push(deployment)
    })
github smartive / kuby / src / commands / preview-deploy / index.ts View on Github external
async function createNamespace(api: KubernetesApi, name: string): Promise {
  try {
    logger.info(`Create preview namespace "${name}".`);
    await api.core.readNamespace(name);
    logger.info(`Namespace "${name}" already exists.`);
  } catch (e) {
    if (e.response.statusCode !== 404) {
      throw e;
    }

    await api.core.createNamespace({
      ...new V1Namespace(),
      apiVersion: 'v1',
      kind: 'Namespace',
      metadata: {
        ...new V1ObjectMeta(),
        name,
      },
    });
    logger.success(`Created namespace "${name}".`);
  }
}