Skip to content

Commit

Permalink
feat: improve node selection, refactor
Browse files Browse the repository at this point in the history
Do lots of refactoring to have better error wrapping, simplify some parts. Reorganize packages, remove internal package.

Improve the node affinity logic. Closes #224.

Signed-off-by: Utku Ozdemir <[email protected]>
  • Loading branch information
utkuozdemir committed Aug 19, 2023
1 parent 1f88348 commit 7c9f2f7
Show file tree
Hide file tree
Showing 44 changed files with 629 additions and 347 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
env:
RICHGO_FORCE_COLOR: "1"
PVMIG_TEST_EXTRA_KUBECONFIG: /home/runner/.kube/kind-2.yaml
run: richgo test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -timeout 20m -v ./...
run: richgo test -tags integration -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -timeout 20m -v ./...
- name: Send coverage
uses: codecov/[email protected]
with:
Expand Down
19 changes: 4 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,16 @@
linters:
enable-all: true
disable:
# deprecated:
# - deadcode
# - exhaustivestruct
# - golint
# - ifshort
# - interfacer
# - maligned
# - nosnakecase
# - scopelint
# - structcheck
# - varcheck
# not useful
- exhaustivestruct
- exhaustruct
- exhaustivestruct # pointless
- exhaustruct # pointless
- gomnd # magic numbers are ok mostly
- goerr113 # no need to wrap all errors, too much work
# breaking things: https://github.com/atc0005/go-ci/issues/1024
- depguard
# todo: consider enabling:
- wrapcheck
- testpackage
- gochecknoglobals
- ireturn

linters-settings:
gci:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ That's it.
## Editing the helm chart

The `pv-migrate` helm chart is located at `helm/pv-migrate`. It is inserted into the go code during build.
The source is a helm package located in `internal/migrator/helm-chart.tgz`.
The source is a helm package located in `migrator/helm-chart.tgz`.

If you want to tweak the helm chart, you must run the following command before recompiling the code in order
to update the chart (you need [helm](https://helm.sh/docs/intro/install/) and [helm-docs](https://github.com/norwoodj/helm-docs) installed):
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tasks:
cmds:
- helm-docs -c helm/pv-migrate/
- helm package helm/pv-migrate/
- mv pv-migrate-*.tgz internal/migrator/helm-chart.tgz
- mv pv-migrate-*.tgz migrator/helm-chart.tgz

clean:
desc: clean
Expand Down
File renamed without changes.
16 changes: 11 additions & 5 deletions internal/app/completion.go → app/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"

"github.com/utkuozdemir/pv-migrate/internal/k8s"
"github.com/utkuozdemir/pv-migrate/k8s"
)

var completionCmdlongDesc = fmt.Sprintf(`To load completions:
Expand Down Expand Up @@ -59,15 +59,21 @@ func buildCompletionCmd() *cobra.Command {
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
var err error

switch args[0] {
case "bash":
return cmd.Root().GenBashCompletion(os.Stdout)
err = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
return cmd.Root().GenZshCompletion(os.Stdout)
err = cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
return cmd.Root().GenFishCompletion(os.Stdout, true)
err = cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
err = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}

if err != nil {
return fmt.Errorf("failed to generate completion script: %w", err)
}

return nil
Expand Down
12 changes: 8 additions & 4 deletions internal/app/migrate.go → app/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

"github.com/utkuozdemir/pv-migrate/engine"
"github.com/utkuozdemir/pv-migrate/internal/ssh"
"github.com/utkuozdemir/pv-migrate/internal/strategy"
"github.com/utkuozdemir/pv-migrate/migration"
"github.com/utkuozdemir/pv-migrate/migrator"
"github.com/utkuozdemir/pv-migrate/ssh"
"github.com/utkuozdemir/pv-migrate/strategy"
)

const (
Expand Down Expand Up @@ -178,7 +178,11 @@ func runMigration(cmd *cobra.Command, args []string) error {
"Extraneous files will be deleted from the destination")
}

return engine.New().Run(&request)
if err := migrator.New().Run(&request); err != nil {
return fmt.Errorf("migration failed: %w", err)
}

return nil
}

func buildSrcPVCInfo(flags *flag.FlagSet, name string) *migration.PVCInfo {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/root.go → app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/spf13/cobra"

applog "github.com/utkuozdemir/pv-migrate/internal/log"
applog "github.com/utkuozdemir/pv-migrate/log"
)

const (
Expand All @@ -25,7 +25,7 @@ func buildRootCmd(version string, commit string, date string) *cobra.Command {
logfmt, _ := f.GetString(FlagLogFormat)
err := applog.Configure(logger, loglvl, logfmt)
if err != nil {
return err
return fmt.Errorf("failed to configure logger: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/pv-migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
// load all auth plugins - needed for gcp, azure etc.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/utkuozdemir/pv-migrate/internal/app"
applog "github.com/utkuozdemir/pv-migrate/internal/log"
"github.com/utkuozdemir/pv-migrate/app"
applog "github.com/utkuozdemir/pv-migrate/log"
)

var (
Expand Down
18 changes: 0 additions & 18 deletions engine/engine.go

This file was deleted.

Loading

0 comments on commit 7c9f2f7

Please sign in to comment.