-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report filter status into vgstatus
- Loading branch information
1 parent
3b83b72
commit 3cc0553
Showing
20 changed files
with
722 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
// log is for logging in this package. | ||
var lvmvolumegrouplog = logf.Log.WithName("lvmvolumegroup-webhook") | ||
|
||
var _ webhook.Validator = &LVMVolumeGroup{} | ||
|
||
//+kubebuilder:webhook:path=/validate-lvm-topolvm-io-v1alpha1-lvmvolumegroup,mutating=false,failurePolicy=fail,sideEffects=None,groups=lvm.topolvm.io,resources=lvmvolumegroups,verbs=create;update,versions=v1alpha1,name=vlvmvolumegroup.kb.io,admissionReviewVersions=v1 | ||
|
||
func (in *LVMVolumeGroup) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(in). | ||
Complete() | ||
} | ||
|
||
func (in *LVMVolumeGroup) ValidateCreate() (warnings admission.Warnings, err error) { | ||
lvmvolumegrouplog.Info("validate create", "name", in.Name) | ||
return in.ValidateUpdate(nil) | ||
} | ||
|
||
func (in *LVMVolumeGroup) ValidateUpdate(_ runtime.Object) (warnings admission.Warnings, err error) { | ||
lvmvolumegrouplog.Info("validate update", "name", in.Name) | ||
if err := in.validateDeviceSelector(); err != nil { | ||
return nil, fmt.Errorf(".Spec.DeviceSelector is invalid: %w", err) | ||
} | ||
return nil, nil | ||
} | ||
|
||
func (in *LVMVolumeGroup) validateDeviceSelector() error { | ||
selector := in.Spec.DeviceSelector | ||
|
||
uniquePaths := make(map[string]bool) | ||
duplicatePaths := make(map[string]bool) | ||
|
||
// Check for duplicate required paths | ||
for _, path := range selector.Paths { | ||
if _, exists := uniquePaths[path]; exists { | ||
duplicatePaths[path] = true | ||
continue | ||
} | ||
|
||
uniquePaths[path] = true | ||
} | ||
|
||
// Check for duplicate optional paths | ||
for _, path := range selector.OptionalPaths { | ||
if _, exists := uniquePaths[path]; exists { | ||
duplicatePaths[path] = true | ||
continue | ||
} | ||
|
||
uniquePaths[path] = true | ||
} | ||
|
||
// Report any duplicate paths | ||
if len(duplicatePaths) > 0 { | ||
keys := make([]string, 0, len(duplicatePaths)) | ||
for k := range duplicatePaths { | ||
keys = append(keys, k) | ||
} | ||
|
||
return fmt.Errorf("duplicate device paths found: %v", keys) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (in *LVMVolumeGroup) ValidateDelete() (warnings admission.Warnings, err error) { | ||
lvmvolumegrouplog.Info("validate delete", "name", in.Name) | ||
return []string{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.