Skip to content

Commit

Permalink
Bump agent version and support airgapped compatibilities + deprecations
Browse files Browse the repository at this point in the history
The deprecations and compatibilities checkers currently poll github to get the freshest matrices needed, but that can break down for orgs with strict firewalls.  A stale but airgapped option is ideal there.
  • Loading branch information
michaeljguarino committed Mar 21, 2024
1 parent 1c5d12c commit 21a7c3b
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 41 deletions.
2 changes: 1 addition & 1 deletion AGENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.13
v0.4.14
23 changes: 12 additions & 11 deletions assets/src/components/cd/pipelines/PipelineDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function PipelineHeading({
}

const tabs = {
'': 'Split',
split: 'Split',
graph: 'Graph',
contexts: 'Contexts',
} as const
Expand All @@ -76,7 +76,7 @@ export function PipelineTabs() {
const tabStateRef = useRef<any>(null)

const view = searchParams.get('view')
const tabKey = view && tabs[view] ? (view as keyof typeof tabs) : ''
const tabKey = view && tabs[view] ? (view as keyof typeof tabs) : 'graph'

return (
<TabList
Expand Down Expand Up @@ -224,19 +224,14 @@ function PipelineDetailsBase() {
)}
</PipelineEditAreaSC>
)

const contentContexts = (
<FullHeightTableWrap>
<PipelineContexts pipeline={pipeline} />
</FullHeightTableWrap>
)

let content = (
<SplitPane
id="pipeline-details"
pane1={contentGraph}
pane2={contentContexts}
/>
)
let content = contentGraph

if (view === 'contexts') {
content = (
Expand All @@ -251,8 +246,14 @@ function PipelineDetailsBase() {
{contentContexts}
</div>
)
} else if (view === 'graph') {
content = contentGraph
} else if (view === 'split') {
content = (
<SplitPane
id="pipeline-details"
pane1={contentGraph}
pane2={contentContexts}
/>
)
}

return (
Expand Down
2 changes: 1 addition & 1 deletion lib/console/deployments/compatibilities/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Console.Deployments.Compatibilities.AddOn do

@type t :: %__MODULE__{versions: [%Compatibilities.Version{}]}

defstruct [:versions, :icon, :git_url, :release_url, :readme_url]
defstruct [:name, :versions, :icon, :git_url, :release_url, :readme_url]

def spec() do
%__MODULE__{
Expand Down
31 changes: 26 additions & 5 deletions lib/console/deployments/compatibilities/table.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Console.Deployments.Compatibilities.Table do
use GenServer
import Console.Deployments.Ecto.Validations, only: [clean_version: 1]
alias Console.Deployments.Compatibilities.AddOn
alias Console.Deployments.{Compatibilities.AddOn, Static}
alias Console.Schema.{RuntimeService}
alias ETS.KeyValueSet
require Logger
Expand All @@ -11,7 +11,7 @@ defmodule Console.Deployments.Compatibilities.Table do
@url "/pluralsh/console/master/static/compatibilities/"

defmodule State do
defstruct [:table, :url]
defstruct [:table, :url, :static]
end

def start_link(opt \\ :ok) do
Expand All @@ -22,7 +22,7 @@ defmodule Console.Deployments.Compatibilities.Table do
:timer.send_interval(@poll, :poll)
send self(), :poll
{:ok, table} = KeyValueSet.new(name: @table, read_concurrency: true, ordered: true)
{:ok, %State{table: table, url: Console.github_raw_url(@url)}}
{:ok, %State{table: table, url: Console.github_raw_url(@url), static: Console.conf(:airgap)}}
end

def fetch(%RuntimeService{name: name, version: vsn}) do
Expand All @@ -38,6 +38,11 @@ defmodule Console.Deployments.Compatibilities.Table do
end
end

def handle_info(:poll, %State{table: table, static: true} = state) do
table = Enum.reduce(Static.compatibilities(), table, &KeyValueSet.put(&2, &1.name, &1))
{:noreply, %{state | table: table}}
end

def handle_info(:poll, %State{table: table, url: url} = state) do
with [_ | _] = addons <- fetch_manifest(url) do
table = Enum.reduce(addons, table, fn name, table ->
Expand All @@ -64,8 +69,24 @@ defmodule Console.Deployments.Compatibilities.Table do

defp fetch_addon(url, addon) do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <- HTTPoison.get(url <> "#{addon}.yaml"),
{:ok, res} <- YamlElixir.read_from_string(body),
do: decode_addon(addon, body)
end

defp decode_addon(name, yaml) do
with {:ok, res} <- YamlElixir.read_from_string(yaml),
{:ok, encoded} <- Jason.encode(res),
do: Poison.decode(encoded, as: AddOn.spec())
{:ok, addon} <- Poison.decode(encoded, as: AddOn.spec()),
do: {:ok, %{addon | name: name}}
end

def static() do
base_path = "static/compatibilities"
{:ok, yaml} = File.read("#{base_path}/manifest.yaml")
{:ok, %{"names" => [_ | _] = addons}} = YamlElixir.read_from_string(yaml)
Enum.map(addons, fn name ->
{:ok, yaml} = File.read("#{base_path}/#{name}.yaml")
{:ok, addon} = decode_addon(name, yaml)
%{addon | name: name}
end)
end
end
17 changes: 15 additions & 2 deletions lib/console/deployments/deprecations/table.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
defmodule Console.Deployments.Deprecations.Table do
use GenServer
alias Console.Schema.ServiceComponent
alias Console.Deployments.Static
alias ETS.KeyValueSet
require Logger

@table :api_deprecations
@poll :timer.minutes(60)
@url "/pluralsh/console/master/static/versions.yml"


defmodule State do
defstruct [:table, :url]
defstruct [:table, :url, :static]
end

defmodule Entry do
Expand All @@ -26,7 +28,7 @@ defmodule Console.Deployments.Deprecations.Table do
:timer.send_interval(@poll, :poll)
send self(), :poll
{:ok, table} = KeyValueSet.new(name: @table, read_concurrency: true, ordered: true)
{:ok, %State{table: table, url: Console.github_raw_url(@url)}}
{:ok, %State{table: table, url: Console.github_raw_url(@url), static: Console.conf(:airgap)}}
end

def fetch(%ServiceComponent{} = component) do
Expand All @@ -36,6 +38,11 @@ defmodule Console.Deployments.Deprecations.Table do
end
end

def handle_info(:poll, %State{table: table, static: true} = state) do
table = Enum.reduce(Static.deprecations(), table, &KeyValueSet.put!(&2, name(&1), &1))
{:noreply, %{state | table: table}}
end

def handle_info(:poll, %State{table: table, url: url} = state) do
with [_ | _] = entries <- fetch_and_parse(url) do
table = Enum.reduce(entries, table, &KeyValueSet.put!(&2, name(&1), &1))
Expand Down Expand Up @@ -74,4 +81,10 @@ defmodule Console.Deployments.Deprecations.Table do
[v] -> {"core", v}
end
end

def static() do
{:ok, yaml} = File.read("static/versions.yml")
{:ok, %{"deprecated-versions" => [_ | _] = deprecated}} = YamlElixir.read_from_string(yaml)
Enum.map(deprecated, &to_entry/1)
end
end
13 changes: 13 additions & 0 deletions lib/console/deployments/static.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Console.Deployments.Static do
@moduledoc """
Static values needed to help airgap the deployment. We ping github for some important data that can
be embedded at compile time for orgs that do not permit egress there or run fully airgapped.
"""
alias Console.Deployments

@compatibilities Deployments.Compatibilities.Table.static()
@deprecations Deployments.Deprecations.Table.static()

def compatibilities(), do: @compatibilities
def deprecations(), do: @deprecations
end
88 changes: 68 additions & 20 deletions priv/notifications/slack/service.update.json.eex
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
{
"text": "Service <%= @service.name %> for cluster <%= @service.cluster.name %> has a new revision",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Service <%= @service.name %> for cluster <%= @service.cluster.name %> has a new revision"
}
},
{
"type": "divider"
"text": "🆕 Service <%= @service.name %> for cluster <%= @service.cluster.name %> has a new revision",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "🆕 *Service <%= @service.name %> for cluster <%= @service.cluster.name %> has a new revision*"
}
},
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Url*\n<%= Console.url("/cd/clusters/#{@service.cluster_id}/services/#{@service.id}/components") %>"},
{"type": "mrkdwn", "text": "*Revision*\n<%= @service.sha %>"},
{"type": "mrkdwn", "text": "*Source*\n<%= @source.url %> <%= @source.ref %>"}
]
}
]
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "URL",
"style": {
"bold": true
}
},
{
"type": "text",
"text": ": "
},
{
"type": "link",
"url": "<%= Console.url("/cd/clusters/#{@service.cluster_id}/services/#{@service.id}/components") %>"
},
{
"type": "text",
"text": "\n\n"
},
{
"type": "text",
"text": "Revision",
"style": {
"bold": true
}
},
{
"type": "text",
"text": ": <%= @service.sha %>\n\n"
},
{
"type": "text",
"text": "Source",
"style": {
"bold": true
}
},
{
"type": "text",
"text": ": "
},
{
"type": "link",
"url": "<%= @source.url %>"
},
{
"type": "text",
"text": " <%= @source.ref %>"
}
]
}
]
}
]
}
4 changes: 3 additions & 1 deletion rel/config/console.exs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ config :console,
provider: provider,
build_id: get_env("CONSOLE_BUILD_ID"),
kas_dns: get_env("KAS_DNS"),
byok: get_env("CONSOLE_BYOK") == "true"
byok: get_env("CONSOLE_BYOK") == "true",
airgap: get_env("CONSOLE_AIRGAP") == "true"

if git_url && String.starts_with?(git_url, "https") do
config :console,
Expand All @@ -119,6 +120,7 @@ if is_set("CONSOLE_ADMIN_EMAILS") do
admin_emails: String.split(get_env("CONSOLE_ADMIN_EMAILS"), ~r/\s*,\s*/, trim: true)
end


if is_set("BACKUP_ACCESS_KEY") and is_set("BACKUP_SECRET_ACCESS_KEY") do
config :console, :backup_keys,
s3_access_key_id: get_env("BACKUP_ACCESS_KEY"),
Expand Down

0 comments on commit 21a7c3b

Please sign in to comment.