From 7808e97bde3f81e93714b715008d3fc766250d33 Mon Sep 17 00:00:00 2001 From: Manabu McCloskey Date: Fri, 21 Jun 2024 22:59:08 +0000 Subject: [PATCH] use internally and externally resolvable git url Signed-off-by: Manabu McCloskey --- pkg/controllers/localbuild/gitea.go | 12 ++++++++++-- pkg/controllers/localbuild/gitea_test.go | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 pkg/controllers/localbuild/gitea_test.go diff --git a/pkg/controllers/localbuild/gitea.go b/pkg/controllers/localbuild/gitea.go index 9c699244..e8478c2f 100644 --- a/pkg/controllers/localbuild/gitea.go +++ b/pkg/controllers/localbuild/gitea.go @@ -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/* @@ -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 @@ -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, "") +} diff --git a/pkg/controllers/localbuild/gitea_test.go b/pkg/controllers/localbuild/gitea_test.go new file mode 100644 index 00000000..5a0a0300 --- /dev/null +++ b/pkg/controllers/localbuild/gitea_test.go @@ -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) +}