Skip to content

Commit ad34e49

Browse files
committed
Add comments on existing tasks
1 parent eb47476 commit ad34e49

5 files changed

Lines changed: 21 additions & 7 deletions

File tree

pkg/task/inspection/commonlogk8sauditv2/impl/common_task.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
commonlogk8sauditv2_contract "github.com/GoogleCloudPlatform/khi/pkg/task/inspection/commonlogk8sauditv2/contract"
2020
)
2121

22+
// LogSorterTask is the task to sort logs by time.
2223
var LogSorterTask = inspectiontaskbase.NewLogSorterByTimeTask(
2324
commonlogk8sauditv2_contract.LogSorterTaskID,
2425
commonlogk8sauditv2_contract.SuccessLogFilterTaskID.Ref(),

pkg/task/inspection/commonlogk8sauditv2/impl/error_historymodifier_task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
commonlogk8sauditv2_contract "github.com/GoogleCloudPlatform/khi/pkg/task/inspection/commonlogk8sauditv2/contract"
2727
)
2828

29+
// NonSuccessLogHistoryModifierTask is the task to generate history from non-success logs.
2930
var NonSuccessLogHistoryModifierTask = inspectiontaskbase.NewHistoryModifierTask[struct{}](commonlogk8sauditv2_contract.NonSuccessLogHistoryModifierTaskID, &nonSuccessLogHistoryModifierTaskSetting{
3031
subresourceMapToWriteToParent: map[string]struct{}{
3132
"status": {},
@@ -35,6 +36,7 @@ var NonSuccessLogHistoryModifierTask = inspectiontaskbase.NewHistoryModifierTask
3536
})
3637

3738
type nonSuccessLogHistoryModifierTaskSetting struct {
39+
// subresourceMapToWriteToParent is the map of subresources to write to the parent resource.
3840
subresourceMapToWriteToParent map[string]struct{}
3941
}
4042

@@ -60,6 +62,7 @@ func (e *nonSuccessLogHistoryModifierTaskSetting) ModifyChangeSetFromLog(ctx con
6062

6163
var _ inspectiontaskbase.HistoryModifer[struct{}] = (*nonSuccessLogHistoryModifierTaskSetting)(nil)
6264

65+
// addEventForLog adds an event for the log.
6366
func (e *nonSuccessLogHistoryModifierTaskSetting) addEventForLog(l *log.Log, cs *history.ChangeSet) error {
6467
fieldSet := log.MustGetFieldSet(l, &commonlogk8sauditv2_contract.K8sAuditLogFieldSet{})
6568
op := *fieldSet.K8sOperation

pkg/task/inspection/commonlogk8sauditv2/impl/logsummary_task.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import (
2626
commonlogk8sauditv2_contract "github.com/GoogleCloudPlatform/khi/pkg/task/inspection/commonlogk8sauditv2/contract"
2727
)
2828

29+
// LogSerializerTask is the task to serialize k8s audit logs.
2930
var LogSerializerTask = inspectiontaskbase.NewLogSerializerTask(
3031
commonlogk8sauditv2_contract.K8sAuditLogSerializerTaskID,
3132
commonlogk8sauditv2_contract.K8sAuditLogProviderRef,
3233
)
3334

35+
// LogSummaryGrouperTask is the task to group logs for summary generation.
3436
var LogSummaryGrouperTask = inspectiontaskbase.NewLogGrouperTask(
3537
commonlogk8sauditv2_contract.LogSummaryGrouperTaskID,
3638
commonlogk8sauditv2_contract.K8sAuditLogProviderRef,
@@ -40,6 +42,7 @@ var LogSummaryGrouperTask = inspectiontaskbase.NewLogGrouperTask(
4042
},
4143
)
4244

45+
// LogSummaryHistoryModifierTask is the task to generate log summary from given k8s audit log.
4346
var LogSummaryHistoryModifierTask = inspectiontaskbase.NewHistoryModifierTask[struct{}](
4447
commonlogk8sauditv2_contract.LogSummaryHistoryModifierTaskID,
4548
&logSummaryHistoryModifierSetting{},
@@ -70,12 +73,13 @@ func (s *logSummaryHistoryModifierSetting) ModifyChangeSetFromLog(ctx context.Co
7073
cs.SetLogSeverity(enum.SeverityError)
7174
}
7275

73-
cs.SetLogSummary(s.getLogSummary(commonFieldSet))
76+
cs.SetLogSummary(s.logSummary(commonFieldSet))
7477

7578
return struct{}{}, nil
7679
}
7780

78-
func (s *logSummaryHistoryModifierSetting) getLogSummary(fieldSet *commonlogk8sauditv2_contract.K8sAuditLogFieldSet) string {
81+
// logSummary generates the summary string from given log field set.
82+
func (s *logSummaryHistoryModifierSetting) logSummary(fieldSet *commonlogk8sauditv2_contract.K8sAuditLogFieldSet) string {
7983
if fieldSet.IsError {
8084
return fmt.Sprintf("【%s(%d)】%s %s", fieldSet.StatusMessage, fieldSet.StatusCode, fieldSet.VerbString(), fieldSet.RequestURI)
8185
} else {

pkg/task/inspection/commonlogk8sauditv2/impl/logsummary_task_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestLogSummaryHistoryModifierSetting_getLogSummary(t *testing.T) {
5959
for _, tc := range testCases {
6060
t.Run(tc.desc, func(t *testing.T) {
6161
setting := &logSummaryHistoryModifierSetting{}
62-
got := setting.getLogSummary(tc.input)
62+
got := setting.logSummary(tc.input)
6363
if got != tc.want {
6464
t.Errorf("got %q, want %q", got, tc.want)
6565
}

pkg/task/inspection/commonlogk8sauditv2/impl/manifest_generator_task.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838

3939
var bodyPlaceholderForMetadataLevelAuditLog = "# Resource data is unavailable. Audit logs for this resource is recorded at metadata level."
4040

41+
// ManifestGeneratorTask is the task to generate manifest from k8s audit logs.
4142
var ManifestGeneratorTask = inspectiontaskbase.NewProgressReportableInspectionTask(commonlogk8sauditv2_contract.ManifestGeneratorTaskID, []taskid.UntypedTaskReference{
4243
commonlogk8sauditv2_contract.ChangeTargetGrouperTaskID.Ref(),
4344
googlecloudk8scommon_contract.K8sResourceMergeConfigTaskID.Ref(),
@@ -96,12 +97,17 @@ var ManifestGeneratorTask = inspectiontaskbase.NewProgressReportableInspectionTa
9697
})
9798

9899
type groupManifestGenerator struct {
99-
prevRevisionReader *structured.NodeReader
100+
// prevRevisionReader is the reader for the previous revision.
101+
prevRevisionReader *structured.NodeReader
102+
// mergeConfigRegistry is the registry for merge config.
100103
mergeConfigRegistry *k8s.K8sManifestMergeConfigRegistry
101-
prevRevisionBody string
102-
resourceName string
104+
// prevRevisionBody is the body of the previous revision.
105+
prevRevisionBody string
106+
// resourceName is the name of the resource.
107+
resourceName string
103108
}
104109

110+
// Process processes the log to generate manifest.
105111
func (g *groupManifestGenerator) Process(ctx context.Context, l *log.Log) (*commonlogk8sauditv2_contract.ResourceChangeLog, error) {
106112
if g.prevRevisionReader == nil {
107113
g.prevRevisionReader = structured.NewNodeReader(structured.NewEmptyMapNode())
@@ -236,7 +242,7 @@ kind: %s
236242
}
237243
}
238244

239-
// Remove @type in response or request payload
245+
// removeAtType removes @type in response or request payload.
240246
func removeAtType(yamlString string) string {
241247
lines := strings.Split(yamlString, "\n")
242248
var result []string

0 commit comments

Comments
 (0)