Skip to content

Commit bafeda0

Browse files
committed
comments to explain code
1 parent b45ed4a commit bafeda0

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

api/v1beta2/ocicluster_webhook.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,34 @@ func (c *OCICluster) ValidateCreate() (admission.Warnings, error) {
9494
}
9595
}
9696

97+
// If Skip field is True, ID field of VCN should be specified
9798
if c.Spec.NetworkSpec.Vcn.Skip == *common.Bool(true) {
9899
if c.Spec.NetworkSpec.Vcn.ID == common.String("") || c.Spec.NetworkSpec.Vcn.ID == nil {
99100
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ID"), c.Spec.NetworkSpec.Vcn.ID, "field is required"))
100101
}
101102

103+
// If Skip field is True, Skip field of InternetGateway should be true
102104
if c.Spec.NetworkSpec.Vcn.InternetGateway.Skip != *common.Bool(true) {
103105
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.InternetGateway.Skip"), c.Spec.NetworkSpec.Vcn.InternetGateway.Skip, "field requires to be true when VCN is skipped"))
104106
}
105107

108+
// If Skip field is True, Skip field of ServiceGateway should be true
106109
if c.Spec.NetworkSpec.Vcn.ServiceGateway.Skip != *common.Bool(true) {
107110
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ServiceGateway.Skip"), c.Spec.NetworkSpec.Vcn.ServiceGateway.Skip, "field requires to be true when VCN is skipped"))
108111
}
109112

113+
// If Skip field is True, Skip field of NATGateway should be true
110114
if c.Spec.NetworkSpec.Vcn.NATGateway.Skip != *common.Bool(true) {
111115
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.NATGateway.Skip"), c.Spec.NetworkSpec.Vcn.NATGateway.Skip, "field requires to be true when VCN is skipped"))
112116
}
113117

118+
// If Skip field is True, Skip field of RouteTable should be true
114119
if c.Spec.NetworkSpec.Vcn.RouteTable.Skip != *common.Bool(true) {
115120
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.RouteTable.Skip"), c.Spec.NetworkSpec.Vcn.RouteTable.Skip, "field requires to be true when VCN is skipped"))
116121
}
117122

123+
// For each subnet if Skip field is True, ID field of Subnet should be specified
124+
// Also for each subnet if ID field is True, Skip field of Subnet should be true
118125
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
119126
if subnet.Skip == *common.Bool(true) {
120127
if subnet.ID == common.String("") || subnet.ID == nil {
@@ -128,19 +135,14 @@ func (c *OCICluster) ValidateCreate() (admission.Warnings, error) {
128135
}
129136
}
130137
} else {
138+
// If Skip field is False, for each subnet in VCN the Skip field of Subnet cannot be true
131139
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
132140
if subnet.Skip == *common.Bool(true) {
133141
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "subnet.Skip"), subnet.Skip, "field cannot be true when VCN is not skipped"))
134142
}
135143
}
136144
}
137145

138-
// if c.Spec.NetworkSpec.Vcn.ID != common.String("") {
139-
// if c.Spec.NetworkSpec.Vcn.Skip != *common.Bool(true) {
140-
// 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"))
141-
// }
142-
// }
143-
144146
allErrs = append(allErrs, c.validate(nil)...)
145147

146148
if len(allErrs) == 0 {
@@ -180,27 +182,34 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) (admission.Warnings, err
180182
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "compartmentId"), c.Spec.CompartmentId, "field is immutable"))
181183
}
182184

185+
// If Skip field is True, ID field of VCN should be specified
183186
if c.Spec.NetworkSpec.Vcn.Skip == *common.Bool(true) {
184187
if c.Spec.NetworkSpec.Vcn.ID == common.String("") || c.Spec.NetworkSpec.Vcn.ID == nil {
185188
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ID"), c.Spec.NetworkSpec.Vcn.ID, "field is required"))
186189
}
187190

191+
// If Skip field is True, Skip field of InternetGateway should be true
188192
if c.Spec.NetworkSpec.Vcn.InternetGateway.Skip != *common.Bool(true) {
189193
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.InternetGateway.Skip"), c.Spec.NetworkSpec.Vcn.InternetGateway.Skip, "field requires to be true when VCN is skipped"))
190194
}
191195

196+
// If Skip field is True, Skip field of ServiceGateway should be true
192197
if c.Spec.NetworkSpec.Vcn.ServiceGateway.Skip != *common.Bool(true) {
193198
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ServiceGateway.Skip"), c.Spec.NetworkSpec.Vcn.ServiceGateway.Skip, "field requires to be true when VCN is skipped"))
194199
}
195200

201+
// If Skip field is True, Skip field of NATGateway should be true
196202
if c.Spec.NetworkSpec.Vcn.NATGateway.Skip != *common.Bool(true) {
197203
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.NATGateway.Skip"), c.Spec.NetworkSpec.Vcn.NATGateway.Skip, "field requires to be true when VCN is skipped"))
198204
}
199205

206+
// If Skip field is True, Skip field of RouteTable should be true
200207
if c.Spec.NetworkSpec.Vcn.RouteTable.Skip != *common.Bool(true) {
201208
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.RouteTable.Skip"), c.Spec.NetworkSpec.Vcn.RouteTable.Skip, "field requires to be true when VCN is skipped"))
202209
}
203210

211+
// For each subnet if Skip field is True, ID field of Subnet should be specified
212+
// Also for each subnet if ID field is True, Skip field of Subnet should be true
204213
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
205214
if subnet.Skip == *common.Bool(true) {
206215
if subnet.ID == common.String("") || subnet.ID == nil {
@@ -214,19 +223,14 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) (admission.Warnings, err
214223
}
215224
}
216225
} else {
226+
// If Skip field is False, for each subnet in VCN the Skip field of Subnet cannot be true
217227
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
218228
if subnet.Skip == *common.Bool(true) {
219229
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "subnet.Skip"), subnet.Skip, "field cannot be true when VCN is not skipped"))
220230
}
221231
}
222232
}
223233

224-
// if c.Spec.NetworkSpec.Vcn.ID != common.String("") {
225-
// if c.Spec.NetworkSpec.Vcn.Skip != *common.Bool(true) {
226-
// 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"))
227-
// }
228-
// }
229-
230234
allErrs = append(allErrs, c.validate(oldCluster)...)
231235

232236
if len(allErrs) == 0 {

0 commit comments

Comments
 (0)