-
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
[TEP-0091] update taskrun and pipelinerun condition based on VerificationResult #6757
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ import ( | |
resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common" | ||
remoteresource "github.com/tektoncd/pipeline/pkg/resolution/resource" | ||
"github.com/tektoncd/pipeline/pkg/trustedresources" | ||
"github.com/tektoncd/pipeline/pkg/trustedresources/verifier" | ||
"github.com/tektoncd/pipeline/pkg/workspace" | ||
"github.com/tektoncd/pipeline/test" | ||
"github.com/tektoncd/pipeline/test/diff" | ||
|
@@ -4958,27 +4959,47 @@ spec: | |
status: | ||
podName: the-pod | ||
`, resolverName)) | ||
|
||
failNoMatchCondition := &apis.Condition{ | ||
Type: trustedresources.ConditionTrustedResourcesVerified, | ||
Status: corev1.ConditionFalse, | ||
Message: fmt.Sprintf("failed to get matched policies: %s: no matching policies are found for resource: %s against source: %s", trustedresources.ErrNoMatchedPolicies, ts.Name, ""), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are duplicate messages, will clean up the error handling when the feature is done, added an item #6356 |
||
} | ||
passCondition := &apis.Condition{ | ||
Type: trustedresources.ConditionTrustedResourcesVerified, | ||
Status: corev1.ConditionTrue, | ||
} | ||
failNoKeysCondition := &apis.Condition{ | ||
Type: trustedresources.ConditionTrustedResourcesVerified, | ||
Status: corev1.ConditionFalse, | ||
Message: fmt.Sprintf("failed to get verifiers for resource %s from namespace %s: %s", ts.Name, ts.Namespace, verifier.ErrEmptyPublicKeys), | ||
} | ||
testCases := []struct { | ||
name string | ||
task []*v1beta1.Task | ||
noMatchPolicy string | ||
verificationPolicies []*v1alpha1.VerificationPolicy | ||
name string | ||
task []*v1beta1.Task | ||
noMatchPolicy string | ||
verificationPolicies []*v1alpha1.VerificationPolicy | ||
wantTrustedResourcesCondition *apis.Condition | ||
}{{ | ||
name: "ignore no match policy", | ||
noMatchPolicy: config.IgnoreNoMatchPolicy, | ||
verificationPolicies: noMatchPolicy, | ||
name: "ignore no match policy", | ||
noMatchPolicy: config.IgnoreNoMatchPolicy, | ||
verificationPolicies: noMatchPolicy, | ||
wantTrustedResourcesCondition: nil, | ||
}, { | ||
name: "warn no match policy", | ||
noMatchPolicy: config.WarnNoMatchPolicy, | ||
verificationPolicies: noMatchPolicy, | ||
name: "warn no match policy", | ||
noMatchPolicy: config.WarnNoMatchPolicy, | ||
verificationPolicies: noMatchPolicy, | ||
wantTrustedResourcesCondition: failNoMatchCondition, | ||
}, { | ||
name: "pass enforce policy", | ||
noMatchPolicy: config.FailNoMatchPolicy, | ||
verificationPolicies: vps, | ||
name: "pass enforce policy", | ||
noMatchPolicy: config.FailNoMatchPolicy, | ||
verificationPolicies: vps, | ||
wantTrustedResourcesCondition: passCondition, | ||
}, { | ||
name: "only fail warn policy", | ||
noMatchPolicy: config.FailNoMatchPolicy, | ||
verificationPolicies: warnPolicy, | ||
name: "only fail warn policy", | ||
noMatchPolicy: config.FailNoMatchPolicy, | ||
verificationPolicies: warnPolicy, | ||
wantTrustedResourcesCondition: failNoKeysCondition, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
|
@@ -5018,6 +5039,10 @@ status: | |
if condition != nil && condition.Reason != v1beta1.TaskRunReasonRunning.String() { | ||
t.Errorf("Expected reason %q but was %s", v1beta1.TaskRunReasonRunning.String(), condition.Reason) | ||
} | ||
gotVerificationCondition := reconciledRun.Status.GetCondition(trustedresources.ConditionTrustedResourcesVerified) | ||
if d := cmp.Diff(tc.wantTrustedResourcesCondition, gotVerificationCondition, ignoreLastTransitionTime); d != "" { | ||
t.Error(diff.PrintWantGot(d)) | ||
} | ||
}) | ||
} | ||
} | ||
|
@@ -5122,6 +5147,10 @@ status: | |
if condition.Type != apis.ConditionSucceeded || condition.Status != corev1.ConditionFalse || condition.Reason != podconvert.ReasonResourceVerificationFailed { | ||
t.Errorf("Expected TaskRun to fail with reason \"%s\" but it did not. Final conditions were:\n%#v", podconvert.ReasonResourceVerificationFailed, tr.Status.Conditions) | ||
} | ||
gotVerificationCondition := reconciledRun.Status.GetCondition(trustedresources.ConditionTrustedResourcesVerified) | ||
if gotVerificationCondition == nil || gotVerificationCondition.Status != corev1.ConditionFalse { | ||
t.Errorf("Expected to have false condition, but had %v", gotVerificationCondition) | ||
} | ||
}) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,12 +33,15 @@ import ( | |
"github.com/tektoncd/pipeline/pkg/trustedresources/verifier" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"knative.dev/pkg/apis" | ||
"knative.dev/pkg/logging" | ||
) | ||
|
||
const ( | ||
// SignatureAnnotation is the key of signature in annotation map | ||
SignatureAnnotation = "tekton.dev/signature" | ||
// ConditionTrustedResourcesVerified specifies that the resources pass trusted resources verification or not. | ||
ConditionTrustedResourcesVerified apis.ConditionType = "TrustedResourcesVerified" | ||
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this may not be the best place to put the ConditionType. But I don't know if there are any other places better than this |
||
) | ||
|
||
const ( | ||
|
@@ -191,7 +194,7 @@ func verifyResource(ctx context.Context, resource metav1.Object, k8s kubernetes. | |
for _, p := range warnPolicies { | ||
verifiers, err := verifier.FromPolicy(ctx, k8s, p) | ||
if err != nil { | ||
warn := fmt.Errorf("fails to get verifiers for resource %s from namespace %s: %w", resource.GetName(), resource.GetNamespace(), err) | ||
warn := fmt.Errorf("failed to get verifiers for resource %s from namespace %s: %w", resource.GetName(), resource.GetNamespace(), err) | ||
logger.Warnf(warn.Error()) | ||
return VerificationResult{VerificationResultType: VerificationWarn, Err: warn} | ||
} | ||
|
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.
The same
switch-case
seems to be repeated. Can this be wrapped into a function to avoid repitition?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.
There are 3 places using the same switch, 2 on pipelinerun and 1 on taskrun. The 2 pipelinerun returns are different.
Do you have any suggestions? 🤔
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.
let me try out, I think we could wrap it into a function
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.
The PipelineRuns returns only seem to be happening for the case of
verificationError
. In one case, you returncontroller.New...
and in other case you returnnil, controller.New...
.What if this function returned
error, conditionToSet
? You could catch that and handle it in both cases?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.
Something like?
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.
☝️ is how you would use it well.
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.
Does that work?
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.
Yeah this should work, just pushed the code.