diff --git a/Makefile b/Makefile index 98c90b5..0e3a639 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Image URL to use all building/pushing image targets -IMG ?= controller:latest +IMG ?= git.realmanual.ru/pub/gitlab-job-runner:latest # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) diff --git a/README.md b/README.md index 41283df..fc38a52 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ metadata: name: cleanup-job spec: gitlabSecretRef: gitlab-credentials - repositoryURL: mygroup/myrepo + repositoryURL: https://gitlab.example.com/mygroup/myrepo.git branch: main scriptPath: scripts/cleanup.sh serviceAccountName: backup-sa @@ -97,7 +97,7 @@ metadata: spec: schedule: "0 2 * * *" gitlabSecretRef: gitlab-credentials - repositoryURL: mygroup/myrepo + repositoryURL: https://gitlab.example.com/mygroup/myrepo.git branch: main scriptPath: scripts/backup.sh serviceAccountName: backup-sa @@ -119,7 +119,7 @@ kubectl apply -f your-gitlabjobrunner.yaml |----------------------|---------|----------|-------------------------------------------------------------------------------| | `schedule` | string | No | Cron schedule for recurring jobs. If empty, runs as one-time Job | | `gitlabSecretRef` | string | Yes | Name of Secret containing GITLAB_URL and GITLAB_TOKEN | -| `repositoryURL` | string | Yes | GitLab repository path (e.g., "group/project") | +| `repositoryURL` | string | Yes | GitLab repository (full URL or relative path like "group/project") | | `branch` | string | No | Git branch to checkout (default: "main") | | `scriptPath` | string | Yes | Relative path to script in repository | | `image` | string | No | Container image for git clone (default: "bitnami/git:latest") | diff --git a/api/v1alpha1/gitlabjobrunner_types.go b/api/v1alpha1/gitlabjobrunner_types.go index 96f888f..fc6a448 100644 --- a/api/v1alpha1/gitlabjobrunner_types.go +++ b/api/v1alpha1/gitlabjobrunner_types.go @@ -34,7 +34,9 @@ type GitlabJobRunnerSpec struct { // +required GitlabSecretRef string `json:"gitlabSecretRef"` - // repositoryURL is the GitLab repository to clone + // repositoryURL is the GitLab repository URL (full URL or relative path like "group/project") + // Full URL: https://gitlab.example.com/group/project.git + // Relative path: group/project (requires GITLAB_URL in secret) // +required RepositoryURL string `json:"repositoryURL"` diff --git a/config/crd/bases/batch.rml.ru_gitlabjobrunners.yaml b/config/crd/bases/batch.rml.ru_gitlabjobrunners.yaml index 81edb6d..443ef30 100644 --- a/config/crd/bases/batch.rml.ru_gitlabjobrunners.yaml +++ b/config/crd/bases/batch.rml.ru_gitlabjobrunners.yaml @@ -55,7 +55,10 @@ spec: description: image is the container image to use for execution type: string repositoryURL: - description: repositoryURL is the GitLab repository to clone + description: |- + repositoryURL is the GitLab repository URL (full URL or relative path like "group/project") + Full URL: https://gitlab.example.com/group/project.git + Relative path: group/project (requires GITLAB_URL in secret) type: string schedule: description: schedule in Cron format for recurring execution. If empty, diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index ad13e96..d252988 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: controller + newName: git.realmanual.ru/pub/gitlab-job-runner newTag: latest diff --git a/config/samples/batch_v1alpha1_gitlabjobrunner.yaml b/config/samples/batch_v1alpha1_gitlabjobrunner.yaml index 4fbfec6..d0b9c3d 100644 --- a/config/samples/batch_v1alpha1_gitlabjobrunner.yaml +++ b/config/samples/batch_v1alpha1_gitlabjobrunner.yaml @@ -8,7 +8,7 @@ metadata: name: gitlabjobrunner-sample-job spec: gitlabSecretRef: gitlab-credentials - repositoryURL: mygroup/myrepo + repositoryURL: https://gitlab.example.com/mygroup/myrepo.git branch: main scriptPath: scripts/cleanup.sh image: bitnami/git:latest @@ -25,7 +25,7 @@ metadata: spec: schedule: "0 2 * * *" gitlabSecretRef: gitlab-credentials - repositoryURL: mygroup/myrepo + repositoryURL: https://gitlab.example.com/mygroup/myrepo.git branch: main scriptPath: scripts/backup.sh image: bitnami/git:latest diff --git a/helm/gitlab-job-runner/README.md b/helm/gitlab-job-runner/README.md index 4499a52..8acc09d 100644 --- a/helm/gitlab-job-runner/README.md +++ b/helm/gitlab-job-runner/README.md @@ -124,7 +124,7 @@ metadata: name: example-job spec: gitlabSecretRef: gitlab-credentials - repositoryURL: mygroup/myrepo + repositoryURL: https://gitlab.example.com/mygroup/myrepo.git branch: main scriptPath: scripts/deploy.sh ``` diff --git a/helm/gitlab-job-runner/values.yaml b/helm/gitlab-job-runner/values.yaml index d98b3b2..2fcf58b 100644 --- a/helm/gitlab-job-runner/values.yaml +++ b/helm/gitlab-job-runner/values.yaml @@ -2,7 +2,7 @@ replicaCount: 1 image: repository: git.realmanual.ru/pub/gitlab-job-runner - pullPolicy: IfNotPresent + pullPolicy: Always #IfNotPresent tag: "latest" imagePullSecrets: [] diff --git a/internal/controller/gitlabjobrunner_controller.go b/internal/controller/gitlabjobrunner_controller.go index 4a1ad72..68326b6 100644 --- a/internal/controller/gitlabjobrunner_controller.go +++ b/internal/controller/gitlabjobrunner_controller.go @@ -310,8 +310,15 @@ func (r *GitlabJobRunnerReconciler) constructPodSpec(runner *batchv1alpha1.Gitla "sh", "-c", fmt.Sprintf(` - git clone -b %s --depth 1 https://oauth2:$GITLAB_TOKEN@$(echo $GITLAB_URL | sed 's|https://||')/%s /workspace - `, branch, runner.Spec.RepositoryURL), + REPO_URL="%s" + if echo "$REPO_URL" | grep -q '^https://'; then + # Full URL provided - use it directly with token injection + git clone -b %s --depth 1 $(echo $REPO_URL | sed "s|https://|https://oauth2:$GITLAB_TOKEN@|") /workspace + else + # Relative path - construct URL from GITLAB_URL + git clone -b %s --depth 1 https://oauth2:$GITLAB_TOKEN@$(echo $GITLAB_URL | sed 's|https://||')/$REPO_URL /workspace + fi + `, runner.Spec.RepositoryURL, branch, branch), }, Env: []corev1.EnvVar{ {