How to use the @kubernetes/client-node.V1Container 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
let initGitSubmodules = project.repo.initGitSubmodules;

  if (!imageTag) {
    imageTag = "brigadecore/git-sidecar:latest";
  }

  // Try to get cloneURL from the event first. This allows gateways to override
	// the project-level cloneURL if the commit that should be built, for
	// instance, exists only within a fork. If this isn't set at the event-level,
	// fall back to the project-level default.
  let cloneURL = e.cloneURL;
  if (cloneURL == "") {
    cloneURL = project.repo.cloneURL
  }

  let spec = new kubernetes.V1Container();
  (spec.name = "vcs-sidecar"),
    (spec.env = [
      envVar("CI", "true"),
      envVar("BRIGADE_BUILD_ID", e.buildID),
      envVar("BRIGADE_COMMIT_ID", e.revision.commit),
      envVar("BRIGADE_COMMIT_REF", e.revision.ref),
      envVar("BRIGADE_EVENT_PROVIDER", e.provider),
      envVar("BRIGADE_EVENT_TYPE", e.type),
      envVar("BRIGADE_PROJECT_ID", project.id),
      envVar("BRIGADE_REMOTE_URL", cloneURL),
      envVar("BRIGADE_WORKSPACE", local),
      envVar("BRIGADE_PROJECT_NAMESPACE", project.kubernetes.namespace),
      envVar("BRIGADE_SUBMODULES", initGitSubmodules.toString()),
      envVar("BRIGADE_LOG_LEVEL", LogLevel[e.logLevel])
    ]);
  spec.image = imageTag;
github brigadecore / brigade / brigade-worker / src / k8s.ts View on Github external
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"];

  c1.imagePullPolicy = imageForcePull ? "Always" : "IfNotPresent";
  c1.securityContext = new kubernetes.V1SecurityContext();

  // Setup pod container resources (requests and limits).
  let resourceRequirements = new kubernetes.V1ResourceRequirements();
  if (resourceRequests) {
    resourceRequirements.requests = {
      cpu: resourceRequests.cpu,
github che-incubator / chectl / src / api / kube.ts View on Github external
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)
    } catch (e) {
      throw this.wrapK8sClientError(e)
    }
  }
github che-incubator / chectl / src / api / kube.ts View on Github external
serviceAccount: string,
                  restartPolicy: string,
                  pullPolicy: string,
                  configMapEnvSource: string,
                  namespace: string) {
    const k8sCoreApi = this.kc.makeApiClient(CoreV1Api)
    let pod = new V1Pod()
    pod.metadata = new V1ObjectMeta()
    pod.metadata.name = name
    pod.metadata.labels = { app: name }
    pod.metadata.namespace = namespace
    pod.spec = new V1PodSpec()
    pod.spec.containers
    pod.spec.restartPolicy = restartPolicy
    pod.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]
    pod.spec.containers = [opContainer]

    try {
      return await k8sCoreApi.createNamespacedPod(namespace, pod)
    } catch (e) {
      throw this.wrapK8sClientError(e)
    }
  }