Merge branch 'main' into deprecate-pvc-node-selection

This commit is contained in:
lyndon-li
2025-09-23 11:39:05 +08:00
committed by GitHub
9 changed files with 126 additions and 42 deletions

View File

@@ -8,18 +8,26 @@ on:
- "design/**" - "design/**"
- "**/*.md" - "**/*.md"
jobs: jobs:
get-go-version:
uses: ./.github/workflows/get-go-version.yaml
with:
ref: ${{ github.event.pull_request.base.ref }}
# Build the Velero CLI and image once for all Kubernetes versions, and cache it so the fan-out workers can get it. # Build the Velero CLI and image once for all Kubernetes versions, and cache it so the fan-out workers can get it.
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: get-go-version
outputs: outputs:
minio-dockerfile-sha: ${{ steps.minio-version.outputs.dockerfile_sha }} minio-dockerfile-sha: ${{ steps.minio-version.outputs.dockerfile_sha }}
steps: steps:
- name: Check out the code - name: Check out the code
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Set up Go
- name: Set up Go version
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: 'go.mod' go-version: ${{ needs.get-go-version.outputs.version }}
# Look for a CLI that's made for this PR # Look for a CLI that's made for this PR
- name: Fetch built CLI - name: Fetch built CLI
id: cli-cache id: cli-cache
@@ -97,6 +105,7 @@ jobs:
needs: needs:
- build - build
- setup-test-matrix - setup-test-matrix
- get-go-version
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: ${{fromJson(needs.setup-test-matrix.outputs.matrix)}} matrix: ${{fromJson(needs.setup-test-matrix.outputs.matrix)}}
@@ -104,10 +113,12 @@ jobs:
steps: steps:
- name: Check out the code - name: Check out the code
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Set up Go
- name: Set up Go version
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: 'go.mod' go-version: ${{ needs.get-go-version.outputs.version }}
# Fetch the pre-built MinIO image from the build job # Fetch the pre-built MinIO image from the build job
- name: Fetch built MinIO Image - name: Fetch built MinIO Image
uses: actions/cache@v4 uses: actions/cache@v4

33
.github/workflows/get-go-version.yaml vendored Normal file
View File

@@ -0,0 +1,33 @@
on:
workflow_call:
inputs:
ref:
description: "The target branch's ref"
required: true
type: string
outputs:
version:
description: "The expected Go version"
value: ${{ jobs.extract.outputs.version }}
jobs:
extract:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.pick-version.outputs.version }}
steps:
- name: Check out the code
uses: actions/checkout@v5
- id: pick-version
run: |
if [ "${{ inputs.ref }}" == "main" ]; then
version=$(grep '^go ' go.mod | awk '{print $2}' | cut -d. -f1-2)
else
goDirectiveVersion=$(grep '^go ' go.mod | awk '{print $2}')
toolChainVersion=$(grep '^toolchain ' go.mod | awk '{print $2}')
version=$(printf "%s\n%s\n" "$goDirectiveVersion" "$toolChainVersion" | sort -V | tail -n1)
fi
echo "version=$version"
echo "version=$version" >> $GITHUB_OUTPUT

View File

@@ -1,18 +1,26 @@
name: Pull Request CI Check name: Pull Request CI Check
on: [pull_request] on: [pull_request]
jobs: jobs:
get-go-version:
uses: ./.github/workflows/get-go-version.yaml
with:
ref: ${{ github.event.pull_request.base.ref }}
build: build:
name: Run CI name: Run CI
needs: get-go-version
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
steps: steps:
- name: Check out the code - name: Check out the code
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Set up Go
- name: Set up Go version
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: 'go.mod' go-version: ${{ needs.get-go-version.outputs.version }}
- name: Make ci - name: Make ci
run: make ci run: make ci
- name: Upload test coverage - name: Upload test coverage

View File

@@ -7,16 +7,24 @@ on:
- "design/**" - "design/**"
- "**/*.md" - "**/*.md"
jobs: jobs:
get-go-version:
uses: ./.github/workflows/get-go-version.yaml
with:
ref: ${{ github.event.pull_request.base.ref }}
build: build:
name: Run Linter Check name: Run Linter Check
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: get-go-version
steps: steps:
- name: Check out the code - name: Check out the code
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Set up Go
- name: Set up Go version
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: 'go.mod' go-version: ${{ needs.get-go-version.outputs.version }}
- name: Linter check - name: Linter check
uses: golangci/golangci-lint-action@v8 uses: golangci/golangci-lint-action@v8
with: with:

View File

@@ -9,17 +9,24 @@ on:
- '*' - '*'
jobs: jobs:
get-go-version:
uses: ./.github/workflows/get-go-version.yaml
with:
ref: ${ github.ref }
build: build:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: get-go-version
steps: steps:
- name: Check out the code - name: Check out the code
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Set up Go
- name: Set up Go version
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: 'go.mod' go-version: ${{ needs.get-go-version.outputs.version }}
- name: Set up QEMU - name: Set up QEMU
id: qemu id: qemu
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3

View File

@@ -0,0 +1 @@
Implement concurrency control for cache of native VolumeSnapshotter plugin.

View File

@@ -366,7 +366,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
discoveryHelper: kb.discoveryHelper, discoveryHelper: kb.discoveryHelper,
podVolumeBackupper: podVolumeBackupper, podVolumeBackupper: podVolumeBackupper,
podVolumeSnapshotTracker: podvolume.NewTracker(), podVolumeSnapshotTracker: podvolume.NewTracker(),
volumeSnapshotterGetter: volumeSnapshotterGetter, volumeSnapshotterCache: NewVolumeSnapshotterCache(volumeSnapshotterGetter),
itemHookHandler: &hook.DefaultItemHookHandler{ itemHookHandler: &hook.DefaultItemHookHandler{
PodCommandExecutor: kb.podCommandExecutor, PodCommandExecutor: kb.podCommandExecutor,
}, },

View File

@@ -70,11 +70,9 @@ type itemBackupper struct {
discoveryHelper discovery.Helper discoveryHelper discovery.Helper
podVolumeBackupper podvolume.Backupper podVolumeBackupper podvolume.Backupper
podVolumeSnapshotTracker *podvolume.Tracker podVolumeSnapshotTracker *podvolume.Tracker
volumeSnapshotterGetter VolumeSnapshotterGetter
kubernetesBackupper *kubernetesBackupper kubernetesBackupper *kubernetesBackupper
volumeSnapshotterCache *VolumeSnapshotterCache
itemHookHandler hook.ItemHookHandler itemHookHandler hook.ItemHookHandler
snapshotLocationVolumeSnapshotters map[string]vsv1.VolumeSnapshotter
hookTracker *hook.HookTracker hookTracker *hook.HookTracker
volumeHelperImpl volumehelper.VolumeHelper volumeHelperImpl volumehelper.VolumeHelper
} }
@@ -502,30 +500,6 @@ func (ib *itemBackupper) executeActions(
return obj, itemFiles, nil return obj, itemFiles, nil
} }
// volumeSnapshotter instantiates and initializes a VolumeSnapshotter given a VolumeSnapshotLocation,
// or returns an existing one if one's already been initialized for the location.
func (ib *itemBackupper) volumeSnapshotter(snapshotLocation *velerov1api.VolumeSnapshotLocation) (vsv1.VolumeSnapshotter, error) {
if bs, ok := ib.snapshotLocationVolumeSnapshotters[snapshotLocation.Name]; ok {
return bs, nil
}
bs, err := ib.volumeSnapshotterGetter.GetVolumeSnapshotter(snapshotLocation.Spec.Provider)
if err != nil {
return nil, err
}
if err := bs.Init(snapshotLocation.Spec.Config); err != nil {
return nil, err
}
if ib.snapshotLocationVolumeSnapshotters == nil {
ib.snapshotLocationVolumeSnapshotters = make(map[string]vsv1.VolumeSnapshotter)
}
ib.snapshotLocationVolumeSnapshotters[snapshotLocation.Name] = bs
return bs, nil
}
// zoneLabelDeprecated is the label that stores availability-zone info // zoneLabelDeprecated is the label that stores availability-zone info
// on PVs this is deprecated on Kubernetes >= 1.17.0 // on PVs this is deprecated on Kubernetes >= 1.17.0
// zoneLabel is the label that stores availability-zone info // zoneLabel is the label that stores availability-zone info
@@ -641,7 +615,7 @@ func (ib *itemBackupper) takePVSnapshot(obj runtime.Unstructured, log logrus.Fie
for _, snapshotLocation := range ib.backupRequest.SnapshotLocations { for _, snapshotLocation := range ib.backupRequest.SnapshotLocations {
log := log.WithField("volumeSnapshotLocation", snapshotLocation.Name) log := log.WithField("volumeSnapshotLocation", snapshotLocation.Name)
bs, err := ib.volumeSnapshotter(snapshotLocation) bs, err := ib.volumeSnapshotterCache.SetNX(snapshotLocation)
if err != nil { if err != nil {
log.WithError(err).Error("Error getting volume snapshotter for volume snapshot location") log.WithError(err).Error("Error getting volume snapshotter for volume snapshot location")
continue continue

View File

@@ -0,0 +1,42 @@
package backup
import (
"sync"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
)
type VolumeSnapshotterCache struct {
cache map[string]vsv1.VolumeSnapshotter
mutex sync.Mutex
getter VolumeSnapshotterGetter
}
func NewVolumeSnapshotterCache(getter VolumeSnapshotterGetter) *VolumeSnapshotterCache {
return &VolumeSnapshotterCache{
cache: make(map[string]vsv1.VolumeSnapshotter),
getter: getter,
}
}
func (c *VolumeSnapshotterCache) SetNX(location *velerov1api.VolumeSnapshotLocation) (vsv1.VolumeSnapshotter, error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if snapshotter, exists := c.cache[location.Name]; exists {
return snapshotter, nil
}
snapshotter, err := c.getter.GetVolumeSnapshotter(location.Spec.Provider)
if err != nil {
return nil, err
}
if err := snapshotter.Init(location.Spec.Config); err != nil {
return nil, err
}
c.cache[location.Name] = snapshotter
return snapshotter, nil
}