diff --git a/api/cloud-control/v1beta1/providerType.go b/api/cloud-control/v1beta1/providerType.go index 64bedaf50..880332bee 100644 --- a/api/cloud-control/v1beta1/providerType.go +++ b/api/cloud-control/v1beta1/providerType.go @@ -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") ) diff --git a/api/cloud-control/v1beta1/scope_types.go b/api/cloud-control/v1beta1/scope_types.go index 2abd655a9..f55734b8b 100644 --- a/api/cloud-control/v1beta1/scope_types.go +++ b/api/cloud-control/v1beta1/scope_types.go @@ -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 { diff --git a/api/cloud-control/v1beta1/zz_generated.deepcopy.go b/api/cloud-control/v1beta1/zz_generated.deepcopy.go index 0fca55b61..e3ebcc626 100644 --- a/api/cloud-control/v1beta1/zz_generated.deepcopy.go +++ b/api/cloud-control/v1beta1/zz_generated.deepcopy.go @@ -626,6 +626,42 @@ func (in *NfsOptionsGcp) DeepCopy() *NfsOptionsGcp { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenStackNetwork) DeepCopyInto(out *OpenStackNetwork) { + *out = *in + if in.Zones != nil { + in, out := &in.Zones, &out.Zones + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackNetwork. +func (in *OpenStackNetwork) DeepCopy() *OpenStackNetwork { + if in == nil { + return nil + } + out := new(OpenStackNetwork) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenStackScope) DeepCopyInto(out *OpenStackScope) { + *out = *in + in.Network.DeepCopyInto(&out.Network) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackScope. +func (in *OpenStackScope) DeepCopy() *OpenStackScope { + if in == nil { + return nil + } + out := new(OpenStackScope) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RedisInstance) DeepCopyInto(out *RedisInstance) { *out = *in @@ -894,6 +930,11 @@ func (in *ScopeInfo) DeepCopyInto(out *ScopeInfo) { *out = new(AwsScope) (*in).DeepCopyInto(*out) } + if in.OpenStack != nil { + in, out := &in.OpenStack, &out.OpenStack + *out = new(OpenStackScope) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeInfo. diff --git a/config/crd/bases/cloud-control.kyma-project.io_scopes.yaml b/config/crd/bases/cloud-control.kyma-project.io_scopes.yaml index a23a37d10..04b893806 100644 --- a/config/crd/bases/cloud-control.kyma-project.io_scopes.yaml +++ b/config/crd/bases/cloud-control.kyma-project.io_scopes.yaml @@ -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 diff --git a/config/dist/kcp/crd/bases/cloud-control.kyma-project.io_scopes.yaml b/config/dist/kcp/crd/bases/cloud-control.kyma-project.io_scopes.yaml index a23a37d10..04b893806 100644 --- a/config/dist/kcp/crd/bases/cloud-control.kyma-project.io_scopes.yaml +++ b/config/dist/kcp/crd/bases/cloud-control.kyma-project.io_scopes.yaml @@ -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 diff --git a/pkg/kcp/scope/createScope.go b/pkg/kcp/scope/createScope.go index 6eccd148d..d72ac8455 100644 --- a/pkg/kcp/scope/createScope.go +++ b/pkg/kcp/scope/createScope.go @@ -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) diff --git a/pkg/kcp/scope/createScopeOpenStack.go b/pkg/kcp/scope/createScopeOpenStack.go new file mode 100644 index 000000000..04b5bf133 --- /dev/null +++ b/pkg/kcp/scope/createScopeOpenStack.go @@ -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 +}