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
5 changes: 5 additions & 0 deletions pkg/core/task/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ func NewTaskResultRetentionLabel(retain bool) LabelOpt {
retain: retain,
}
}

// WithTaskDescription returns a LabelOpt to attach a human-readable description to the task.
func WithTaskDescription(description string) LabelOpt {
return WithLabelValue(LabelKeyTaskDescription, description)
}
90 changes: 90 additions & 0 deletions pkg/core/task/label_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package coretask

import (
"testing"

"github.com/GoogleCloudPlatform/khi/pkg/common/typedmap"
)

func TestWithLabelValue(t *testing.T) {
testStringKey := NewTaskLabelKey[string]("test-string-key")
testIntKey := NewTaskLabelKey[int]("test-int-key")

t.Run("string label", func(t *testing.T) {
testCases := []struct {
name string
value string
want string
}{
{
name: "sets non-empty string value",
value: "hello",
want: "hello",
},
{
name: "sets empty string value",
value: "",
want: "",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
labels := NewLabelSet(WithLabelValue(testStringKey, tc.value))
got, found := typedmap.Get(labels, testStringKey)
if !found {
t.Fatalf("key %q not found in label set", testStringKey)
}
if got != tc.want {
t.Errorf("got %q, want %q", got, tc.want)
}
})
}
})

t.Run("int label", func(t *testing.T) {
testCases := []struct {
name string
value int
want int
}{
{
name: "sets positive integer",
value: 42,
want: 42,
},
{
name: "sets zero",
value: 0,
want: 0,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
labels := NewLabelSet(WithLabelValue(testIntKey, tc.value))
got, found := typedmap.Get(labels, testIntKey)
if !found {
t.Fatalf("key %q not found in label set", testIntKey)
}
if got != tc.want {
t.Errorf("got %d, want %d", got, tc.want)
}
})
}
})
}
3 changes: 3 additions & 0 deletions pkg/core/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ var LabelKeySubsequentTaskRefs = NewTaskLabelKey[[]taskid.UntypedTaskReference](
// LabelKeyTaskResultRetention indicates whether the task result should be retained in the runner after all dependent tasks finish.
var LabelKeyTaskResultRetention = NewTaskLabelKey[bool](KHISystemPrefix + "task-result-retention")

// LabelKeyTaskDescription is the task label to record a human-readable description of the task.
var LabelKeyTaskDescription = NewTaskLabelKey[string](KHISystemPrefix + "task-description")

type UntypedTask interface {
UntypedID() taskid.UntypedTaskImplementationID
// Labels returns KHITaskLabelSet assigned to this task unit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
)

// DefaultK8sResourceMergeConfigTask is the task that generates the default patch request merge config.
var DefaultK8sResourceMergeConfigTask = coretask.NewTask(commonlogk8saudit_contract.K8sResourceMergeConfigTaskID, []taskid.UntypedTaskReference{}, func(ctx context.Context) (*k8s.K8sManifestMergeConfigRegistry, error) {
return k8s.GenerateDefaultMergeConfig()
})
var DefaultK8sResourceMergeConfigTask = coretask.NewTask(
commonlogk8saudit_contract.K8sResourceMergeConfigTaskID,
[]taskid.UntypedTaskReference{},
func(ctx context.Context) (*k8s.K8sManifestMergeConfigRegistry, error) {
return k8s.GenerateDefaultMergeConfig()
},
coretask.WithTaskDescription("Generates the default Kubernetes manifest patch request merge configuration."),
)
1 change: 1 addition & 0 deletions pkg/task/inspection/inspectioncore/contract/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (f *FormTaskLabelOpt) Write(label *typedmap.TypedMap) {
typedmap.Set(label, TaskLabelKeyIsFormTask, true)
typedmap.Set(label, TaskLabelKeyFormFieldLabel, f.label)
typedmap.Set(label, TaskLabelKeyFormFieldDescription, f.description)
typedmap.Set(label, coretask.LabelKeyTaskDescription, f.description)
}

// NewFormTaskLabelOpt constructs a new instance of task.LabelOpt for form related tasks.
Expand Down
1 change: 1 addition & 0 deletions pkg/task/inspection/inspectioncore/contract/tasklabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (ftl *FeatureTaskLabelImpl) Write(label *typedmap.TypedMap) {
typedmap.Set(label, LabelKeyInspectionFeatureFlag, true)
typedmap.Set(label, LabelKeyFeatureTaskTitle, ftl.title)
typedmap.Set(label, LabelKeyFeatureTaskDescription, ftl.description)
typedmap.Set(label, coretask.LabelKeyTaskDescription, ftl.description)
typedmap.Set(label, LabelKeyFeatureTaskOrder, ftl.featureOrder)
typedmap.Set(label, LabelKeyInspectionDefaultFeatureFlag, ftl.isDefaultFeature)
}
Expand Down
Loading