Skip to content

Commit a230e63

Browse files
add support for git source
1 parent 904d532 commit a230e63

File tree

10 files changed

+51
-7
lines changed

10 files changed

+51
-7
lines changed
58 Bytes
Binary file not shown.
31 Bytes
Binary file not shown.
-2 Bytes
Binary file not shown.

charts/controller/crds/deployments.plural.sh_prautomations.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ spec:
426426
when to use it, and any prerequisites or considerations.
427427
type: string
428428
git:
429-
description: Git location to source external files from.
429+
description: Git location to source external files from. If `creates.git`
430+
is also specified, the results will be merged.
430431
properties:
431432
files:
432433
description: Optional files to add to the manifests for this service

go/controller/api/v1alpha1/prautomation_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ type PrAutomationSpec struct {
159159
// +kubebuilder:validation:Optional
160160
RepositoryRef *corev1.ObjectReference `json:"repositoryRef,omitempty"`
161161

162-
// Git location to source external files from.
162+
// Git location to source external files from. If `creates.git` is also specified, the results will be merged.
163163
// +kubebuilder:validation:Optional
164164
Git *GitRef `json:"git,omitempty"`
165165

go/controller/config/crd/bases/deployments.plural.sh_prautomations.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ spec:
426426
when to use it, and any prerequisites or considerations.
427427
type: string
428428
git:
429-
description: Git location to source external files from.
429+
description: Git location to source external files from. If `creates.git`
430+
is also specified, the results will be merged.
430431
properties:
431432
files:
432433
description: Optional files to add to the manifests for this service

go/controller/docs/api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,7 @@ _Appears in:_
15101510
- [AiApprovalConfiguration](#aiapprovalconfiguration)
15111511
- [InfrastructureStackSpec](#infrastructurestackspec)
15121512
- [PrAutomationCreateConfiguration](#prautomationcreateconfiguration)
1513+
- [PrAutomationSpec](#prautomationspec)
15131514
- [SentinelCheckIntegrationTestConfiguration](#sentinelcheckintegrationtestconfiguration)
15141515
- [SentinelSpec](#sentinelspec)
15151516
- [ServiceHelm](#servicehelm)
@@ -3273,6 +3274,23 @@ _Appears in:_
32733274
| `folders` _string array_ | Entire folders to delete. | | Optional: \{\} <br /> |
32743275

32753276

3277+
#### PrAutomationLuaConfiguration
3278+
3279+
3280+
3281+
3282+
3283+
3284+
3285+
_Appears in:_
3286+
- [PrAutomationSpec](#prautomationspec)
3287+
3288+
| Field | Description | Default | Validation |
3289+
| --- | --- | --- | --- |
3290+
| `script` _string_ | File of a flat script to use | | Optional: \{\} <br /> |
3291+
| `folder` _string_ | Folder with lua library code and scripts to use | | Optional: \{\} <br /> |
3292+
3293+
32763294
#### PrAutomationSecretConfiguration
32773295

32783296

@@ -3338,6 +3356,7 @@ _Appears in:_
33383356
| `clusterRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | ClusterRef references a specific cluster that this PR operates on. | | Optional: \{\} <br /> |
33393357
| `scmConnectionRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | ScmConnectionRef references the SCM connection to use for authentication when creating pull requests. | | Required: \{\} <br /> |
33403358
| `repositoryRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | RepositoryRef references a Git repository resource this automation uses. | | Optional: \{\} <br /> |
3359+
| `git` _[GitRef](#gitref)_ | Git location to source external files from. If `creates.git` is also specified, the results will be merged. | | Optional: \{\} <br /> |
33413360
| `serviceRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | ServiceRef references a specific service that this PR automation acts upon. | | Optional: \{\} <br /> |
33423361
| `projectRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | ProjectRef references the project this automation belongs to, enabling<br />project-scoped organization and access control. | | Optional: \{\} <br /> |
33433362
| `catalogRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | CatalogRef references the catalog this automation belongs to for<br />organizational purposes and discoverability in the service catalog. | | Optional: \{\} <br /> |
@@ -3348,6 +3367,7 @@ _Appears in:_
33483367
| `creates` _[PrAutomationCreateConfiguration](#prautomationcreateconfiguration)_ | Creates defines specifications for generating new files from templates,<br />allowing the automation to add new configuration files to the repository. | | Optional: \{\} <br /> |
33493368
| `updates` _[PrAutomationUpdateConfiguration](#prautomationupdateconfiguration)_ | Updates specifies how to modify existing files using regex replacements<br />or YAML overlays, enabling precise changes to infrastructure code. | | Optional: \{\} <br /> |
33503369
| `deletes` _[PrAutomationDeleteConfiguration](#prautomationdeleteconfiguration)_ | Deletes specifies files and folders to remove from the repository as part<br />of the PR, useful for cleanup or migration scenarios. | | Optional: \{\} <br /> |
3370+
| `lua` _[PrAutomationLuaConfiguration](#prautomationluaconfiguration)_ | Lua specification to source lua scripts to preprocess the PR automation. | | Optional: \{\} <br /> |
33513371
| `reconciliation` _[Reconciliation](#reconciliation)_ | Reconciliation settings for this resource.<br />Controls drift detection and reconciliation intervals. | | Optional: \{\} <br /> |
33523372
| `labels` _string array_ | Labels to apply to all created PRs from this pr automation | | Optional: \{\} <br /> |
33533373

lib/console/deployments/pr/dispatcher.ex

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,42 @@ defmodule Console.Deployments.Pr.Dispatcher do
128128
impl.pr_info(url)
129129
end
130130

131+
defp external_git(%PrAutomation{repository: %GitRepository{} = git, git: %{ref: _, folder: _} = ref1, creates: %{git: %{ref: _, folder: _} = ref2}}),
132+
do: external_git(git, [ref1, ref2])
131133
defp external_git(%PrAutomation{repository: %GitRepository{} = git, git: %{ref: _, folder: _} = ref}),
132134
do: external_git(git, ref)
133135
defp external_git(%PrAutomation{repository: %GitRepository{} = git, creates: %{git: %{ref: _, folder: _} = ref}}),
134136
do: external_git(git, ref)
135137
defp external_git(_), do: {:ok, nil}
136138

137-
defp external_git(%GitRepository{} = git, %{ref: _, folder: _} = ref) do
139+
defp external_git(%GitRepository{} = git, ref) when is_map(ref) or is_list(ref) do
138140
with {:ok, dir} <- Briefly.create(directory: true),
139-
{:ok, f} <- Discovery.fetch(git, ref),
140-
{:ok, contents} <- Tar.tar_stream(f),
141+
{:ok, contents} <- git_contents(git, ref),
141142
:ok <- Console.dump_folder(dir, contents),
142143
do: {:ok, dir}
143144
end
144145
defp external_git(_, _), do: {:ok, nil}
145146

147+
defp git_contents(%GitRepository{} = git, [_ | _] = refs) do
148+
Enum.reduce_while(refs, %{}, fn ref, acc ->
149+
with {:ok, f} <- Discovery.fetch(git, ref),
150+
{:ok, contents} <- Tar.tar_stream(f) do
151+
{:cont, Map.merge(acc, Map.new(contents))}
152+
else
153+
{:error, _} = err -> {:halt, err}
154+
end
155+
end)
156+
|> case do
157+
%{} = contents -> {:ok, contents}
158+
{:error, _} = err -> err
159+
end
160+
end
161+
162+
defp git_contents(%GitRepository{} = git, %{ref: _, folder: _} = ref) do
163+
with {:ok, f} <- Discovery.fetch(git, ref),
164+
do: Tar.tar_stream(f)
165+
end
166+
146167
defp resolve_repo("mgmt") do
147168
case Settings.cached() do
148169
%DeploymentSettings{mgmt_repo: r} when is_binary(r) -> r
37 Bytes
Binary file not shown.

plural/helm/console/crds/deployments.plural.sh_prautomations.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ spec:
426426
when to use it, and any prerequisites or considerations.
427427
type: string
428428
git:
429-
description: Git location to source external files from.
429+
description: Git location to source external files from. If `creates.git`
430+
is also specified, the results will be merged.
430431
properties:
431432
files:
432433
description: Optional files to add to the manifests for this service

0 commit comments

Comments
 (0)