Skip to content

Commit

Permalink
chore: allow aliases that aren't simple alpha-numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Nov 19, 2024
1 parent bca7d49 commit fd072b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/alias/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/otto8-ai/nah/pkg/name"
"github.com/otto8-ai/nah/pkg/router"
"github.com/otto8-ai/otto8/pkg/hash"
v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.otto8.ai/v1"
"github.com/otto8-ai/otto8/pkg/system"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -53,7 +54,7 @@ func Get(ctx context.Context, c kclient.Client, obj v1.Aliasable, namespace stri
}

func KeyFromScopeID(scope, id string) string {
return strings.ToLower(name.SafeHashConcatName(id, scope))
return system.AliasPrefix + hash.String(name.SafeHashConcatName(id, scope))[:8]
}

func GetScope(gvk schema.GroupVersionKind, obj v1.Aliasable) string {
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/handlers/alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func UnassignAlias(req router.Request, _ router.Response) error {
return err
}

// Check if alias name algorithm has changed
if src.Name != alias.KeyFromScopeID(alias.GetScope(gvk, aliasable), src.Spec.Name) {
log.Infof("Alias name algorithm has changed, deleting alias %s", src.Name)
return req.Delete(src)
}

aliasName, err := alias.Name(req.Client, aliasable)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/system/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
OAuthAppLoginPrefix = "oal1"
EmailReceiverPrefix = "er1"
ModelPrefix = "m1"
AliasPrefix = "al1"
)

func IsThreadID(id string) bool {
Expand Down

0 comments on commit fd072b4

Please sign in to comment.