Skip to content

external-secrets-inc/tenant-manager

Repository files navigation

Contributing

Please do commits following conventional commits approach. There is a github action that will prevent your commit if you dont do it! Run make setup in order to install pre-commit checks to prevent that from happening

tenant-manager

Responsible to manage tenant information, including:

  • Tenant Account creation/deletion
  • Agents Creation/deletion
  • Agent Life checks
  • Billing Consolidation

Is tenant manager a full fledged backend for the web ui (aka our portal)?

  • Maybe. I'm not yet sure that we are going to go more granular on services with an api gateway or not.

This picture below summarizes the bits that could change still

pic

Setup

These are needed to run/set up the application. You should only proceeed to the next steps after having these installed.

Add Go binaries to your PATH. If you don't have a GOPATH variable, create it.

export GOPATH=$HOME/go
export PATH=$PATH:$(go env GOPATH)/bin

Dependencies

Install Swag with Go:

go install github.com/swaggo/swag/cmd/swag@latest

Install the dependencies:

make install

Running the application

Create the dev cluster:

make dev

Forward the port to access the api from your machine:

kubectl port-forward -n tenant-manager svc/tenant-manager 8080:8080&
curl localhost:8080/api/agents

on debugging session:

kubectl port-forward -n tenant-manager svc/postgres 5432:5432&
# Start debugging session on vscode or dlv

Some information is already seeded to speed up development. If you need a valid user locally, you can simply use the following credentials:

{"email": "dev@test.com", "tenant": "Acme Corp", "password": "password"}

Note

By Default, tenant-manager will not connect to GCP on local development (make dev command). In this environment, manifests generated for agents need to be applied within your local cluster to see the agent working.

If you need to do something related to GCP, first login to GCP and expose the database port:

gcloud auth application-default login
kubectl port-forward svc/postgres 5432:5432&

Then, call the client with the appropriate parameters:

go run main.go --gcpProjectId="external-secrets-inc-dev"

Project structure

├── api
│   ├── binders         #Code for custom binders. No binders defined atm
│   ├── handlers        #API Handlers
│   │   ├── agent       #Agent Handler
│   │   ├── auth        #Auth (login, signup) Handler
│   │   ├── common      #Common request/response and methods
│   │   ├── tenant      #Tenant Handler (internal only)
│   │   └── user        #User Handler
│   └── middleware      #Custom Middleware goes here.
├── cmd                 #Where the server main routine is.
├── dev                 #Folder with manifests called with `make dev`
├── docs                #OpenAPi Generated docs
├── domain              #Models are defined here
├── event               #Asynchronous Jobs
│   ├── agent           #Agent Jobs
│   ├── pubsub          #Base Definition of Event Scheme (Golang channels)
│   └── tenant          #Tenant Jobs
├── images              #For this page basically
├── service             #API Services
│   ├── agent           #Agent service
│   ├── auth            #Auth Service
│   ├── tenant          #Tenant Service
│   └── user            #User Service
└── store               #DB store (not for multiple engines, but for tenancy mostly)

Using Tilt

Tenant manager development supports using tilt. To use tilt, simply download it, create a kind cluster and run tilt up. Press <space> and watch the whole thing start up.

To modify the admin username and admin password, create a tilt-settings.yaml file that contains the following values:

admin:
    username: username
    password: password

And that's it. Tilt will automatically port-forward the tenant. And since tilt is using a process manager inside the pod to update the running binary, the port-forward will always point to the right thing.

Adding another file into the Dockerfile

To add additional files into the container like local_manifest.yaml just define a tilt-settings.yaml and add a statement like this:

extra_files:
  ./local_manifest.yaml: /local_manifest.yaml

Multiple files can be added this way.

Troubleshooting

swag: command not found

Make sure to install swag (see Dependencies) before running any make commands. Also, ensure that your GOPATH is available on your PATH. Contact the team if the issue persists.

General Structure

The current project strucutre follows the picture below: pic

Eventually we will move out of local asynchronous jobs into a proper queue management system (either GCP PubSub/NATS, whichever is cheaper)

Debuggin locally with VSCode and dlv.

Firts make sure to create the debugger launch.json file in the .vscode directory inside the project

mkdir .vscode
touch .vscode/launch.json

Inside that file configure the debugger so you can run the code with the local env vars

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    // add env vars to the launch.json file
    "version": "0.2.0",
    "configurations": [
        {
            "type": "go",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/main.go",
            "env": {
                "LOCAL_DEVELOPMENT": "true",
                "ADMIN_PASSWORD": "admin",
                "ADMIN_USERNAME": "admin"
            }
        },
    ]
}

Be sure to run the database and expose its port locally (you can usekubectl -n tenant-manager port-forward svc/postgres 5432:5432).

Create one ore more breakpoints in code in a line where there is a statement (no comments or global declarations).

Hit play in the VSCode debugger.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 9

Languages