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

Cleanup: addressed various nolint items. 🧹 🧹 🧹 #6477

Merged
merged 1 commit into from
Apr 5, 2023
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
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
13 changes: 8 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 @@ -7157,11 +7157,14 @@ 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.Fatalf("want condition, got nil")
}
if condition != nil && condition.Reason != conditionReason {
t.Errorf("Expected reason %s but was %s", conditionReason, condition.Reason)
if condition.Status != conditionStatus {
t.Errorf("want status %v, got %v", conditionStatus, condition.Status)
}
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
refSource = s.URI
}
if err := trustedresources.VerifyPipeline(ctx, p, k8s, refSource, 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.
bendory marked this conversation as resolved.
Show resolved Hide resolved
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
refSource = s.URI
}
if err := trustedresources.VerifyTask(ctx, t, k8s, refSource, 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