Skip to content

Commit 883d42c

Browse files
committed
Validate cluster resource, a cluster should have pv set
1 parent b51b048 commit 883d42c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/internal/mysqlcluster/validation.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,20 @@ func (c *MysqlCluster) Validate() error {
3131
return fmt.Errorf("%s is not a valid MySQL version", c.Spec.MysqlVersion)
3232
}
3333

34+
// volume spec should be specified on the cluster
35+
vs := c.Spec.VolumeSpec
36+
if anyNull(vs.PersistentVolumeClaim, vs.HostPath, vs.EmptyDir) {
37+
return fmt.Errorf("no .spec.volumeSpec is specified")
38+
}
39+
3440
return nil
3541
}
42+
43+
// anyNull checks if any of the given parameters is null and returns true if so
44+
func anyNull(vars ...interface{}) bool {
45+
isNull := false
46+
for _, v := range vars {
47+
isNull = isNull || v == nil
48+
}
49+
return isNull
50+
}

0 commit comments

Comments
 (0)