Skip to content

Commit

Permalink
use internally and externally resolvable git url (#326)
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey authored Jun 22, 2024
1 parent a4d6883 commit d6c83b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/controllers/localbuild/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
giteaIngressURL = "%s://gitea.cnoe.localtest.me:%s"
// this is the URL accessible within cluster for ArgoCD to fetch resources.
// resolves to cluster ip
giteaSvcURL = "http://my-gitea-http.gitea.svc.cluster.local:3000"
giteaSvcURL = "%s://%s%s:%s%s"
)

//go:embed resources/gitea/k8s/*
Expand Down Expand Up @@ -116,7 +116,7 @@ func (r *LocalbuildReconciler) ReconcileGitea(ctx context.Context, req ctrl.Requ
}

resource.Status.Gitea.ExternalURL = baseUrl
resource.Status.Gitea.InternalURL = giteaSvcURL
resource.Status.Gitea.InternalURL = giteaInternalBaseUrl(r.Config)
resource.Status.Gitea.AdminUserSecretName = giteaAdminSecret
resource.Status.Gitea.AdminUserSecretNamespace = giteaNamespace
resource.Status.Gitea.Available = true
Expand All @@ -126,3 +126,11 @@ func (r *LocalbuildReconciler) ReconcileGitea(ctx context.Context, req ctrl.Requ
func giteaBaseUrl(config util.CorePackageTemplateConfig) string {
return fmt.Sprintf(giteaIngressURL, config.Protocol, config.Port)
}

// gitea URL reachable within the cluster with proper coredns config. Mainly for argocd
func giteaInternalBaseUrl(config util.CorePackageTemplateConfig) string {
if config.UsePathRouting {
return fmt.Sprintf(giteaSvcURL, config.Protocol, "", config.Host, config.Port, "/gitea")
}
return fmt.Sprintf(giteaSvcURL, config.Protocol, "gitea.", config.Host, config.Port, "")
}
23 changes: 23 additions & 0 deletions pkg/controllers/localbuild/gitea_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package localbuild

import (
"testing"

"github.com/cnoe-io/idpbuilder/pkg/util"
"github.com/stretchr/testify/assert"
)

func TestGiteaInternalBaseUrl(t *testing.T) {
c := util.CorePackageTemplateConfig{
Protocol: "http",
Port: "8080",
Host: "cnoe.localtest.me",
UsePathRouting: false,
}

s := giteaInternalBaseUrl(c)
assert.Equal(t, "http://gitea.cnoe.localtest.me:8080", s)
c.UsePathRouting = true
s = giteaInternalBaseUrl(c)
assert.Equal(t, "http://cnoe.localtest.me:8080/gitea", s)
}

0 comments on commit d6c83b7

Please sign in to comment.