-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds structs and validation for v1 TaskRun, including params, resultRef and workspaces. This is copied from v1beta1 with the following exceptions: - omitted TaskRunResources - This includes the `TaskRunInputs` and `TaskRunOutputs` and respective test - omitted `CloudEvents` related fields including `CloudEventDeliveryState` - renamed the Go fields of `StepState.ContainerName` to `StepState.Container`and `SidecarState.ContainerName` to `SidecarState.Container` but not the api fields - renamed `taskResults` to `results`
- Loading branch information
Showing
27 changed files
with
5,596 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,73 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
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 v1 | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/tektoncd/pipeline/pkg/apis/config" | ||
pod "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
var _ apis.Defaultable = (*TaskRun)(nil) | ||
|
||
// ManagedByLabelKey is the label key used to mark what is managing this resource | ||
const ManagedByLabelKey = "app.kubernetes.io/managed-by" | ||
|
||
// SetDefaults implements apis.Defaultable | ||
func (tr *TaskRun) SetDefaults(ctx context.Context) { | ||
ctx = apis.WithinParent(ctx, tr.ObjectMeta) | ||
tr.Spec.SetDefaults(ctx) | ||
|
||
// If the TaskRun doesn't have a managed-by label, apply the default | ||
// specified in the config. | ||
cfg := config.FromContextOrDefaults(ctx) | ||
if tr.ObjectMeta.Labels == nil { | ||
tr.ObjectMeta.Labels = map[string]string{} | ||
} | ||
if _, found := tr.ObjectMeta.Labels[ManagedByLabelKey]; !found { | ||
tr.ObjectMeta.Labels[ManagedByLabelKey] = cfg.Defaults.DefaultManagedByLabelValue | ||
} | ||
} | ||
|
||
// SetDefaults implements apis.Defaultable | ||
func (trs *TaskRunSpec) SetDefaults(ctx context.Context) { | ||
cfg := config.FromContextOrDefaults(ctx) | ||
if trs.TaskRef != nil && trs.TaskRef.Kind == "" { | ||
trs.TaskRef.Kind = NamespacedTaskKind | ||
} | ||
|
||
if trs.Timeout == nil { | ||
trs.Timeout = &metav1.Duration{Duration: time.Duration(cfg.Defaults.DefaultTimeoutMinutes) * time.Minute} | ||
} | ||
|
||
defaultSA := cfg.Defaults.DefaultServiceAccount | ||
if trs.ServiceAccountName == "" && defaultSA != "" { | ||
trs.ServiceAccountName = defaultSA | ||
} | ||
|
||
defaultPodTemplate := cfg.Defaults.DefaultPodTemplate | ||
trs.PodTemplate = pod.MergePodTemplateWithDefault(trs.PodTemplate, defaultPodTemplate) | ||
|
||
// If this taskrun has an embedded task, apply the usual task defaults | ||
if trs.TaskSpec != nil { | ||
trs.TaskSpec.SetDefaults(ctx) | ||
} | ||
} |
Oops, something went wrong.