Skip to content

Commit

Permalink
Merge pull request #706 from ts-mini/tsmini.support-any-gitlab
Browse files Browse the repository at this point in the history
✨ Allow accepting self-hosted gitlab installations
  • Loading branch information
k8s-ci-robot authored Feb 6, 2025
2 parents d6591a7 + 63b6f1f commit bfcacce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/controller/phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ func TestRepositoryFactory(t *testing.T) {
name: "gitlab repo",
fetchURL: "https://gitlab.example.org/api/v4/projects/group%2Fproject/packages/generic/cluster-api-proviver-aws/v1.4.1/path",
},
{
name: "gitlab hyphenated repo",
fetchURL: "https://gitlab-test.example.org/api/v4/projects/group%2Fproject/packages/generic/cluster-api-proviver-aws/v1.4.1/path",
},
{
name: "unsupported url",
fetchURL: "https://unsupported.xyz/kubernetes-sigs/cluster-api-provider-aws/releases/v1.4.1/infrastructure-components.yaml",
Expand Down
8 changes: 5 additions & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"net/url"
"regexp"
"strings"

operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
Expand All @@ -33,7 +34,7 @@ import (
const (
httpsScheme = "https"
githubDomain = "github.com"
gitlabHostPrefix = "gitlab."
gitlabHostPrefix = "gitlab"
gitlabPackagesAPIPrefix = "/api/v4/projects/"
)

Expand Down Expand Up @@ -128,8 +129,9 @@ func RepositoryFactory(ctx context.Context, providerConfig configclient.Provider
return repo, err
}

// if the url is a GitLab repository
if strings.HasPrefix(rURL.Host, gitlabHostPrefix) && strings.HasPrefix(rURL.Path, gitlabPackagesAPIPrefix) {
// if the url is a GitLab repository starting with gitlab- or gitlab.
gitlabHostRegex := regexp.MustCompile(`^` + regexp.QuoteMeta(gitlabHostPrefix) + `(-.*)?\.`) // ^gitlab(-.*)?\. to match gitlab- or gitlab.
if gitlabHostRegex.MatchString(rURL.Host) && strings.HasPrefix(rURL.Path, gitlabPackagesAPIPrefix) {
repo, err := repository.NewGitLabRepository(providerConfig, configVariablesClient)
if err != nil {
return nil, fmt.Errorf("error creating the GitLab repository client: %w", err)
Expand Down

0 comments on commit bfcacce

Please sign in to comment.