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

Feat/ PreSync mode #270

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
63 changes: 60 additions & 3 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Test
run: make test
Expand All @@ -29,7 +30,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Build
run: make build
Expand All @@ -46,6 +48,32 @@ jobs:
- name: Validate Cluster End State
run: ./testing/validate.sh

integration-test-presync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Build
run: make build

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.10.0

- name: Create Testdata in Cluster
run: ./testing/init.sh

- name: Run PVMigrate
run: ./bin/pvmigrate --source-sc int-source --dest-sc int-dest --pre-sync-mode

- name: Validate Cluster End State
run: ./testing/validate.sh

integration-test-incluster:
runs-on: ubuntu-latest
steps:
Expand All @@ -54,7 +82,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Build and push
uses: docker/build-push-action@v6
Expand All @@ -74,3 +103,31 @@ jobs:

- name: Validate Cluster End State
run: ./testing/validate.sh

# this job will validate that all the tests passed
# it is used for the github branch protection rule
validate-success:
name: Validate success
runs-on: ubuntu-24.04
needs:
- unit-test
- integration-test
- integration-test-presync
- integration-test-incluster
if: always()
steps:
# https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
- name: fail if unit-test job was not successful
if: needs.unit-test.result != 'success'
run: exit 1
- name: fail if integration-test job was not successful
if: needs.integration-test.result != 'success'
run: exit 1
- name: fail if integration-test-presync job was not successful
if: needs.integration-test-presync.result != 'success'
run: exit 1
- name: fail if integration-test-incluster job was not successful
if: needs.integration-test-incluster.result != 'success'
run: exit 1
- name: succeed if everything else passed
run: echo "Validation succeeded"
39 changes: 35 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Test
run: make test
Expand All @@ -28,7 +29,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Build
run: make build
Expand All @@ -45,6 +47,32 @@ jobs:
- name: Validate Cluster End State
run: ./testing/validate.sh

integration-test-presync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Build
run: make build

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.10.0

- name: Create Testdata in Cluster
run: ./testing/init.sh

- name: Run PVMigrate
run: ./bin/pvmigrate --source-sc int-source --dest-sc int-dest --pre-sync-mode

- name: Validate Cluster End State
run: ./testing/validate.sh

integration-test-incluster:
runs-on: ubuntu-latest
steps:
Expand All @@ -53,7 +81,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Build and push
uses: docker/build-push-action@v6
Expand All @@ -80,6 +109,7 @@ jobs:
- unit-test
- integration-test
- integration-test-incluster
- integration-test-presync
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
Expand All @@ -90,7 +120,8 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: 1.22
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
Expand Down
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func main() {
flag.StringVar(&options.Namespace, "namespace", "", "only migrate PVCs within this namespace")
flag.BoolVar(&options.SetDefaults, "set-defaults", false, "change default storage class from source to dest")
flag.BoolVar(&options.VerboseCopy, "verbose-copy", false, "show output from the rsync command used to copy data between PVCs")
flag.BoolVar(&options.PreSyncMode, "pre-sync-mode", false, "create the new PVC and copy the data, then scale down, run another copy and finally swap the PVCs")
flag.BoolVar(&options.SkipSourceValidation, "skip-source-validation", false, "migrate from PVCs using a particular StorageClass name, even if that StorageClass does not exist")
flag.IntVar(&options.MaxPVs, "max-pvs", 0, "maximum number of PVs to process. default to 0 (unlimited)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like an explanation in this as to what happens if the max is exceeded - do you process that number of PVs and then come back for the rest? Do you process that many PVs and then leave the rest? Do you just exit early?

It looks like it's the second option right now but that needs to be communicated

flag.IntVar(&podReadyTimeout, "pod-ready-timeout", 60, "length of time to wait (in seconds) for validation pod(s) to go into Ready phase")
flag.IntVar(&deletePVTimeout, "delete-pv-timeout", 300, "length of time to wait (in seconds) for backing PV to be removed when temporary PVC is deleted")
flag.BoolVar(&skipPreflightValidation, "skip-preflight-validation", false, "skip preflight migration validation on the destination storage provider")
Expand Down
4 changes: 2 additions & 2 deletions pkg/k8sutil/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package k8sutil

import "fmt"

const nameSuffix = "-pvcmigrate"
const PVCNameSuffix = "-pvcmigrate"

// if the length after adding the suffix is more than 253 characters, we need to reduce that to fit within k8s limits
// pruning from the end runs the risk of dropping the '0'/'1'/etc of a statefulset's PVC name
// pruning from the front runs the risk of making a-replica-... and b-replica-... collide
// so this removes characters from the middle of the string
func NewPvcName(originalName string) string {
candidate := originalName + nameSuffix
candidate := originalName + PVCNameSuffix
if len(candidate) <= 253 {
return candidate
}
Expand Down
Loading