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

Change the storage version to v1beta1 types #2577

Merged
merged 1 commit into from
May 12, 2020
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
4 changes: 2 additions & 2 deletions config/300-clustertask.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spec:
versions:
- name: v1alpha1
served: true
storage: true
storage: false
- name: v1beta1
served: true
storage: false
storage: true
names:
kind: ClusterTask
plural: clustertasks
Expand Down
4 changes: 2 additions & 2 deletions config/300-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spec:
versions:
- name: v1alpha1
served: true
storage: true
storage: false
- name: v1beta1
served: true
storage: false
storage: true
names:
kind: Pipeline
plural: pipelines
Expand Down
4 changes: 2 additions & 2 deletions config/300-pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spec:
versions:
- name: v1alpha1
served: true
storage: true
storage: false
- name: v1beta1
served: true
storage: false
storage: true
names:
kind: PipelineRun
plural: pipelineruns
Expand Down
4 changes: 2 additions & 2 deletions config/300-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spec:
versions:
- name: v1alpha1
served: true
storage: true
storage: false
- name: v1beta1
served: true
storage: false
storage: true
names:
kind: Task
plural: tasks
Expand Down
4 changes: 2 additions & 2 deletions config/300-taskrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spec:
versions:
- name: v1alpha1
served: true
storage: true
storage: false
- name: v1beta1
served: true
storage: false
storage: true
names:
kind: TaskRun
plural: taskruns
Expand Down
46 changes: 0 additions & 46 deletions internal/builder/v1alpha1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never import pkg/reconciler packages outside of pkg/reconciler 😈

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -76,9 +75,6 @@ type TaskRunInputsOp func(*v1alpha1.TaskRunInputs)
// TaskRunOutputsOp is an operation which modify a TaskRunOutputs struct.
type TaskRunOutputsOp func(*v1alpha1.TaskRunOutputs)

// ResolvedTaskResourcesOp is an operation which modify a ResolvedTaskResources struct.
type ResolvedTaskResourcesOp func(*resources.ResolvedTaskResources)

// StepStateOp is an operation which modifies a StepState struct.
type StepStateOp func(*v1alpha1.StepState)

Expand Down Expand Up @@ -932,45 +928,3 @@ func TaskRunWorkspaceVolumeClaimTemplate(name, subPath string, volumeClaimTempla
})
}
}

// ResolvedTaskResources creates a ResolvedTaskResources with default values.
// Any number of ResolvedTaskResources modifier can be passed to transform it.
func ResolvedTaskResources(ops ...ResolvedTaskResourcesOp) *resources.ResolvedTaskResources {
resources := &resources.ResolvedTaskResources{}
for _, op := range ops {
op(resources)
}
return resources
}

// ResolvedTaskResourcesTaskSpec sets a TaskSpec to the ResolvedTaskResources.
// Any number of TaskSpec modifier can be passed to transform it.
func ResolvedTaskResourcesTaskSpec(ops ...TaskSpecOp) ResolvedTaskResourcesOp {
return func(r *resources.ResolvedTaskResources) {
spec := &v1alpha1.TaskSpec{}
for _, op := range ops {
op(spec)
}
r.TaskSpec = spec
}
}

// ResolvedTaskResourcesInputs adds an input PipelineResource, with specified name, to the ResolvedTaskResources.
func ResolvedTaskResourcesInputs(name string, resource *v1alpha1.PipelineResource) ResolvedTaskResourcesOp {
return func(r *resources.ResolvedTaskResources) {
if r.Inputs == nil {
r.Inputs = map[string]*v1alpha1.PipelineResource{}
}
r.Inputs[name] = resource
}
}

// ResolvedTaskResourcesOutputs adds an output PipelineResource, with specified name, to the ResolvedTaskResources.
func ResolvedTaskResourcesOutputs(name string, resource *v1alpha1.PipelineResource) ResolvedTaskResourcesOp {
return func(r *resources.ResolvedTaskResources) {
if r.Outputs == nil {
r.Outputs = map[string]*v1alpha1.PipelineResource{}
}
r.Outputs[name] = resource
}
}
38 changes: 0 additions & 38 deletions internal/builder/v1alpha1/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -421,40 +420,3 @@ func TestTaskRunWithPodTemplate(t *testing.T) {
t.Fatalf("TaskRun diff -want, +got: %v", d)
}
}

func TestResolvedTaskResources(t *testing.T) {
resolvedTaskResources := tb.ResolvedTaskResources(
tb.ResolvedTaskResourcesTaskSpec(
tb.Step("image", tb.StepCommand("/mycmd")),
),
tb.ResolvedTaskResourcesInputs("foo", tb.PipelineResource("bar", tb.PipelineResourceNamespace("baz"))),
tb.ResolvedTaskResourcesOutputs("qux", tb.PipelineResource("quux", tb.PipelineResourceNamespace("quuz"))),
)
expectedResolvedTaskResources := &resources.ResolvedTaskResources{
TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: corev1.Container{
Image: "image",
Command: []string{"/mycmd"},
}}},
}},
Inputs: map[string]*v1alpha1.PipelineResource{
"foo": {
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "baz",
},
},
},
Outputs: map[string]*v1alpha1.PipelineResource{
"qux": {
ObjectMeta: metav1.ObjectMeta{
Name: "quux",
Namespace: "quuz",
},
},
},
}
if d := cmp.Diff(expectedResolvedTaskResources, resolvedTaskResources); d != "" {
t.Fatalf("ResolvedTaskResources diff -want, +got: %v", d)
}
}
4 changes: 2 additions & 2 deletions internal/builder/v1beta1/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestPipelineRunWithResourceSpec(t *testing.T) {
tb.PipelineRunResourceBinding("some-resource",
tb.PipelineResourceBindingResourceSpec(&resource.PipelineResourceSpec{
Type: v1beta1.PipelineResourceTypeGit,
Params: []v1beta1.ResourceParam{{
Params: []resource.ResourceParam{{
Name: "url",
Value: "git",
}}})),
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestPipelineRunWithResourceSpec(t *testing.T) {
Name: "some-resource",
ResourceSpec: &resource.PipelineResourceSpec{
Type: v1beta1.PipelineResourceType("git"),
Params: []v1beta1.ResourceParam{{
Params: []resource.ResourceParam{{
Name: "url",
Value: "git",
}},
Expand Down
2 changes: 1 addition & 1 deletion internal/builder/v1beta1/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestPipelineResource(t *testing.T) {
Spec: resource.PipelineResourceSpec{
Description: "test description",
Type: v1beta1.PipelineResourceTypeGit,
Params: []v1beta1.ResourceParam{{
Params: []resource.ResourceParam{{
Name: "URL", Value: "https://foo.git",
}},
},
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/pipeline/v1beta1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,32 @@ package v1beta1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

// ConditionCheck represents a single evaluation of a Condition step.
type ConditionCheck TaskRun

func NewConditionCheck(tr *TaskRun) *ConditionCheck {
if tr == nil {
return nil
}

cc := ConditionCheck(*tr)
return &cc
}

// IsDone returns true if the ConditionCheck's status indicates that it is done.
func (cc *ConditionCheck) IsDone() bool {
return !cc.Status.GetCondition(apis.ConditionSucceeded).IsUnknown()
}

// IsSuccessful returns true if the ConditionCheck's status indicates that it is done.
func (cc *ConditionCheck) IsSuccessful() bool {
return cc.Status.GetCondition(apis.ConditionSucceeded).IsTrue()
}

// ConditionCheckStatus defines the observed state of ConditionCheck
type ConditionCheckStatus struct {
duckv1beta1.Status `json:",inline"`
Expand Down
72 changes: 72 additions & 0 deletions pkg/apis/pipeline/v1beta1/container_replacements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2019 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 v1beta1

import (
"github.com/tektoncd/pipeline/pkg/substitution"
corev1 "k8s.io/api/core/v1"
)

func ApplyContainerReplacements(step *corev1.Container, stringReplacements map[string]string, arrayReplacements map[string][]string) {
step.Name = substitution.ApplyReplacements(step.Name, stringReplacements)
step.Image = substitution.ApplyReplacements(step.Image, stringReplacements)

// Use ApplyArrayReplacements here, as additional args may be added via an array parameter.
var newArgs []string
for _, a := range step.Args {
newArgs = append(newArgs, substitution.ApplyArrayReplacements(a, stringReplacements, arrayReplacements)...)
}
step.Args = newArgs

for ie, e := range step.Env {
step.Env[ie].Value = substitution.ApplyReplacements(e.Value, stringReplacements)
if step.Env[ie].ValueFrom != nil {
if e.ValueFrom.SecretKeyRef != nil {
step.Env[ie].ValueFrom.SecretKeyRef.LocalObjectReference.Name = substitution.ApplyReplacements(e.ValueFrom.SecretKeyRef.LocalObjectReference.Name, stringReplacements)
step.Env[ie].ValueFrom.SecretKeyRef.Key = substitution.ApplyReplacements(e.ValueFrom.SecretKeyRef.Key, stringReplacements)
}
if e.ValueFrom.ConfigMapKeyRef != nil {
step.Env[ie].ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name = substitution.ApplyReplacements(e.ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name, stringReplacements)
step.Env[ie].ValueFrom.ConfigMapKeyRef.Key = substitution.ApplyReplacements(e.ValueFrom.ConfigMapKeyRef.Key, stringReplacements)
}
}
}

for ie, e := range step.EnvFrom {
step.EnvFrom[ie].Prefix = substitution.ApplyReplacements(e.Prefix, stringReplacements)
if e.ConfigMapRef != nil {
step.EnvFrom[ie].ConfigMapRef.LocalObjectReference.Name = substitution.ApplyReplacements(e.ConfigMapRef.LocalObjectReference.Name, stringReplacements)
}
if e.SecretRef != nil {
step.EnvFrom[ie].SecretRef.LocalObjectReference.Name = substitution.ApplyReplacements(e.SecretRef.LocalObjectReference.Name, stringReplacements)
}
}
step.WorkingDir = substitution.ApplyReplacements(step.WorkingDir, stringReplacements)

// Use ApplyArrayReplacements here, as additional commands may be added via an array parameter.
var newCommand []string
for _, c := range step.Command {
newCommand = append(newCommand, substitution.ApplyArrayReplacements(c, stringReplacements, arrayReplacements)...)
}
step.Command = newCommand

for iv, v := range step.VolumeMounts {
step.VolumeMounts[iv].Name = substitution.ApplyReplacements(v.Name, stringReplacements)
step.VolumeMounts[iv].MountPath = substitution.ApplyReplacements(v.MountPath, stringReplacements)
step.VolumeMounts[iv].SubPath = substitution.ApplyReplacements(v.SubPath, stringReplacements)
}
}
Loading