-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add conversion for v1 Task #5202
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,39 @@ | ||
/* | ||
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" | ||
"fmt" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
var _ apis.Convertible = (*Task)(nil) | ||
|
||
// ConvertTo implements apis.Convertible | ||
func (t *Task) ConvertTo(ctx context.Context, sink apis.Convertible) error { | ||
if apis.IsInDelete(ctx) { | ||
return nil | ||
} | ||
return fmt.Errorf("v1 is the highest known version, got: %T", sink) | ||
} | ||
|
||
// ConvertFrom implements apis.Convertible | ||
func (t *Task) ConvertFrom(ctx context.Context, source apis.Convertible) error { | ||
if apis.IsInDelete(ctx) { | ||
return nil | ||
} | ||
return fmt.Errorf("v1 is the highest known version, got: %T", source) | ||
} |
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,43 @@ | ||
/* | ||
Copyright 2022 The Tetkon 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_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
type convertible struct{} | ||
|
||
func (c *convertible) ConvertTo(ctx context.Context, sink apis.Convertible) error { | ||
return nil | ||
} | ||
func (c *convertible) ConvertFrom(ctx context.Context, source apis.Convertible) error { | ||
return nil | ||
} | ||
|
||
func TestTaskConversionBadType(t *testing.T) { | ||
good, bad := &v1.Task{}, &convertible{} | ||
|
||
if err := good.ConvertTo(context.Background(), bad); err == nil { | ||
t.Errorf("ConvertTo() = %#v, wanted error", bad) | ||
} | ||
|
||
if err := good.ConvertFrom(context.Background(), bad); err == nil { | ||
t.Errorf("ConvertFrom() = %#v, wanted error", good) | ||
} | ||
} |
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,160 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
|
||
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" | ||
) | ||
|
||
func (s Step) convertTo(ctx context.Context, sink *v1.Step) { | ||
sink.Name = s.Name | ||
sink.Image = s.Image | ||
sink.Command = s.Command | ||
sink.Args = s.Args | ||
sink.WorkingDir = s.WorkingDir | ||
sink.EnvFrom = s.EnvFrom | ||
sink.Env = s.Env | ||
sink.Resources = s.Resources | ||
sink.VolumeMounts = s.VolumeMounts | ||
sink.VolumeDevices = s.VolumeDevices | ||
sink.ImagePullPolicy = s.ImagePullPolicy | ||
sink.SecurityContext = s.SecurityContext | ||
sink.Script = s.Script | ||
sink.Timeout = s.Timeout | ||
|
||
sink.Workspaces = nil | ||
for _, w := range s.Workspaces { | ||
new := v1.WorkspaceUsage{} | ||
w.convertTo(ctx, &new) | ||
sink.Workspaces = append(sink.Workspaces, new) | ||
} | ||
sink.OnError = s.OnError | ||
sink.StdoutConfig = (*v1.StepOutputConfig)(s.StdoutConfig) | ||
sink.StderrConfig = (*v1.StepOutputConfig)(s.StderrConfig) | ||
|
||
// TODO(#4546): Handle deprecated fields | ||
// Ports, LivenessProbe, ReadinessProbe, StartupProbe, Lifecycle, TerminationMessagePath | ||
// TerminationMessagePolicy, Stdin, StdinOnce, TTY | ||
} | ||
|
||
func (s *Step) convertFrom(ctx context.Context, source v1.Step) { | ||
s.Name = source.Name | ||
s.Image = source.Image | ||
s.Command = source.Command | ||
s.Args = source.Args | ||
s.WorkingDir = source.WorkingDir | ||
s.EnvFrom = source.EnvFrom | ||
s.Env = source.Env | ||
s.Resources = source.Resources | ||
s.VolumeMounts = source.VolumeMounts | ||
s.VolumeDevices = source.VolumeDevices | ||
s.ImagePullPolicy = source.ImagePullPolicy | ||
s.SecurityContext = source.SecurityContext | ||
s.Script = source.Script | ||
s.Timeout = source.Timeout | ||
|
||
s.Workspaces = nil | ||
for _, w := range source.Workspaces { | ||
new := WorkspaceUsage{} | ||
new.convertFrom(ctx, w) | ||
s.Workspaces = append(s.Workspaces, new) | ||
} | ||
s.OnError = source.OnError | ||
s.StdoutConfig = (*StepOutputConfig)(source.StdoutConfig) | ||
s.StderrConfig = (*StepOutputConfig)(source.StderrConfig) | ||
} | ||
|
||
func (s StepTemplate) convertTo(ctx context.Context, sink *v1.StepTemplate) { | ||
sink.Image = s.Image | ||
sink.Command = s.Command | ||
sink.Args = s.Args | ||
sink.WorkingDir = s.WorkingDir | ||
sink.EnvFrom = s.EnvFrom | ||
sink.Env = s.Env | ||
sink.Resources = s.Resources | ||
sink.VolumeMounts = s.VolumeMounts | ||
sink.VolumeDevices = s.VolumeDevices | ||
sink.ImagePullPolicy = s.ImagePullPolicy | ||
sink.SecurityContext = s.SecurityContext | ||
// TODO(#4546): Handle deprecated fields | ||
// Name, Ports, LivenessProbe, ReadinessProbe, StartupProbe, Lifecycle, TerminationMessagePath | ||
// TerminationMessagePolicy, Stdin, StdinOnce, TTY | ||
} | ||
|
||
func (s *StepTemplate) convertFrom(ctx context.Context, source *v1.StepTemplate) { | ||
s.Image = source.Image | ||
s.Command = source.Command | ||
s.Args = source.Args | ||
s.WorkingDir = source.WorkingDir | ||
s.EnvFrom = source.EnvFrom | ||
s.Env = source.Env | ||
s.Resources = source.Resources | ||
s.VolumeMounts = source.VolumeMounts | ||
s.VolumeDevices = source.VolumeDevices | ||
s.ImagePullPolicy = source.ImagePullPolicy | ||
s.SecurityContext = source.SecurityContext | ||
} | ||
|
||
func (s Sidecar) convertTo(ctx context.Context, sink *v1.Sidecar) { | ||
sink.Name = s.Name | ||
sink.Image = s.Image | ||
sink.Command = s.Command | ||
sink.Args = s.Args | ||
sink.WorkingDir = s.WorkingDir | ||
sink.Ports = s.Ports | ||
sink.EnvFrom = s.EnvFrom | ||
sink.Env = s.Env | ||
sink.Resources = s.Resources | ||
sink.VolumeMounts = s.VolumeMounts | ||
sink.VolumeDevices = s.VolumeDevices | ||
sink.LivenessProbe = s.LivenessProbe | ||
sink.ReadinessProbe = s.ReadinessProbe | ||
sink.StartupProbe = s.StartupProbe | ||
sink.Lifecycle = s.Lifecycle | ||
sink.TerminationMessagePath = s.TerminationMessagePath | ||
sink.TerminationMessagePolicy = s.TerminationMessagePolicy | ||
sink.ImagePullPolicy = s.ImagePullPolicy | ||
sink.SecurityContext = s.SecurityContext | ||
sink.Stdin = s.Stdin | ||
sink.StdinOnce = s.StdinOnce | ||
sink.TTY = s.TTY | ||
sink.Script = s.Script | ||
sink.Workspaces = nil | ||
for _, w := range s.Workspaces { | ||
new := v1.WorkspaceUsage{} | ||
w.convertTo(ctx, &new) | ||
sink.Workspaces = append(sink.Workspaces, new) | ||
} | ||
} | ||
|
||
func (s *Sidecar) convertFrom(ctx context.Context, source v1.Sidecar) { | ||
s.Name = source.Name | ||
s.Image = source.Image | ||
s.Command = source.Command | ||
s.Args = source.Args | ||
s.WorkingDir = source.WorkingDir | ||
s.Ports = source.Ports | ||
s.EnvFrom = source.EnvFrom | ||
s.Env = source.Env | ||
s.Resources = source.Resources | ||
s.VolumeMounts = source.VolumeMounts | ||
s.VolumeDevices = source.VolumeDevices | ||
s.LivenessProbe = source.LivenessProbe | ||
s.ReadinessProbe = source.ReadinessProbe | ||
s.StartupProbe = source.StartupProbe | ||
s.Lifecycle = source.Lifecycle | ||
s.TerminationMessagePath = source.TerminationMessagePath | ||
s.TerminationMessagePolicy = source.TerminationMessagePolicy | ||
s.ImagePullPolicy = source.ImagePullPolicy | ||
s.SecurityContext = source.SecurityContext | ||
s.Stdin = source.Stdin | ||
s.StdinOnce = source.StdinOnce | ||
s.TTY = source.TTY | ||
s.Script = source.Script | ||
s.Workspaces = nil | ||
for _, w := range source.Workspaces { | ||
new := WorkspaceUsage{} | ||
new.convertFrom(ctx, w) | ||
s.Workspaces = append(s.Workspaces, new) | ||
} | ||
} |
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,47 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
|
||
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" | ||
) | ||
|
||
func (p ParamSpec) convertTo(ctx context.Context, sink *v1.ParamSpec) { | ||
sink.Name = p.Name | ||
sink.Type = v1.ParamType(p.Type) | ||
sink.Description = p.Description | ||
var properties map[string]v1.PropertySpec | ||
if p.Properties != nil { | ||
properties = make(map[string]v1.PropertySpec) | ||
} | ||
for k, v := range p.Properties { | ||
properties[k] = v1.PropertySpec{Type: v1.ParamType(v.Type)} | ||
} | ||
sink.Properties = properties | ||
if p.Default != nil { | ||
sink.Default = &v1.ArrayOrString{ | ||
Type: v1.ParamType(p.Default.Type), StringVal: p.Default.StringVal, | ||
ArrayVal: p.Default.ArrayVal, ObjectVal: p.Default.ObjectVal, | ||
} | ||
} | ||
} | ||
|
||
func (p *ParamSpec) convertFrom(ctx context.Context, source v1.ParamSpec) { | ||
p.Name = source.Name | ||
p.Type = ParamType(source.Type) | ||
p.Description = source.Description | ||
var properties map[string]PropertySpec | ||
if source.Properties != nil { | ||
properties = make(map[string]PropertySpec) | ||
} | ||
for k, v := range source.Properties { | ||
properties[k] = PropertySpec{Type: ParamType(v.Type)} | ||
} | ||
p.Properties = properties | ||
if source.Default != nil { | ||
p.Default = &ArrayOrString{ | ||
Type: ParamType(source.Default.Type), StringVal: source.Default.StringVal, | ||
ArrayVal: source.Default.ArrayVal, ObjectVal: source.Default.ObjectVal, | ||
} | ||
} | ||
} |
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,29 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
|
||
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" | ||
) | ||
|
||
func (r TaskResult) convertTo(ctx context.Context, sink *v1.TaskResult) { | ||
sink.Name = r.Name | ||
sink.Type = v1.ResultsType(r.Type) | ||
sink.Description = r.Description | ||
properties := make(map[string]v1.PropertySpec) | ||
for k, v := range r.Properties { | ||
properties[k] = v1.PropertySpec{Type: v1.ParamType(v.Type)} | ||
} | ||
sink.Properties = properties | ||
} | ||
|
||
func (r *TaskResult) convertFrom(ctx context.Context, source v1.TaskResult) { | ||
r.Name = source.Name | ||
r.Type = ResultsType(source.Type) | ||
r.Description = source.Description | ||
properties := make(map[string]PropertySpec) | ||
for k, v := range source.Properties { | ||
properties[k] = PropertySpec{Type: ParamType(v.Type)} | ||
} | ||
r.Properties = properties | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Will conversions fail if we do not implement this in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, since we don't have the v1 version added to our CRD yet. I have a follow-up PR almost ready that adds conversion for Resources. If we did have v1 versions in the task crd, conversion wouldn't fail, but it would silently drop any resources the user has defined. (I think this may only be backwards incompatible once we update the storage version of the crd but I'm not completely sure)