npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@endeavorb2b/rancher2api

v1.0.5

Published

Rancher2 API library

Downloads

323

Readme

Rancher2 API Library

This project provides access to a subset of the Rancher 2.x API in a highly opinionated fashion, intended primarily to address deployment concerns to Rancher2 and K8S within the @endeavorb2b stack.

Usage

This library can be included in your project to allow native access to the Rancher2 API methods via node-fetch. Fetch allows both backend and browser access to the API, but does not obscure credentials -- beware of this if building a browser application using this library.

All methods require at minimum a Rancher 2.x v3 API URL (such as https://cows.my-doma.in/api/v3) and a Rancher 2.x API key. While scoped keys are supported, this library assumes a hard dependancy of knowing the cluster ID at runtime. The Bearer Token format should be passed to the library methods (username:secretKey.)

Methods


Cluster

Supported: List.

cluster.list

Parameters: (uri, token)

Returns an array of cluster objects ({ id, name }).

Project

Supported: List and Create.

project.list

Parameters: ({ uri, token, clusterId })

Returns an array of project objects ({ id, name }).

project.create

Parameters: ({ uri, token, clusterId, name })

Creates and returns a project object ({ id, name }).

Service

Supported: List and Create.

service.list

Parameters: ({ uri, token, projectId })

Returns an array of service objects ({ id, name }).

service.create

Parameters: ({ uri, token, projectId, namespaceId, name, targetWorkloadIds })

Creates and returns a service object ({ id, name }).

Namespace

Supported: List and Create.

namespace.list

Parameters: ({ uri, token, clusterId }) Returns an array of namespace objects ({ id, name }).

namespace.create

Parameters: ({ uri, token, clusterId, projectId, name })

Creates and returns a namespace object ({ id, name }) within a project.

Workload

Supported: List, Create, and Update.

workload.list

Parameters: ({ uri, token, projectId })

Returns an array of workload objects ({ id, deploymentId, name }).

workload.create

Parameters: ({ uri, token, projectId, namespaceId, name, deploymentConfig, containers })

Creates and returns a workload object ({ id, deploymentId, name, ... }) within a project+namespace.

labels, if not specified, will default to the following:

{
  'workload.user.cattle.io/workloadselector': `deployment-${namespaceId}-${name}`
}

deploymentConfig, if not specified, will default to the following:

{
  maxSurge: 1,
  maxUnavailable: 0,
  minReadySeconds: 0,
  progressDeadlineSeconds: 600,
  revisionHistoryLimit: 10,
  strategy: 'RollingUpdate',
}

containers, if not specified or without a valid container definition, will default to the following:

[{
  env: [],
  image: 'busybox:latest',
  imagePullPolicy: 'IfNotPresent',
  name,
  entrypoint: ['top'],
  securityContext: {
    allowPrivilegeEscalation: false,
    capabilities: {},
    privileged: false,
    procMount: 'Default',
    readOnlyRootFilesystem: false,
    runAsNonRoot: false,
  },
  stdin: true,
  terminationMessagePath: '/dev/termination-log',
  terminationMessagePolicy: 'File',
  tty: true,
}]

cronJobConfig, if specified, should provide the following:

{
  concurrencyPolicy: 'Allow',
  failedJobsHistoryLimit: 10,
  schedule: '* * * * *', // A valid cron schedule
  successfulJobsHistoryLimit: 10,
  suspend: false,
}

workload.update

Parameters: ({ uri, token, projectId, workloadId, deploymentConfig, containers })

Updates and returns a workload object ({ id, deploymentId, name, ... }) within a project+namespace.

labels, if specified, MUST include the following:

{
  'workload.user.cattle.io/workloadselector': `deployment-${namespaceId}-${name}`
}

deploymentConfig, if not specified, will default to the following:

{
  maxSurge: 1,
  maxUnavailable: 0,
  minReadySeconds: 0,
  progressDeadlineSeconds: 600,
  revisionHistoryLimit: 10,
  strategy: 'RollingUpdate',
}

Ingress

Supported: List, Create, and Update.

ingress.list

Parameters: ({ uri, token, projectId })

Returns an array of ingress objects ({ id, name }).

ingress.create

Parameters: ({ uri, token, projectId, namespaceId, name, rules })

Creates and returns a ingress object ({ id, name, ... }) within a project+namespace.

rules must be an array of rule objects specifying the port and workloadIds. The URI path is optional:

{
  path: '/test2/test2',
  targetPort: 80,
  workloadIds: [ 'deployment:<namespaceId>:<workloadName>'],
}

ingress.update

Parameters: ({ uri, token, projectId, ingressId, rules })

Updates and returns a ingress object ({ id, name, ... }) within a project+namespace.

rules must be an array of rule objects specifying the port and workloadIds. The URI path is optional:

{
  path: '/test2/test2',
  targetPort: 80,
  workloadIds: [ 'deployment:<namespaceId>:<workloadName>'],
}

Contributing

Contributions are always welcome -- if you would like access to another module or would like to include support for some other feature of the Rancher2 API, please submit a pull request.

To get started, pull this repository and execute yarn && yarn start from the project root.

Resources