Skip to content

Commit

Permalink
add resolution for management repo
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Dec 18, 2024
1 parent d5e1442 commit 9f60eae
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 5 deletions.
3 changes: 3 additions & 0 deletions assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,8 @@ export type DeploymentSettings = {
logging?: Maybe<LoggingSettings>;
/** the way we can connect to your loki instance */
lokiConnection?: Maybe<HttpConnection>;
/** the root repo you used to run `plural up` */
mgmtRepo?: Maybe<Scalars['String']['output']>;
name: Scalars['String']['output'];
/** the way we can connect to your prometheus instance */
prometheusConnection?: Maybe<HttpConnection>;
Expand Down Expand Up @@ -2387,6 +2389,7 @@ export type DeploymentSettingsAttributes = {
gitBindings?: InputMaybe<Array<InputMaybe<PolicyBindingAttributes>>>;
/** connection details for a loki instance to use */
lokiConnection?: InputMaybe<HttpConnectionAttributes>;
mgmtRepo?: InputMaybe<Scalars['String']['input']>;
/** connection details for a prometheus instance to use */
prometheusConnection?: InputMaybe<HttpConnectionAttributes>;
readBindings?: InputMaybe<Array<InputMaybe<PolicyBindingAttributes>>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ spec:
required:
- host
type: object
managementRepo:
description: The root repo for setting up your infrastructure with
Plural. Usually this will be your `plural up repo`
type: string
prometheusConnection:
description: PrometheusConnection connection details for a prometheus
instance to use
Expand Down
3 changes: 3 additions & 0 deletions go/client/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/controller/api/v1alpha1/deploymentsettings_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ type DeploymentSettingsSpec struct {
// +kubebuilder:validation:Optional
AgentHelmValues *runtime.RawExtension `json:"agentHelmValues,omitempty"`

// The root repo for setting up your infrastructure with Plural. Usually this will be your `plural up repo`
//
// +kubebuilder:validation:Optional
ManagementRepo *string `json:"managementRepo,omitempty"`

// Stacks global configuration for stack execution
//
// +kubebuilder:validation:Optional
Expand Down
5 changes: 5 additions & 0 deletions go/controller/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ spec:
required:
- host
type: object
managementRepo:
description: The root repo for setting up your infrastructure with
Plural. Usually this will be your `plural up repo`
type: string
prometheusConnection:
description: PrometheusConnection connection details for a prometheus
instance to use
Expand Down
1 change: 1 addition & 0 deletions go/controller/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `agentHelmValues` _[RawExtension](https://pkg.go.dev/k8s.io/apimachinery/pkg/runtime#RawExtension)_ | AgentHelmValues custom helm values to apply to all agents (useful for things like adding customary annotations/labels) | | Optional: {} <br /> |
| `managementRepo` _string_ | The root repo for setting up your infrastructure with Plural. Usually this will be your `plural up repo` | | Optional: {} <br /> |
| `stacks` _[StackSettings](#stacksettings)_ | Stacks global configuration for stack execution | | Optional: {} <br /> |
| `bindings` _[DeploymentSettingsBindings](#deploymentsettingsbindings)_ | Bindings | | Optional: {} <br /> |
| `prometheusConnection` _[HTTPConnection](#httpconnection)_ | PrometheusConnection connection details for a prometheus instance to use | | Optional: {} <br /> |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ func (r *DeploymentSettingsReconciler) SetupWithManager(mgr ctrl.Manager) error
}

func (r *DeploymentSettingsReconciler) genDeploymentSettingsAttr(ctx context.Context, settings *v1alpha1.DeploymentSettings) (*console.DeploymentSettingsAttributes, error) {
attr := &console.DeploymentSettingsAttributes{}
attr := &console.DeploymentSettingsAttributes{
MgmtRepo: settings.Spec.ManagementRepo,
}

if settings.Spec.AgentHelmValues != nil {
var obj runtime.Object
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(settings.Spec.AgentHelmValues, &obj, nil); err != nil {
Expand Down
14 changes: 11 additions & 3 deletions lib/console/deployments/pr/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ defmodule Console.Deployments.Pr.Dispatcher do
import Console.Deployments.Pr.Git
import Console.Deployments.Pr.Utils
alias Console.Repo
alias Console.Deployments.{Pr.Config, Git.Discovery, Tar}
alias Console.Deployments.{Pr.Config, Git.Discovery, Tar, Settings}
alias Console.Commands.{Plural}
alias Console.Deployments.Pr.Impl.{Github, Gitlab, BitBucket}
alias Console.Schema.{PrAutomation, PullRequest, ScmConnection, ScmWebhook, GitRepository}
alias Console.Schema.{PrAutomation, PullRequest, ScmConnection, ScmWebhook, GitRepository, DeploymentSettings}

@type pr_resp :: {:ok, binary, binary} | Console.error

Expand Down Expand Up @@ -37,7 +37,7 @@ defmodule Console.Deployments.Pr.Dispatcher do
def create(%PrAutomation{} = pr, branch, ctx) when is_binary(branch) do
%PrAutomation{connection: conn} = pr = Repo.preload(pr, [:connection, :repository])
impl = dispatcher(conn)
with {:ok, conn} <- setup(%{conn | branch: pr.branch}, pr.identifier, branch),
with {:ok, conn} <- setup(%{conn | branch: pr.branch}, resolve_repo(pr.identifier), branch),
{:ok, f} <- Config.config(pr, branch, ctx),
{:ok, ext} <- external_git(pr),
{:ok, _} <- Plural.template(f, conn.dir, ext),
Expand Down Expand Up @@ -72,6 +72,14 @@ defmodule Console.Deployments.Pr.Dispatcher do
end
defp external_git(_), do: {:ok, nil}

defp resolve_repo("MGMT") do
case Settings.cached() do
%DeploymentSettings{mgmt_repo: r} when is_binary(r) -> r
_ -> "MGMT"
end
end
defp resolve_repo(identifier), do: identifier

def dispatcher(%{type: :github}), do: Github
def dispatcher(%{type: :gitlab}), do: Gitlab
def dispatcher(%{type: :bitbucket}), do: BitBucket
Expand Down
2 changes: 2 additions & 0 deletions lib/console/graphql/deployments/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule Console.GraphQl.Deployments.Settings do
field :stacks, :stack_settings_attributes, description: "global configuration for stack execution"
field :prometheus_connection, :http_connection_attributes, description: "connection details for a prometheus instance to use"
field :loki_connection, :http_connection_attributes, description: "connection details for a loki instance to use"
field :mgmt_repo, :string

field :smtp, :smtp_settings_attributes, description: "configuration for smtp message delivery"

Expand Down Expand Up @@ -163,6 +164,7 @@ defmodule Console.GraphQl.Deployments.Settings do
field :ai, :ai_settings, description: "settings for LLM provider clients"
field :cost, :cost_settings, description: "settings for cost management"
field :logging, :logging_settings, description: "settings for connections to log aggregation datastores"
field :mgmt_repo, :string, description: "the root repo you used to run `plural up`"

field :agent_vsn, non_null(:string), description: "The console's expected agent version",
resolve: fn _, _, _ -> {:ok, Settings.agent_vsn()} end
Expand Down
3 changes: 2 additions & 1 deletion lib/console/schema/deployment_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule Console.Schema.DeploymentSettings do
field :read_policy_id, :binary_id
field :create_policy_id, :binary_id
field :git_policy_id, :binary_id
field :mgmt_repo, :string

field :agent_helm_values, EncryptedString

Expand Down Expand Up @@ -152,7 +153,7 @@ defmodule Console.Schema.DeploymentSettings do

def smtp_config(), do: @smtp

@valid ~w(name enabled agent_version agent_helm_values manage_agents self_managed artifact_repository_id deployer_repository_id)a
@valid ~w(name enabled mgmt_repo agent_version agent_helm_values manage_agents self_managed artifact_repository_id deployer_repository_id)a

def changeset(model, attrs \\ %{}) do
model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ spec:
required:
- host
type: object
managementRepo:
description: The root repo for setting up your infrastructure with
Plural. Usually this will be your `plural up repo`
type: string
prometheusConnection:
description: PrometheusConnection connection details for a prometheus
instance to use
Expand Down
9 changes: 9 additions & 0 deletions priv/repo/migrations/20241218145152_add_mgmt_repo_setting.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Console.Repo.Migrations.AddMgmtRepoSetting do
use Ecto.Migration

def change do
alter table(:deployment_settings) do
add :mgmt_repo, :string
end
end
end
5 changes: 5 additions & 0 deletions schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ input DeploymentSettingsAttributes {
"connection details for a loki instance to use"
lokiConnection: HttpConnectionAttributes

mgmtRepo: String

"configuration for smtp message delivery"
smtp: SmtpSettingsAttributes

Expand Down Expand Up @@ -1331,6 +1333,9 @@ type DeploymentSettings {
"settings for connections to log aggregation datastores"
logging: LoggingSettings

"the root repo you used to run `plural up`"
mgmtRepo: String

"The console's expected agent version"
agentVsn: String!

Expand Down

0 comments on commit 9f60eae

Please sign in to comment.