-
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
refactor trusted resources verification to move verification to reconcile #6502
refactor trusted resources verification to move verification to reconcile #6502
Conversation
Skipping CI for Draft Pull Request. |
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
7ce383c
to
81ba41c
Compare
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
81ba41c
to
0f4f4ca
Compare
/test all |
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
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.
Looking good! Few more cleanups/clarifications.
TaskName string | ||
Kind v1beta1.TaskKind | ||
TaskSpec *v1beta1.TaskSpec | ||
Task *v1beta1.Task |
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.
Some of this data seems duplicated - e.g. wouldn't TaskSpec/Name be included in Task?
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.
In cases like inline task&taskspec already in status, there is no "task" but we have the "taskSpec", so I think we cannot use task here to replace the other fields? Another reason is try to reduce the code changes
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.
This is a bit confusing though because there are similar pieces of data and it's not clear when to use one over the other. e.g.
- Task.spec vs TaskSpec
- Task.ObjectMeta.Name vs TaskName
- Task.TypeMeta.Kind vs Kind
If these are the same, then we should ideally just use a single type (probably Task). If they're different then we should document the differences and explain when you'd want to use each.
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.
Emmm, I agree there are similar pieces of data, it looks like some data may be contained in other data and this may get people confused.
But we probably cannot use Task.***
to replace TaskSpec
, TaskName
and Kind
(correct me if I'm wrong), take this code for example:
pipeline/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
Lines 678 to 704 in 3d6ec63
if pipelineTask.TaskRef != nil { | |
// If the TaskRun has already a stored TaskSpec in its status, use it as source of truth | |
if taskRun != nil && taskRun.Status.TaskSpec != nil { | |
spec = *taskRun.Status.TaskSpec | |
taskName = pipelineTask.TaskRef.Name | |
} else { | |
// Following minimum status principle (TEP-0100), no need to propagate the RefSource about PipelineTask up to PipelineRun status. | |
// Instead, the child TaskRun's status will be the place recording the RefSource of individual task. | |
t, _, err = getTask(ctx, pipelineTask.TaskRef.Name) | |
switch { | |
case errors.Is(err, remote.ErrRequestInProgress): | |
return v1beta1.TaskSpec{}, "", "", err | |
case errors.Is(err, trustedresources.ErrResourceVerificationFailed): | |
return v1beta1.TaskSpec{}, "", "", err | |
case err != nil: | |
return v1beta1.TaskSpec{}, "", "", &TaskNotFoundError{ | |
Name: pipelineTask.TaskRef.Name, | |
Msg: err.Error(), | |
} | |
default: | |
spec = t.TaskSpec() | |
taskName = t.TaskMetadata().Name | |
} | |
} | |
kind = pipelineTask.TaskRef.Kind | |
} else { | |
spec = pipelineTask.TaskSpec.TaskSpec |
the TaskSpec is from *taskRun.Status.TaskSpec,
the taskName is from pipelineTask.TaskRef.Name and kind is from pipelineTask.TaskRef.Kind. There is no "Task" in the pipeline taskref case,
I will add doc strings for these fields to clarify. And maybe rename the Task
to ReferredTask(since it is not inlined task)
?
vp, err := c.verificationPolicyLister.VerificationPolicies(pr.Namespace).List(labels.Everything()) | ||
if err != nil { | ||
return fmt.Errorf("failed to list VerificationPolicies from namespace %s with error %w", pr.Namespace, err) | ||
} | ||
var refSourceURI string | ||
if pipelineMeta.RefSource != nil { | ||
refSourceURI = pipelineMeta.RefSource.URI | ||
} |
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.
This looks duplicated with the other verify calls. Should we just move this into the verify func if it's always needed?
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.
sure
e747c3a
to
1ed3a35
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
@@ -703,7 +700,7 @@ func resolveTask( | |||
} else { | |||
spec = pipelineTask.TaskSpec.TaskSpec | |||
} | |||
return spec, taskName, kind, err | |||
return spec, taskName, kind, t.DeepCopy(), refSource, err |
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.
Similar to the ResolvedTask object below, could this be simplified to (*v1beta1.Task, *v1beta1.RefSource, error)
?
- task can come from t.TaskSpec
- taskName can come from t.ObjectMeta.Name
- kind can come from t.TypeMeta
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.
Should this also be a ResolvedTask? 🤔
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.
Should this also be a ResolvedTask? 🤔
🤔 Yeah that's a great suggestion, I think we could refactor this part of code a bit
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.
Refactored the code to return a ResolvedTask here
TaskName string | ||
Kind v1beta1.TaskKind | ||
TaskSpec *v1beta1.TaskSpec | ||
Task *v1beta1.Task |
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.
This is a bit confusing though because there are similar pieces of data and it's not clear when to use one over the other. e.g.
- Task.spec vs TaskSpec
- Task.ObjectMeta.Name vs TaskName
- Task.TypeMeta.Kind vs Kind
If these are the same, then we should ideally just use a single type (probably Task). If they're different then we should document the differences and explain when you'd want to use each.
if pipelineMeta != nil { | ||
pipelineToBeVerified = &v1beta1.Pipeline{ | ||
ObjectMeta: *pipelineMeta.ObjectMeta, | ||
Spec: *pipelineSpec, |
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.
These could panic if they're nil (same with taskToBeVerified below)
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.
Did you mean pipelineMeta.ObjectMeta
and pipelineSpec
could be nil? Both of them are from
pipeline/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec.go
Lines 35 to 38 in 54c9b51
func GetPipelineData(ctx context.Context, pipelineRun *v1beta1.PipelineRun, getPipeline GetPipeline) (*resolutionutil.ResolvedObjectMeta, *v1beta1.PipelineSpec, error) { | |
pipelineMeta := metav1.ObjectMeta{} | |
var refSource *v1beta1.RefSource | |
pipelineSpec := v1beta1.PipelineSpec{} |
and they are initialized so I think they cannot be nil?
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.
That's not obvious from this func though 🙃
I think you should change this to:
if pipelineMeta != nil && pipelineSpec != nil {
pipelineToBeVerified = &v1beta1.Pipeline{
ObjectMeta: pipelineMeta.ObjectMeta,
Spec: *pipelineSpec,
}
}
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.
Oh ok, I will update
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
1d2eadc
to
9d1c684
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
TaskName string | ||
Kind v1beta1.TaskKind | ||
TaskSpec *v1beta1.TaskSpec | ||
// PipelineResolvedTask is used to store the Pipeline resolved task for trusted resources verification | ||
PipelineResolvedTask *v1beta1.Task | ||
// RefSource is used to store the RefSource of Pipeline task | ||
RefSource *v1beta1.RefSource |
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.
Same question as before - how should callers interpret the difference between overlapping fields TaskSpec
and PipelineResolvedTask.TaskSpec
, TaskName
and PipelineResolvedTask.Name
, etc.?
if pipelineMeta != nil { | ||
pipelineToBeVerified = &v1beta1.Pipeline{ | ||
ObjectMeta: *pipelineMeta.ObjectMeta, | ||
Spec: *pipelineSpec, |
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.
That's not obvious from this func though 🙃
I think you should change this to:
if pipelineMeta != nil && pipelineSpec != nil {
pipelineToBeVerified = &v1beta1.Pipeline{
ObjectMeta: pipelineMeta.ObjectMeta,
Spec: *pipelineSpec,
}
}
…cile This commit refactor the trusted resources code, move verification logic from GetVerifiedTaskFunc and GetVerifiedPipelineFunc to reconcile. This will help to set the conditions for taskrun/pipelinerun. Signed-off-by: Yongxuan Zhang yongxuanzhang@google.com
9d1c684
to
d5daaab
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
/hold We will try to refactor the code to not block v1 |
Changes
This commit refactor the trusted resources code, move verification logic from GetVerifiedTaskFunc and GetVerifiedPipelineFunc to reconcile. This will help to set the conditions for taskrun/pipelinerun.
/kind misc
Signed-off-by: Yongxuan Zhang yongxuanzhang@google.com
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes