A Go-based tool for scanning OpenShift/Kubernetes resources using the oc CLI.
- Concurrent Scanning: Scans multiple resource types simultaneously using goroutines
- Modular Architecture: Easy to extend with new resource scanners
- OpenShift Native: Uses
ocCLI for cluster interactions - Namespace Support: Scan resources in specific namespaces
- Pods: Scan and list all pods in a namespace
- Deployments: Scan and list all deployments in a namespace
- OpenShift CLI (
oc) installed and configured - Access to an OpenShift cluster (logged in via
oc login) - Go 1.19+ (for building from source)
git clone https://github.com/ItzikEzra-rh/oc-scanner.git
cd oc-scanner
go build -o oc-scanner .# Scan pods in a specific namespace
./oc-scanner scan <namespace> pods
# Scan deployments in a specific namespace
./oc-scanner scan <namespace> deployments
# Scan multiple resources simultaneously
./oc-scanner scan <namespace> pods deployments# Scan pods in the openshift-kmm namespace
./oc-scanner scan openshift-kmm pods
# Scan both pods and deployments in default namespace
./oc-scanner scan default pods deployments
# Development mode (using go run)
go run main.go scan openshift-kmm podsThe scanner follows a modular design:
oc-scanner/
├── main.go # Main application logic
├── scanner/
│ ├── interface.go # Scanner interface definition
│ ├── pods.go # Pod scanner implementation
│ └── deployments.go # Deployment scanner implementation
├── go.mod
└── go.sum
type Scanner interface {
Scan() error
}Each resource type implements this interface, making it easy to add new scanners.
- Create a new file in the
scanner/directory (e.g.,services.go) - Implement the
Scannerinterface:
package scanner
type ServiceScanner struct {
Namespace string
}
func (s ServiceScanner) Scan() error {
// Implementation here
return nil
}- Add the scanner to the factory map in
main.go:
scannerMap := map[string]func(string) scanner.Scanner{
"pods": func(ns string) scanner.Scanner { return scanner.PodScanner{Namespace: ns} },
"deployments": func(ns string) scanner.Scanner { return scanner.DeploymentScanner{Namespace: ns} },
"services": func(ns string) scanner.Scanner { return scanner.ServiceScanner{Namespace: ns} },
}The scanner uses Go's goroutines and sync.WaitGroup to scan multiple resource types concurrently:
- Each resource type runs in its own goroutine
- All scans complete in parallel, improving performance
- Proper synchronization ensures all scans complete before exit
- Individual scanner errors don't stop other scanners
- Errors are logged with resource context
- Non-zero exit codes for critical failures
go test ./...go build -o oc-scanner .go run main.go scan <namespace> <resource-types...>- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Go 1.19+
- OpenShift CLI (
oc) - Active OpenShift cluster connection