Skip to content

Commit

Permalink
Modify unnecessarily exported methods to unexported
Browse files Browse the repository at this point in the history
  • Loading branch information
kobayashi authored and tekton-robot committed Mar 1, 2021
1 parent 93e368d commit 84a72d4
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 132 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/conversion_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ type CannotConvertError = v1beta1.CannotConvertError

var _ error = (*CannotConvertError)(nil)

// ConvertErrorf creates a CannotConvertError from the field name and format string.
var ConvertErrorf = v1beta1.ConvertErrorf
// convertErrorf creates a CannotConvertError from the field name and format string.
var convertErrorf = v1beta1.ConvertErrorf
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/pipeline_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (sink *PipelineSpec) ConvertFrom(ctx context.Context, source v1beta1.Pipeli
}
// finally clause was introduced in v1beta1 and not available in v1alpha1
if len(source.Finally) > 0 {
return ConvertErrorf(FinallyFieldName, ConversionErrorFieldNotAvailableMsg)
return convertErrorf(FinallyFieldName, ConversionErrorFieldNotAvailableMsg)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (ts *TaskSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
errs = errs.Also(apis.ErrMissingField("steps"))
}
errs = errs.Also(ValidateVolumes(ts.Volumes).ViaField("volumes"))
errs = errs.Also(ValidateDeclaredWorkspaces(ts.Workspaces, ts.Steps, ts.StepTemplate).ViaField("workspaces"))
errs = errs.Also(validateDeclaredWorkspaces(ts.Workspaces, ts.Steps, ts.StepTemplate).ViaField("workspaces"))
mergedSteps, err := MergeStepsWithStepTemplate(ts.StepTemplate, ts.Steps)
if err != nil {
errs = errs.Also(&apis.FieldError{
Expand Down Expand Up @@ -79,7 +79,7 @@ func (tr TaskResult) Validate(_ context.Context) *apis.FieldError {

// a mount path which conflicts with any other declared workspaces, with the explicitly
// declared volume mounts, or with the stepTemplate. The names must also be unique.
func ValidateDeclaredWorkspaces(workspaces []WorkspaceDeclaration, steps []Step, stepTemplate *corev1.Container) (errs *apis.FieldError) {
func validateDeclaredWorkspaces(workspaces []WorkspaceDeclaration, steps []Step, stepTemplate *corev1.Container) (errs *apis.FieldError) {
mountPaths := sets.NewString()
for _, step := range steps {
for _, vm := range step.VolumeMounts {
Expand Down
12 changes: 6 additions & 6 deletions pkg/artifacts/artifact_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
}
defaultStorageClass *string
customStorageClass = "custom-storage-class"
persistentVolumeClaim = GetPersistentVolumeClaim(config.DefaultPVCSize, defaultStorageClass)
persistentVolumeClaim = getPersistentVolumeClaim(config.DefaultPVCSize, defaultStorageClass)
quantityComparer = cmp.Comparer(func(x, y resource.Quantity) bool {
return x.Cmp(y) == 0
})
Expand Down Expand Up @@ -99,7 +99,7 @@ var (
}
)

func GetPersistentVolumeClaim(size string, storageClassName *string) *corev1.PersistentVolumeClaim {
func getPersistentVolumeClaim(size string, storageClassName *string) *corev1.PersistentVolumeClaim {
pvc := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{Name: "pipelineruntest-pvc", Namespace: pipelinerun.Namespace, OwnerReferences: []metav1.OwnerReference{pipelinerun.GetOwnerReference()}},
Spec: corev1.PersistentVolumeClaimSpec{
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestNeedsPVC(t *testing.T) {
ArtifactBucket: artifactBucket,
}
ctx := config.ToContext(context.Background(), &configs)
needed := NeedsPVC(ctx)
needed := needsPVC(ctx)
if needed != c.pvcNeeded {
t.Fatalf("Expected that ConfigMapNeedsPVC would be %t, but was %t", c.pvcNeeded, needed)
}
Expand All @@ -179,7 +179,7 @@ func TestInitializeArtifactStorage(t *testing.T) {
storagetype: "pvc",
expectedArtifactStorage: &storage.ArtifactPVC{
Name: "pipelineruntest",
PersistentVolumeClaim: GetPersistentVolumeClaim("10Gi", defaultStorageClass),
PersistentVolumeClaim: getPersistentVolumeClaim("10Gi", defaultStorageClass),
ShellImage: "busybox",
},
}, {
Expand All @@ -190,7 +190,7 @@ func TestInitializeArtifactStorage(t *testing.T) {
storagetype: "pvc",
expectedArtifactStorage: &storage.ArtifactPVC{
Name: "pipelineruntest",
PersistentVolumeClaim: GetPersistentVolumeClaim("5Gi", &customStorageClass),
PersistentVolumeClaim: getPersistentVolumeClaim("5Gi", &customStorageClass),
ShellImage: "busybox",
},
}, {
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
storageConfig: map[string]string{},
}} {
t.Run(c.desc, func(t *testing.T) {
fakekubeclient := fakek8s.NewSimpleClientset(GetPVCSpec(pipelinerun, persistentVolumeClaim.Spec.Resources.Requests["storage"], defaultStorageClass))
fakekubeclient := fakek8s.NewSimpleClientset(getPVCSpec(pipelinerun, persistentVolumeClaim.Spec.Resources.Requests["storage"], defaultStorageClass))
ab, err := config.NewArtifactBucketFromMap(c.storageConfig)
if err != nil {
t.Fatalf("Error getting an ArtifactBucket from data %s, %s", c.storageConfig, err)
Expand Down
24 changes: 12 additions & 12 deletions pkg/artifacts/artifacts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ func InitializeArtifactStorage(ctx context.Context, images pipeline.Images, pr *
return &ArtifactStorageNone{}, nil
}

if NeedsPVC(ctx) {
if needsPVC(ctx) {
pvc, err := createPVC(ctx, pr, c)
if err != nil {
return nil, err
}
return &storage.ArtifactPVC{Name: pr.Name, PersistentVolumeClaim: pvc, ShellImage: images.ShellImage}, nil
}

return NewArtifactBucketFromConfig(ctx, images), nil
return newArtifactBucketFromConfig(ctx, images), nil
}

// CleanupArtifactStorage will delete the PipelineRun's artifact storage PVC if it exists. The PVC is created for using
// an output workspace or artifacts from one Task to another Task. No other PVCs will be impacted by this cleanup.
func CleanupArtifactStorage(ctx context.Context, pr *v1beta1.PipelineRun, c kubernetes.Interface) error {

if NeedsPVC(ctx) {
if needsPVC(ctx) {
err := deletePVC(ctx, pr, c)
if err != nil {
return err
Expand All @@ -128,9 +128,9 @@ func CleanupArtifactStorage(ctx context.Context, pr *v1beta1.PipelineRun, c kube
return nil
}

// NeedsPVC checks if the Tekton is is configured to use a bucket for artifact storage,
// needsPVC checks if the Tekton is is configured to use a bucket for artifact storage,
// returning true if instead a PVC is needed.
func NeedsPVC(ctx context.Context) bool {
func needsPVC(ctx context.Context) bool {
bucketConfig := config.FromContextOrDefaults(ctx).ArtifactBucket
if bucketConfig == nil {
return true
Expand All @@ -145,14 +145,14 @@ func NeedsPVC(ctx context.Context) bool {
// GetArtifactStorage returns the storage interface to enable
// consumer code to get a container step for copy to/from storage
func GetArtifactStorage(ctx context.Context, images pipeline.Images, prName string, c kubernetes.Interface) ArtifactStorageInterface {
if NeedsPVC(ctx) {
if needsPVC(ctx) {
return &storage.ArtifactPVC{Name: prName, ShellImage: images.ShellImage}
}
return NewArtifactBucketFromConfig(ctx, images)
return newArtifactBucketFromConfig(ctx, images)
}

// NewArtifactBucketFromConfig creates a Bucket from the supplied ConfigMap
func NewArtifactBucketFromConfig(ctx context.Context, images pipeline.Images) *storage.ArtifactBucket {
// newArtifactBucketFromConfig creates a Bucket from the supplied ConfigMap
func newArtifactBucketFromConfig(ctx context.Context, images pipeline.Images) *storage.ArtifactBucket {
c := &storage.ArtifactBucket{
ShellImage: images.ShellImage,
GsutilImage: images.GsutilImage,
Expand Down Expand Up @@ -191,7 +191,7 @@ func createPVC(ctx context.Context, pr *v1beta1.PipelineRun, c kubernetes.Interf
pvcStorageClassName = &pvcConfig.StorageClassName
}

pvcSpec := GetPVCSpec(pr, pvcSize, pvcStorageClassName)
pvcSpec := getPVCSpec(pr, pvcSize, pvcStorageClassName)
pvc, err := c.CoreV1().PersistentVolumeClaims(pr.Namespace).Create(ctx, pvcSpec, metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("failed to claim Persistent Volume %q due to error: %w", pr.Name, err)
Expand All @@ -214,8 +214,8 @@ func deletePVC(ctx context.Context, pr *v1beta1.PipelineRun, c kubernetes.Interf
return nil
}

// GetPVCSpec returns the PVC to create for a given PipelineRun
func GetPVCSpec(pr *v1beta1.PipelineRun, pvcSize resource.Quantity, storageClassName *string) *corev1.PersistentVolumeClaim {
// getPVCSpec returns the PVC to create for a given PipelineRun
func getPVCSpec(pr *v1beta1.PipelineRun, pvcSize resource.Quantity, storageClassName *string) *corev1.PersistentVolumeClaim {
return &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Namespace: pr.Namespace,
Expand Down
8 changes: 4 additions & 4 deletions pkg/contexts/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import "context"
// with a context.Context.
type hdcnKey struct{}

// WithDefaultConfigurationName notes on the context for nested validation
// withDefaultConfigurationName notes on the context for nested validation
// that there is a default configuration name, which affects how an empty
// configurationName is validated.
func WithDefaultConfigurationName(ctx context.Context) context.Context {
func withDefaultConfigurationName(ctx context.Context) context.Context {
return context.WithValue(ctx, hdcnKey{}, struct{}{})
}

// HasDefaultConfigurationName checks to see whether the given context has
// hasDefaultConfigurationName checks to see whether the given context has
// been marked as having a default configurationName.
func HasDefaultConfigurationName(ctx context.Context) bool {
func hasDefaultConfigurationName(ctx context.Context) bool {
return ctx.Value(hdcnKey{}) != nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/contexts/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func TestContexts(t *testing.T) {
want bool
}{{
name: "has default config name",
ctx: WithDefaultConfigurationName(ctx),
check: HasDefaultConfigurationName,
ctx: withDefaultConfigurationName(ctx),
check: hasDefaultConfigurationName,
want: true,
}, {
name: "doesn't have default config name",
ctx: ctx,
check: HasDefaultConfigurationName,
check: hasDefaultConfigurationName,
want: false,
}, {
name: "are upgrading via defaulting",
Expand Down
14 changes: 7 additions & 7 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
if err != nil {
return err
}
ref, err := ShowRef(logger, "HEAD", spec.Path)
ref, err := showRef(logger, "HEAD", spec.Path)
if err != nil {
return err
}
logger.Infof("Successfully cloned %s @ %s (%s) in path %s", trimmedURL, commit, ref, spec.Path)
if spec.Submodules {
if err := SubmoduleFetch(logger, spec); err != nil {
if err := submoduleFetch(logger, spec); err != nil {
return err
}
}
Expand All @@ -183,15 +183,15 @@ func ShowCommit(logger *zap.SugaredLogger, revision, path string) (string, error
return strings.TrimSuffix(output, "\n"), nil
}

func ShowRef(logger *zap.SugaredLogger, revision, path string) (string, error) {
func showRef(logger *zap.SugaredLogger, revision, path string) (string, error) {
output, err := run(logger, path, "show", "-q", "--pretty=format:%D", revision)
if err != nil {
return "", err
}
return strings.TrimSuffix(output, "\n"), nil
}

func SubmoduleFetch(logger *zap.SugaredLogger, spec FetchSpec) error {
func submoduleFetch(logger *zap.SugaredLogger, spec FetchSpec) error {
if spec.Path != "" {
if err := os.Chdir(spec.Path); err != nil {
return fmt.Errorf("failed to change directory with path %s; err: %w", spec.Path, err)
Expand Down Expand Up @@ -270,16 +270,16 @@ func validateGitAuth(logger *zap.SugaredLogger, credsDir, url string) {
if _, err := os.Stat(credsDir + "/.ssh"); os.IsNotExist(err) {
sshCred = false
}
urlSSHFormat := ValidateGitSSHURLFormat(url)
urlSSHFormat := validateGitSSHURLFormat(url)
if sshCred && !urlSSHFormat {
logger.Warnf("SSH credentials have been provided but the URL(%q) is not a valid SSH URL. This warning can be safely ignored if the URL is for a public repo or you are using basic auth", url)
} else if !sshCred && urlSSHFormat {
logger.Warnf("URL(%q) appears to need SSH authentication but no SSH credentials have been provided", url)
}
}

// ValidateGitSSHURLFormat validates the given URL format is SSH or not
func ValidateGitSSHURLFormat(url string) bool {
// validateGitSSHURLFormat validates the given URL format is SSH or not
func validateGitSSHURLFormat(url string) bool {
if sshURLRegexFormat.MatchString(url) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestValidateGitSSHURLFormat(t *testing.T) {
}

for _, tt := range tests {
got := ValidateGitSSHURLFormat(tt.url)
got := validateGitSSHURLFormat(tt.url)
if got != tt.want {
t.Errorf("Validate URL(%v)'s SSH format got %v, want %v", tt.url, got, tt.want)
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (
ReasonPodCreationFailed = "PodCreationFailed"

// ReasonPending indicates that the pod is in corev1.Pending, and the reason is not
// ReasonExceededNodeResources or IsPodHitConfigError
// ReasonExceededNodeResources or isPodHitConfigError
ReasonPending = "Pending"

//timeFormat is RFC3339 with millisecond
Expand Down Expand Up @@ -100,7 +100,7 @@ func MakeTaskRunStatus(logger *zap.SugaredLogger, tr v1beta1.TaskRun, pod *corev
trs := &tr.Status
if trs.GetCondition(apis.ConditionSucceeded) == nil || trs.GetCondition(apis.ConditionSucceeded).Status == corev1.ConditionUnknown {
// If the taskRunStatus doesn't exist yet, it's because we just started running
MarkStatusRunning(trs, v1beta1.TaskRunReasonRunning.String(), "Not all Steps in the Task have finished executing")
markStatusRunning(trs, v1beta1.TaskRunReasonRunning.String(), "Not all Steps in the Task have finished executing")
}

sortPodContainerStatuses(pod.Status.ContainerStatuses, pod.Spec.Containers)
Expand Down Expand Up @@ -271,9 +271,9 @@ func extractStartedAtTimeFromResults(results []v1beta1.PipelineResourceResult) (
func updateCompletedTaskRunStatus(logger *zap.SugaredLogger, trs *v1beta1.TaskRunStatus, pod *corev1.Pod) {
if DidTaskRunFail(pod) {
msg := getFailureMessage(logger, pod)
MarkStatusFailure(trs, v1beta1.TaskRunReasonFailed.String(), msg)
markStatusFailure(trs, v1beta1.TaskRunReasonFailed.String(), msg)
} else {
MarkStatusSuccess(trs)
markStatusSuccess(trs)
}

// update tr completed time
Expand All @@ -283,15 +283,15 @@ func updateCompletedTaskRunStatus(logger *zap.SugaredLogger, trs *v1beta1.TaskRu
func updateIncompleteTaskRunStatus(trs *v1beta1.TaskRunStatus, pod *corev1.Pod) {
switch pod.Status.Phase {
case corev1.PodRunning:
MarkStatusRunning(trs, v1beta1.TaskRunReasonRunning.String(), "Not all Steps in the Task have finished executing")
markStatusRunning(trs, v1beta1.TaskRunReasonRunning.String(), "Not all Steps in the Task have finished executing")
case corev1.PodPending:
switch {
case IsPodExceedingNodeResources(pod):
MarkStatusRunning(trs, ReasonExceededNodeResources, "TaskRun Pod exceeded available resources")
case IsPodHitConfigError(pod):
MarkStatusFailure(trs, ReasonCreateContainerConfigError, "Failed to create pod due to config error")
markStatusRunning(trs, ReasonExceededNodeResources, "TaskRun Pod exceeded available resources")
case isPodHitConfigError(pod):
markStatusFailure(trs, ReasonCreateContainerConfigError, "Failed to create pod due to config error")
default:
MarkStatusRunning(trs, ReasonPending, getWaitingMessage(pod))
markStatusRunning(trs, ReasonPending, getWaitingMessage(pod))
}
}
}
Expand Down Expand Up @@ -374,8 +374,8 @@ func IsPodExceedingNodeResources(pod *corev1.Pod) bool {
return false
}

// IsPodHitConfigError returns true if the Pod's status undicates there are config error raised
func IsPodHitConfigError(pod *corev1.Pod) bool {
// isPodHitConfigError returns true if the Pod's status undicates there are config error raised
func isPodHitConfigError(pod *corev1.Pod) bool {
for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.State.Waiting != nil && containerStatus.State.Waiting.Reason == ReasonCreateContainerConfigError {
return true
Expand Down Expand Up @@ -411,8 +411,8 @@ func getWaitingMessage(pod *corev1.Pod) string {
return "Pending"
}

// MarkStatusRunning sets taskrun status to running
func MarkStatusRunning(trs *v1beta1.TaskRunStatus, reason, message string) {
// markStatusRunning sets taskrun status to running
func markStatusRunning(trs *v1beta1.TaskRunStatus, reason, message string) {
trs.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionUnknown,
Expand All @@ -421,8 +421,8 @@ func MarkStatusRunning(trs *v1beta1.TaskRunStatus, reason, message string) {
})
}

// MarkStatusFailure sets taskrun status to failure with specified reason
func MarkStatusFailure(trs *v1beta1.TaskRunStatus, reason string, message string) {
// markStatusFailure sets taskrun status to failure with specified reason
func markStatusFailure(trs *v1beta1.TaskRunStatus, reason string, message string) {
trs.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionFalse,
Expand All @@ -431,8 +431,8 @@ func MarkStatusFailure(trs *v1beta1.TaskRunStatus, reason string, message string
})
}

// MarkStatusSuccess sets taskrun status to success
func MarkStatusSuccess(trs *v1beta1.TaskRunStatus) {
// markStatusSuccess sets taskrun status to success
func markStatusSuccess(trs *v1beta1.TaskRunStatus) {
trs.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: corev1.ConditionTrue,
Expand Down
Loading

0 comments on commit 84a72d4

Please sign in to comment.