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

organize utils and remove unused ones #4602

Merged
merged 3 commits into from
Oct 13, 2024
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
3 changes: 2 additions & 1 deletion cmd/cli/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"github.com/spf13/viper"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/hook"
"github.com/bacalhau-project/bacalhau/pkg/config"
"github.com/bacalhau-project/bacalhau/pkg/config/types"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var setExample = templates.Examples(i18n.T(`
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/devstack/devstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/webui"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/pkg/devstack"
"github.com/bacalhau-project/bacalhau/pkg/telemetry"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"

"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/docker/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/spf13/viper"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/cli/helpers"
"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
Expand All @@ -20,7 +22,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
clientv2 "github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/userstrings"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/util/idgen"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/output"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/output"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/util/idgen"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var executionsOrderByFields = []string{"modified_at", "created_at"}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"github.com/spf13/viper"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/configflags"
"github.com/bacalhau-project/bacalhau/cmd/util/hook"
"github.com/bacalhau-project/bacalhau/pkg/config/types"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/cols"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/output"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/output"
Expand All @@ -18,7 +20,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/util/idgen"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var orderByFields = []string{"id", "created_at"}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/cliflags"
"github.com/bacalhau-project/bacalhau/cmd/util/printer"
"github.com/bacalhau-project/bacalhau/pkg/userstrings"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/printer"
"github.com/bacalhau-project/bacalhau/pkg/bacerrors"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/job/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/pkg/lib/marshaller"
"github.com/bacalhau-project/bacalhau/pkg/userstrings"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/spf13/viper"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags/configflags"
"github.com/bacalhau-project/bacalhau/pkg/analytics"
Expand All @@ -23,7 +25,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/repo"
"github.com/bacalhau-project/bacalhau/pkg/setup"
"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
"github.com/bacalhau-project/bacalhau/pkg/version"
"github.com/bacalhau-project/bacalhau/webui"
)
Expand Down
12 changes: 0 additions & 12 deletions cmd/cli/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/setup"

"github.com/bacalhau-project/bacalhau/pkg/docker"
"github.com/bacalhau-project/bacalhau/pkg/lib/marshaller"
"github.com/bacalhau-project/bacalhau/pkg/lib/network"

cmd2 "github.com/bacalhau-project/bacalhau/cmd/cli"
"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/bacalhau-project/bacalhau/pkg/types"
"github.com/bacalhau-project/bacalhau/pkg/util/closer"
)

Expand Down Expand Up @@ -170,16 +168,6 @@ func (s *ServeSuite) curlEndpoint(URL string) ([]byte, int, error) {
}
return responseText, resp.StatusCode, nil
}
func (s *ServeSuite) TestHealthcheck() {
port, _ := s.serve()
healthzText, statusCode, err := s.curlEndpoint(fmt.Sprintf("http://127.0.0.1:%d/api/v1/healthz", port))
s.Require().NoError(err)

var healthzJSON types.HealthInfo
s.Require().NoError(marshaller.JSONUnmarshalWithMax(healthzText, &healthzJSON), "Error unmarshalling healthz JSON.")
s.Require().Greater(int(healthzJSON.DiskFreeSpace.ROOT.All), 0, "Did not report DiskFreeSpace > 0.")
s.Require().Equal(http.StatusOK, statusCode, "Did not return 200 OK.")
}

func (s *ServeSuite) TestCanSubmitJob() {
docker.MustHaveDocker(s.T())
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/wasm/wasm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"k8s.io/kubectl/pkg/util/i18n"

"k8s.io/kubectl/pkg/util/templates"

"github.com/bacalhau-project/bacalhau/cmd/cli/helpers"
"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/cmd/util/flags"
Expand All @@ -32,7 +34,6 @@ import (
storage_ipfs "github.com/bacalhau-project/bacalhau/pkg/storage/ipfs"
"github.com/bacalhau-project/bacalhau/pkg/userstrings"
"github.com/bacalhau-project/bacalhau/pkg/util/closer"
"github.com/bacalhau-project/bacalhau/pkg/util/templates"
)

var (
Expand Down
10 changes: 5 additions & 5 deletions pkg/executor/wasm/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/lib/math"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/telemetry"
"github.com/bacalhau-project/bacalhau/pkg/util/generic"

"github.com/bacalhau-project/bacalhau/pkg/bidstrategy"
"github.com/bacalhau-project/bacalhau/pkg/executor"
wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models"
wasmlogs "github.com/bacalhau-project/bacalhau/pkg/logger/wasm"
"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/filefs"
wasmlogs "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/logger"
"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/mountfs"
"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/touchfs"
"github.com/bacalhau-project/bacalhau/pkg/storage"
"github.com/bacalhau-project/bacalhau/pkg/storage/util"
"github.com/bacalhau-project/bacalhau/pkg/util/filefs"
"github.com/bacalhau-project/bacalhau/pkg/util/generic"
"github.com/bacalhau-project/bacalhau/pkg/util/mountfs"
"github.com/bacalhau-project/bacalhau/pkg/util/touchfs"
)

type Executor struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/bacalhau-project/bacalhau/pkg/executor"
wasmmodels "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/models"
wasmlogs "github.com/bacalhau-project/bacalhau/pkg/logger/wasm"
wasmlogs "github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/logger"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/storage"
"github.com/bacalhau-project/bacalhau/pkg/telemetry"
Expand Down
14 changes: 0 additions & 14 deletions pkg/util/filefs/fs.go → pkg/executor/wasm/util/filefs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,3 @@ func (f fileFs) Open(name string) (fs.File, error) {
return nil, os.ErrNotExist
}
}

func IsWritable(path string) (bool, error) {
tmpFile := "tmpfile"

file, err := os.CreateTemp(path, tmpFile)
if err != nil {
return false, err
}

defer os.Remove(file.Name())
defer file.Close()

return true, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/generic"
_ "github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/util/generic"
)

type BroadcasterTestSuite struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"testing"
"time"

_ "github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/util/generic"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/generic"
_ "github.com/bacalhau-project/bacalhau/pkg/logger"
)

type RingBufferTestSuite struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

"github.com/rs/zerolog/log"

"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/generic"
"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/util"
"github.com/bacalhau-project/bacalhau/pkg/util/generic"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"io"
"os"

"github.com/bacalhau-project/bacalhau/pkg/util/generic"
"github.com/rs/zerolog/log"

"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/generic"
)

const (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package wasmlogs

import "github.com/bacalhau-project/bacalhau/pkg/util/generic"
import (
"github.com/bacalhau-project/bacalhau/pkg/executor/wasm/util/generic"
)

type LogWriterTransform func([]byte) *LogMessage

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions pkg/ipfs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import (
ma "github.com/multiformats/go-multiaddr"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/samber/lo"

"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/bacalhau-project/bacalhau/pkg/util/generic"
"github.com/bacalhau-project/bacalhau/pkg/util/multiaddresses"
)

// Client is a front-end for an ipfs node's API endpoints
Expand Down Expand Up @@ -95,7 +94,7 @@ func (cl Client) SwarmMultiAddresses(ctx context.Context) ([]ma.Multiaddr, error
return nil, fmt.Errorf("error fetching node's swarm addresses: %w", err)
}

addrs = generic.Map(addrs, func(f ma.Multiaddr) ma.Multiaddr {
addrs = lo.Map(addrs, func(f ma.Multiaddr, _ int) ma.Multiaddr {
return f.Encapsulate(p2pID)
})

Expand All @@ -117,9 +116,9 @@ func (cl Client) SwarmAddresses(ctx context.Context) ([]string, error) {
// This sorts the addresses so IPv4 localhost is first, with the aim of using the localhost connection during tests
// and so avoid any unneeded network hops. Other callers to this either sort the list themselves or just output the
// full list.
multiAddresses = multiaddresses.SortLocalhostFirst(multiAddresses)
multiAddresses = SortLocalhostFirst(multiAddresses)

addresses := generic.Map(multiAddresses, func(f ma.Multiaddr) string {
addresses := lo.Map(multiAddresses, func(f ma.Multiaddr, _ int) string {
return f.String()
})

Expand Down
Loading
Loading