Skip to content

Commit e2683a1

Browse files
committed
added checks for igw, sgw, ngw and rt
1 parent 53cb306 commit e2683a1

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

api/v1beta2/ocicluster_webhook.go

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ func (c *OCICluster) ValidateCreate() (admission.Warnings, error) {
9999
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ID"), c.Spec.NetworkSpec.Vcn.ID, "field is required"))
100100
}
101101

102+
if c.Spec.NetworkSpec.Vcn.InternetGateway.Skip != *common.Bool(true) {
103+
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"))
104+
}
105+
106+
if c.Spec.NetworkSpec.Vcn.ServiceGateway.Skip != *common.Bool(true) {
107+
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"))
108+
}
109+
110+
if c.Spec.NetworkSpec.Vcn.NATGateway.Skip != *common.Bool(true) {
111+
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"))
112+
}
113+
114+
if c.Spec.NetworkSpec.Vcn.RouteTable.Skip != *common.Bool(true) {
115+
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"))
116+
}
117+
102118
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
103119
if subnet.Skip == *common.Bool(true) {
104120
if subnet.ID == common.String("") || subnet.ID == nil {
@@ -119,11 +135,11 @@ func (c *OCICluster) ValidateCreate() (admission.Warnings, error) {
119135
}
120136
}
121137

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-
}
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+
// }
127143

128144
allErrs = append(allErrs, c.validate(nil)...)
129145

@@ -169,6 +185,22 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) (admission.Warnings, err
169185
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "NetworkSpec.Vcn.ID"), c.Spec.NetworkSpec.Vcn.ID, "field is required"))
170186
}
171187

188+
if c.Spec.NetworkSpec.Vcn.InternetGateway.Skip != *common.Bool(true) {
189+
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"))
190+
}
191+
192+
if c.Spec.NetworkSpec.Vcn.ServiceGateway.Skip != *common.Bool(true) {
193+
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"))
194+
}
195+
196+
if c.Spec.NetworkSpec.Vcn.NATGateway.Skip != *common.Bool(true) {
197+
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"))
198+
}
199+
200+
if c.Spec.NetworkSpec.Vcn.RouteTable.Skip != *common.Bool(true) {
201+
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"))
202+
}
203+
172204
for _, subnet := range c.Spec.NetworkSpec.Vcn.Subnets {
173205
if subnet.Skip == *common.Bool(true) {
174206
if subnet.ID == common.String("") || subnet.ID == nil {
@@ -189,11 +221,11 @@ func (c *OCICluster) ValidateUpdate(old runtime.Object) (admission.Warnings, err
189221
}
190222
}
191223

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-
}
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+
// }
197229

198230
allErrs = append(allErrs, c.validate(oldCluster)...)
199231

0 commit comments

Comments
 (0)