Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors handling were fixed for peerings validation #509

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions apis/clusterresources/v1beta1/azurevnetpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,20 @@ func init() {

func (azure *AzureVNetPeeringSpec) Validate() error {
dataCentreIDMatched, err := regexp.Match(models.UUIDStringRegExp, []byte(azure.DataCentreID))
if !dataCentreIDMatched || err != nil {
return fmt.Errorf("data centre ID is a UUID formated string. It must fit the pattern: %s. %s", models.UUIDStringRegExp, err.Error())
if err != nil {
return err
}
if !dataCentreIDMatched {
return fmt.Errorf("data centre ID is a UUID formated string. It must fit the pattern: %s", models.UUIDStringRegExp)
}

for _, subnet := range azure.PeerSubnets {
peerSubnetMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(subnet))
if !peerSubnetMatched || err != nil {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28. %s", subnet, err.Error())
if err != nil {
return err
}
if !peerSubnetMatched {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28", subnet)
}
}

Expand Down
14 changes: 10 additions & 4 deletions apis/clusterresources/v1beta1/gcpvpcpeering_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ func init() {

func (gcp *GCPVPCPeeringSpec) Validate() error {
dataCentreIDMatched, err := regexp.Match(models.UUIDStringRegExp, []byte(gcp.DataCentreID))
if !dataCentreIDMatched || err != nil {
return fmt.Errorf("data centre ID is a UUID formated string. It must fit the pattern: %s. %s", models.UUIDStringRegExp, err.Error())
if err != nil {
return err
}
if !dataCentreIDMatched {
return fmt.Errorf("data centre ID is a UUID formated string. It must fit the pattern: %s", models.UUIDStringRegExp)
}

for _, subnet := range gcp.PeerSubnets {
peerSubnetMatched, err := regexp.Match(models.PeerSubnetsRegExp, []byte(subnet))
if !peerSubnetMatched || err != nil {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28. %s", subnet, err.Error())
if err != nil {
return err
}
if !peerSubnetMatched {
return fmt.Errorf("the provided CIDR: %s must contain four dot separated parts and form the Private IP address. All bits in the host part of the CIDR must be 0. Suffix must be between 16-28", subnet)
}
}

Expand Down
10 changes: 6 additions & 4 deletions apis/kafkamanagement/v1beta1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ func (kacl *KafkaACL) validateCreate() error {

for _, acl := range kacl.Spec.ACLs {
principalMatched, err := regexp.Match(models.ACLPrincipalRegExp, []byte(acl.Principal))
if !principalMatched || err != nil {
return fmt.Errorf("acl principal should fit pattern: %s, err: %s",
models.ACLPrincipalRegExp,
err.Error())
if err != nil {
return err
}
if !principalMatched {
return fmt.Errorf("acl principal should fit pattern: %s",
models.ACLPrincipalRegExp)
}

err = validate(acl)
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/clusters.instaclustr.com_cassandras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ spec:
- email
type: object
type: array
userRef:
userRefs:
items:
properties:
name:
Expand Down
7 changes: 3 additions & 4 deletions config/samples/clusterresources_v1beta1_azurevnetpeering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ kind: AzureVNetPeering
metadata:
name: azurevnetpeering-sample
spec:
cdcId: 9e2499cb-8db4-48c7-b8b0-c1ce7f1fab63
cdcId: f8581465-098c-4576-9e52-ea8308a27d8a
peerResourceGroup: rnd
peerSubnets:
- 192.168.0.0/16
- 172.16.0.0/16
- 10.224.0.0/16
peerSubscriptionId: 1a2f3ab8-6815-49c5-a47e-b1a354b51240
peerVirtualNetworkName: rnd-vn
peerVirtualNetworkName: aks-vnet-17973335