Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 97 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ metadata:
openapi.aggregator.io/swagger: "true" # Required
openapi.aggregator.io/path: "/v2/api-docs" # Optional (default: /v2/api-docs)
openapi.aggregator.io/port: "8080" # Optional (default: 8080)
openapi.aggregator.io/allowed-methods: "get,post" # Optional: Filter allowed HTTP methods
```

### 3. Create Aggregator Instance
Expand Down Expand Up @@ -59,6 +60,7 @@ Then open http://localhost:9090 in your browser.
- 🌐 **Unified UI**: Single Swagger UI interface to browse all discovered APIs
- 📝 **Service Information**: Displays service metadata including namespace and resource type
- ⚡ **Zero-config Services**: Works with any service that exposes an OpenAPI/Swagger specification
- 🔒 **Secure API Access**: All API requests from Swagger UI are proxied through the aggregator server instead of direct service access

### 5. Ingress/Route Integration

Expand Down Expand Up @@ -122,6 +124,20 @@ spec:
- Serves unified Swagger UI interface
- Fetches OpenAPI specs in real-time
- Provides API selection and documentation
- Acts as a proxy for all API requests, enhancing security by preventing direct access to services

### Request Flow

1. User accesses Swagger UI and selects an API endpoint
2. API request is sent to the Swagger UI Server
3. Server proxies the request to the target service
4. Response is returned through the proxy to Swagger UI

This proxy architecture provides several benefits:
- Enhanced security by preventing direct access to services
- Consistent request routing and handling
- Ability to add request/response transformations
- Centralized access control and monitoring

### Project Structure

Expand Down Expand Up @@ -169,43 +185,105 @@ make deploy

For installation via Operator Lifecycle Manager, see detailed instructions in [OLM Installation Guide](docs/olm-install.md).

### Development Environment Setup
### Development Setup

### Prerequisites

- Go 1.19 or higher
- Kubernetes cluster (local or remote)
- kubectl
- kustomize
- controller-gen

### Local Development

1. Deploy the test service:
1. Clone the repository:
```bash
# First, deploy the test service that provides OpenAPI specs
kubectl apply -f config/samples/test-service.yaml
git clone https://github.com/hellices/openapi-aggregator-operator.git
cd openapi-aggregator-operator
```

# Port forward the test service to localhost:8080
kubectl port-forward svc/test-service 8080:8080
2. Install dependencies:
```bash
make install-tools
```

2. Run the operator in development mode:
3. Run the operator locally:
```bash
# Run locally
make run
```

### Building and Testing

# Run tests
- Build the operator:
```bash
make build
```

- Run tests:
```bash
make test
```

- Build docker image:
```bash
make docker-build
```

## Configuration

# Build and push image
make docker-build docker-push
### Annotation Options

# Generate manifests
make manifests
| Annotation | Description | Default | Required |
|------------|-------------|---------|----------|
| openapi.aggregator.io/swagger | Enable swagger aggregation | - | Yes |
| openapi.aggregator.io/path | Path to OpenAPI/Swagger endpoint | /v2/api-docs | No |
| openapi.aggregator.io/port | Port for OpenAPI/Swagger endpoint | 8080 | No |
| openapi.aggregator.io/allowed-methods | Comma-separated list of allowed HTTP methods | All methods | No |

### OpenAPIAggregator CR Options

```yaml
apiVersion: observability.aggregator.io/v1alpha1
kind: OpenAPIAggregator
metadata:
name: openapi-aggregator
spec:
labelSelector:
matchLabels:
app: myapp # Optional: Filter services by labels
updateInterval: 10s # Optional: Specification update interval
```

Note: When running the operator in development mode with `make run`, ensure that the test service is running and port-forwarded to localhost:8080. This is required for the operator to properly fetch and display the OpenAPI specifications in the Swagger UI.
## Troubleshooting

### Common Issues

1. **Services not being discovered**
- Verify service annotations are correct
- Check if service is in the same namespace as the operator
- Ensure service endpoints are accessible

### Version Management
2. **Swagger UI not loading**
- Verify port-forward is running correctly
- Check if swagger-ui service is deployed
- Ensure OpenAPI specifications are valid

- Version is managed in `versions.txt`
- Used for Docker images, releases, and binary info
- Format: `ghcr.io/hellices/openapi-aggregator-operator:<version>`
3. **API endpoints not accessible**
- Verify allowed-methods annotation
- Check if service is running and healthy
- Ensure network policies allow access

### Logs

To check operator logs:
```bash
kubectl logs -n openapi-aggregator-system deployment/openapi-aggregator-controller-manager -c manager
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.

## License

Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: ghcr.io/hellices/openapi-aggregator-operator
newTag: 0.1.0
newTag: 0.2.0
2 changes: 1 addition & 1 deletion config/samples/test-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
openapi.aggregator.io/swagger: "true"
openapi.aggregator.io/path: "/api/swagger.json" # 옵션
openapi.aggregator.io/port: "8080" # 옵션
openapi.aggregator.io/allowed-methods: "get" # get만 허용, 'get,post'처럼 쉼표로 구분하여 여러 메서드 허용 가능
openapi.aggregator.io/allowed-methods: "get,post" # get만 허용, 'get,post'처럼 쉼표로 구분하여 여러 메서드 허용 가능
spec:
ports:
- port: 8080
Expand Down
13 changes: 12 additions & 1 deletion install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ spec:
spec:
description: OpenAPIAggregatorSpec defines the desired state of OpenAPIAggregator
properties:
allowedMethodsAnnotation:
default: openapi.aggregator.io/allowed-methods
description: AllowedMethodsAnnotation is the annotation key for allowed
HTTP methods in Swagger UI
type: string
defaultPath:
default: /v2/api-docs
description: DefaultPath is the default path for OpenAPI documentation
Expand Down Expand Up @@ -85,6 +90,12 @@ spec:
description: APIInfo contains information about a collected OpenAPI
spec
properties:
allowedMethods:
description: AllowedMethods stores the allowed HTTP methods
for Swagger UI
items:
type: string
type: array
annotations:
additionalProperties:
type: string
Expand Down Expand Up @@ -437,7 +448,7 @@ spec:
- --metrics-bind-address=:8080
command:
- /manager
image: ghcr.io/hellices/openapi-aggregator-operator:0.1.0
image: ghcr.io/hellices/openapi-aggregator-operator:0.2.0
livenessProbe:
httpGet:
path: /healthz
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/openapiaggregator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func (r *OpenAPIAggregatorReconciler) processService(ctx context.Context, svc co
}
}

// Ensure path starts with "/"
if path != "" && !strings.HasPrefix(path, "/") {
path = "/" + path
}

// Create API info
apiInfo := &observabilityv1alpha1.APIInfo{
Name: svc.Name,
Expand Down
Loading
Loading