Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning up label keys 🧹 #4154

Merged
merged 1 commit into from
Aug 17, 2021
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
20 changes: 10 additions & 10 deletions pkg/apis/pipeline/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ const (
GroupName = "tekton.dev"

// ClusterTaskLabelKey is used as the label identifier for a ClusterTask
ClusterTaskLabelKey = "/clusterTask"
ClusterTaskLabelKey = GroupName + "/clusterTask"

// TaskLabelKey is used as the label identifier for a Task
TaskLabelKey = "/task"
TaskLabelKey = GroupName + "/task"

// TaskRunLabelKey is used as the label identifier for a TaskRun
TaskRunLabelKey = "/taskRun"
TaskRunLabelKey = GroupName + "/taskRun"

// PipelineLabelKey is used as the label identifier for a Pipeline
PipelineLabelKey = "/pipeline"
PipelineLabelKey = GroupName + "/pipeline"

// PipelineRunLabelKey is used as the label identifier for a PipelineRun
PipelineRunLabelKey = "/pipelineRun"
PipelineRunLabelKey = GroupName + "/pipelineRun"

// PipelineTaskLabelKey is used as the label identifier for a PipelineTask
PipelineTaskLabelKey = "/pipelineTask"
PipelineTaskLabelKey = GroupName + "/pipelineTask"

// ConditionCheckKey is used as the label identifier for a ConditionCheck
ConditionCheckKey = "/conditionCheck"
ConditionCheckKey = GroupName + "/conditionCheck"

// ConditionNameKey is used as the label identifier for a Condition
ConditionNameKey = "/conditionName"
ConditionNameKey = GroupName + "/conditionName"

// RunKey is used as the label identifier for a Run
RunKey = "/run"
RunKey = GroupName + "/run"

// MemberOfLabelKey is used as the label identifier for a PipelineTask
// Set to Tasks/Finally depending on the position of the PipelineTask
MemberOfLabelKey = "/memberOf"
MemberOfLabelKey = GroupName + "/memberOf"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func (tr *TaskRun) IsPartOfPipeline() (bool, string, string) {
return false, "", ""
}

if pl, ok := tr.Labels[pipeline.GroupName+pipeline.PipelineLabelKey]; ok {
return true, pl, tr.Labels[pipeline.GroupName+pipeline.PipelineRunLabelKey]
if pl, ok := tr.Labels[pipeline.PipelineLabelKey]; ok {
return true, pl, tr.Labels[pipeline.PipelineRunLabelKey]
}

return false, "", ""
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func TestTaskRunIsOfPipelinerun(t *testing.T) {
}{{
name: "yes",
tr: tb.TaskRun("taskrunname",
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineLabelKey, "pipeline"),
tb.TaskRunLabel(pipeline.GroupName+pipeline.PipelineRunLabelKey, "pipelinerun"),
tb.TaskRunLabel(pipeline.PipelineLabelKey, "pipeline"),
tb.TaskRunLabel(pipeline.PipelineRunLabelKey, "pipelinerun"),
),
expectedValue: true,
expetectedPipeline: "pipeline",
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ func (tr *TaskRun) IsPartOfPipeline() (bool, string, string) {
return false, "", ""
}

if pl, ok := tr.Labels[pipeline.GroupName+pipeline.PipelineLabelKey]; ok {
return true, pl, tr.Labels[pipeline.GroupName+pipeline.PipelineRunLabelKey]
if pl, ok := tr.Labels[pipeline.PipelineLabelKey]; ok {
return true, pl, tr.Labels[pipeline.PipelineRunLabelKey]
}

return false, "", ""
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func TestTaskRunIsOfPipelinerun(t *testing.T) {
tr: &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
pipeline.GroupName + pipeline.PipelineLabelKey: "pipeline",
pipeline.GroupName + pipeline.PipelineRunLabelKey: "pipelinerun",
pipeline.PipelineLabelKey: "pipeline",
pipeline.PipelineRunLabelKey: "pipelinerun",
},
},
},
Expand Down
5 changes: 1 addition & 4 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import (
)

const (
// TaskRunLabelKey is the name of the label added to the Pod to identify the TaskRun
TaskRunLabelKey = pipeline.GroupName + pipeline.TaskRunLabelKey

// TektonHermeticEnvVar is the env var we set in containers to indicate they should be run hermetically
TektonHermeticEnvVar = "TEKTON_HERMETIC"

Expand Down Expand Up @@ -356,7 +353,7 @@ func makeLabels(s *v1beta1.TaskRun) map[string]string {

// NB: Set this *after* passing through TaskRun Labels. If the TaskRun
// specifies this label, it should be overridden by this value.
labels[TaskRunLabelKey] = s.Name
labels[pipeline.TaskRunLabelKey] = s.Name
return labels
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1806,9 +1806,9 @@ func TestPodBuildwithAlphaAPIEnabled(t *testing.T) {
func TestMakeLabels(t *testing.T) {
taskRunName := "task-run-name"
want := map[string]string{
TaskRunLabelKey: taskRunName,
"foo": "bar",
"hello": "world",
pipeline.TaskRunLabelKey: taskRunName,
"foo": "bar",
"hello": "world",
}
got := makeLabels(&v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/affinity_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func getStatefulSetLabels(pr *v1beta1.PipelineRun, affinityAssistantName string)
for key, val := range pr.ObjectMeta.Labels {
labels[key] = val
}
labels[pipeline.GroupName+pipeline.PipelineRunLabelKey] = pr.Name
labels[pipeline.PipelineRunLabelKey] = pr.Name

// LabelInstance is used to configure PodAffinity for all TaskRuns belonging to this Affinity Assistant
// LabelComponent is used to configure PodAntiAffinity to other Affinity Assistants
Expand Down
22 changes: 11 additions & 11 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get
for key, value := range pipelineMeta.Labels {
pr.ObjectMeta.Labels[key] = value
}
pr.ObjectMeta.Labels[pipeline.GroupName+pipeline.PipelineLabelKey] = pipelineMeta.Name
pr.ObjectMeta.Labels[pipeline.PipelineLabelKey] = pipelineMeta.Name

// Propagate annotations from Pipeline to PipelineRun.
if pr.ObjectMeta.Annotations == nil {
Expand Down Expand Up @@ -940,22 +940,22 @@ func getTaskrunLabels(pr *v1beta1.PipelineRun, pipelineTaskName string, includeP
labels[key] = val
}
}
labels[pipeline.GroupName+pipeline.PipelineRunLabelKey] = pr.Name
labels[pipeline.PipelineRunLabelKey] = pr.Name
if pipelineTaskName != "" {
labels[pipeline.GroupName+pipeline.PipelineTaskLabelKey] = pipelineTaskName
labels[pipeline.PipelineTaskLabelKey] = pipelineTaskName
}
if pr.Status.PipelineSpec != nil {
// check if a task is part of the "tasks" section, add a label to identify it during the runtime
for _, f := range pr.Status.PipelineSpec.Tasks {
if pipelineTaskName == f.Name {
labels[pipeline.GroupName+pipeline.MemberOfLabelKey] = v1beta1.PipelineTasks
labels[pipeline.MemberOfLabelKey] = v1beta1.PipelineTasks
break
}
}
// check if a task is part of the "finally" section, add a label to identify it during the runtime
for _, f := range pr.Status.PipelineSpec.Finally {
if pipelineTaskName == f.Name {
labels[pipeline.GroupName+pipeline.MemberOfLabelKey] = v1beta1.PipelineFinallyTasks
labels[pipeline.MemberOfLabelKey] = v1beta1.PipelineFinallyTasks
break
}
}
Expand Down Expand Up @@ -1133,8 +1133,8 @@ func (c *Reconciler) updateLabelsAndAnnotations(ctx context.Context, pr *v1beta1

func (c *Reconciler) makeConditionCheckContainer(ctx context.Context, rprt *resources.ResolvedPipelineRunTask, rcc *resources.ResolvedConditionCheck, pr *v1beta1.PipelineRun) (*v1beta1.ConditionCheck, error) {
labels := getTaskrunLabels(pr, rprt.PipelineTask.Name, true)
labels[pipeline.GroupName+pipeline.ConditionCheckKey] = rcc.ConditionCheckName
labels[pipeline.GroupName+pipeline.ConditionNameKey] = rcc.Condition.Name
labels[pipeline.ConditionCheckKey] = rcc.ConditionCheckName
labels[pipeline.ConditionNameKey] = rcc.Condition.Name

for key, value := range rcc.Condition.ObjectMeta.Labels {
labels[key] = value
Expand Down Expand Up @@ -1234,8 +1234,8 @@ func updatePipelineRunStatusFromTaskRuns(logger *zap.SugaredLogger, pr *v1beta1.
continue
}
lbls := taskrun.GetLabels()
pipelineTaskName := lbls[pipeline.GroupName+pipeline.PipelineTaskLabelKey]
if _, ok := lbls[pipeline.GroupName+pipeline.ConditionCheckKey]; ok {
pipelineTaskName := lbls[pipeline.PipelineTaskLabelKey]
if _, ok := lbls[pipeline.ConditionCheckKey]; ok {
// Save condition for looping over them after this
if _, ok := conditionTaskRuns[pipelineTaskName]; !ok {
// If it's the first condition taskrun, initialise the slice
Expand Down Expand Up @@ -1284,7 +1284,7 @@ func updatePipelineRunStatusFromTaskRuns(logger *zap.SugaredLogger, pr *v1beta1.
// The condition check was not found, so we need to add it
// We only add the condition name, the status can now be gathered by the
// normal reconcile process
if conditionName, ok := lbls[pipeline.GroupName+pipeline.ConditionNameKey]; ok {
if conditionName, ok := lbls[pipeline.ConditionNameKey]; ok {
conditionChecks[foundTaskRun.Name] = &v1beta1.PipelineRunConditionCheckStatus{
ConditionName: fmt.Sprintf("%s-%s", conditionName, strconv.Itoa(i)),
}
Expand Down Expand Up @@ -1316,7 +1316,7 @@ func updatePipelineRunStatusFromRuns(logger *zap.SugaredLogger, pr *v1beta1.Pipe
continue
}
lbls := run.GetLabels()
pipelineTaskName := lbls[pipeline.GroupName+pipeline.PipelineTaskLabelKey]
pipelineTaskName := lbls[pipeline.PipelineTaskLabelKey]
if _, ok := pr.Status.Runs[run.Name]; !ok {
// This run was missing from the status.
pr.Status.Runs[run.Name] = &v1beta1.PipelineRunRunStatus{
Expand Down
Loading