Skip to content

Commit 2e9255f

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

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
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"k8s.io/apimachinery/pkg/util/validation/field"
2021
"k8s.io/utils/ptr"
2122

2223
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
@@ -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 [ImageParam].
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)