Skip to content

Commit e0f0e2f

Browse files
committed
webhook for nsg feature
1 parent 130b37f commit e0f0e2f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

api/v1beta2/ocicluster_webhook.go

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

97+
if c.Spec.NetworkSpec.Vcn.Skip != *common.Bool(true) {
98+
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
99+
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"))
101+
}
102+
}
103+
} else {
104+
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
105+
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+
}
109+
}
110+
}
111+
}
112+
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+
// }
124+
97125
allErrs = append(allErrs, c.validate(nil)...)
98126

99127
if len(allErrs) == 0 {
@@ -133,6 +161,34 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) (admission.Warnings, err
133161
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "compartmentId"), c.Spec.CompartmentId, "field is immutable"))
134162
}
135163

164+
if c.Spec.NetworkSpec.Vcn.Skip != *common.Bool(true) {
165+
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
166+
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"))
168+
}
169+
}
170+
} else {
171+
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
172+
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+
}
176+
}
177+
}
178+
}
179+
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+
// }
191+
136192
allErrs = append(allErrs, c.validate(oldCluster)...)
137193

138194
if len(allErrs) == 0 {

0 commit comments

Comments
 (0)