# Project Pause Plugin

A OpenShift Console plugin that allows users to pause and resume projects (namespaces) through the web interface. This plugin integrates with the project-pause-operator to manage project state.

## Features

- Pause/Resume projects from the OpenShift Console
- View project pause status in project overview
- Track when projects were paused
- Integration with project-pause-operator

## Development

### Prerequisites

- [Node.js](https://nodejs.org/en/)
- [yarn](https://yarnpkg.com)
- [Docker](https://www.docker.com) or [podman 3.2.0+](https://podman.io)
- [oc](https://console.redhat.com/openshift/downloads)

### Local Development

In one terminal window:
```bash
yarn install
yarn run start
```

In another terminal window:
```bash
oc login  # login to your cluster
yarn run start-console
```

The plugin HTTP server runs on port 9001. Navigate to http://localhost:9000/example to see the running plugin.

### Building the Image

1. Build:
```bash
docker build -t quay.io/my-repository/project-pause-plugin:latest .
```

2. Push:
```bash
docker push quay.io/my-repository/project-pause-plugin:latest
```

Note: For Apple Silicon Macs, add `--platform=linux/amd64` when building.

### Deployment

Deploy using Helm:
```bash
helm upgrade -i project-pause-plugin charts/openshift-console-plugin \
  -n plugin__project-pause-plugin --create-namespace \
  --set plugin.image=quay.io/my-repository/project-pause-plugin:latest
```

## Required Operator Integration

The plugin requires a project-pause-operator that implements the following REST endpoints:

### 1. Get Project State
```
GET /api/proxy/project-pause-operator/v1/namespaces/{namespace}/state

Response:
{
  "isPaused": boolean,
  "pausedSince": string (ISO 8601 timestamp),
  "error": string (optional)
}
```

### 2. Toggle Project State
```
POST /api/proxy/project-pause-operator/v1/namespaces/{namespace}/toggle

Request:
{
  "pause": boolean
}

Response:
{
  "success": boolean,
  "error": string (optional)
}
```

### CRD Annotations

The operator should manage these annotations on namespaces:
```yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    project-pause-operator.openshift.io/paused: "true"
    project-pause-operator.openshift.io/paused-since: "2024-03-19T10:30:00Z"
```

### Example Operator Implementation

```go
const (
    PausedAnnotation = "project-pause-operator.openshift.io/paused"
    PausedSinceAnnotation = "project-pause-operator.openshift.io/paused-since"
)

type ProjectState struct {
    IsPaused    bool   `json:"isPaused"`
    PausedSince string `json:"pausedSince,omitempty"`
    Error       string `json:"error,omitempty"`
}

// GetProjectState handles the GET state endpoint
func (r *ProjectPauseReconciler) GetProjectState(w http.ResponseWriter, req *http.Request) {
    namespace := mux.Vars(req)["namespace"]
    
    ns, err := r.KubeClient.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
    if err != nil {
        respondWithError(w, http.StatusNotFound, "namespace not found")
        return
    }
    
    state := ProjectState{
        IsPaused: ns.Annotations[PausedAnnotation] == "true",
    }
    
    if state.IsPaused {
        state.PausedSince = ns.Annotations[PausedSinceAnnotation]
    }
    
    json.NewEncoder(w).Encode(state)
}

// See full example in operator repository
```

## Plugin Architecture

The plugin provides:
1. Example test page at `/example`
2. Project overview integration using `console.project-overview/inventory-item`

### i18n Support

The plugin uses the namespace `plugin__project-pause-plugin` for translations. Update messages by running:
```bash
yarn i18n
```

## Contributing

1. Fork the repository
2. Create a feature branch
3. Submit a Pull Request

## References

- [Console Plugin SDK](https://github.com/openshift/console/tree/master/frontend/packages/console-dynamic-plugin-sdk)
- [Dynamic Plugin Enhancement Proposal](https://github.com/openshift/enhancements/blob/master/enhancements/console/dynamic-plugins.md)

## License

Apache License 2.0
