...

Text file src/edge-infra.dev/cmd/sds/terminalctl/README.md

Documentation: edge-infra.dev/cmd/sds/terminalctl

     1# Terminal Controller
     2
     3The terminal controller reconciles on create and update of a `terminal` resource.
     4
     5## How to run the terminalctl locally
     6- Create a .env file in the cmd/sds/terminalctl directory
     7- The GOOGLE_APPLICATION_CREDENTIALS will be the path to the terminalctl service account
     8- Set your kubectl context to the context of the kubernetes cluster you will like to run the controller against.
     9- For VSCode users you can add a new configuration to your launch.json file that will look like so
    10
    11```
    12{
    13    "name": "Terminalctl",
    14    "type": "go",
    15    "request": "launch",
    16    "mode": "debug",
    17    "program": "${workspaceFolder}/cmd/sds/terminalctl",
    18    "envFile": "${workspaceFolder}/cmd/sds/terminalctl/.env"
    19},
    20``` 
    21This will enable you to run the terminalctl in debug mode with the advantages of adding breakpoints and stepping into and through functions.
    22
    23## Plugins
    24Plugins allow us to add functionality to the terminal controller without modifying it, to create a plugin follow the steps below:
    25
    261) Implement the `TerminalRegistrationPlugin` interface found in `pkg/sds/k8s/controllers/terminalctl/pkg/plugins/plugins.go`
    27
    282) Register the plugins in the `registerPlugins` function in `pkg/sds/k8s/controllers/terminalctl/controller.go`
    29```go
    30// registerPlugins add new plugins here to be automatically executed by controller.
    31func registerPlugins() {
    32	plugins.Register(terminalctlplugin.AgentMonitoringSAPlugin{
    33		SecretManagerProvider: func(ctx context.Context, projectID string) (types.SecretManagerService, error) {
    34			return secretMgrApi.NewWithOptions(ctx, projectID)
    35		},
    36	})
    37}
    38```
    39
    403) Add kubebuilder rbac annotations in `pkg/sds/k8s/controllers/terminalctl/terminal_controller.go` to create role needed by your plugin.
    41Once done, run `just update-manifest` to generate those roles.
    42```go
    43// +kubebuilder:rbac:groups=edge.ncr.com,resources=terminals,verbs=get;list;watch
    44// +kubebuilder:rbac:groups=edge.ncr.com,resources=terminals/status,verbs=get
    45// +kubebuilder:rbac:groups=edge.ncr.com,resources=syncedobjects,verbs=create;get;list;update;patch;watch
    46// +kubebuilder:rbac:groups=edge.ncr.com,resources=syncedobjects/status,verbs=get
    47```

View as plain text