Add priority class support for Velero server and node-agent

- Add --server-priority-class-name and --node-agent-priority-class-name flags to velero install command
- Configure data mover pods (PVB/PVR/DataUpload/DataDownload) to use priority class from node-agent-configmap
- Configure maintenance jobs to use priority class from repo-maintenance-job-configmap (global config only)
- Add priority class validation with ValidatePriorityClass and GetDataMoverPriorityClassName utilities
- Update e2e tests to include PriorityClass testing utilities
- Move priority class design document to Implemented folder
- Add comprehensive unit tests for all priority class implementations
- Update documentation for priority class configuration
- Add changelog entry for #8883

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

remove unused test utils

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

feat: add unit test for getting priority class name in maintenance jobs

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

doc update

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

feat: add priority class validation for repository maintenance jobs

- Add ValidatePriorityClassWithClient function to validate priority class existence
- Integrate validation in maintenance.go when creating maintenance jobs
- Update tests to cover the new validation functionality
- Return boolean from ValidatePriorityClass to allow fallback behavior

This ensures maintenance jobs don't fail due to non-existent priority classes,
following the same pattern used for data mover pods.

Addresses feedback from:
https://github.com/vmware-tanzu/velero/pull/8883#discussion_r2238681442

Refs #8869

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

refactor: clean up priority class handling for data mover pods

- Fix comment in node_agent.go to clarify PriorityClassName is only for data mover pods
- Simplify server.go to use dataPathConfigs.PriorityClassName directly
- Remove redundant priority class logging from controllers as it's already logged during server startup
- Keep logging centralized in the node-agent server initialization

This reduces code duplication and clarifies the scope of priority class configuration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

refactor: remove GetDataMoverPriorityClassName from kube utilities

Remove GetDataMoverPriorityClassName function and its tests as priority
class is now read directly from dataPathConfigs instead of parsing from
ConfigMap. This simplifies the codebase by eliminating the need for
indirect ConfigMap parsing.

Refs #8869

🤖 Generated with [Claude Code](https://claude.ai/code)

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>

refactor: remove priority class validation from install command

Remove priority class validation during install as it's redundant
since validation already occurs during server startup. Users cannot
see console logs during install, making the validation warnings
ineffective at this stage.

The validation remains in place during server and node-agent startup
where it's more appropriate and visible to users.

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Tiger Kaovilai
2025-04-25 00:56:11 -04:00
parent a410c316d3
commit 35d2cc0890
40 changed files with 1732 additions and 153 deletions

View File

@@ -0,0 +1,64 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"context"
"github.com/sirupsen/logrus"
schedulingv1 "k8s.io/api/scheduling/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// ValidatePriorityClass checks if the specified priority class exists in the cluster
// Returns true if the priority class exists or if priorityClassName is empty
// Returns false if the priority class doesn't exist or validation fails
// Logs warnings when the priority class doesn't exist
func ValidatePriorityClass(ctx context.Context, kubeClient kubernetes.Interface, priorityClassName string, logger logrus.FieldLogger) bool {
if priorityClassName == "" {
return true
}
_, err := kubeClient.SchedulingV1().PriorityClasses().Get(ctx, priorityClassName, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
logger.Warnf("Priority class %q not found in cluster. Pod creation may fail if the priority class doesn't exist when pods are scheduled.", priorityClassName)
} else {
logger.WithError(err).Warnf("Failed to validate priority class %q", priorityClassName)
}
return false
}
logger.Infof("Validated priority class %q exists in cluster", priorityClassName)
return true
}
// ValidatePriorityClassWithClient checks if the specified priority class exists in the cluster using controller-runtime client
// Returns nil if the priority class exists or if priorityClassName is empty
// Returns error if the priority class doesn't exist or validation fails
func ValidatePriorityClassWithClient(ctx context.Context, cli client.Client, priorityClassName string) error {
if priorityClassName == "" {
return nil
}
priorityClass := &schedulingv1.PriorityClass{}
err := cli.Get(ctx, types.NamespacedName{Name: priorityClassName}, priorityClass)
return err
}

View File

@@ -0,0 +1,128 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
schedulingv1 "k8s.io/api/scheduling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
k8stesting "k8s.io/client-go/testing"
velerotesting "github.com/vmware-tanzu/velero/pkg/test"
)
func TestValidatePriorityClass(t *testing.T) {
tests := []struct {
name string
priorityClassName string
existingPCs []runtime.Object
clientReactors []k8stesting.ReactionFunc
expectedLogs []string
expectedLogLevel string
expectedResult bool
}{
{
name: "empty priority class name should return without logging",
priorityClassName: "",
existingPCs: nil,
expectedLogs: nil,
expectedResult: true,
},
{
name: "existing priority class should log info message",
priorityClassName: "high-priority",
existingPCs: []runtime.Object{
&schedulingv1.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "high-priority",
},
Value: 100,
},
},
expectedLogs: []string{"Validated priority class \\\"high-priority\\\" exists in cluster"},
expectedLogLevel: "info",
expectedResult: true,
},
{
name: "non-existing priority class should log warning",
priorityClassName: "does-not-exist",
existingPCs: nil,
expectedLogs: []string{"Priority class \\\"does-not-exist\\\" not found in cluster. Pod creation may fail if the priority class doesn't exist when pods are scheduled."},
expectedLogLevel: "warning",
expectedResult: false,
},
{
name: "API error should log warning with error",
priorityClassName: "test-priority",
existingPCs: nil,
clientReactors: []k8stesting.ReactionFunc{
func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
if action.GetVerb() == "get" && action.GetResource().Resource == "priorityclasses" {
return true, nil, fmt.Errorf("API server error")
}
return false, nil, nil
},
},
expectedLogs: []string{"Failed to validate priority class \\\"test-priority\\\""},
expectedLogLevel: "warning",
expectedResult: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// Create fake client with existing priority classes
kubeClient := fake.NewSimpleClientset(test.existingPCs...)
// Add any custom reactors
for _, reactor := range test.clientReactors {
kubeClient.PrependReactor("*", "*", reactor)
}
// Create test logger with buffer
buffer := []string{}
logger := velerotesting.NewMultipleLogger(&buffer)
// Call the function
result := ValidatePriorityClass(t.Context(), kubeClient, test.priorityClassName, logger)
// Check result
assert.Equal(t, test.expectedResult, result, "ValidatePriorityClass returned unexpected result")
// Check logs
if test.expectedLogs == nil {
assert.Empty(t, buffer)
} else {
assert.Len(t, buffer, len(test.expectedLogs))
for i, expectedLog := range test.expectedLogs {
assert.Contains(t, buffer[i], expectedLog)
if test.expectedLogLevel == "info" {
assert.Contains(t, buffer[i], "level=info")
} else if test.expectedLogLevel == "warning" {
assert.Contains(t, buffer[i], "level=warning")
}
}
}
})
}
}