Skip to content

Commit

Permalink
main workspace name is special
Browse files Browse the repository at this point in the history
Signed-off-by: John Belamaric <[email protected]>
  • Loading branch information
johnbelamaric committed Nov 22, 2023
1 parent 546cd02 commit fa49ede
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions porch/pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (cad *cadEngine) CreatePackageRevision(ctx context.Context, repositoryObj *
return nil, fmt.Errorf("error listing package revisions: %w", err)
}

if err := ensureUniqueWorkspaceName(obj, revs); err != nil {
if err := ensureUniqueWorkspaceName(repositoryObj, obj, revs); err != nil {
return nil, err
}

Expand Down Expand Up @@ -351,9 +351,20 @@ func (cad *cadEngine) CreatePackageRevision(ctx context.Context, repositoryObj *
}

// The workspaceName must be unique, because it used to generate the package revision's metadata.name.
func ensureUniqueWorkspaceName(obj *api.PackageRevision, existingRevs []repository.PackageRevision) error {
func ensureUniqueWorkspaceName(repositoryObj *configapi.Repository, obj *api.PackageRevision, existingRevs []repository.PackageRevision) error {
// HACK
// It's ok for the "main" revision to have the same workspace name
// So ignore main revisions in this calculation
mainRev := ""
if repositoryObj.Spec.Git != nil {
mainRev = repositoryObj.Spec.Git.Branch
}

for _, r := range existingRevs {
k := r.Key()
if mainRev != "" && k.Revision == mainRev {
continue
}
if k.WorkspaceName == obj.Spec.WorkspaceName {
return fmt.Errorf("package revision workspaceNames must be unique; package revision with name %s in repo %s with "+
"workspaceName %s already exists", obj.Spec.PackageName, obj.Spec.RepositoryName, obj.Spec.WorkspaceName)
Expand Down
4 changes: 4 additions & 0 deletions porch/pkg/engine/fake/packagerevision.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type PackageRevision struct {
Kptfile kptfile.KptFile
}

func (pr *PackageRevision) CachedIdentifier() repository.CachedIdentifier {
return repository.CachedIdentifier{Key: pr.Key().String(), Version: pr.Key().Revision}
}

func (pr *PackageRevision) KubeObjectName() string {
return pr.Name
}
Expand Down

0 comments on commit fa49ede

Please sign in to comment.