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

feat(net): Add multizone deployment capabilities to subnets #276

Merged
12 commits merged into from
Dec 4, 2023
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test/e2e/config/*.-envsubst.yaml
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
apicovers.txt
covers.txt
apicovers.html
covers.html

secret.*
*.kubeconfig
Expand Down
26 changes: 23 additions & 3 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type OscNetwork struct {
// The Nat Service configuration
// +optional
NatService OscNatService `json:"natService,omitempty"`
// The Nat Services configuration
// +optional
NatServices []*OscNatService `json:"natServices,omitempty"`
// The Route Table configuration
// +optional
RouteTables []*OscRouteTable `json:"routeTables,omitempty"`
Expand Down Expand Up @@ -164,6 +167,9 @@ type OscSubnet struct {
// Subnet Ip range with CIDR notation
// +optional
IpSubnetRange string `json:"ipSubnetRange,omitempty"`
// The subregion name of the Subnet
// +optional
SubregionName string `json:"subregionName,omitempty"`
// The Subnet Id response
// +optional
ResourceId string `json:"resourceId,omitempty"`
Expand Down Expand Up @@ -1213,10 +1219,11 @@ func (network *OscNetwork) SetSubnetDefaultValue() {
var subnetKcpName string = DefaultSubnetKcpName
var subnetKwName string = DefaultSubnetKwName
var subnetPublicName string = DefaultSubnetPublicName

if network.ClusterName != "" {
subnetKcpName = strings.Replace(DefaultSubnetKcpName, DefaultClusterName, network.ClusterName, -1)
subnetKwName = strings.Replace(DefaultSubnetKwName, DefaultClusterName, network.ClusterName, -1)
subnetPublicName = strings.Replace(DefaultSubnetPublicName, DefaultClusterName, network.ClusterName, -1)
subnetKcpName = strings.Replace(subnetKcpName, DefaultClusterName, network.ClusterName, -1)
subnetKwName = strings.Replace(subnetKwName, DefaultClusterName, network.ClusterName, -1)
subnetPublicName = strings.Replace(subnetPublicName, DefaultClusterName, network.ClusterName, -1)
}
subnetKcp := OscSubnet{
Name: subnetKcpName,
Expand All @@ -1238,6 +1245,19 @@ func (network *OscNetwork) SetSubnetDefaultValue() {
}
}

// SetSubnetSubregionNameValue set the Subnet Subregion Name values from OscNetwork configuration
func (network *OscNetwork) SetSubnetSubregionNameDefaultValue() {
var defaultSubregionName string = DefaultSubregionName
if network.SubregionName != "" {
defaultSubregionName = network.SubregionName
}
for _, subnet := range network.Subnets {
if subnet.SubregionName == "" {
subnet.SubregionName = defaultSubregionName
}
}
}

// SetDefaultValue set the LoadBalancer Service default values
func (lb *OscLoadBalancer) SetDefaultValue() {
var subnetPublicName string = DefaultSubnetPublicName
Expand Down
3 changes: 3 additions & 0 deletions capm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ spec:
resourceId:
description: The Subnet Id response
type: string
subregionName:
description: The subregion name of the Subnet
type: string
type: object
type: array
subregionName:
Expand Down
5 changes: 5 additions & 0 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (s *ClusterScope) GetNatService() *infrastructurev1beta1.OscNatService {
return &s.OscCluster.Spec.Network.NatService
}

// GetNatServices return the natServices of the cluster
func (s *ClusterScope) GetNatServices() []*infrastructurev1beta1.OscNatService {
return s.OscCluster.Spec.Network.NatServices
}

// GetNatServiceRef get the status of natService (a Map with tag name with cluster uid associate with resource response id)
func (s *ClusterScope) GetNatServiceRef() *infrastructurev1beta1.OscResourceReference {
return &s.OscCluster.Status.Network.NatServiceRef
Expand Down
8 changes: 4 additions & 4 deletions cloud/services/net/mock_net/subnet_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions cloud/services/net/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,33 @@ import (

"errors"

_nethttp "net/http"

infrastructurev1beta1 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta1"
tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag"
"github.com/outscale-dev/cluster-api-provider-outscale.git/util/reconciler"
osc "github.com/outscale/osc-sdk-go/v2"
"k8s.io/apimachinery/pkg/util/wait"
_nethttp "net/http"
)

//go:generate ../../../bin/mockgen -destination mock_net/subnet_mock.go -package mock_net -source ./subnet.go
type OscSubnetInterface interface {
CreateSubnet(spec *infrastructurev1beta1.OscSubnet, netId string, clusterName string, subnetName string, subregionName string) (*osc.Subnet, error)
CreateSubnet(spec *infrastructurev1beta1.OscSubnet, netId string, clusterName string, subnetName string) (*osc.Subnet, error)
DeleteSubnet(subnetId string) error
GetSubnet(subnetId string) (*osc.Subnet, error)
GetSubnetIdsFromNetIds(netId string) ([]string, error)
}

// CreateSubnet create the subnet associate to the net
func (s *Service) CreateSubnet(spec *infrastructurev1beta1.OscSubnet, netId string, clusterName string, subnetName string, subregionName string) (*osc.Subnet, error) {
func (s *Service) CreateSubnet(spec *infrastructurev1beta1.OscSubnet, netId string, clusterName string, subnetName string) (*osc.Subnet, error) {
ipSubnetRange, err := infrastructurev1beta1.ValidateCidr(spec.IpSubnetRange)
if err != nil {
return nil, err
}
subregionName, err := infrastructurev1beta1.ValidateSubregionName(spec.SubregionName)
if err != nil {
return nil, err
}
subnetRequest := osc.CreateSubnetRequest{
IpRange: ipSubnetRange,
NetId: netId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1-0.20230203165829-9084e41bb752
controller-gen.kubebuilder.io/version: v0.9.1-0.20220825130208-40db49591af1
creationTimestamp: null
name: oscclusters.infrastructure.cluster.x-k8s.io
spec:
Expand Down Expand Up @@ -219,6 +219,28 @@ spec:
description: The subnet tag name associate with a Subnet
type: string
type: object
natServices:
description: The Nat Services configuration
items:
properties:
clusterName:
description: The name of the cluster
type: string
name:
description: The tag name associate with the Nat Service
type: string
publicipname:
description: The Public Ip tag name associated wtih a Public
Ip
type: string
resourceId:
description: The Nat Service Id response
type: string
subnetname:
description: The subnet tag name associate with a Subnet
type: string
type: object
type: array
net:
description: The Net configuration
properties:
Expand Down Expand Up @@ -351,6 +373,9 @@ spec:
resourceId:
description: The Subnet Id response
type: string
subregionName:
description: The subregion name of the Subnet
type: string
type: object
type: array
subregionName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1-0.20230203165829-9084e41bb752
controller-gen.kubebuilder.io/version: v0.9.1-0.20220825130208-40db49591af1
creationTimestamp: null
name: oscclustertemplates.infrastructure.cluster.x-k8s.io
spec:
Expand Down Expand Up @@ -276,6 +276,30 @@ spec:
Subnet
type: string
type: object
natServices:
description: The Nat Services configuration
items:
properties:
clusterName:
description: The name of the cluster
type: string
name:
description: The tag name associate with the Nat
Service
type: string
publicipname:
description: The Public Ip tag name associated wtih
a Public Ip
type: string
resourceId:
description: The Nat Service Id response
type: string
subnetname:
description: The subnet tag name associate with
a Subnet
type: string
type: object
type: array
net:
description: The Net configuration
properties:
Expand Down Expand Up @@ -415,6 +439,9 @@ spec:
resourceId:
description: The Subnet Id response
type: string
subregionName:
description: The subregion name of the Subnet
type: string
type: object
type: array
subregionName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1-0.20230203165829-9084e41bb752
controller-gen.kubebuilder.io/version: v0.9.1-0.20220825130208-40db49591af1
creationTimestamp: null
name: oscmachines.infrastructure.cluster.x-k8s.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1-0.20230203165829-9084e41bb752
controller-gen.kubebuilder.io/version: v0.9.1-0.20220825130208-40db49591af1
creationTimestamp: null
name: oscmachinetemplates.infrastructure.cluster.x-k8s.io
spec:
Expand Down
Loading