Skip to content

Commit

Permalink
Change ns clone/import to not require slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tjerman committed Mar 11, 2024
1 parent 9eb62d9 commit 2349193
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions server/compose/rest/namespace.go
Expand Up @@ -207,6 +207,11 @@ func (ctrl Namespace) Clone(ctx context.Context, r *request.NamespaceClone) (int
Slug: r.Slug,
}

// @todo temporary workaround cause Envoy requires some identifiable thing
if dup.Slug == "" {
dup.Slug = fmt.Sprintf("cl_%d", r.NamespaceID)
}

nodes, err := ctrl.gatherNodes(ctx, r.NamespaceID)
if err != nil {
return nil, err
Expand All @@ -217,6 +222,18 @@ func (ctrl Namespace) Clone(ctx context.Context, r *request.NamespaceClone) (int
}

ns, err := ctrl.namespace.Clone(ctx, r.NamespaceID, dup, decoder)
if err != nil {
return nil, err
}

// @todo temporary workaround cause Envoy requires some identifiable thing
if r.Slug == "" {
ns.Slug = ""
ns, err = ctrl.namespace.Update(ctx, ns)
if err != nil {
return nil, err
}
}
return ctrl.makePayload(ctx, ns, err)
}

Expand Down Expand Up @@ -279,7 +296,24 @@ func (ctrl Namespace) ImportRun(ctx context.Context, r *request.NamespaceImportR
}
)

// @todo temporary workaround cause Envoy requires some identifiable thing
if dup.Slug == "" {
dup.Slug = fmt.Sprintf("cl_%d", r.SessionID)
}

ns, err := ctrl.namespace.ImportRun(ctx, r.SessionID, dup)
if err != nil {
return nil, err
}

// @todo temporary workaround cause Envoy requires some identifiable thing
if r.Slug == "" {
ns.Slug = ""
ns, err = ctrl.namespace.Update(ctx, ns)
if err != nil {
return nil, err
}
}
return ctrl.makePayload(ctx, ns, err)
}

Expand Down
6 changes: 6 additions & 0 deletions server/compose/service/namespace.go
Expand Up @@ -485,6 +485,11 @@ func (svc namespace) ImportRun(ctx context.Context, sessionID uint64, dup *types
return err
}

newNS, err = store.LookupComposeNamespaceBySlug(ctx, s, newNS.Slug)
if err != nil {
return err
}

aProps.setNamespace(newNS)
return nil
})
Expand All @@ -493,6 +498,7 @@ func (svc namespace) ImportRun(ctx context.Context, sessionID uint64, dup *types
}

err = svc.reloadServices(ctx, newNS)
dup = newNS
return err
}()

Expand Down

0 comments on commit 2349193

Please sign in to comment.