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 11, 2024
1 parent eb6b40b commit e8476fa
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 9 deletions.
6 changes: 3 additions & 3 deletions modules/api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ require (
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
Expand All @@ -264,7 +264,7 @@ require (
k8s.io/kube-aggregator v0.31.0 // indirect
k8s.io/kube-openapi v0.0.0-20240816214639-573285566f34 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.2.4 // indirect
sigs.k8s.io/gateway-api v1.0.1-0.20240305045206-346e951245f2 // indirect
sigs.k8s.io/gateway-api v1.1.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
12 changes: 12 additions & 0 deletions modules/api/pkg/api/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ type PresetBodyMetadata struct {
type PresetProvider struct {
Name kubermaticv1.ProviderType `json:"name"`
Enabled bool `json:"enabled"`
IsEditable bool `json:"isEditable"`
VMwareCloudDirector *VMwareCloudDirectorAPIPreset `json:"vmwareCloudDirector,omitempty"`
OpenStack *OpenStackAPIPreset `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 OpenStackAPIPreset 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
9 changes: 7 additions & 2 deletions modules/api/pkg/handler/common/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ 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.
// Change condition to check if the isEditable preset is true and if the customizable fields have changed.
if body.Cluster.Spec.Cloud.Openstack == nil {
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.OpenStack = &apiv2.OpenStackAPIPreset{
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
7 changes: 4 additions & 3 deletions modules/api/pkg/provider/kubernetes/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,18 @@ func (m *PresetProvider) setOpenStackCredentials(preset *kubermaticv1.Preset, cl
cloud.Openstack.ApplicationCredentialID = credentials.ApplicationCredentialID
cloud.Openstack.ApplicationCredentialSecret = credentials.ApplicationCredentialSecret

// check if the preset is editable then no need to update these value since it will be updated from the req.body
// Change condition to check if the isEditable preset is true and if the customizable fields have changed.
cloud.Openstack.SubnetID = credentials.SubnetID
cloud.Openstack.Network = credentials.Network
cloud.Openstack.RouterID = credentials.RouterID
cloud.Openstack.FloatingIPPool = credentials.FloatingIPPool
cloud.Openstack.SecurityGroups = credentials.SecurityGroups

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

return &cloud, nil
}

Expand Down

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

7 changes: 7 additions & 0 deletions modules/api/pkg/test/e2e/utils/apiclient/models/kube_l_b.go

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

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

0 comments on commit e8476fa

Please sign in to comment.