-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding document generator for inspection types
- Loading branch information
Showing
7 changed files
with
340 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/GoogleCloudPlatform/khi/pkg/document/generator" | ||
"github.com/GoogleCloudPlatform/khi/pkg/document/model" | ||
"github.com/GoogleCloudPlatform/khi/pkg/inspection" | ||
"github.com/GoogleCloudPlatform/khi/pkg/inspection/common" | ||
"github.com/GoogleCloudPlatform/khi/pkg/source/gcp" | ||
) | ||
|
||
var taskSetRegistrer []inspection.PrepareInspectionServerFunc = make([]inspection.PrepareInspectionServerFunc, 0) | ||
|
||
// fatal logs the error and exits if err is not nil. | ||
func fatal(err error, msg string) { | ||
if err != nil { | ||
slog.Error(fmt.Sprintf("%s: %v", msg, err)) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
taskSetRegistrer = append(taskSetRegistrer, common.PrepareInspectionServer) | ||
taskSetRegistrer = append(taskSetRegistrer, gcp.PrepareInspectionServer) | ||
} | ||
|
||
func main() { | ||
inspectionServer, err := inspection.NewServer() | ||
if err != nil { | ||
slog.Error(fmt.Sprintf("Failed to construct the inspection server due to unexpected error\n%v", err)) | ||
} | ||
|
||
for i, taskSetRegistrer := range taskSetRegistrer { | ||
err = taskSetRegistrer(inspectionServer) | ||
if err != nil { | ||
slog.Error(fmt.Sprintf("Failed to call initialize calls for taskSetRegistrer(#%d)\n%v", i, err)) | ||
} | ||
} | ||
|
||
generator, err := generator.NewDocumentGeneratorFromTemplateFileGlob("./docs/template/*.template.md") | ||
fatal(err, "failed to load template files") | ||
|
||
inspectionTypeDocumentModel := model.GetInspectionTypeDocumentModel(inspectionServer) | ||
err = generator.GenerateDocument("./docs/en/inspection-type.md", "inspection-type-template", inspectionTypeDocumentModel, false) | ||
fatal(err, "failed to generate inspection type document") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<!-- BEGIN GENERATED PART: inspection-type-header --> | ||
# Inspection types | ||
|
||
Inspection type is ... | ||
|
||
<!-- END GENERATED PART: inspection-type-header --> | ||
|
||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke --> | ||
## [Google Kubernetes Engine](#gcp-gke) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com//feature/audit-parser-v2 --> | ||
* Kubernetes Audit Log(v2) | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com//feature/audit-parser-v2 --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/event-parser --> | ||
* Kubernetes Event Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/event-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/nodelog-parser --> | ||
* Kubernetes Node Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/nodelog-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/container-parser --> | ||
* Kubernetes container logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/container-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/gke-audit-parser --> | ||
* GKE Audit logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/gke-audit-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/compute-api-parser --> | ||
* Compute API Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/compute-api-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/network-api-parser --> | ||
* GCE Network Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/network-api-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/autoscaler-parser --> | ||
* Autoscaler Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/autoscaler-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/controlplane-component-parser --> | ||
* Kubernetes Control plane component logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/controlplane-component-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/serialport --> | ||
* Node serial port logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-cloud.google.com/feature/serialport --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer --> | ||
## [Cloud Composer](#gcp-composer) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com//feature/audit-parser-v2 --> | ||
* Kubernetes Audit Log(v2) | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com//feature/audit-parser-v2 --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/event-parser --> | ||
* Kubernetes Event Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/event-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/nodelog-parser --> | ||
* Kubernetes Node Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/nodelog-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/container-parser --> | ||
* Kubernetes container logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/container-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/gke-audit-parser --> | ||
* GKE Audit logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/gke-audit-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/compute-api-parser --> | ||
* Compute API Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/compute-api-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/network-api-parser --> | ||
* GCE Network Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/network-api-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/autoscaler-parser --> | ||
* Autoscaler Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/autoscaler-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/controlplane-component-parser --> | ||
* Kubernetes Control plane component logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/controlplane-component-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/serialport --> | ||
* Node serial port logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/feature/serialport --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/composer/scheduler --> | ||
* (Alpha) Composer / Airflow Scheduler | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/composer/scheduler --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/composer/worker --> | ||
* (Alpha) Cloud Composer / Airflow Worker | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/composer/worker --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/composer/dagprocessor --> | ||
* (Alpha) Composer / Airflow DagProcessorManager | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-composer-cloud.google.com/composer/dagprocessor --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws --> | ||
## [GKE on AWS(Anthos on AWS)](#gcp-gke-on-aws) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com//feature/audit-parser-v2 --> | ||
* Kubernetes Audit Log(v2) | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com//feature/audit-parser-v2 --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/event-parser --> | ||
* Kubernetes Event Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/event-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/nodelog-parser --> | ||
* Kubernetes Node Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/nodelog-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/container-parser --> | ||
* Kubernetes container logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/container-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/multicloud-audit-parser --> | ||
* MultiCloud API logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/multicloud-audit-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/controlplane-component-parser --> | ||
* Kubernetes Control plane component logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-aws-cloud.google.com/feature/controlplane-component-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure --> | ||
## [GKE on Azure(Anthos on Azure)](#gcp-gke-on-azure) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com//feature/audit-parser-v2 --> | ||
* Kubernetes Audit Log(v2) | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com//feature/audit-parser-v2 --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/event-parser --> | ||
* Kubernetes Event Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/event-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/nodelog-parser --> | ||
* Kubernetes Node Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/nodelog-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/container-parser --> | ||
* Kubernetes container logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/container-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/multicloud-audit-parser --> | ||
* MultiCloud API logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/multicloud-audit-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/controlplane-component-parser --> | ||
* Kubernetes Control plane component logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gke-on-azure-cloud.google.com/feature/controlplane-component-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal --> | ||
## [GDCV for Baremetal(GKE on Baremetal, Anthos on Baremetal)](#gcp-gdcv-for-baremetal) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com//feature/audit-parser-v2 --> | ||
* Kubernetes Audit Log(v2) | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com//feature/audit-parser-v2 --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/event-parser --> | ||
* Kubernetes Event Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/event-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/nodelog-parser --> | ||
* Kubernetes Node Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/nodelog-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/container-parser --> | ||
* Kubernetes container logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/container-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/onprem-audit-parser --> | ||
* OnPrem API logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/onprem-audit-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/controlplane-component-parser --> | ||
* Kubernetes Control plane component logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-baremetal-cloud.google.com/feature/controlplane-component-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware --> | ||
## [GDCV for VMWare(GKE on VMWare, Anthos on VMWare)](#gcp-gdcv-for-vmware) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com//feature/audit-parser-v2 --> | ||
* Kubernetes Audit Log(v2) | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com//feature/audit-parser-v2 --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/event-parser --> | ||
* Kubernetes Event Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/event-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/nodelog-parser --> | ||
* Kubernetes Node Logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/nodelog-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/container-parser --> | ||
* Kubernetes container logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/container-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/onprem-audit-parser --> | ||
* OnPrem API logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/onprem-audit-parser --> | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/controlplane-component-parser --> | ||
* Kubernetes Control plane component logs | ||
<!-- END GENERATED PART: inspection-type-element-header-gcp-gdcv-for-vmware-cloud.google.com/feature/controlplane-component-parser --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{define "inspection-type-template"}} | ||
<!-- BEGIN GENERATED PART: inspection-type-header --> | ||
# Inspection types | ||
|
||
Inspection type is ... | ||
|
||
<!-- END GENERATED PART: inspection-type-header --> | ||
{{range $index,$type := .InspectionTypes }} | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-{{$type.ID}} --> | ||
## [{{$type.Name}}](#{{$type.ID}}) | ||
|
||
### Supported features | ||
|
||
<!-- END GENERATED PART: inspection-type-element-header-{{$type.ID}} --> | ||
|
||
{{range $feature := $type.SupportedFeatures}} | ||
<!-- BEGIN GENERATED PART: inspection-type-element-header-{{$type.ID}}-{{$feature.ID}} --> | ||
* {{$feature.Name}} | ||
<!-- END GENERATED PART: inspection-type-element-header-{{$type.ID}}-{{$feature.ID}} --> | ||
{{end}} | ||
{{end}} | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/GoogleCloudPlatform/khi/pkg/inspection" | ||
inspection_task "github.com/GoogleCloudPlatform/khi/pkg/inspection/task" | ||
"github.com/GoogleCloudPlatform/khi/pkg/inspection/taskfilter" | ||
) | ||
|
||
// InspectionTypeDocumentModel is a document model type for generating docs/en/inspection-type.md | ||
type InspectionTypeDocumentModel struct { | ||
InspectionTypes []InspectionTypeDocumentElement | ||
} | ||
|
||
type InspectionTypeDocumentElement struct { | ||
ID string | ||
Name string | ||
DocumentDescription string | ||
|
||
SupportedFeatures []InspectionTypeDocumentElementFeature | ||
} | ||
|
||
type InspectionTypeDocumentElementFeature struct { | ||
ID string | ||
Name string | ||
Description string | ||
} | ||
|
||
// GetInspectionTypeDocumentModel returns the document model from task server. | ||
func GetInspectionTypeDocumentModel(taskServer *inspection.InspectionTaskServer) InspectionTypeDocumentModel { | ||
result := InspectionTypeDocumentModel{} | ||
inspectionTypes := taskServer.GetAllInspectionTypes() | ||
for _, inspectionType := range inspectionTypes { | ||
tasks := taskServer.RootTaskSet. | ||
FilteredSubset(inspection_task.LabelKeyInspectionTypes, taskfilter.ContainsElement(inspectionType.Id), true). | ||
FilteredSubset(inspection_task.LabelKeyInspectionFeatureFlag, taskfilter.HasTrue, false). | ||
GetAll() | ||
features := []InspectionTypeDocumentElementFeature{} | ||
for _, task := range tasks { | ||
features = append(features, InspectionTypeDocumentElementFeature{ | ||
ID: task.ID().String(), | ||
Name: task.Labels().GetOrDefault(inspection_task.LabelKeyFeatureTaskTitle, "").(string), | ||
Description: task.Labels().GetOrDefault(inspection_task.LabelKeyFeatureTaskDescription, "").(string), | ||
}) | ||
} | ||
result.InspectionTypes = append(result.InspectionTypes, InspectionTypeDocumentElement{ | ||
ID: inspectionType.Id, | ||
Name: inspectionType.Name, | ||
DocumentDescription: inspectionType.DocumentDescription, | ||
|
||
SupportedFeatures: features, | ||
}) | ||
} | ||
return result | ||
} |
Oops, something went wrong.