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 f97de28
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 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: 6 additions & 6 deletions modules/api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,10 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 h1:+/tmTy5zAieooKIXfzDm9KiA3Bv6JBwriRN9LY+yayk=
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988/go.mod h1:4+X6GvPs+25wZKbQq9qyAXrwIRExv7w0Ea6MgZLZiDM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 h1:V71AcdLZr2p8dC9dbOIMCpqi4EmRl8wUwnJzXXLmbmc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
Expand Down Expand Up @@ -1019,8 +1019,8 @@ sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC
sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/controller-tools v0.16.1 h1:gvIsZm+2aimFDIBiDKumR7EBkc+oLxljoUVfRbDI6RI=
sigs.k8s.io/controller-tools v0.16.1/go.mod h1:0I0xqjR65YTfoO12iR+mZR6s6UAVcUARgXRlsu0ljB0=
sigs.k8s.io/gateway-api v1.0.1-0.20240305045206-346e951245f2 h1:Cop3UHLUBBPvVBwd7K/HggPEx1aT0ICLxY2TODjmIzM=
sigs.k8s.io/gateway-api v1.0.1-0.20240305045206-346e951245f2/go.mod h1:N633Wiqx6+sMTK6FEquSHsZl8KddnoMFkimrnXE5SFk=
sigs.k8s.io/gateway-api v1.1.0 h1:DsLDXCi6jR+Xz8/xd0Z1PYl2Pn0TyaFMOPPZIj4inDM=
sigs.k8s.io/gateway-api v1.1.0/go.mod h1:ZH4lHrL2sDi0FHZ9jjneb8kKnGzFWyrTya35sWUTrRs=
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6/go.mod h1:p4QtZmO4uMYipTQNzagwnNoseA6OxSUutVw05NhYDRs=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
Expand Down
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

0 comments on commit f97de28

Please sign in to comment.