Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use https for gitea #121

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ This command creates a kind cluster, expose associated endpoints to your local m
They are deployed as ArgoCD Applications with the Gitea repositories set as their sources.

UIs for Backstage, Gitea, and ArgoCD are accessible on the machine:
* Gitea: http://gitea.cnoe.localtest.me:8443/explore/repos
* Backstage: http://backstage.cnoe.localtest.me:8880/
* Gitea: https://gitea.cnoe.localtest.me:8443/explore/repos
* Backstage: https://backstage.cnoe.localtest.me:8443/
* ArgoCD: https://argocd.cnoe.localtest.me:8443/applications

ArgoCD username is `admin` and the password can be obtained with
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/custom_package_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type CustomPackageSpec struct {
// +kubebuilder:default:=false
Replicate bool `json:"replicate"`
// GitServerURL specifies the base URL for the git server for API calls.
// for example, http://gitea.cnoe.localtest.me:8880
// for example, https://gitea.cnoe.localtest.me:8443
GitServerURL string `json:"gitServerURL"`
// InternalGitServeURL specifies the base URL for the git server accessible within the cluster.
// for example, http://my-gitea-http.gitea.svc.cluster.local:3000
Expand Down
25 changes: 17 additions & 8 deletions pkg/controllers/gitrepository/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package gitrepository

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"os"
"path/filepath"
"time"
Expand All @@ -13,7 +15,7 @@ import (
"github.com/cnoe-io/idpbuilder/pkg/util"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport/http"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -75,12 +77,12 @@ func (r *RepositoryReconciler) getCredentials(ctx context.Context, repo *v1alpha
return string(username), string(password), nil
}

func (r *RepositoryReconciler) getBasicAuth(ctx context.Context, repo *v1alpha1.GitRepository) (http.BasicAuth, error) {
func (r *RepositoryReconciler) getBasicAuth(ctx context.Context, repo *v1alpha1.GitRepository) (githttp.BasicAuth, error) {
u, p, err := r.getCredentials(ctx, repo)
if err != nil {
return http.BasicAuth{}, err
return githttp.BasicAuth{}, err
}
return http.BasicAuth{
return githttp.BasicAuth{
Username: u,
Password: p,
}, nil
Expand Down Expand Up @@ -123,7 +125,12 @@ func (r *RepositoryReconciler) postProcessReconcile(ctx context.Context, req ctr
func (r *RepositoryReconciler) reconcileGitRepo(ctx context.Context, repo *v1alpha1.GitRepository) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.Info("reconciling", "name", repo.Name, "dir", repo.Spec.Source)
giteaClient, err := r.GiteaClientFunc(repo.Spec.GitURL)

tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
giteaClient, err := r.GiteaClientFunc(repo.Spec.GitURL, gitea.SetHTTPClient(client))
if err != nil {
return ctrl.Result{Requeue: true, RequeueAfter: requeueTime}, fmt.Errorf("failed to get gitea client: %w", err)
}
Expand Down Expand Up @@ -159,8 +166,9 @@ func (r *RepositoryReconciler) reconcileRepoContent(ctx context.Context, repo *v
}

clonedRepo, err := git.PlainClone(tempDir, false, &git.CloneOptions{
URL: giteaRepo.CloneURL,
NoCheckout: true,
URL: giteaRepo.CloneURL,
NoCheckout: true,
InsecureSkipTLS: true,
})
if err != nil {
return fmt.Errorf("cloning repo: %w", err)
Expand Down Expand Up @@ -210,7 +218,8 @@ func (r *RepositoryReconciler) reconcileRepoContent(ctx context.Context, repo *v
return fmt.Errorf("getting basic auth: %w", err)
}
err = clonedRepo.Push(&git.PushOptions{
Auth: &auth,
Auth: &auth,
InsecureSkipTLS: true,
})
if err != nil {
return fmt.Errorf("pushing to git: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/localbuild/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package localbuild
import (
"context"
"embed"

"github.com/cnoe-io/idpbuilder/api/v1alpha1"
"github.com/cnoe-io/idpbuilder/pkg/util"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -14,7 +15,7 @@ const (
giteaNamespace = "gitea"
giteaAdminSecret = "gitea-admin-secret"
// this is the URL accessible outside cluster. resolves to localhost
giteaIngressURL = "http://gitea.cnoe.localtest.me:8880"
giteaIngressURL = "https://gitea.cnoe.localtest.me:8443"
// 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stringData:
ENABLE_PPROF=false
HTTP_PORT=3000
PROTOCOL=http
ROOT_URL=http://gitea.cnoe.localtest.me:8880
ROOT_URL=https://gitea.cnoe.localtest.me:8443
SSH_DOMAIN=gitea.cnoe.localtest.me
SSH_LISTEN_PORT=2222
SSH_PORT=22
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/localbuild/resources/gitea/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gitea:
TYPE: level
server:
DOMAIN: gitea.cnoe.localtest.me
ROOT_URL: 'http://gitea.cnoe.localtest.me:8880'
ROOT_URL: 'https://gitea.cnoe.localtest.me:8443'

service:
ssh:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ spec:
type: object
gitServerURL:
description: GitServerURL specifies the base URL for the git server
for API calls. for example, http://gitea.cnoe.localtest.me:8880
for API calls. for example, https://gitea.cnoe.localtest.me:8443
type: string
internalGitServeURL:
description: InternalGitServeURL specifies the base URL for the git
Expand Down
6 changes: 0 additions & 6 deletions pkg/kind/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ nodes:
system-reserved: memory=4Gi
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8880
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
Expand Down Expand Up @@ -73,9 +70,6 @@ nodes:
system-reserved: memory=4Gi
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8880
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
Expand Down
3 changes: 0 additions & 3 deletions pkg/kind/resources/kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ nodes:
system-reserved: memory=4Gi
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 8880
protocol: TCP
- containerPort: 443
hostPort: 8443
protocol: TCP
Expand Down