@@ -94,33 +94,36 @@ func (c *OCICluster) ValidateCreate() (admission.Warnings, error) {
9494 }
9595 }
9696
97- if c .Spec .NetworkSpec .Vcn .Skip != * common .Bool (true ) {
97+ if c .Spec .NetworkSpec .Vcn .Skip == * common .Bool (true ) {
98+ if c .Spec .NetworkSpec .Vcn .ID == common .String ("" ) || c .Spec .NetworkSpec .Vcn .ID == nil {
99+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "NetworkSpec.Vcn.ID" ), c .Spec .NetworkSpec .Vcn .ID , "field is required" ))
100+ }
101+
98102 for _ , subnet := range c .Spec .NetworkSpec .Vcn .Subnets {
99103 if subnet .Skip == * common .Bool (true ) {
100- allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.Skip" ), subnet .Skip , "field cannot be true when VCN is not skipped" ))
104+ if subnet .ID == common .String ("" ) || subnet .ID == nil {
105+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.ID" ), subnet .ID , "field is required" ))
106+ }
107+ }
108+ if subnet .ID != common .String ("" ) {
109+ if subnet .Skip != * common .Bool (true ) {
110+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.Skip" ), subnet .Skip , "field requires to be true if Subnet ID is specified" ))
111+ }
101112 }
102113 }
103114 } else {
104115 for _ , subnet := range c .Spec .NetworkSpec .Vcn .Subnets {
105116 if subnet .Skip == * common .Bool (true ) {
106- if subnet .ID == nil {
107- allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.ID" ), subnet .ID , "field is required" ))
108- }
117+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.Skip" ), subnet .Skip , "field cannot be true when VCN is not skipped" ))
109118 }
110119 }
111120 }
112121
113- // if c.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List != nil {
114- // if c.Spec.NetworkSpec.Vcn.Skip != *common.Bool(true) {
115- // if c.Spec.NetworkSpec.Vcn.CIDR == "" {
116- // allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.CIDR"), c.Spec.NetworkSpec.Vcn.CIDR, "field is required"))
117- // }
118- // } else {
119- // if c.Spec.NetworkSpec.Vcn.ID == nil {
120- // allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ID"), c.Spec.NetworkSpec.Vcn.ID, "field is required"))
121- // }
122- // }
123- // }
122+ if c .Spec .NetworkSpec .Vcn .ID != common .String ("" ) {
123+ if c .Spec .NetworkSpec .Vcn .Skip != * common .Bool (true ) {
124+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "NetworkSpec.Vcn.Skip" ), c .Spec .NetworkSpec .Vcn .Skip , "field requires to be true if VCN ID is specified" ))
125+ }
126+ }
124127
125128 allErrs = append (allErrs , c .validate (nil )... )
126129
@@ -161,33 +164,36 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) (admission.Warnings, err
161164 allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "compartmentId" ), c .Spec .CompartmentId , "field is immutable" ))
162165 }
163166
164- if c .Spec .NetworkSpec .Vcn .Skip != * common .Bool (true ) {
167+ if c .Spec .NetworkSpec .Vcn .Skip == * common .Bool (true ) {
168+ if c .Spec .NetworkSpec .Vcn .ID == common .String ("" ) || c .Spec .NetworkSpec .Vcn .ID == nil {
169+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "NetworkSpec.Vcn.ID" ), c .Spec .NetworkSpec .Vcn .ID , "field is required" ))
170+ }
171+
165172 for _ , subnet := range c .Spec .NetworkSpec .Vcn .Subnets {
166173 if subnet .Skip == * common .Bool (true ) {
167- allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.Skip" ), subnet .Skip , "field cannot be true when VCN is not skipped" ))
174+ if subnet .ID == common .String ("" ) || subnet .ID == nil {
175+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.ID" ), subnet .ID , "field is required" ))
176+ }
177+ }
178+ if subnet .ID != common .String ("" ) {
179+ if subnet .Skip != * common .Bool (true ) {
180+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.Skip" ), subnet .Skip , "field requires to be true if Subnet ID is specified" ))
181+ }
168182 }
169183 }
170184 } else {
171185 for _ , subnet := range c .Spec .NetworkSpec .Vcn .Subnets {
172186 if subnet .Skip == * common .Bool (true ) {
173- if subnet .ID == nil {
174- allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.ID" ), subnet .ID , "field is required" ))
175- }
187+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "subnet.Skip" ), subnet .Skip , "field cannot be true when VCN is not skipped" ))
176188 }
177189 }
178190 }
179191
180- // if c.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List != nil {
181- // if c.Spec.NetworkSpec.Vcn.Skip != *common.Bool(true) {
182- // if c.Spec.NetworkSpec.Vcn.CIDR == "" {
183- // allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.CIDR"), c.Spec.NetworkSpec.Vcn.CIDR, "field is required"))
184- // }
185- // } else {
186- // if c.Spec.NetworkSpec.Vcn.ID == nil {
187- // allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ID"), c.Spec.NetworkSpec.Vcn.ID, "field is required"))
188- // }
189- // }
190- // }
192+ if c .Spec .NetworkSpec .Vcn .ID != common .String ("" ) {
193+ if c .Spec .NetworkSpec .Vcn .Skip != * common .Bool (true ) {
194+ allErrs = append (allErrs , field .Invalid (field .NewPath ("spec" , "NetworkSpec.Vcn.Skip" ), c .Spec .NetworkSpec .Vcn .Skip , "field requires to be true if VCN ID is specified" ))
195+ }
196+ }
191197
192198 allErrs = append (allErrs , c .validate (oldCluster )... )
193199
0 commit comments