{"id":17281384,"url":"https://github.com/mr-karan/nomctx","last_synced_at":"2025-03-17T11:30:38.984Z","repository":{"id":64304276,"uuid":"479366850","full_name":"mr-karan/nomctx","owner":"mr-karan","description":"Faster way to switch between clusters and namespaces in nomad ","archived":false,"fork":false,"pushed_at":"2024-10-10T07:33:34.000Z","size":405,"stargazers_count":54,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-10T16:02:15.613Z","etag":null,"topics":["nomad"],"latest_commit_sha":null,"homepage":"","language":"Go","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/mr-karan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-08T11:40:17.000Z","updated_at":"2025-03-04T05:54:50.000Z","dependencies_parsed_at":"2024-05-07T05:31:54.067Z","dependency_job_id":"10a11f7a-2e5c-4697-a27a-b4c4e7f5ed57","html_url":"https://github.com/mr-karan/nomctx","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-karan%2Fnomctx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-karan%2Fnomctx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-karan%2Fnomctx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-karan%2Fnomctx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mr-karan","download_url":"https://codeload.github.com/mr-karan/nomctx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858056,"owners_count":20359271,"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":["nomad"],"created_at":"2024-10-15T09:45:44.589Z","updated_at":"2025-03-17T11:30:38.357Z","avatar_url":"https://github.com/mr-karan.png","language":"Go","funding_links":[],"categories":["DevOps tools"],"sub_categories":["User Interfaces and Dashboards"],"readme":"\u003ca href=\"https://zerodha.tech\"\u003e\u003cimg src=\"https://zerodha.tech/static/images/github-badge.svg\" align=\"right\" /\u003e\u003c/a\u003e\n\n# nomctx\n\nFaster way to switch between [Nomad](https://www.nomadproject.io/) clusters and namespaces. Inspired from [kubectx](https://github.com/ahmetb/kubectx/).\n\n![nomctx demo GIF](assets/demo.gif)\n\n## Why was this created\n\nIf you're operating multiple Nomad clusters, switching between these clusters is a cumbersome task of exporting variables in shell. Ideally `nomad`, should use a file similar to `~/.kube/config` for authenticating against multiple clusters as described in this [issue](https://github.com/hashicorp/nomad/issues/11043). Since this feature isn't available as of yet, I've created `nomctx` which can emit the [environment-variables](https://www.nomadproject.io/docs/commands#environment-variables) required by `nomad` CLI for authentication.\n\n## Installation\n\n- Binaries: [Releases](https://github.com/mr-karan/nomctx/releases).\n- Go: `go install github.com/mr-karan/nomctx@latest`\n\nTo run:\n\n```bash\n$ nomctx\n```\n\nBy default `nomctx` searches for the file in `~/.nomctx/config.hcl` but you can override that with `--config=\u003c/path/to/config.hcl\u003e` flag.\n\n\n## Usage\n\n```bash\nNAME:\n   nomctx - Faster way to switch across multiple Nomad clusters and namespaces\n\nUSAGE:\n   nomctx [global options] command [command options] \n\nVERSION:\n   v0.2.3 (Commit: 2023-12-05 13:09:16 +0530 (ff9fe08), Build: 2024-01-30 21:06:48 +0530)\n\nCOMMANDS:\n   list-clusters     List all clusters\n   list-namespaces   List all namespaces\n   set-cluster       Set the current cluster context\n   set-namespace     Set namespace\n   switch-cluster    Switch cluster\n   switch-namespace  Switch namespace\n   current-context   Display the current context\n   login             Login to a cluster\n   add-cluster       Add a new cluster to the config\n   help, h           Shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --config value  Path to a config file to load. (default: \"/Users/karan/.nomctx/config.hcl\")\n   --help, -h      show help\n   --version, -v   print the version\n```\n\n### Interactive Mode\n\nIf you have [`fzf`](https://github.com/junegunn/fzf) installed, the tool will show an interactive prompt for switching `clusters` or `namespace`.\n\n![nomctx cluster img](assets/nomctx_clusters.png)\n\n![nomctx namespace img](assets/nomctx_namespaces.png)\n\n\n### Login with SSO\n\nIf you've configured authentication with SSO, you can use `login` command to login to a cluster. This will open a browser window where you can authenticate with your SSO provider.\n\nBy default, `nomctx` will login to the active cluster set in the config file. If you want to login to a specific cluster, use `--cluster=\u003ccluster-name\u003e` flag.\n\n```bash\n# Login to the active cluster\nnomctx login\n# or specify a cluster\nnomctx login --cluster=dev\n\n# Persist the session token to a file in `~/.nomctx/\u003ccluster\u003e.env`\nnomctx login --cluster=dev --persist\n```\n\nSee [Persist variables](#persist-variables) section for more details on how to persist the Nomad session tokens to a file.\n\n### Non Interactive Mode\n\nIf you don't have `fzf`, you can use switch manually with `set-cluster=\u003c\u003e` and `set-namespace=\u003c\u003e` commands.\n\n#### List all clusters\n\n```bash\nnomctx list-clusters\nlocal\nbangalore\ntokyo\nparis\nsingapore\n```\n\n#### List all namespaces\n\n```bash\nnomctx list-namespaces\nhomelab\nuat\nqa\ndefault\n```\n\n#### Set a cluster\n\n```bash\nnomctx set-cluster bangalore\nexport NOMAD_ADDR=http://10.0.0.1:4646\nexport NOMAD_TOKEN=f8cb5774-749a-4548-acc9-054df3b52e83\nexport NOMAD_HTTP_AUTH=user:pass\nexport NOMAD_NAMESPACE=pink\n```\n\n#### Set a namespace\n\n```bash\nnomctx set-namespace=uat    \nexport NOMAD_NAMESPACE=uat\n```\n\n#### View current context\n\n```bash\n$ nomctx current-context\nCluster: local\nNamespace: default\n```\n\n### Add a Cluster\n\n```bash\nnomctx add-cluster --cluster=\u003cname\u003e [--addr=\u003caddress\u003e] [--token=\u003ctoken\u003e] [--namespace=\u003cnamespace\u003e] [--region=\u003cregion\u003e] [--auth-method=\u003cmethod\u003e]\n```\n\nThe `add-cluster` command allows you to add a new cluster configuration to your `nomctx` setup. This command is useful for managing multiple Nomad clusters, enabling you to switch between them easily.\n\n#### Parameters\n- `--cluster`: (Required) Name of the new cluster.\n- `--addr`: (Required) Address of the cluster (e.g., `http://127.0.0.1:4646`).\n- `--token`: (Optional) Access token for the cluster.\n- `--namespace`: (Optional) Default namespace for the cluster.\n- `--region`: (Optional) Region of the cluster.\n- `--auth-method`: (Optional) Authentication method for the cluster (e.g., `\"github\"`).\n\n#### Examples\nAdd a new cluster named `my-cluster`:\n```bash\nnomctx add-cluster --cluster=\"my-cluster\" --addr=\"http://10.0.0.5:4646\"\n```\n\nAdd a new cluster with complete details:\n```bash\nnomctx add-cluster --cluster=\"my-cluster\" --addr=\"http://10.0.0.5:4646\" --token=\"abcd1234\" --namespace=\"default\" --region=\"us-west\" --auth-method=\"github\"\n```\n\n#### Notes\n- The new cluster configuration is appended to the existing `~/.nomctx/config.hcl` file.\n- Ensure the cluster name is unique to avoid conflicts in the configuration.\n\n### Persist variables\n\nWith `--persist` flag, you can persist the environment variables to a file. This is useful if you want to use the variables in a script.\nThe variables are written to `~/.nomctx/\u003ccluster\u003e.env` file.\n\n```bash\nnomctx set-cluster --persist dev\n\n# You can see the env variables are written to the file.\ncat ~/.nomctx/dev.env\nNOMAD_ADDR=http://127.0.0.1:4646\nNOMAD_NAMESPACE=default\n```\n\n### Set variables on shell\n\nYou can use `eval` to directly set the environment variables on shell. This works with both the interactive and non-interactive modes.\n\nFor eg, to switch a cluster in interactive mode **and** set the env vars on shell:\n\n```bash\neval $(nomctx)\n\n# You can see the env variables are automatically exported on shell.\nenv | grep NOMAD_\nNOMAD_ADDR=http://10.0.0.1:4646\nNOMAD_TOKEN=c0a7d714-46df-4c6e-954a-269578c3804d\nNOMAD_NAMESPACE=pink\nNOMAD_HTTP_AUTH=user:pass\nNOMAD_REGION=paris\n```\n\n## Configuration\n\nHere's a sample config file which shows 2 clusters: `dev` and `prod`:\n\n```hcl\ncluster \"dev\" {\n  address   = \"http://127.0.0.1:4646\"\n  namespace = \"default\"\n}\n\ncluster \"uat\" {\n  address = \"https://nomad.hashicorp.rocks\"\n  auth {\n    method   = \"gitlab\"\n    provider = \"nomad\"\n  }\n}\n\ncluster \"prod\" {\n  address   = \"http://10.0.0.3:4646\"\n  namespace = \"blue\"\n  region    = \"blr\"\n  token     = \"f8cb5774-749a-4548-acc9-054df3b52e83\"\n}\n```\n\n## LICENSE\n\nSee [LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-karan%2Fnomctx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmr-karan%2Fnomctx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-karan%2Fnomctx/lists"}