Skip to content

Commit

Permalink
Cleanup: addressed various nolint items.
Browse files Browse the repository at this point in the history
- Addressed newly identified `errorlint` items.
- Narrowed `nolint` --> `nolint:gocritic`.
- Removed 2 `nolint` comments by addressing identified issues.
- Also: cleaned up some test code in pipelinerun_test.go.

There are no expected functional changes in this PR.

Context: #5899

/kind cleanup
  • Loading branch information
bendory committed Mar 31, 2023
1 parent b00226c commit 218b106
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
10 changes: 5 additions & 5 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
// Superceded by podTemplate envs
if len(implicitEnvVars) > 0 {
for i, s := range stepContainers {
env := append(implicitEnvVars, s.Env...) //nolint
env := append(implicitEnvVars, s.Env...) // nolint:gocritic
stepContainers[i].Env = env
}
}
Expand All @@ -235,15 +235,15 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
}
if len(podTemplate.Env) > 0 {
for i, s := range stepContainers {
env := append(s.Env, filteredEnvs...) //nolint
env := append(s.Env, filteredEnvs...) // nolint:gocritic
stepContainers[i].Env = env
}
}
// Add env var if hermetic execution was requested & if the alpha API is enabled
if taskRun.Annotations[ExecutionModeAnnotation] == ExecutionModeHermetic && alphaAPIEnabled {
for i, s := range stepContainers {
// Add it at the end so it overrides
env := append(s.Env, corev1.EnvVar{Name: TektonHermeticEnvVar, Value: "1"}) //nolint
env := append(s.Env, corev1.EnvVar{Name: TektonHermeticEnvVar, Value: "1"}) // nolint:gocritic
stepContainers[i].Env = env
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
toAdd = append(toAdd, imp)
}
}
vms := append(s.VolumeMounts, toAdd...) //nolint
vms := append(s.VolumeMounts, toAdd...) // nolint:gocritic
stepContainers[i].VolumeMounts = vms
}

Expand All @@ -301,7 +301,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
toAdd = append(toAdd, imp)
}
}
vms := append(s.VolumeMounts, toAdd...) //nolint
vms := append(s.VolumeMounts, toAdd...) // nolint:gocritic
sidecarContainers[i].VolumeMounts = vms
}
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ spec:
prt := newPipelineRunTest(t, d)
defer prt.Cancel()

wantEvents := append(tc.wantEvents, "Warning InternalError 1 error occurred") //nolint
wantEvents := append(tc.wantEvents, "Warning InternalError 1 error occurred") //nolint:gocritic
reconciledRun, _ := prt.reconcileRun("foo", tc.pipelineRun.Name, wantEvents, tc.permanentError)

if reconciledRun.Status.CompletionTime == nil {
Expand Down Expand Up @@ -7156,11 +7156,15 @@ func checkPipelineRunConditionStatusAndReason(t *testing.T, reconciledRun *v1bet
t.Helper()

condition := reconciledRun.Status.GetCondition(apis.ConditionSucceeded)
if condition == nil || condition.Status != conditionStatus {
t.Errorf("Expected PipelineRun status to be %s, but was %v", conditionStatus, condition)
if condition == nil {
t.Errorf("want condition, got nil")
return
}
if condition.Status != conditionStatus {
t.Errorf("want status %v, got %v", conditionStatus, condition.Status)
}
if condition != nil && condition.Reason != conditionReason {
t.Errorf("Expected reason %s but was %s", conditionReason, condition.Reason)
if condition.Reason != conditionReason {
t.Errorf("want reason %v, got %v", conditionReason, condition.Reason)
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/reconciler/pipelinerun/resources/pipelineref.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func GetVerifiedPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekt
source = s.URI
}
if err := trustedresources.VerifyPipeline(ctx, p, k8s, source, verificationpolicies); err != nil {
return nil, nil, fmt.Errorf("GetVerifiedPipelineFunc failed: %w: %v", trustedresources.ErrResourceVerificationFailed, err)
// FixMe: the below %v should be %w (and the nolint pragma removed)
// but making that change causes e2e test failures.
return nil, nil, fmt.Errorf("GetVerifiedPipelineFunc failed: %w: %v", trustedresources.ErrResourceVerificationFailed, err) // nolint:errorlint
}
return p, s, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/resources/taskref.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func GetVerifiedTaskFunc(ctx context.Context, k8s kubernetes.Interface, tekton c
source = s.URI
}
if err := trustedresources.VerifyTask(ctx, t, k8s, source, verificationpolicies); err != nil {
return nil, nil, fmt.Errorf("GetVerifiedTaskFunc failed: %w: %v", trustedresources.ErrResourceVerificationFailed, err)
return nil, nil, fmt.Errorf("GetVerifiedTaskFunc failed: %w: %v", trustedresources.ErrResourceVerificationFailed, err) // nolint:errorlint
}
return t, s, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/trustedresources/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func fromKeyRef(ctx context.Context, keyRef string, hashAlgorithm crypto.Hash, k
}
raw, err := os.ReadFile(filepath.Clean(keyRef))
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrFailedLoadKeyFile, err) // nolint -- needs errorlint cleanup
return nil, fmt.Errorf("%w: %v", ErrFailedLoadKeyFile, err) // nolint:errorlint
}
v, err := fromData(raw, hashAlgorithm)
if err != nil {
Expand Down Expand Up @@ -136,11 +136,11 @@ func fromSecret(ctx context.Context, secretRef string, hashAlgorithm crypto.Hash
func fromData(raw []byte, hashAlgorithm crypto.Hash) (signature.Verifier, error) {
pubKey, err := cryptoutils.UnmarshalPEMToPublicKey(raw)
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrDecodeKey, err) // nolint -- needs errorlint cleanup
return nil, fmt.Errorf("%w: %v", ErrDecodeKey, err) // nolint:errorlint
}
v, err := signature.LoadVerifier(pubKey, hashAlgorithm)
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrLoadVerifier, err) // nolint -- needs errorlint cleanup
return nil, fmt.Errorf("%w: %v", ErrLoadVerifier, err) // nolint:errorlint
}
return v, nil
}
Expand All @@ -156,7 +156,7 @@ func getKeyPairSecret(ctx context.Context, k8sRef string, k8s kubernetes.Interfa

s, err := k8s.CoreV1().Secrets(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrSecretNotFound, err) // nolint -- needs errorlint cleanup
return nil, fmt.Errorf("%w: %v", ErrSecretNotFound, err) // nolint:errorlint
}

return s, nil
Expand Down
6 changes: 4 additions & 2 deletions pkg/trustedresources/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func getMatchedPolicies(resourceName string, source string, policies []*v1alpha1
for _, r := range p.Spec.Resources {
matching, err := regexp.MatchString(r.Pattern, source)
if err != nil {
return matchedPolicies, fmt.Errorf("%v: %w", err, ErrRegexMatch) // nolint -- needs errorlint cleanup
// FixMe: changing %v to %w breaks integration tests.
return matchedPolicies, fmt.Errorf("%v: %w", err, ErrRegexMatch) // nolint:errorlint
}
if matching {
matchedPolicies = append(matchedPolicies, p)
Expand Down Expand Up @@ -177,7 +178,8 @@ func verifyInterface(obj interface{}, verifier signature.Verifier, signature []b
h.Write(ts)

if err := verifier.VerifySignature(bytes.NewReader(signature), bytes.NewReader(h.Sum(nil))); err != nil {
return fmt.Errorf("%w:%v", ErrResourceVerificationFailed, err.Error()) // nolint -- needs errorlint cleanup
// FixMe: changing %v to %w breaks integration tests.
return fmt.Errorf("%w:%v", ErrResourceVerificationFailed, err.Error()) // nolint:errorlint
}

return nil
Expand Down

0 comments on commit 218b106

Please sign in to comment.