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
42 changes: 21 additions & 21 deletions apps/console/internal/domain/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package domain

import (
"maps"

"github.com/kloudlite/api/apps/console/internal/entities"
fc "github.com/kloudlite/api/apps/console/internal/entities/field-constants"
"github.com/kloudlite/api/common"
Expand Down Expand Up @@ -101,10 +99,12 @@ func (d *domain) CreateConfig(ctx ResourceContext, config entities.Config) (*ent
config.AccountName = ctx.AccountName
config.ProjectName = ctx.ProjectName
config.EnvironmentName = ctx.EnvironmentName

if config.Annotations == nil {
config.Annotations = types.ConfigWatchingAnnotation
} else {
maps.Copy(config.Annotations, types.ConfigWatchingAnnotation)
config.Annotations = make(map[string]string, len(types.ConfigWatchingAnnotation))
}
for k, v := range types.ConfigWatchingAnnotation {
config.Annotations[k] = v
}

return d.createAndApplyConfig(ctx, &config)
Expand All @@ -126,8 +126,8 @@ func (d *domain) createAndApplyConfig(ctx ResourceContext, config *entities.Conf
return nil, errors.NewE(err)
}

if err := d.applyK8sResource(ctx, config.ProjectName, &cfg.ConfigMap, cfg.RecordVersion); err != nil {
return cfg, errors.NewE(err)
if err := d.applyK8sResource(ctx, cfg.ProjectName, &cfg.ConfigMap, cfg.RecordVersion); err != nil {
return nil, errors.NewE(err)
}

return cfg, nil
Expand All @@ -140,27 +140,27 @@ func (d *domain) UpdateConfig(ctx ResourceContext, config entities.Config) (*ent

config.SetGroupVersionKind(fn.GVK("v1", "ConfigMap"))

patchForUpdate := common.PatchForUpdate(
ctx,
&config,
common.PatchOpts{
XPatch: repos.Document{
fc.ConfigData: config.Data,
},
})
if config.Annotations == nil {
config.Annotations = make(map[string]string, len(types.ConfigWatchingAnnotation))
}

upConfig, err := d.configRepo.Patch(
ctx,
ctx.DBFilters().Add(fields.MetadataName, config.Name),
patchForUpdate,
for k, v := range types.ConfigWatchingAnnotation {
config.Annotations[k] = v
}

upConfig, err := d.configRepo.Patch(ctx, ctx.DBFilters().Add(fields.MetadataName, config.Name),
common.PatchForUpdate(ctx, &config, common.PatchOpts{XPatch: repos.Document{
fc.ConfigData: config.Data,
}}),
)
if err != nil {
return nil, errors.NewE(err)
}

d.resourceEventPublisher.PublishResourceEvent(ctx, entities.ResourceTypeConfig, upConfig.Name, PublishUpdate)

if err := d.applyK8sResource(ctx, ctx.ProjectName, &upConfig.ConfigMap, upConfig.RecordVersion); err != nil {
return upConfig, errors.NewE(err)
if err := d.applyK8sResource(ctx, upConfig.ProjectName, &upConfig.ConfigMap, upConfig.RecordVersion); err != nil {
return nil, errors.NewE(err)
}

return upConfig, nil
Expand Down
2 changes: 1 addition & 1 deletion apps/console/internal/domain/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (d *domain) DeleteEnvironment(ctx ConsoleContext, projectName string, name

if err := d.deleteK8sResource(ctx, uenv.ProjectName, &uenv.Environment); err != nil {
if errors.Is(err, ErrNoClusterAttached) {
return d.appRepo.DeleteById(ctx, uenv.Id)
return d.environmentRepo.DeleteById(ctx, uenv.Id)
}
return errors.NewE(err)
}
Expand Down
25 changes: 16 additions & 9 deletions apps/console/internal/domain/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,21 @@ func (d *domain) CreateSecret(ctx ResourceContext, secret entities.Secret) (*ent
secret.EnvironmentName = ctx.EnvironmentName
secret.SyncStatus = t.GenSyncStatus(t.SyncActionApply, secret.RecordVersion)

if secret.Annotations == nil {
secret.Annotations = make(map[string]string, len(types.SecretWatchingAnnotation))
}

for k, v := range types.SecretWatchingAnnotation {
secret.Annotations[k] = v
}

return d.createAndApplySecret(ctx, &secret)
}

func (d *domain) createAndApplySecret(ctx ResourceContext, secret *entities.Secret) (*entities.Secret, error) {
if _, err := d.upsertEnvironmentResourceMapping(ctx, secret); err != nil {
return nil, errors.NewE(err)
}

nsecret, err := d.secretRepo.Create(ctx, secret)
if err != nil {
if d.secretRepo.ErrAlreadyExists(err) {
Expand All @@ -135,14 +142,6 @@ func (d *domain) createAndApplySecret(ctx ResourceContext, secret *entities.Secr
return nil, errors.NewE(err)
}

if nsecret.Annotations == nil {
nsecret.Annotations = make(map[string]string)
}

for k, v := range types.SecretWatchingAnnotation {
nsecret.Annotations[k] = v
}

if err := d.applyK8sResource(ctx, nsecret.ProjectName, &nsecret.Secret, nsecret.RecordVersion); err != nil {
return nsecret, errors.NewE(err)
}
Expand All @@ -155,6 +154,14 @@ func (d *domain) UpdateSecret(ctx ResourceContext, secret entities.Secret) (*ent
return nil, errors.NewE(err)
}

if secret.Annotations == nil {
secret.Annotations = make(map[string]string, len(types.SecretWatchingAnnotation))
}

for k, v := range types.SecretWatchingAnnotation {
secret.Annotations[k] = v
}

patchForUpdate := common.PatchForUpdate(
ctx,
&secret,
Expand Down