Skip to content

Commit

Permalink
update editable values api
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadhamzh committed Sep 9, 2024
1 parent 86324c8 commit 447bd20
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
18 changes: 15 additions & 3 deletions modules/api/pkg/api/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ type PresetBodyMetadata struct {
// PresetProvider represents a preset provider
// swagger:model PresetProvider
type PresetProvider struct {
Name kubermaticv1.ProviderType `json:"name"`
Enabled bool `json:"enabled"`
VMwareCloudDirector *VMwareCloudDirectorAPIPreset `json:"vmwareCloudDirector,omitempty"`
Name kubermaticv1.ProviderType `json:"name"`
Enabled bool `json:"enabled"`
IsEditable bool `json:"isEditable"`
VMwareCloudDirector *VMwareCloudDirectorAPIPreset `json:"vmwareCloudDirector,omitempty"`
OpenStackCloudDirector *OpenStackCloudDirectorAPIPreset `json:"openStackCloudDirector,omitempty"`
}

// VMwareCloudDirectorPreset represents a preset for VMware Cloud Director
Expand All @@ -169,6 +171,16 @@ type VMwareCloudDirectorAPIPreset struct {
OVDCNetworks []string `json:"ovdcNetworks,omitempty"`
}

// OpenStackCloudDirectorPreset represents a preset for OpenStack Cloud Director
// swagger:model OpenStackCloudDirectorAPIPreset
type OpenStackCloudDirectorAPIPreset struct {
Network string `json:"network,omitempty"`
SecurityGroups string `json:"securityGroups,omitempty"`
FloatingIPPool string `json:"floatingIPPool,omitempty"`
RouterID string `json:"routerID,omitempty"`
SubnetID string `json:"subnetID,omitempty"`
}

// PresetStats represents a preset statistics
// swagger:model PresetStats
type PresetStats struct {
Expand Down
17 changes: 15 additions & 2 deletions modules/api/pkg/handler/common/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,22 @@ func GenerateCluster(
if err != nil {
return nil, utilerrors.NewBadRequest("invalid credentials: %v", err)
}

//
// At the moment, the only provider that can be customized is OpenStack.
//
if body.Cluster.Spec.Cloud.Openstack != nil {
cloudSpec.Openstack.Network = body.Cluster.Spec.Cloud.Openstack.Network
cloudSpec.Openstack.SecurityGroups = body.Cluster.Spec.Cloud.Openstack.SecurityGroups
cloudSpec.Openstack.FloatingIPPool = body.Cluster.Spec.Cloud.Openstack.FloatingIPPool
cloudSpec.Openstack.RouterID = body.Cluster.Spec.Cloud.Openstack.RouterID
cloudSpec.Openstack.SubnetID = body.Cluster.Spec.Cloud.Openstack.SubnetID
body.Cluster.Credential = ""
} else {
partialCluster.Labels[kubermaticv1.IsCredentialPresetLabelKey] = "true"
partialCluster.Annotations[kubermaticv1.PresetNameAnnotation] = credentialName
}
body.Cluster.Spec.Cloud = *cloudSpec
partialCluster.Labels[kubermaticv1.IsCredentialPresetLabelKey] = "true"
partialCluster.Annotations[kubermaticv1.PresetNameAnnotation] = credentialName
}

// Fetch the defaulting ClusterTemplate.
Expand Down
10 changes: 10 additions & 0 deletions modules/api/pkg/handler/v2/preset/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,16 @@ func newAPIPreset(preset *kubermaticv1.Preset, enabled bool) apiv2.Preset {
}
}

if providerType == kubermaticv1.OpenstackCloudProvider {
provider.OpenStackCloudDirector = &apiv2.OpenStackCloudDirectorAPIPreset{
Network: preset.Spec.Openstack.Network,
SecurityGroups: preset.Spec.Openstack.SecurityGroups,
FloatingIPPool: preset.Spec.Openstack.FloatingIPPool,
RouterID: preset.Spec.Openstack.RouterID,
SubnetID: preset.Spec.Openstack.SubnetID,
}
}

providers = append(providers, provider)
}
}
Expand Down
1 change: 0 additions & 1 deletion modules/api/pkg/handler/v2/provider/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ func DecodeOpenstackSubnetReq(c context.Context, r *http.Request) (interface{},
if err != nil {
return nil, err
}

networkID := r.URL.Query().Get("network_id")
if networkID == "" {
return nil, fmt.Errorf("'network_id' is a required parameter and may not be empty")
Expand Down
14 changes: 11 additions & 3 deletions modules/api/pkg/provider/kubernetes/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,24 @@ func (m *PresetProvider) setOpenStackCredentials(preset *kubermaticv1.Preset, cl
cloud.Openstack.ApplicationCredentialID = credentials.ApplicationCredentialID
cloud.Openstack.ApplicationCredentialSecret = credentials.ApplicationCredentialSecret

cloud.Openstack.SubnetID = credentials.SubnetID
cloud.Openstack.Network = credentials.Network
cloud.Openstack.FloatingIPPool = credentials.FloatingIPPool

if cloud.Openstack.FloatingIPPool == "" && dc.Spec.Openstack != nil && dc.Spec.Openstack.EnforceFloatingIP {
return nil, fmt.Errorf("preset error, no floating ip pool specified for OpenStack")
}

cloud.Openstack.RouterID = credentials.RouterID
cloud.Openstack.SecurityGroups = credentials.SecurityGroups
if cloud.Openstack.SecurityGroups == "" {
cloud.Openstack.SecurityGroups = credentials.SecurityGroups
}

if cloud.Openstack.SubnetID == "" {
cloud.Openstack.SubnetID = credentials.SubnetID
}

if cloud.Openstack.Network == "" {
cloud.Openstack.Network = credentials.Network
}

return &cloud, nil
}
Expand Down

0 comments on commit 447bd20

Please sign in to comment.