Add ConfigMap parameters validation for install CLI and server start.

Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
Xun Jiang
2025-08-22 20:31:38 +08:00
parent ab8af5cd34
commit c62a486765
21 changed files with 370 additions and 183 deletions
+3 -63
View File
@@ -29,6 +29,7 @@ import (
"k8s.io/client-go/kubernetes"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
velerotypes "github.com/vmware-tanzu/velero/pkg/types"
"github.com/vmware-tanzu/velero/pkg/util/kube"
)
@@ -56,67 +57,6 @@ var (
ErrNodeAgentTolerationNotFound = errors.New("node-agent toleration not found")
)
type LoadConcurrency struct {
// GlobalConfig specifies the concurrency number to all nodes for which per-node config is not specified
GlobalConfig int `json:"globalConfig,omitempty"`
// PerNodeConfig specifies the concurrency number to nodes matched by rules
PerNodeConfig []RuledConfigs `json:"perNodeConfig,omitempty"`
// PrepareQueueLength specifies the max number of loads that are under expose
PrepareQueueLength int `json:"prepareQueueLength,omitempty"`
}
type LoadAffinity struct {
// NodeSelector specifies the label selector to match nodes
NodeSelector metav1.LabelSelector `json:"nodeSelector"`
}
type RuledConfigs struct {
// NodeSelector specifies the label selector to match nodes
NodeSelector metav1.LabelSelector `json:"nodeSelector"`
// Number specifies the number value associated to the matched nodes
Number int `json:"number"`
}
type BackupPVC struct {
// StorageClass is the name of storage class to be used by the backupPVC
StorageClass string `json:"storageClass,omitempty"`
// ReadOnly sets the backupPVC's access mode as read only
ReadOnly bool `json:"readOnly,omitempty"`
// SPCNoRelabeling sets Spec.SecurityContext.SELinux.Type to "spc_t" for the pod mounting the backupPVC
// ignored if ReadOnly is false
SPCNoRelabeling bool `json:"spcNoRelabeling,omitempty"`
}
type RestorePVC struct {
// IgnoreDelayBinding indicates to ignore delay binding the restorePVC when it is in WaitForFirstConsumer mode
IgnoreDelayBinding bool `json:"ignoreDelayBinding,omitempty"`
}
type Configs struct {
// LoadConcurrency is the config for data path load concurrency per node.
LoadConcurrency *LoadConcurrency `json:"loadConcurrency,omitempty"`
// LoadAffinity is the config for data path load affinity.
LoadAffinity []*kube.LoadAffinity `json:"loadAffinity,omitempty"`
// BackupPVCConfig is the config for backupPVC (intermediate PVC) of snapshot data movement
BackupPVCConfig map[string]BackupPVC `json:"backupPVC,omitempty"`
// RestoreVCConfig is the config for restorePVC (intermediate PVC) of generic restore
RestorePVCConfig *RestorePVC `json:"restorePVC,omitempty"`
// PodResources is the resource config for various types of pods launched by node-agent, i.e., data mover pods.
PodResources *kube.PodResources `json:"podResources,omitempty"`
// PriorityClassName is the priority class name for data mover pods created by the node agent
PriorityClassName string `json:"priorityClassName,omitempty"`
}
func IsRunningOnLinux(ctx context.Context, kubeClient kubernetes.Interface, namespace string) error {
return isRunning(ctx, kubeClient, namespace, daemonSet)
}
@@ -193,7 +133,7 @@ func GetPodSpec(ctx context.Context, kubeClient kubernetes.Interface, namespace
return &ds.Spec.Template.Spec, nil
}
func GetConfigs(ctx context.Context, namespace string, kubeClient kubernetes.Interface, configName string) (*Configs, error) {
func GetConfigs(ctx context.Context, namespace string, kubeClient kubernetes.Interface, configName string) (*velerotypes.NodeAgentConfigs, error) {
cm, err := kubeClient.CoreV1().ConfigMaps(namespace).Get(ctx, configName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "error to get node agent configs %s", configName)
@@ -208,7 +148,7 @@ func GetConfigs(ctx context.Context, namespace string, kubeClient kubernetes.Int
jsonString = v
}
configs := &Configs{}
configs := &velerotypes.NodeAgentConfigs{}
err = json.Unmarshal([]byte(jsonString), configs)
if err != nil {
return nil, errors.Wrapf(err, "error to unmarshall configs from %s", configName)
+8 -7
View File
@@ -31,6 +31,7 @@ import (
clientFake "sigs.k8s.io/controller-runtime/pkg/client/fake"
"github.com/vmware-tanzu/velero/pkg/builder"
velerotypes "github.com/vmware-tanzu/velero/pkg/types"
"github.com/vmware-tanzu/velero/pkg/util/kube"
)
@@ -254,7 +255,7 @@ func TestGetConfigs(t *testing.T) {
kubeClientObj []runtime.Object
namespace string
kubeReactors []reactor
expectResult *Configs
expectResult *velerotypes.NodeAgentConfigs
expectErr string
}{
{
@@ -293,7 +294,7 @@ func TestGetConfigs(t *testing.T) {
kubeClientObj: []runtime.Object{
cmWithoutCocurrentData,
},
expectResult: &Configs{},
expectResult: &velerotypes.NodeAgentConfigs{},
},
{
name: "success",
@@ -301,8 +302,8 @@ func TestGetConfigs(t *testing.T) {
kubeClientObj: []runtime.Object{
cmWithValidData,
},
expectResult: &Configs{
LoadConcurrency: &LoadConcurrency{
expectResult: &velerotypes.NodeAgentConfigs{
LoadConcurrency: &velerotypes.LoadConcurrency{
GlobalConfig: 5,
},
},
@@ -313,7 +314,7 @@ func TestGetConfigs(t *testing.T) {
kubeClientObj: []runtime.Object{
cmWithPriorityClass,
},
expectResult: &Configs{
expectResult: &velerotypes.NodeAgentConfigs{
PriorityClassName: "high-priority",
},
},
@@ -323,9 +324,9 @@ func TestGetConfigs(t *testing.T) {
kubeClientObj: []runtime.Object{
cmWithPriorityClassAndOther,
},
expectResult: &Configs{
expectResult: &velerotypes.NodeAgentConfigs{
PriorityClassName: "low-priority",
LoadConcurrency: &LoadConcurrency{
LoadConcurrency: &velerotypes.LoadConcurrency{
GlobalConfig: 3,
},
},