Skip to content

Commit

Permalink
feat: CC Scope (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos77 authored Jul 19, 2024
1 parent b00cd2e commit e3fa7d4
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 3 deletions.
7 changes: 4 additions & 3 deletions api/cloud-control/v1beta1/providerType.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package v1beta1
type ProviderType string

const (
ProviderGCP = ProviderType("gcp")
ProviderAzure = ProviderType("azure")
ProviderAws = ProviderType("aws")
ProviderGCP = ProviderType("gcp")
ProviderAzure = ProviderType("azure")
ProviderAws = ProviderType("aws")
ProviderOpenStack = ProviderType("openstack")
)
25 changes: 25 additions & 0 deletions api/cloud-control/v1beta1/scope_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ type ScopeInfo struct {

// +optional
Aws *AwsScope `json:"aws,omitempty"`

// +optional
OpenStack *OpenStackScope `json:"openstack,omitempty"`
}

type OpenStackScope struct {
VpcNetwork string `json:"vpcNetwork"`
DomainName string `json:"domainName"`
TenantName string `json:"tenantName"`

Network OpenStackNetwork `json:"network"`
}

type OpenStackNetwork struct {
// +optional
Nodes string `json:"nodes,omitempty"`

// +optional
Pods string `json:"pods,omitempty"`

// +optional
Services string `json:"services,omitempty"`

// +optional
Zones []string `json:"zones,omitempty"`
}

type GcpScope struct {
Expand Down
41 changes: 41 additions & 0 deletions api/cloud-control/v1beta1/zz_generated.deepcopy.go

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

27 changes: 27 additions & 0 deletions config/crd/bases/cloud-control.kyma-project.io_scopes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ spec:
- project
- vpcNetwork
type: object
openstack:
properties:
domainName:
type: string
network:
properties:
nodes:
type: string
pods:
type: string
services:
type: string
zones:
items:
type: string
type: array
type: object
tenantName:
type: string
vpcNetwork:
type: string
required:
- domainName
- network
- tenantName
- vpcNetwork
type: object
type: object
shootName:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ spec:
- project
- vpcNetwork
type: object
openstack:
properties:
domainName:
type: string
network:
properties:
nodes:
type: string
pods:
type: string
services:
type: string
zones:
items:
type: string
type: array
type: object
tenantName:
type: string
vpcNetwork:
type: string
required:
- domainName
- network
- tenantName
- vpcNetwork
type: object
type: object
shootName:
type: string
Expand Down
2 changes: 2 additions & 0 deletions pkg/kcp/scope/createScope.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func createScope(ctx context.Context, st composed.State) (error, context.Context
return createScopeAzure(ctx, state)
case cloudcontrolv1beta1.ProviderAws:
return createScopeAws(ctx, state)
case cloudcontrolv1beta1.ProviderOpenStack:
return createScopeOpenStack(ctx, state)
}

err := fmt.Errorf("unable to handle unknown provider '%s'", state.provider)
Expand Down
41 changes: 41 additions & 0 deletions pkg/kcp/scope/createScopeOpenStack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package scope

import (
"context"
"github.com/elliotchance/pie/v2"
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
"github.com/kyma-project/cloud-manager/pkg/composed"
"k8s.io/utils/ptr"
)

func createScopeOpenStack(ctx context.Context, st composed.State) (error, context.Context) {
state := st.(*State)

var zones []string
for _, worker := range state.shoot.Spec.Provider.Workers {
zones = append(zones, worker.Zones...)
}
zones = pie.Unique(zones)
zones = pie.Sort(zones)
scope := &cloudcontrolv1beta1.Scope{
Spec: cloudcontrolv1beta1.ScopeSpec{
Scope: cloudcontrolv1beta1.ScopeInfo{
OpenStack: &cloudcontrolv1beta1.OpenStackScope{
VpcNetwork: commonVpcName(state.shootNamespace, state.shootName), // ???
DomainName: state.credentialData["domainName"],
TenantName: state.credentialData["tenantName"],
Network: cloudcontrolv1beta1.OpenStackNetwork{
Nodes: ptr.Deref(state.shoot.Spec.Networking.Nodes, ""),
Pods: ptr.Deref(state.shoot.Spec.Networking.Pods, ""),
Services: ptr.Deref(state.shoot.Spec.Networking.Services, ""),
Zones: zones,
},
},
},
},
}

state.SetObj(scope)

return nil, nil
}

0 comments on commit e3fa7d4

Please sign in to comment.