Skip to content

Commit

Permalink
Cleanup unused arguments - mostly removing unused ctx 🧹
Browse files Browse the repository at this point in the history
In this change, we cleanup unused arguments in functions, mostly
removing unused "ctx".
  • Loading branch information
jerop authored and tekton-robot committed Jun 23, 2022
1 parent 3aab18c commit 5663279
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 36 deletions.
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1beta1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type PropertySpec struct {
}

// SetDefaults set the default type
func (pp *ParamSpec) SetDefaults(ctx context.Context) {
func (pp *ParamSpec) SetDefaults(context.Context) {
if pp == nil {
return
}
Expand All @@ -72,11 +72,11 @@ func (pp *ParamSpec) SetDefaults(ctx context.Context) {
switch {
case pp.Type != "":
// If param type is provided by the author, do nothing but just set default type for PropertySpec in case `properties` section is provided.
pp.setDefaultsForProperties(ctx)
pp.setDefaultsForProperties()
case pp.Properties != nil:
pp.Type = ParamTypeObject
// Also set default type for PropertySpec
pp.setDefaultsForProperties(ctx)
pp.setDefaultsForProperties()
case pp.Default == nil:
// ParamTypeString is the default value (when no type can be inferred from the default value)
pp.Type = ParamTypeString
Expand All @@ -92,7 +92,7 @@ func (pp *ParamSpec) SetDefaults(ctx context.Context) {
}

// setDefaultsForProperties sets default type for PropertySpec (string) if it's not specified
func (pp *ParamSpec) setDefaultsForProperties(ctx context.Context) {
func (pp *ParamSpec) setDefaultsForProperties() {
for key, propertySpec := range pp.Properties {
if propertySpec.Type == "" {
pp.Properties[key] = PropertySpec{Type: ParamTypeString}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipelinerun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (ps *PipelineRunSpec) Validate(ctx context.Context) (errs *apis.FieldError)
}
}

errs = errs.Also(validateSpecStatus(ctx, ps.Status))
errs = errs.Also(validateSpecStatus(ps.Status))

if ps.Workspaces != nil {
wsNames := make(map[string]int)
Expand All @@ -117,7 +117,7 @@ func (ps *PipelineRunSpec) Validate(ctx context.Context) (errs *apis.FieldError)
return errs
}

func validateSpecStatus(ctx context.Context, status PipelineRunSpecStatus) *apis.FieldError {
func validateSpecStatus(status PipelineRunSpecStatus) *apis.FieldError {
switch status {
case "":
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/resource_types_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// Validate implements apis.Validatable
func (tr *TaskResources) Validate(ctx context.Context) (errs *apis.FieldError) {
func (tr *TaskResources) Validate(context.Context) (errs *apis.FieldError) {
if tr != nil {
errs = errs.Also(validateTaskResources(tr.Inputs).ViaField("inputs"))
errs = errs.Also(validateTaskResources(tr.Outputs).ViaField("outputs"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/result_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package v1beta1
import "context"

// SetDefaults set the default type for TaskResult
func (tr *TaskResult) SetDefaults(ctx context.Context) {
func (tr *TaskResult) SetDefaults(context.Context) {
if tr != nil && tr.Type == "" {
// ResultsTypeString is the default value
tr.Type = ResultsTypeString
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/workspace_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var allVolumeSourceFields = []string{
// Validate looks at the Volume provided in wb and makes sure that it is valid.
// This means that only one VolumeSource can be specified, and also that the
// supported VolumeSource is itself valid.
func (b *WorkspaceBinding) Validate(ctx context.Context) *apis.FieldError {
func (b *WorkspaceBinding) Validate(context.Context) *apis.FieldError {
if equality.Semantic.DeepEqual(b, &WorkspaceBinding{}) || b == nil {
return apis.ErrMissingField(apis.CurrentField)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/internal/limitrange/limitrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ limitations under the License.
package limitrange

import (
"context"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/labels"
corev1listers "k8s.io/client-go/listers/core/v1"
)

func getVirtualLimitRange(ctx context.Context, namespace string, lister corev1listers.LimitRangeLister) (*corev1.LimitRange, error) {
func getVirtualLimitRange(namespace string, lister corev1listers.LimitRangeLister) (*corev1.LimitRange, error) {
limitRanges, err := lister.LimitRanges(namespace).List(labels.Everything())
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/limitrange/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func isZero(q resource.Quantity) bool {
// NewTransformer returns a pod.Transformer that will modify limits if needed
func NewTransformer(ctx context.Context, namespace string, lister corev1listers.LimitRangeLister) pod.Transformer {
return func(p *corev1.Pod) (*corev1.Pod, error) {
limitRange, err := getVirtualLimitRange(ctx, namespace, lister)
limitRange, err := getVirtualLimitRange(namespace, lister)
if err != nil {
return p, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1beta1.TaskRun) pkg
}

// Check for Pod Failures
if failed, reason, message := c.checkPodFailed(ctx, tr); failed {
if failed, reason, message := c.checkPodFailed(tr); failed {
err := c.failTaskRun(ctx, tr, reason, message)
return c.finishReconcileUpdateEmitEvents(ctx, tr, before, err)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1beta1.TaskRun) pkg
return nil
}

func (c *Reconciler) checkPodFailed(ctx context.Context, tr *v1beta1.TaskRun) (bool, v1beta1.TaskRunReason, string) {
func (c *Reconciler) checkPodFailed(tr *v1beta1.TaskRun) (bool, v1beta1.TaskRunReason, string) {
for index, step := range tr.Status.Steps {
if step.Waiting != nil && step.Waiting.Reason == "ImagePullBackOff" {
image := tr.Status.TaskSpec.Steps[index].Image
Expand Down Expand Up @@ -264,7 +264,7 @@ func (c *Reconciler) stopSidecars(ctx context.Context, tr *v1beta1.TaskRun) erro
// Check if any SidecarStatuses are still shown as Running after stopping
// Sidecars. If any Running, update SidecarStatuses based on Pod ContainerStatuses.
if podconvert.IsSidecarStatusRunning(tr) {
err = updateStoppedSidecarStatus(ctx, pod, tr, c)
err = updateStoppedSidecarStatus(pod, tr)
}
}
if k8serrors.IsNotFound(err) {
Expand Down Expand Up @@ -360,7 +360,7 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1
return nil, nil, controller.NewPermanentError(err)
}

if err := validateTaskSpecRequestResources(ctx, taskSpec); err != nil {
if err := validateTaskSpecRequestResources(taskSpec); err != nil {
logger.Errorf("TaskRun %s taskSpec request resources are invalid: %v", tr.Name, err)
tr.Status.MarkResourceFailed(podconvert.ReasonFailedValidation, err)
return nil, nil, controller.NewPermanentError(err)
Expand Down Expand Up @@ -392,7 +392,7 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1
}
}

if err := validateOverrides(ctx, taskSpec, &tr.Spec); err != nil {
if err := validateOverrides(taskSpec, &tr.Spec); err != nil {
logger.Errorf("TaskRun %q step or sidecar overrides are invalid: %v", tr.Name, err)
tr.Status.MarkResourceFailed(podconvert.ReasonFailedValidation, err)
return nil, nil, controller.NewPermanentError(err)
Expand Down Expand Up @@ -471,7 +471,7 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1beta1.TaskRun, rtr *re
}
pod, err = c.createPod(ctx, ts, tr, rtr)
if err != nil {
newErr := c.handlePodCreationError(ctx, tr, err)
newErr := c.handlePodCreationError(tr, err)
logger.Errorf("Failed to create task run pod for taskrun %q: %v", tr.Name, newErr)
return newErr
}
Expand Down Expand Up @@ -562,7 +562,7 @@ func (c *Reconciler) updateLabelsAndAnnotations(ctx context.Context, tr *v1beta1
return newTr, nil
}

func (c *Reconciler) handlePodCreationError(ctx context.Context, tr *v1beta1.TaskRun, err error) error {
func (c *Reconciler) handlePodCreationError(tr *v1beta1.TaskRun, err error) error {
switch {
case isExceededResourceQuotaError(err):
// If we are struggling to create the pod, then it hasn't started.
Expand Down Expand Up @@ -767,7 +767,7 @@ func resourceImplBinding(resources map[string]*resourcev1alpha1.PipelineResource

// updateStoppedSidecarStatus updates SidecarStatus for sidecars that were
// terminated by nop image
func updateStoppedSidecarStatus(ctx context.Context, pod *corev1.Pod, tr *v1beta1.TaskRun, c *Reconciler) error {
func updateStoppedSidecarStatus(pod *corev1.Pod, tr *v1beta1.TaskRun) error {
tr.Status.Sidecars = []v1beta1.SidecarState{}
for _, s := range pod.Status.ContainerStatuses {
if !podconvert.IsContainerStep(s.Name) {
Expand Down
13 changes: 5 additions & 8 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ status:
}}
for _, tc := range testcases {
t.Run(tc.description, func(t *testing.T) {
c.handlePodCreationError(testAssets.Ctx, taskRun, tc.err)
c.handlePodCreationError(taskRun, tc.err)
foundCondition := false
for _, cond := range taskRun.Status.Conditions {
if cond.Type == tc.expectedType && cond.Status == tc.expectedStatus && cond.Reason == tc.expectedReason {
Expand Down Expand Up @@ -4132,8 +4132,6 @@ status:
}

func Test_validateTaskSpecRequestResources_ValidResources(t *testing.T) {
ctx := context.Background()

tcs := []struct {
name string
taskSpec *v1beta1.TaskSpec
Expand Down Expand Up @@ -4238,7 +4236,7 @@ func Test_validateTaskSpecRequestResources_ValidResources(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
if err := validateTaskSpecRequestResources(ctx, tc.taskSpec); err != nil {
if err := validateTaskSpecRequestResources(tc.taskSpec); err != nil {
t.Fatalf("Expected to see error when validating invalid TaskSpec resources but saw none")
}
})
Expand All @@ -4247,7 +4245,6 @@ func Test_validateTaskSpecRequestResources_ValidResources(t *testing.T) {
}

func Test_validateTaskSpecRequestResources_InvalidResources(t *testing.T) {
ctx := context.Background()
tcs := []struct {
name string
taskSpec *v1beta1.TaskSpec
Expand Down Expand Up @@ -4294,7 +4291,7 @@ func Test_validateTaskSpecRequestResources_InvalidResources(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
if err := validateTaskSpecRequestResources(ctx, tc.taskSpec); err == nil {
if err := validateTaskSpecRequestResources(tc.taskSpec); err == nil {
t.Fatalf("Expected to see error when validating invalid TaskSpec resources but saw none")
}
})
Expand Down Expand Up @@ -4347,7 +4344,7 @@ func podVolumeMounts(idx, totalSteps int) []corev1.VolumeMount {
return mnts
}

func podArgs(stepName string, cmd string, additionalArgs []string, idx int) []string {
func podArgs(cmd string, additionalArgs []string, idx int) []string {
args := []string{
"-wait_file",
}
Expand Down Expand Up @@ -4452,7 +4449,7 @@ func expectedPod(podName, taskName, taskRunName, ns, saName string, isClusterTas
VolumeMounts: podVolumeMounts(idx, len(steps)),
TerminationMessagePath: "/tekton/termination",
}
stepContainer.Args = podArgs(s.name, s.cmd, s.args, idx)
stepContainer.Args = podArgs(s.cmd, s.args, idx)

for k, v := range s.envVars {
stepContainer.Env = append(stepContainer.Env, corev1.EnvVar{
Expand Down
12 changes: 6 additions & 6 deletions pkg/reconciler/taskrun/validate_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func ValidateResolvedTaskResources(ctx context.Context, params []v1beta1.Param,
return nil
}

func validateTaskSpecRequestResources(ctx context.Context, taskSpec *v1beta1.TaskSpec) error {
func validateTaskSpecRequestResources(taskSpec *v1beta1.TaskSpec) error {
if taskSpec != nil {
for _, step := range taskSpec.Steps {
for k, request := range step.Resources.Requests {
Expand All @@ -250,13 +250,13 @@ func validateTaskSpecRequestResources(ctx context.Context, taskSpec *v1beta1.Tas
}

// validateOverrides validates that all stepOverrides map to valid steps, and likewise for sidecarOverrides
func validateOverrides(ctx context.Context, ts *v1beta1.TaskSpec, trs *v1beta1.TaskRunSpec) error {
stepErr := validateStepOverrides(ctx, ts, trs)
sidecarErr := validateSidecarOverrides(ctx, ts, trs)
func validateOverrides(ts *v1beta1.TaskSpec, trs *v1beta1.TaskRunSpec) error {
stepErr := validateStepOverrides(ts, trs)
sidecarErr := validateSidecarOverrides(ts, trs)
return multierror.Append(stepErr, sidecarErr).ErrorOrNil()
}

func validateStepOverrides(ctx context.Context, ts *v1beta1.TaskSpec, trs *v1beta1.TaskRunSpec) error {
func validateStepOverrides(ts *v1beta1.TaskSpec, trs *v1beta1.TaskRunSpec) error {
var err error
stepNames := sets.NewString()
for _, step := range ts.Steps {
Expand All @@ -270,7 +270,7 @@ func validateStepOverrides(ctx context.Context, ts *v1beta1.TaskSpec, trs *v1bet
return err
}

func validateSidecarOverrides(ctx context.Context, ts *v1beta1.TaskSpec, trs *v1beta1.TaskRunSpec) error {
func validateSidecarOverrides(ts *v1beta1.TaskSpec, trs *v1beta1.TaskRunSpec) error {
var err error
sidecarNames := sets.NewString()
for _, sidecar := range ts.Sidecars {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/validate_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func TestValidateOverrides(t *testing.T) {
}}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
err := validateOverrides(context.Background(), tc.ts, tc.trs)
err := validateOverrides(tc.ts, tc.trs)
if (err != nil) != tc.wantErr {
t.Errorf("expected err: %t, but got err %s", tc.wantErr, err)
}
Expand Down

0 comments on commit 5663279

Please sign in to comment.