{"id":21582371,"url":"https://github.com/base-cms/rancher2api","last_synced_at":"2025-03-18T08:22:27.442Z","repository":{"id":40749289,"uuid":"177661452","full_name":"base-cms/rancher2api","owner":"base-cms","description":"Rancher 2 API Library","archived":false,"fork":false,"pushed_at":"2022-12-03T03:37:19.000Z","size":673,"stargazers_count":0,"open_issues_count":14,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-24T14:47:50.279Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@endeavorb2b/rancher2api","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/base-cms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-25T20:43:52.000Z","updated_at":"2020-10-06T14:32:43.000Z","dependencies_parsed_at":"2023-01-22T21:00:14.019Z","dependency_job_id":null,"html_url":"https://github.com/base-cms/rancher2api","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-cms%2Francher2api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-cms%2Francher2api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-cms%2Francher2api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-cms%2Francher2api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/base-cms","download_url":"https://codeload.github.com/base-cms/rancher2api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244181478,"owners_count":20411646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T14:15:39.169Z","updated_at":"2025-03-18T08:22:27.417Z","avatar_url":"https://github.com/base-cms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rancher2 API Library\nThis 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.\n\n## Usage\n\nThis 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.\n\nAll 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`.)\n\n## Methods\n- [Cluster.list()](#cluster.list)\n- [Ingress.create()](#ingress.create)\n- [Ingress.list()](#ingress.list)\n- [Ingress.update()](#ingress.update)\n- [Namespace.create()](#namespace.create)\n- [Namespace.list()](#namespace.list)\n- [Project.create()](#project.create)\n- [Project.list()](#project.list)\n- [Service.create()](#service.create)\n- [Service.list()](#service.list)\n- [Workload.create()](#workload.create)\n- [Workload.list()](#workload.list)\n- [Workload.update()](#workload.update)\n\n----\n\n## Cluster\nSupported: `List`.\n\n#### cluster.list\nParameters: `(uri, token)`\n\nReturns an array of cluster objects ({ id, name }).\n\n## Project\nSupported: `List` and `Create`.\n\n#### project.list\nParameters: `({ uri, token, clusterId })`\n\nReturns an array of project objects ({ id, name }).\n\n#### project.create\nParameters: `({ uri, token, clusterId, name })`\n\nCreates and returns a project object ({ id, name }).\n\n## Service\nSupported: `List` and `Create`.\n\n#### service.list\nParameters: `({ uri, token, projectId })`\n\nReturns an array of service objects ({ id, name }).\n\n#### service.create\nParameters: `({ uri, token, projectId, namespaceId, name, targetWorkloadIds })`\n\nCreates and returns a service object ({ id, name }).\n\n## Namespace\nSupported: `List` and `Create`.\n\n#### namespace.list\nParameters: `({ uri, token, clusterId })`\nReturns an array of namespace objects ({ id, name }).\n\n#### namespace.create\nParameters: `({ uri, token, clusterId, projectId, name })`\n\nCreates and returns a namespace object ({ id, name }) within a project.\n\n## Workload\nSupported: `List`, `Create`, and `Update`.\n\n#### workload.list\nParameters: `({ uri, token, projectId })`\n\nReturns an array of workload objects ({ id, deploymentId, name }).\n\n#### workload.create\nParameters: `({ uri, token, projectId, namespaceId, name, deploymentConfig, containers })`\n\nCreates and returns a workload object ({ id, deploymentId, name, ... }) within a project+namespace.\n\n`labels`, if not specified, will default to the following:\n```js\n{\n  'workload.user.cattle.io/workloadselector': `deployment-${namespaceId}-${name}`\n}\n```\n\n`deploymentConfig`, if not specified, will default to the following:\n```js\n{\n  maxSurge: 1,\n  maxUnavailable: 0,\n  minReadySeconds: 0,\n  progressDeadlineSeconds: 600,\n  revisionHistoryLimit: 10,\n  strategy: 'RollingUpdate',\n}\n```\n\n`containers`, if not specified or without a valid container definition, will default to the following:\n```js\n[{\n  env: [],\n  image: 'busybox:latest',\n  imagePullPolicy: 'IfNotPresent',\n  name,\n  entrypoint: ['top'],\n  securityContext: {\n    allowPrivilegeEscalation: false,\n    capabilities: {},\n    privileged: false,\n    procMount: 'Default',\n    readOnlyRootFilesystem: false,\n    runAsNonRoot: false,\n  },\n  stdin: true,\n  terminationMessagePath: '/dev/termination-log',\n  terminationMessagePolicy: 'File',\n  tty: true,\n}]\n```\n\n`cronJobConfig`, if specified, should provide the following:\n```js\n{\n  concurrencyPolicy: 'Allow',\n  failedJobsHistoryLimit: 10,\n  schedule: '* * * * *', // A valid cron schedule\n  successfulJobsHistoryLimit: 10,\n  suspend: false,\n}\n```\n\n#### workload.update\nParameters: `({ uri, token, projectId, workloadId, deploymentConfig, containers })`\n\nUpdates and returns a workload object ({ id, deploymentId, name, ... }) within a project+namespace.\n\n`labels`, if specified, MUST include the following:\n```js\n{\n  'workload.user.cattle.io/workloadselector': `deployment-${namespaceId}-${name}`\n}\n```\n\n`deploymentConfig`, if not specified, will default to the following:\n```js\n{\n  maxSurge: 1,\n  maxUnavailable: 0,\n  minReadySeconds: 0,\n  progressDeadlineSeconds: 600,\n  revisionHistoryLimit: 10,\n  strategy: 'RollingUpdate',\n}\n```\n\n## Ingress\nSupported: `List`, `Create`, and `Update`.\n\n#### ingress.list\nParameters: `({ uri, token, projectId })`\n\nReturns an array of ingress objects ({ id, name }).\n\n#### ingress.create\nParameters: `({ uri, token, projectId, namespaceId, name, rules })`\n\nCreates and returns a ingress object ({ id, name, ... }) within a project+namespace.\n\n`rules` must be an array of rule objects specifying the port and workloadIds. The URI `path` is optional:\n```js\n{\n  path: '/test2/test2',\n  targetPort: 80,\n  workloadIds: [ 'deployment:\u003cnamespaceId\u003e:\u003cworkloadName\u003e'],\n}\n```\n\n#### ingress.update\nParameters: `({ uri, token, projectId, ingressId, rules })`\n\nUpdates and returns a ingress object ({ id, name, ... }) within a project+namespace.\n\n`rules` must be an array of rule objects specifying the port and workloadIds. The URI `path` is optional:\n```js\n{\n  path: '/test2/test2',\n  targetPort: 80,\n  workloadIds: [ 'deployment:\u003cnamespaceId\u003e:\u003cworkloadName\u003e'],\n}\n```\n\n----\n\n## Contributing\n\nContributions 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.\n\nTo get started, pull this repository and execute `yarn \u0026\u0026 yarn start` from the project root.\n\n## Resources\n\n- [Rancher 2.x API Documentation](https://rancher.com/docs/rancher/v2.x/en/api/)\n- [@endeavorb2b/rancher2cli](https://github.com/endeavorb2b/rancher2cli)\u003cbr\u003eA CLI implementation of this library, suitable for use via TravisCI or other CI/CD environs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbase-cms%2Francher2api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbase-cms%2Francher2api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbase-cms%2Francher2api/lists"}