Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/infra/internal/domain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ type Domain interface {

ListClusterManagedServices(ctx InfraContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.ClusterManagedService], error)
GetClusterManagedService(ctx InfraContext, serviceName string) (*entities.ClusterManagedService, error)

CreateClusterManagedService(ctx InfraContext, cmsvc entities.ClusterManagedService) (*entities.ClusterManagedService, error)
CloneClusterManagedService(ctx InfraContext, args CloneManagedServiceArgs) (*entities.ClusterManagedService, error)
UpdateClusterManagedService(ctx InfraContext, cmsvc entities.ClusterManagedService) (*entities.ClusterManagedService, error)
DeleteClusterManagedService(ctx InfraContext, name string) error
ArchiveClusterManagedService(ctx InfraContext, clusterName string) error

OnClusterManagedServiceApplyError(ctx InfraContext, clusterName, name, errMsg string, opts UpdateAndDeleteOpts) error
OnClusterManagedServiceDeleteMessage(ctx InfraContext, clusterName string, service entities.ClusterManagedService) error
Expand Down
32 changes: 32 additions & 0 deletions apps/infra/internal/domain/cluster-managed-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,38 @@ func (d *domain) CloneClusterManagedService(ctx InfraContext, args CloneManagedS
return destMsvc, nil
}

func (d *domain) ArchiveClusterManagedService(ctx InfraContext, clusterName string) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider adding a check for empty or invalid clusterName.

Adding a check for an empty or invalid clusterName at the beginning of the function can prevent unnecessary database queries and potential errors.

Suggested change
func (d *domain) ArchiveClusterManagedService(ctx InfraContext, clusterName string) error {
func (d *domain) ArchiveClusterManagedService(ctx InfraContext, clusterName string) error {
if clusterName == "" {
return errors.New("clusterName cannot be empty")
}

filter := repos.Filter{
fields.AccountName: ctx.AccountName,
fields.ClusterName: clusterName,
}

msvc, err := d.clusterManagedServiceRepo.Find(ctx, repos.Query{
Filter: filter,
Sort: nil,
})
if err != nil {
return errors.NewE(err)
}

for i := range msvc {
patchForUpdate := repos.Document{
fc.ClusterManagedServiceIsArchived: true,
}
patchFilter := repos.Filter{
fields.AccountName: ctx.AccountName,
fields.ClusterName: clusterName,
fields.MetadataName: msvc[i].Name,
}

_, err := d.clusterManagedServiceRepo.Patch(ctx, patchFilter, patchForUpdate)
if err != nil {
return errors.NewE(err)
}
}
return nil
}

func (d *domain) UpdateClusterManagedService(ctx InfraContext, cmsvc entities.ClusterManagedService) (*entities.ClusterManagedService, error) {
if err := d.canPerformActionInAccount(ctx, iamT.UpdateClusterManagedService); err != nil {
return nil, errors.NewE(err)
Expand Down
4 changes: 4 additions & 0 deletions apps/infra/internal/domain/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ func (d *domain) DeleteCluster(ctx InfraContext, name string) error {
return errors.NewE(err)
}

if err := d.ArchiveClusterManagedService(ctx, name); err != nil {
return errors.NewE(err)
}

d.resourceEventPublisher.PublishInfraEvent(ctx, ResourceTypeCluster, ucluster.Name, PublishUpdate)
if err := d.deleteK8sResource(ctx, &ucluster.Cluster); err != nil {
if !apiErrors.IsNotFound(err) {
Expand Down
2 changes: 2 additions & 0 deletions apps/infra/internal/entities/cluster-managed-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type ClusterManagedService struct {
AccountName string `json:"accountName" graphql:"noinput"`
ClusterName string `json:"clusterName"`

IsArchived *bool `json:"isArchived,omitempty" graphql:"noinput"`

SyncedOutputSecretRef *corev1.Secret `json:"syncedOutputSecretRef" graphql:"ignore"`

common.ResourceMetadata `json:",inline"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const (

// constant vars generated for struct ClusterManagedService
const (
ClusterManagedServiceIsArchived = "isArchived"
ClusterManagedServiceOutput = "output"
ClusterManagedServiceOutputCredentialsRef = "output.credentialsRef"
ClusterManagedServiceOutputCredentialsRefName = "output.credentialsRef.name"
Expand Down