This repository was archived by the owner on Jun 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/cluster update console vpn dev #239
Merged
abdheshnayak
merged 10 commits into
release-1.0.5
from
feature/cluster-update-console-vpn-dev
Jan 26, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
702d90f
:art: In device, fixed iam, deletion of device
abdheshnayak 7839416
:art: In device, fixed iam, deletion of device
abdheshnayak 7f48600
:art: Added device resource type for both console and infra
abdheshnayak a778fd3
Merge branch 'release-1.0.5' of github.com:kloudlite/api into release…
abdheshnayak 4b117ac
Merge branch 'release-1.0.5' of github.com:kloudlite/api into release…
abdheshnayak eb86907
Merge branch 'release-1.0.5' of github.com:kloudlite/api into release…
abdheshnayak 5c1f6b3
Merge branch 'release-1.0.5' of github.com:kloudlite/api into release…
abdheshnayak 674e6e6
Merge branch 'release-1.0.5' of github.com:kloudlite/api into release…
abdheshnayak 39fb847
:sparkles: Added support of cluster updated and namespace update in c…
abdheshnayak dcc9328
:lock: Added iam check while getting kubeconfig
abdheshnayak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,10 @@ func (d *domain) getClusterFromDevice(ctx ConsoleContext, device *entities.Conso | |
| return "", errors.Newf("device is nil") | ||
| } | ||
|
|
||
| if device.ProjectName == nil && device.ClusterName != nil { | ||
| return *device.ClusterName, nil | ||
| } | ||
|
|
||
| if device.ProjectName == nil { | ||
| return "", errors.NewE(errors.Newf("project name is nil")) | ||
| } | ||
|
|
@@ -62,13 +66,14 @@ func (d *domain) updateVpnOnCluster(ctx ConsoleContext, ndev, xdev *entities.Con | |
| return errors.NewE(err) | ||
| } | ||
|
|
||
| if ndev.ProjectName != nil && ndev.EnvironmentName != nil { | ||
| if (ndev.ProjectName != nil && ndev.EnvironmentName != nil) || ndev.ClusterName != nil { | ||
| if err := d.applyVPNDevice(ctx, ndev); err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
| } | ||
|
|
||
| if (xdev.ProjectName != nil) && (*xdev.ProjectName != *ndev.ProjectName) { | ||
| if (xdev.ProjectName != nil && (ndev.ProjectName == nil || *xdev.ProjectName != *ndev.ProjectName)) || | ||
| (xdev.ClusterName != nil && (ndev.ClusterName == nil || *xdev.ClusterName != *ndev.ClusterName)) { | ||
| xdev.Spec.Disabled = true | ||
| if err := d.applyVPNDevice(ctx, xdev); err != nil { | ||
| return errors.NewE(err) | ||
|
|
@@ -143,6 +148,14 @@ func (d *domain) applyVPNDevice(ctx ConsoleContext, device *entities.ConsoleVPND | |
| if err := d.applyK8sResource(ctx, *device.ProjectName, &device.Device, device.RecordVersion); err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| if device.ClusterName != nil { | ||
| if err := d.applyK8sResourceOnCluster(ctx, *device.ClusterName, &device.Device, device.RecordVersion); err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
|
|
@@ -219,7 +232,39 @@ func (d *domain) CreateVPNDevice(ctx ConsoleContext, device entities.ConsoleVPND | |
| return nDevice, nil | ||
| } | ||
|
|
||
| func (d *domain) UpdateVPNDevice(ctx ConsoleContext, device entities.ConsoleVPNDevice) (*entities.ConsoleVPNDevice, error) { | ||
| func (d *domain) UpdateVpnDeviceNs(ctx ConsoleContext, devName string, namespace string) (device error) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (llm): The function |
||
| if err := d.canPerformActionInDevice(ctx, iamT.UpdateVPNDevice, devName); err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
|
|
||
| xDevice, err := d.findVPNDevice(ctx, devName) | ||
| if err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
|
|
||
| patchForUpdate := common.PatchForUpdate( | ||
| ctx, | ||
| xDevice, | ||
| common.PatchOpts{ | ||
| XPatch: repos.Document{ | ||
| fc.ConsoleVPNDeviceSpecActiveNamespace: namespace, | ||
| }, | ||
| }) | ||
|
|
||
| upDevice, err := d.vpnDeviceRepo.PatchById(ctx, xDevice.Id, patchForUpdate) | ||
| if err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
| d.resourceEventPublisher.PublishConsoleEvent(ctx, entities.ResourceTypeVPNDevice, devName, PublishUpdate) | ||
|
|
||
| if err := d.applyVPNDevice(ctx, upDevice); err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (d *domain) updateVpnDevice(ctx ConsoleContext, device entities.ConsoleVPNDevice, projectName, envName, clusterName *string) (*entities.ConsoleVPNDevice, error) { | ||
| if err := d.canPerformActionInDevice(ctx, iamT.UpdateVPNDevice, device.Name); err != nil { | ||
| return nil, errors.NewE(err) | ||
| } | ||
|
|
@@ -233,23 +278,35 @@ func (d *domain) UpdateVPNDevice(ctx ConsoleContext, device entities.ConsoleVPND | |
|
|
||
| device.Spec.ActiveNamespace = nil | ||
|
|
||
| if device.ProjectName != nil && device.EnvironmentName != nil { | ||
| activeNamespace, err := d.envTargetNamespace(ctx, *device.ProjectName, *device.EnvironmentName) | ||
| if clusterName != nil && !slices.Contains(linkedClusters, *clusterName) { | ||
| linkedClusters = append(linkedClusters, *clusterName) | ||
| } | ||
|
|
||
| if projectName != nil && envName != nil { | ||
| activeNamespace, err := d.envTargetNamespace(ctx, *projectName, *envName) | ||
| if err != nil { | ||
| return nil, errors.NewE(err) | ||
| } | ||
| device.Spec.ActiveNamespace = &activeNamespace | ||
|
|
||
| clusterName, err := d.getClusterAttachedToProject(ctx, *device.ProjectName) | ||
| cName, err := d.getClusterAttachedToProject(ctx, *projectName) | ||
| if err != nil { | ||
| return nil, errors.NewE(err) | ||
| } | ||
|
|
||
| if clusterName != nil && !slices.Contains(linkedClusters, *clusterName) { | ||
| linkedClusters = append(linkedClusters, *clusterName) | ||
| if cName != nil && !slices.Contains(linkedClusters, *cName) { | ||
| linkedClusters = append(linkedClusters, *cName) | ||
| } | ||
| } | ||
|
|
||
| device.ClusterName = nil | ||
| if clusterName != nil { | ||
| device.ClusterName = clusterName | ||
|
|
||
| device.ProjectName = nil | ||
| device.EnvironmentName = nil | ||
| } | ||
|
|
||
| patchForUpdate := common.PatchForUpdate( | ||
| ctx, | ||
| &device, | ||
|
|
@@ -258,6 +315,7 @@ func (d *domain) UpdateVPNDevice(ctx ConsoleContext, device entities.ConsoleVPND | |
| fc.ConsoleVPNDeviceSpec: device.Spec, | ||
| fields.ProjectName: device.ProjectName, | ||
| fields.EnvironmentName: device.EnvironmentName, | ||
| fields.ClusterName: device.ClusterName, | ||
| fc.ConsoleVPNDeviceLinkedClusters: linkedClusters, | ||
| }, | ||
| }) | ||
|
|
@@ -279,6 +337,10 @@ func (d *domain) UpdateVPNDevice(ctx ConsoleContext, device entities.ConsoleVPND | |
| return upDevice, nil | ||
| } | ||
|
|
||
| func (d *domain) UpdateVPNDevice(ctx ConsoleContext, device entities.ConsoleVPNDevice) (*entities.ConsoleVPNDevice, error) { | ||
| return d.updateVpnDevice(ctx, device, device.ProjectName, device.EnvironmentName, nil) | ||
| } | ||
|
|
||
| func (d *domain) DeleteVPNDevice(ctx ConsoleContext, name string) error { | ||
| if err := d.canPerformActionInDevice(ctx, iamT.DeleteVPNDevice, name); err != nil { | ||
| return errors.NewE(err) | ||
|
|
@@ -356,13 +418,32 @@ func (d *domain) UpdateVpnDeviceEnvironment(ctx ConsoleContext, devName string, | |
| xdevice.ProjectName = &projectName | ||
| xdevice.EnvironmentName = &envName | ||
|
|
||
| _, err = d.UpdateVPNDevice(ctx, *xdevice) | ||
| _, err = d.updateVpnDevice(ctx, *xdevice, xdevice.ProjectName, xdevice.EnvironmentName, nil) | ||
| if err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (d *domain) UpdateVpnDeviceCluster(ctx ConsoleContext, devName string, clusterName string) error { | ||
| d.canPerformActionInAccount(ctx, iamT.GetCluster) | ||
|
|
||
| xdevice, err := d.findVPNDevice(ctx, devName) | ||
| if err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
|
|
||
| // TODO: check if cluster exists in account | ||
|
|
||
| xdevice.ClusterName = &clusterName | ||
| _, err = d.updateVpnDevice(ctx, *xdevice, nil, nil, &clusterName) | ||
| if err != nil { | ||
| return errors.NewE(err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (d *domain) OnVPNDeviceUpdateMessage(ctx ConsoleContext, device entities.ConsoleVPNDevice, status types.ResourceStatus, opts UpdateAndDeleteOpts, clusterName string) error { | ||
| xdevice, err := d.findVPNDevice(ctx, device.Name) | ||
| if err != nil { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (llm): The new function
applyK8sResourceOnClusteris a good addition for applying resources directly to a specified cluster. Ensure that the clusterName is validated before applying the resource to avoid potential issues with non-existent or incorrect cluster names.