Skip to content

Commit 251c9ea

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

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

api/v1beta1/types.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"k8s.io/apimachinery/pkg/util/validation/field"
2021
"k8s.io/utils/ptr"
21-
2222
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2323
)
2424

@@ -75,6 +75,24 @@ func (f *ImageFilter) IsZero() bool {
7575
return f.Name == nil && len(f.Tags) == 0
7676
}
7777

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

0 commit comments

Comments
 (0)