Skip to content

Commit d1e453a

Browse files
committed
Add image validation for opestack machine
Signed-off-by: smoshiur1237 <[email protected]>
1 parent ae9422e commit d1e453a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

api/v1beta1/types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"k8s.io/utils/ptr"
2121

22+
"k8s.io/apimachinery/pkg/util/validation/field"
2223
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2324
)
2425

@@ -75,6 +76,24 @@ func (f *ImageFilter) IsZero() bool {
7576
return f.Name == nil && len(f.Tags) == 0
7677
}
7778

79+
// Validate performs validation on [ImageParam], returning a list of field errors using the provided base path.
80+
// It is intended to be used in the validation webhooks of resources containing [Image].
81+
func (i *ImageParam) Validate(base field.Path) field.ErrorList {
82+
var errors field.ErrorList
83+
// Not possible to validate the image if it is missing
84+
if i == nil {
85+
errors = append(errors, field.Required(&base, "image is required"))
86+
return errors
87+
}
88+
if i.Filter.Name == nil || i.Filter.Tags == nil {
89+
errors = append(errors, field.Required(base.Child("Image filter"), "either name or tags of image are missing"))
90+
}
91+
if i.ImageRef.Name == "" {
92+
errors = append(errors, field.Required(base.Child("ORC mage Regerecne"), "Orc image is missing"))
93+
}
94+
return errors
95+
}
96+
7897
type ExternalRouterIPParam struct {
7998
// The FixedIP in the corresponding subnet
8099
FixedIP string `json:"fixedIP,omitempty"`

0 commit comments

Comments
 (0)