# Terminal Controller The terminal controller reconciles on create and update of a `terminal` resource. ## How to run the terminalctl locally - Create a .env file in the cmd/sds/terminalctl directory - The GOOGLE_APPLICATION_CREDENTIALS will be the path to the terminalctl service account - Set your kubectl context to the context of the kubernetes cluster you will like to run the controller against. - For VSCode users you can add a new configuration to your launch.json file that will look like so ``` { "name": "Terminalctl", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceFolder}/cmd/sds/terminalctl", "envFile": "${workspaceFolder}/cmd/sds/terminalctl/.env" }, ``` This will enable you to run the terminalctl in debug mode with the advantages of adding breakpoints and stepping into and through functions. ## Plugins Plugins allow us to add functionality to the terminal controller without modifying it, to create a plugin follow the steps below: 1) Implement the `TerminalRegistrationPlugin` interface found in `pkg/sds/k8s/controllers/terminalctl/pkg/plugins/plugins.go` 2) Register the plugins in the `registerPlugins` function in `pkg/sds/k8s/controllers/terminalctl/controller.go` ```go // registerPlugins add new plugins here to be automatically executed by controller. func registerPlugins() { plugins.Register(terminalctlplugin.AgentMonitoringSAPlugin{ SecretManagerProvider: func(ctx context.Context, projectID string) (types.SecretManagerService, error) { return secretMgrApi.NewWithOptions(ctx, projectID) }, }) } ``` 3) Add kubebuilder rbac annotations in `pkg/sds/k8s/controllers/terminalctl/terminal_controller.go` to create role needed by your plugin. Once done, run `just update-manifest` to generate those roles. ```go // +kubebuilder:rbac:groups=edge.ncr.com,resources=terminals,verbs=get;list;watch // +kubebuilder:rbac:groups=edge.ncr.com,resources=terminals/status,verbs=get // +kubebuilder:rbac:groups=edge.ncr.com,resources=syncedobjects,verbs=create;get;list;update;patch;watch // +kubebuilder:rbac:groups=edge.ncr.com,resources=syncedobjects/status,verbs=get ```