@@ -20,13 +20,7 @@ func (atom *Atom) ValidateCreate(c client.Client) ([]string, error) {
2020 var warnings []string
2121 var allErrs field.ErrorList
2222
23- err := smoothoperatorvalidation .ValidateLabelsOnCreate (atom .Labels )
24- if err != nil {
25- allErrs = append (allErrs , err )
26- }
27-
28- ValidateAtom (atom , & warnings , & allErrs )
29- ValidateOwnerInfo (c , atom , & allErrs )
23+ validateCreate (& c , atom , & warnings , & allErrs )
3024
3125 if len (allErrs ) == 0 {
3226 return warnings , nil
@@ -40,26 +34,8 @@ func (atom *Atom) ValidateCreate(c client.Client) ([]string, error) {
4034func (atom * Atom ) ValidateUpdate (c client.Client , atomOld * Atom ) ([]string , error ) {
4135 var warnings []string
4236 var allErrs field.ErrorList
43- smoothoperatorvalidation .ValidateLabelsOnUpdate (atomOld .Labels , atom .Labels , & allErrs )
4437
45- if atom .Spec .IngressRouteURLs == nil {
46- smoothoperatorvalidation .CheckURLImmutability (
47- atomOld .Spec .Service .BaseURL ,
48- atom .Spec .Service .BaseURL ,
49- & allErrs ,
50- field .NewPath ("spec" ).Child ("service" ).Child ("baseUrl" ),
51- )
52- } else if atom .Spec .Service .BaseURL .String () != atomOld .Spec .Service .BaseURL .String () {
53- err := smoothoperatorvalidation .ValidateIngressRouteURLsContainsBaseURL (atom .Spec .IngressRouteURLs , atomOld .Spec .Service .BaseURL , nil )
54- if err != nil {
55- allErrs = append (allErrs , err )
56- }
57- }
58-
59- smoothoperatorvalidation .ValidateIngressRouteURLsNotRemoved (atomOld .Spec .IngressRouteURLs , atom .Spec .IngressRouteURLs , & allErrs , nil )
60-
61- ValidateAtom (atom , & warnings , & allErrs )
62- ValidateOwnerInfo (c , atom , & allErrs )
38+ validateUpdate (& c , atom , atomOld , & warnings , & allErrs )
6339
6440 if len (allErrs ) == 0 {
6541 return warnings , nil
@@ -70,6 +46,16 @@ func (atom *Atom) ValidateUpdate(c client.Client, atomOld *Atom) ([]string, erro
7046 atom .Name , allErrs )
7147}
7248
49+ // ValidateCreateAtom validates Atom creation without k8s client
50+ func ValidateCreateAtom (atom * Atom , warnings * []string , allErrs * field.ErrorList ) {
51+ validateCreate (nil , atom , warnings , allErrs )
52+ }
53+
54+ // ValidateUpdateAtom validates Atom update without k8s client
55+ func ValidateUpdateAtom (atom * Atom , atomOld * Atom , warnings * []string , allErrs * field.ErrorList ) {
56+ validateUpdate (nil , atom , atomOld , warnings , allErrs )
57+ }
58+
7359func ValidateOwnerInfo (c client.Client , atom * Atom , allErrs * field.ErrorList ) {
7460 ownerInfoRef := atom .Spec .Service .OwnerInfoRef
7561 ownerInfo := & smoothoperatorv1.OwnerInfo {}
@@ -117,6 +103,48 @@ func validateMetadataTemplates(atom *Atom, ownerInfo *smoothoperatorv1.OwnerInfo
117103 }
118104}
119105
106+ func validateCreate (c * client.Client , atom * Atom , warnings * []string , allErrs * field.ErrorList ) {
107+ err := smoothoperatorvalidation .ValidateLabelsOnCreate (atom .Labels )
108+ if err != nil {
109+ * allErrs = append (* allErrs , err )
110+ }
111+
112+ ValidateAtom (atom , warnings , allErrs )
113+
114+ // Only validate owner info if k8s client is available
115+ if c != nil {
116+ ValidateOwnerInfo (* c , atom , allErrs )
117+ }
118+
119+ }
120+
121+ func validateUpdate (c * client.Client , atom * Atom , atomOld * Atom , warnings * []string , allErrs * field.ErrorList ) {
122+ smoothoperatorvalidation .ValidateLabelsOnUpdate (atomOld .Labels , atom .Labels , allErrs )
123+
124+ if atom .Spec .IngressRouteURLs == nil {
125+ smoothoperatorvalidation .CheckURLImmutability (
126+ atomOld .Spec .Service .BaseURL ,
127+ atom .Spec .Service .BaseURL ,
128+ allErrs ,
129+ field .NewPath ("spec" ).Child ("service" ).Child ("baseUrl" ),
130+ )
131+ } else if atom .Spec .Service .BaseURL .String () != atomOld .Spec .Service .BaseURL .String () {
132+ err := smoothoperatorvalidation .ValidateIngressRouteURLsContainsBaseURL (atom .Spec .IngressRouteURLs , atomOld .Spec .Service .BaseURL , nil )
133+ if err != nil {
134+ * allErrs = append (* allErrs , err )
135+ }
136+ }
137+
138+ smoothoperatorvalidation .ValidateIngressRouteURLsNotRemoved (atomOld .Spec .IngressRouteURLs , atom .Spec .IngressRouteURLs , allErrs , nil )
139+
140+ ValidateAtom (atom , warnings , allErrs )
141+
142+ // Only validate owner info if k8s client is available
143+ if c != nil {
144+ ValidateOwnerInfo (* c , atom , allErrs )
145+ }
146+ }
147+
120148func ValidateAtom (atom * Atom , warnings * []string , allErrs * field.ErrorList ) {
121149 var fieldPath * field.Path
122150 if strings .Contains (atom .GetName (), "atom" ) {
0 commit comments