Skip to content
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
6 changes: 6 additions & 0 deletions api/v1/kataconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ type KataConfigSpec struct {
// +optional
// +kubebuilder:default:=false
EnablePeerPods bool `json:"enablePeerPods"`

// +optional
// +kubebuilder:default:=350
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If the answer is yes, should they stay in sync ?

// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=2048
MemoryOverheadMB *int32 `json:"memoryOverheadMB,omitempty"`
}

// KataConfigStatus defines the observed state of KataConfig
Expand Down
37 changes: 29 additions & 8 deletions api/v1/kataconfig_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,28 @@ func (r *KataConfig) ValidateCreate(ctx context.Context, obj runtime.Object) (ad

kataconfiglog.Info("validate create", "name", kataconfig.Name)

kataConfigList := &KataConfigList{}
listOpts := []client.ListOption{
client.InNamespace(corev1.NamespaceAll),
}
if err := clientInst.List(ctx, kataConfigList, listOpts...); err != nil {
return nil, fmt.Errorf("Failed to list KataConfig custom resources: %v", err)
// Skip client-dependent validation if clientInst is nil (e.g., during testing)
if clientInst != nil {
kataConfigList := &KataConfigList{}
listOpts := []client.ListOption{
client.InNamespace(corev1.NamespaceAll),
}
if err := clientInst.List(ctx, kataConfigList, listOpts...); err != nil {
return nil, fmt.Errorf("Failed to list KataConfig custom resources: %v", err)
}

if len(kataConfigList.Items) == 1 {
return nil, fmt.Errorf("A KataConfig instance already exists, refusing to create a duplicate")
}
}

if len(kataConfigList.Items) == 1 {
return nil, fmt.Errorf("A KataConfig instance already exists, refusing to create a duplicate")
if r.Spec.MemoryOverheadMB != nil {
if *r.Spec.MemoryOverheadMB < 60 {
return nil, fmt.Errorf("memoryOverheadMB must be at least 60MB")
}
if *r.Spec.MemoryOverheadMB > 4096*1024 {
return nil, fmt.Errorf("memoryOverheadMB must be at most 4GB")
}
Copy link
Member

@gkurz gkurz Oct 9, 2025

Choose a reason for hiding this comment

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

Can you clarify how you came up with these numbers ?

}

return nil, nil
Expand All @@ -85,6 +97,15 @@ func (r *KataConfig) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.

kataconfiglog.Info("validate update", "name", kataconfig.Name)

if r.Spec.MemoryOverheadMB != nil {
if *r.Spec.MemoryOverheadMB < 60 {
return nil, fmt.Errorf("memoryOverheadMB must be at least 60MB")
}
if *r.Spec.MemoryOverheadMB > 4096*1024 {
return nil, fmt.Errorf("memoryOverheadMB must be at most 4GB")
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Can you move the duplicate code block to some helper ?

// TODO(user): fill in your validation logic upon object update.
return nil, nil
}
Expand Down
Loading