From 5351de360f644e00a9ea8e669457710925bdaeb7 Mon Sep 17 00:00:00 2001 From: Nima Kaviani Date: Tue, 17 Oct 2023 23:41:06 -0700 Subject: [PATCH] wip - install gitea fixes 32 --- api/v1alpha1/localbuild_types.go | 8 + api/v1alpha1/zz_generated.deepcopy.go | 16 + pkg/build/build.go | 3 + pkg/controllers/localbuild/argo.go | 4 +- pkg/controllers/localbuild/controller.go | 6 + pkg/controllers/localbuild/gitea.go | 129 +++++ .../resources/gitea/k8s/install.yaml | 546 ++++++++++++++++++ .../localbuild/resources/gitea/values.yaml | 20 + .../idpbuilder.cnoe.io_localbuilds.yaml | 10 + 9 files changed, 740 insertions(+), 2 deletions(-) create mode 100644 pkg/controllers/localbuild/gitea.go create mode 100644 pkg/controllers/localbuild/resources/gitea/k8s/install.yaml create mode 100644 pkg/controllers/localbuild/resources/gitea/values.yaml diff --git a/api/v1alpha1/localbuild_types.go b/api/v1alpha1/localbuild_types.go index 3ba5f3b8..26256735 100644 --- a/api/v1alpha1/localbuild_types.go +++ b/api/v1alpha1/localbuild_types.go @@ -20,7 +20,14 @@ type EmbeddedArgoApplicationsPackageConfigSpec struct { Enabled bool `json:"enabled,omitempty"` } +// GitConfigSpec controls what git server to use for the idpbuilder +// It can take on the values of either gitea or gitserver +type GitConfigSpec struct { + Type string `json:"type,omitempty"` +} + type PackageConfigsSpec struct { + GitConfig GitConfigSpec `json:"gitConfig,omitempty"` Argo ArgoPackageConfigSpec `json:"argoPackageConfigs,omitempty"` EmbeddedArgoApplications EmbeddedArgoApplicationsPackageConfigSpec `json:"embeddedArgoApplicationsPackageConfigs,omitempty"` } @@ -35,6 +42,7 @@ type LocalbuildStatus struct { ObservedGeneration int64 `json:"observedGeneration,omitempty"` GitServerAvailable bool `json:"gitServerAvailable,omitempty"` + GiteaAvailable bool `json:"giteaAvailable,omitempty"` ArgoAvailable bool `json:"argoAvailable,omitempty"` ArgoAppsCreated bool `json:"argoAppsCreated,omitempty"` } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index bc5b1c71..53926bc5 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -55,6 +55,21 @@ func (in *EmbeddedArgoApplicationsPackageConfigSpec) DeepCopy() *EmbeddedArgoApp return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GitConfigSpec) DeepCopyInto(out *GitConfigSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitConfigSpec. +func (in *GitConfigSpec) DeepCopy() *GitConfigSpec { + if in == nil { + return nil + } + out := new(GitConfigSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GitServer) DeepCopyInto(out *GitServer) { *out = *in @@ -253,6 +268,7 @@ func (in *LocalbuildStatus) DeepCopy() *LocalbuildStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PackageConfigsSpec) DeepCopyInto(out *PackageConfigsSpec) { *out = *in + out.GitConfig = in.GitConfig out.Argo = in.Argo out.EmbeddedArgoApplications = in.EmbeddedArgoApplications } diff --git a/pkg/build/build.go b/pkg/build/build.go index 5d2be830..bc2d8f0e 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -148,6 +148,9 @@ func (b *Build) Run(ctx context.Context, recreateCluster bool) error { EmbeddedArgoApplications: v1alpha1.EmbeddedArgoApplicationsPackageConfigSpec{ Enabled: true, }, + GitConfig: v1alpha1.GitConfigSpec{ + Type: "gitea", + }, }, } return nil diff --git a/pkg/controllers/localbuild/argo.go b/pkg/controllers/localbuild/argo.go index b6545501..73d8dbf1 100644 --- a/pkg/controllers/localbuild/argo.go +++ b/pkg/controllers/localbuild/argo.go @@ -19,7 +19,7 @@ import ( ) //go:embed resources/argo/* -var installFS embed.FS +var installArgoFS embed.FS const ( argoApplicationControllerName string = "argocd-application-controller" @@ -28,7 +28,7 @@ const ( ) func GetRawInstallResources() ([][]byte, error) { - return util.ConvertFSToBytes(installFS, "resources/argo") + return util.ConvertFSToBytes(installArgoFS, "resources/argo") } func GetK8sInstallResources(scheme *runtime.Scheme) ([]client.Object, error) { diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index a9847241..e7dd7730 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -69,6 +69,7 @@ func (r *LocalbuildReconciler) Reconcile(ctx context.Context, req ctrl.Request) subReconcilers := []subReconciler{ r.ReconcileProjectNamespace, r.ReconcileArgo, + r.ReconcileGitea, r.ReconcileEmbeddedGitServer, r.ReconcileArgoApps, } @@ -125,6 +126,11 @@ func (r *LocalbuildReconciler) ReconcileProjectNamespace(ctx context.Context, re func (r *LocalbuildReconciler) ReconcileEmbeddedGitServer(ctx context.Context, req ctrl.Request, resource *v1alpha1.Localbuild) (ctrl.Result, error) { log := log.FromContext(ctx) + if resource.Spec.PackageConfigs.GitConfig.Type != gitServerResourceName { + log.Info("GitServer installation disabled, skipping") + return ctrl.Result{}, nil + } + // Bail if argo is not yet available if !resource.Status.ArgoAvailable { log.Info("argo not yet available, not installing embedded git server") diff --git a/pkg/controllers/localbuild/gitea.go b/pkg/controllers/localbuild/gitea.go new file mode 100644 index 00000000..ecf80d90 --- /dev/null +++ b/pkg/controllers/localbuild/gitea.go @@ -0,0 +1,129 @@ +package localbuild + +import ( + "context" + "embed" + "errors" + "time" + + "github.com/cnoe-io/idpbuilder/api/v1alpha1" + "github.com/cnoe-io/idpbuilder/pkg/k8s" + "github.com/cnoe-io/idpbuilder/pkg/util" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" +) + +//go:embed resources/gitea/k8s/* +var installGiteaFS embed.FS +var timeout = time.After(30 * time.Second) + +const ( + giteaServerName string = "my-gitea" +) + +const giteaResourceName = "gitea" + +func GetRawGiteaInstallResources() ([][]byte, error) { + return util.ConvertFSToBytes(installGiteaFS, "resources/gitea/k8s") +} + +func GetK8sGiteaInstallResources(scheme *runtime.Scheme) ([]client.Object, error) { + rawResources, err := GetRawGiteaInstallResources() + if err != nil { + return nil, err + } + + return k8s.ConvertRawResourcesToObjects(scheme, rawResources) +} + +func newGiteaNamespace() *corev1.Namespace { + return &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: "gitea", + }, + } +} + +func (r *LocalbuildReconciler) ReconcileGitea(ctx context.Context, req ctrl.Request, resource *v1alpha1.Localbuild) (ctrl.Result, error) { + log := log.FromContext(ctx) + + if resource.Spec.PackageConfigs.GitConfig.Type != giteaResourceName { + log.Info("Gitea installation disabled, skipping") + return ctrl.Result{}, nil + } + + // Install Gitea + giteansClient := client.NewNamespacedClient(r.Client, "gitea") + installObjs, err := GetK8sGiteaInstallResources(r.Scheme) + if err != nil { + return ctrl.Result{}, err + } + + // Ensure namespace exists + giteaNS := newGiteaNamespace() + if err = r.Client.Get(ctx, types.NamespacedName{Name: "gitea"}, giteaNS); err != nil { + // We got an error so try creating the NS + if err = r.Client.Create(ctx, giteaNS); err != nil { + return ctrl.Result{}, err + } + } + + log.Info("Installing gitea resources") + for _, obj := range installObjs { + if obj.GetObjectKind().GroupVersionKind().Kind == "Deployment" { + switch obj.GetName() { + case giteaServerName: + gotObj := appsv1.Deployment{} + if err := r.Client.Get(ctx, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, &gotObj); err != nil { + if err = controllerutil.SetControllerReference(resource, obj, r.Scheme); err != nil { + log.Error(err, "Setting controller reference for Gitea deployment", "deployment", obj) + return ctrl.Result{}, err + } + } + } + } + + // Create object + if err = k8s.EnsureObject(ctx, giteansClient, obj, "gitea"); err != nil { + return ctrl.Result{}, err + } + } + + // Wait for Gitea to become available + ready := make(chan bool) + go func() { + for { + for _, obj := range installObjs { + if obj.GetObjectKind().GroupVersionKind().Kind == "Deployment" { + switch obj.GetName() { + case giteaServerName: + gotObj := appsv1.Deployment{} + if gotObj.Status.AvailableReplicas >= 1 { + ready <- true + return + } + } + } + } + + time.Sleep(1 * time.Second) + } + }() + + select { + case <-timeout: + log.Error(errors.New("Timeout"), "Didn't reconcile Gitea on time.") + case <-ready: + log.Info("Gitea is ready!") + } + + resource.Status.GiteaAvailable = true + return ctrl.Result{}, nil +} diff --git a/pkg/controllers/localbuild/resources/gitea/k8s/install.yaml b/pkg/controllers/localbuild/resources/gitea/k8s/install.yaml new file mode 100644 index 00000000..d4cff704 --- /dev/null +++ b/pkg/controllers/localbuild/resources/gitea/k8s/install.yaml @@ -0,0 +1,546 @@ +--- +# Source: gitea/templates/gitea/config.yaml +apiVersion: v1 +kind: Secret +metadata: + name: my-gitea-inline-config + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm +type: Opaque +stringData: + _generals_: "" + cache: ADAPTER=memory + database: DB_TYPE=sqlite3 + indexer: ISSUE_INDEXER_TYPE=db + metrics: ENABLED=false + queue: TYPE=level + repository: ROOT=/data/git/gitea-repositories + security: INSTALL_LOCK=true + server: |- + APP_DATA_PATH=/data + DOMAIN=git.example.com + ENABLE_PPROF=false + HTTP_PORT=3000 + PROTOCOL=http + ROOT_URL=http://git.example.com + SSH_DOMAIN=git.example.com + SSH_LISTEN_PORT=2222 + SSH_PORT=22 + START_SSH_SERVER=true + session: |- + PROVIDER=memory + PROVIDER_CONFIG= +--- +# Source: gitea/templates/gitea/config.yaml +apiVersion: v1 +kind: Secret +metadata: + name: my-gitea + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm +type: Opaque +stringData: + assertions: | + config_environment.sh: |- + #!/usr/bin/env bash + set -euo pipefail + + function env2ini::log() { + printf "${1}\n" + } + + function env2ini::read_config_to_env() { + local section="${1}" + local line="${2}" + + if [[ -z "${line}" ]]; then + # skip empty line + return + fi + + # 'xargs echo -n' trims all leading/trailing whitespaces and a trailing new line + local setting="$(awk -F '=' '{print $1}' <<< "${line}" | xargs echo -n)" + + if [[ -z "${setting}" ]]; then + env2ini::log ' ! invalid setting' + exit 1 + fi + + local value='' + local regex="^${setting}(\s*)=(\s*)(.*)" + if [[ $line =~ $regex ]]; then + value="${BASH_REMATCH[3]}" + else + env2ini::log ' ! invalid setting' + exit 1 + fi + + env2ini::log " + '${setting}'" + + if [[ -z "${section}" ]]; then + export "GITEA____${setting^^}=${value}" # '^^' makes the variable content uppercase + return + fi + + local masked_section="${section//./_0X2E_}" # '//' instructs to replace all matches + masked_section="${masked_section//-/_0X2D_}" + + export "GITEA__${masked_section^^}__${setting^^}=${value}" # '^^' makes the variable content uppercase + } + + function env2ini::reload_preset_envs() { + env2ini::log "Reloading preset envs..." + + while read -r line; do + if [[ -z "${line}" ]]; then + # skip empty line + return + fi + + # 'xargs echo -n' trims all leading/trailing whitespaces and a trailing new line + local setting="$(awk -F '=' '{print $1}' <<< "${line}" | xargs echo -n)" + + if [[ -z "${setting}" ]]; then + env2ini::log ' ! invalid setting' + exit 1 + fi + + local value='' + local regex="^${setting}(\s*)=(\s*)(.*)" + if [[ $line =~ $regex ]]; then + value="${BASH_REMATCH[3]}" + else + env2ini::log ' ! invalid setting' + exit 1 + fi + + env2ini::log " + '${setting}'" + + export "${setting^^}=${value}" # '^^' makes the variable content uppercase + done < "/tmp/existing-envs" + + rm /tmp/existing-envs + } + + + function env2ini::process_config_file() { + local config_file="${1}" + local section="$(basename "${config_file}")" + + if [[ $section == '_generals_' ]]; then + env2ini::log " [ini root]" + section='' + else + env2ini::log " ${section}" + fi + + while read -r line; do + env2ini::read_config_to_env "${section}" "${line}" + done < <(awk 1 "${config_file}") # Helm .toYaml trims the trailing new line which breaks line processing; awk 1 ... adds it back while reading + } + + function env2ini::load_config_sources() { + local path="${1}" + + if [[ -d "${path}" ]]; then + env2ini::log "Processing $(basename "${path}")..." + + while read -d '' configFile; do + env2ini::process_config_file "${configFile}" + done < <(find "${path}" -type l -not -name '..data' -print0) + + env2ini::log "\n" + fi + } + + function env2ini::generate_initial_secrets() { + # These environment variables will either be + # - overwritten with user defined values, + # - initially used to set up Gitea + # Anyway, they won't harm existing app.ini files + + export GITEA__SECURITY__INTERNAL_TOKEN=$(gitea generate secret INTERNAL_TOKEN) + export GITEA__SECURITY__SECRET_KEY=$(gitea generate secret SECRET_KEY) + export GITEA__OAUTH2__JWT_SECRET=$(gitea generate secret JWT_SECRET) + export GITEA__SERVER__LFS_JWT_SECRET=$(gitea generate secret LFS_JWT_SECRET) + + env2ini::log "...Initial secrets generated\n" + } + + # save existing envs prior to script execution. Necessary to keep order of preexisting and custom envs + env | (grep GITEA || [[ $? == 1 ]]) > /tmp/existing-envs + + # MUST BE CALLED BEFORE OTHER CONFIGURATION + env2ini::generate_initial_secrets + + env2ini::load_config_sources '/env-to-ini-mounts/inlines/' + env2ini::load_config_sources '/env-to-ini-mounts/additionals/' + + # load existing envs to override auto generated envs + env2ini::reload_preset_envs + + env2ini::log "=== All configuration sources loaded ===\n" + + # safety to prevent rewrite of secret keys if an app.ini already exists + if [ -f ${GITEA_APP_INI} ]; then + env2ini::log 'An app.ini file already exists. To prevent overwriting secret keys, these settings are dropped and remain unchanged:' + env2ini::log ' - security.INTERNAL_TOKEN' + env2ini::log ' - security.SECRET_KEY' + env2ini::log ' - oauth2.JWT_SECRET' + env2ini::log ' - server.LFS_JWT_SECRET' + + unset GITEA__SECURITY__INTERNAL_TOKEN + unset GITEA__SECURITY__SECRET_KEY + unset GITEA__OAUTH2__JWT_SECRET + unset GITEA__SERVER__LFS_JWT_SECRET + fi + + environment-to-ini -o $GITEA_APP_INI +--- +# Source: gitea/templates/gitea/init.yaml +apiVersion: v1 +kind: Secret +metadata: + name: my-gitea-init + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm +type: Opaque +stringData: + configure_gpg_environment.sh: |- + #!/usr/bin/env bash + set -eu + + gpg --batch --import /raw/private.asc + init_directory_structure.sh: |- + #!/usr/bin/env bash + + set -euo pipefail + + set -x + mkdir -p /data/git/.ssh + chmod -R 700 /data/git/.ssh + [ ! -d /data/gitea/conf ] && mkdir -p /data/gitea/conf + + # prepare temp directory structure + mkdir -p "${GITEA_TEMP}" + chmod ug+rwx "${GITEA_TEMP}" + + + + configure_gitea.sh: |- + #!/usr/bin/env bash + + set -euo pipefail + + echo '==== BEGIN GITEA CONFIGURATION ====' + + { # try + gitea migrate + } || { # catch + echo "Gitea migrate might fail due to database connection...This init-container will try again in a few seconds" + exit 1 + } + function configure_admin_user() { + local ACCOUNT_ID=$(gitea admin user list --admin | grep -e "\s\+${GITEA_ADMIN_USERNAME}\s\+" | awk -F " " "{printf \$1}") + if [[ -z "${ACCOUNT_ID}" ]]; then + echo "No admin user '${GITEA_ADMIN_USERNAME}' found. Creating now..." + gitea admin user create --admin --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}" --email "gitea@local.domain" --must-change-password=false + echo '...created.' + else + echo "Admin account '${GITEA_ADMIN_USERNAME}' already exist. Running update to sync password..." + gitea admin user change-password --username "${GITEA_ADMIN_USERNAME}" --password "${GITEA_ADMIN_PASSWORD}" + echo '...password sync done.' + fi + } + + configure_admin_user + + function configure_ldap() { + echo 'no ldap configuration... skipping.' + } + + configure_ldap + + function configure_oauth() { + echo 'no oauth configuration... skipping.' + } + + configure_oauth + + echo '==== END GITEA CONFIGURATION ====' +--- +# Source: gitea/templates/gitea/http-svc.yaml +apiVersion: v1 +kind: Service +metadata: + name: my-gitea-http + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm + annotations: + {} +spec: + type: ClusterIP + clusterIP: None + ports: + - name: http + port: 3000 + targetPort: + selector: + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea +--- +# Source: gitea/templates/gitea/ssh-svc.yaml +apiVersion: v1 +kind: Service +metadata: + name: my-gitea-ssh + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm + annotations: + {} +spec: + type: ClusterIP + clusterIP: None + ports: + - name: ssh + port: 22 + targetPort: 2222 + protocol: TCP + selector: + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea +--- +# Source: gitea/templates/gitea/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-gitea + annotations: + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + maxSurge: 100% + selector: + matchLabels: + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + template: + metadata: + annotations: + checksum/config: 9e24e050273683638b3530eea2cf02e80335b05aa73370ce73f4c7a6e5fb164e + labels: + helm.sh/chart: gitea-9.5.1 + app: gitea + app.kubernetes.io/name: gitea + app.kubernetes.io/instance: my-gitea + app.kubernetes.io/version: "1.20.5" + version: "1.20.5" + app.kubernetes.io/managed-by: Helm + spec: + + securityContext: + fsGroup: 1000 + initContainers: + - name: init-directories + image: "gitea/gitea:1.20.5-rootless" + imagePullPolicy: Always + command: ["/usr/sbin/init_directory_structure.sh"] + env: + - name: GITEA_APP_INI + value: /data/gitea/conf/app.ini + - name: GITEA_CUSTOM + value: /data/gitea + - name: GITEA_WORK_DIR + value: /data + - name: GITEA_TEMP + value: /tmp/gitea + volumeMounts: + - name: init + mountPath: /usr/sbin + - name: temp + mountPath: /tmp + - name: data + mountPath: /data + + securityContext: + {} + resources: + limits: {} + requests: + cpu: 100m + memory: 128Mi + - name: init-app-ini + image: "gitea/gitea:1.20.5-rootless" + imagePullPolicy: Always + command: ["/usr/sbin/config_environment.sh"] + env: + - name: GITEA_APP_INI + value: /data/gitea/conf/app.ini + - name: GITEA_CUSTOM + value: /data/gitea + - name: GITEA_WORK_DIR + value: /data + - name: GITEA_TEMP + value: /tmp/gitea + volumeMounts: + - name: config + mountPath: /usr/sbin + - name: temp + mountPath: /tmp + - name: data + mountPath: /data + - name: inline-config-sources + mountPath: /env-to-ini-mounts/inlines/ + + securityContext: + {} + resources: + limits: {} + requests: + cpu: 100m + memory: 128Mi + - name: configure-gitea + image: "gitea/gitea:1.20.5-rootless" + command: ["/usr/sbin/configure_gitea.sh"] + imagePullPolicy: Always + securityContext: + runAsUser: 1000 + env: + - name: GITEA_APP_INI + value: /data/gitea/conf/app.ini + - name: GITEA_CUSTOM + value: /data/gitea + - name: GITEA_WORK_DIR + value: /data + - name: GITEA_TEMP + value: /tmp/gitea + - name: HOME + value: /data/gitea/git + - name: GITEA_ADMIN_USERNAME + value: "gitea_admin" + - name: GITEA_ADMIN_PASSWORD + value: "r8sA8CPHD9!bt6d" + volumeMounts: + - name: init + mountPath: /usr/sbin + - name: temp + mountPath: /tmp + - name: data + mountPath: /data + + resources: + limits: {} + requests: + cpu: 100m + memory: 128Mi + terminationGracePeriodSeconds: 60 + containers: + - name: gitea + image: "gitea/gitea:1.20.5-rootless" + imagePullPolicy: Always + env: + # SSH Port values have to be set here as well for openssh configuration + - name: SSH_LISTEN_PORT + value: "2222" + - name: SSH_PORT + value: "22" + - name: GITEA_APP_INI + value: /data/gitea/conf/app.ini + - name: GITEA_CUSTOM + value: /data/gitea + - name: GITEA_WORK_DIR + value: /data + - name: GITEA_TEMP + value: /tmp/gitea + - name: TMPDIR + value: /tmp/gitea + - name: HOME + value: /data/gitea/git + ports: + - name: ssh + containerPort: 2222 + - name: http + containerPort: 3000 + livenessProbe: + failureThreshold: 10 + initialDelaySeconds: 200 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: http + timeoutSeconds: 1 + readinessProbe: + failureThreshold: 3 + initialDelaySeconds: 5 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: http + timeoutSeconds: 1 + resources: + {} + securityContext: + {} + volumeMounts: + - name: temp + mountPath: /tmp + - name: data + mountPath: /data + + volumes: + - name: init + secret: + secretName: my-gitea-init + defaultMode: 110 + - name: config + secret: + secretName: my-gitea + defaultMode: 110 + - name: inline-config-sources + secret: + secretName: my-gitea-inline-config + - name: temp + emptyDir: {} + - name: data + emptyDir: {} \ No newline at end of file diff --git a/pkg/controllers/localbuild/resources/gitea/values.yaml b/pkg/controllers/localbuild/resources/gitea/values.yaml new file mode 100644 index 00000000..0a22eb57 --- /dev/null +++ b/pkg/controllers/localbuild/resources/gitea/values.yaml @@ -0,0 +1,20 @@ +redis-cluster: + enabled: false +postgresql: + enabled: false +postgresql-ha: + enabled: false + +persistence: + enabled: false + +gitea: + config: + database: + DB_TYPE: sqlite3 + session: + PROVIDER: memory + cache: + ADAPTER: memory + queue: + TYPE: level \ No newline at end of file diff --git a/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml b/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml index cac27634..36485783 100644 --- a/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml +++ b/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml @@ -52,6 +52,14 @@ spec: argo applications and the associated GitServer type: boolean type: object + gitConfig: + description: GitConfigSpec controls what git server to use for + the idpbuilder It can take on the values of either gitea or + gitserver + properties: + type: + type: string + type: object type: object type: object status: @@ -62,6 +70,8 @@ spec: type: boolean gitServerAvailable: type: boolean + giteaAvailable: + type: boolean observedGeneration: description: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.