Skip to content

Commit

Permalink
Upgrade insight CRUD (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Aug 30, 2024
1 parent e1d4833 commit 311cda6
Show file tree
Hide file tree
Showing 18 changed files with 535 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ENV HELM_VERSION=v3.10.3
ENV TERRAFORM_VERSION=v1.2.9

# renovate: datasource=github-releases depName=pluralsh/plural-cli
ENV CLI_VERSION=v0.9.13
ENV CLI_VERSION=v0.9.14

# renovate: datasource=github-tags depName=kubernetes/kubernetes
ENV KUBECTL_VERSION=v1.25.5
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ We are currently trying to aggregate compatibility and dependency information fo

* $50 for adding compatibilities for a specific version of an application
* $150 for adding a new application and all to-date compatibility information
* $300 for a new compatibility scraper (these are all defined in `utils/compatibility/scrapers`)

To be eligible for the upgrade bounty you'll need to submit a PR to this repo with the changes and a link to whatever documentation confirms the correctness of the information. We'll then review and if it's correct and useful for the broader community, you'll be eligible for the reward once merged.

Expand Down
5 changes: 5 additions & 0 deletions assets/src/generated/graphql-plural.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ export type Cluster = {
/** The ID of the cluster. */
id: Scalars['ID']['output'];
insertedAt?: Maybe<Scalars['DateTime']['output']>;
/** whether this is a legacy OSS cluster */
legacy?: Maybe<Scalars['Boolean']['output']>;
/** whether any installation in the cluster has been locked */
locked?: Maybe<Scalars['Boolean']['output']>;
/** The name of the cluster. */
Expand Down Expand Up @@ -464,6 +466,8 @@ export type ClusterAttributes = {
domain?: InputMaybe<Scalars['String']['input']>;
/** The git repository URL for the cluster. */
gitUrl?: InputMaybe<Scalars['String']['input']>;
/** whether this is a legacy oss cluster */
legacy?: InputMaybe<Scalars['Boolean']['input']>;
/** The name of the cluster. */
name: Scalars['String']['input'];
/** The cluster's cloud provider. */
Expand Down Expand Up @@ -4926,6 +4930,7 @@ export type UpgradeQueueUpgradesArgs = {
export type UpgradeQueueAttributes = {
domain?: InputMaybe<Scalars['String']['input']>;
git?: InputMaybe<Scalars['String']['input']>;
legacy?: InputMaybe<Scalars['Boolean']['input']>;
name: Scalars['String']['input'];
provider?: InputMaybe<Provider>;
};
Expand Down
68 changes: 68 additions & 0 deletions assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ export type Cluster = {
/** key/value tags to filter clusters */
tags?: Maybe<Array<Maybe<Tag>>>;
updatedAt?: Maybe<Scalars['DateTime']['output']>;
/** any upgrade insights provided by your cloud provider that have been discovered by our agent */
upgradeInsights?: Maybe<Array<Maybe<UpgradeInsight>>>;
/** Checklist of tasks to complete to safely upgrade this cluster */
upgradePlan?: Maybe<ClusterUpgradePlan>;
/** desired k8s version for the cluster */
Expand Down Expand Up @@ -1308,6 +1310,7 @@ export type ConsoleConfiguration = {
features?: Maybe<AvailableFeatures>;
gitCommit?: Maybe<Scalars['String']['output']>;
gitStatus?: Maybe<GitStatus>;
/** whether at least one cluster has been installed, false if a user hasn't fully onboarded */
installed?: Maybe<Scalars['Boolean']['output']>;
isDemoProject?: Maybe<Scalars['Boolean']['output']>;
isSandbox?: Maybe<Scalars['Boolean']['output']>;
Expand Down Expand Up @@ -4622,6 +4625,8 @@ export type RootMutationType = {
/** upserts a pipeline with a given name */
savePipeline?: Maybe<Pipeline>;
saveServiceContext?: Maybe<ServiceContext>;
/** agent api to persist upgrade insights for its cluster */
saveUpgradeInsights?: Maybe<Array<Maybe<UpgradeInsight>>>;
selfManage?: Maybe<ServiceDeployment>;
/** creates the service to enable self-hosted renovate in one pass */
setupRenovate?: Maybe<ServiceDeployment>;
Expand Down Expand Up @@ -5286,6 +5291,11 @@ export type RootMutationTypeSaveServiceContextArgs = {
};


export type RootMutationTypeSaveUpgradeInsightsArgs = {
insights?: InputMaybe<Array<InputMaybe<UpgradeInsightAttributes>>>;
};


export type RootMutationTypeSelfManageArgs = {
values: Scalars['String']['input'];
};
Expand Down Expand Up @@ -7990,6 +8000,64 @@ export enum Tool {
Terraform = 'TERRAFORM'
}

export type UpgradeInsight = {
__typename?: 'UpgradeInsight';
/** longform description of this insight */
description?: Maybe<Scalars['String']['output']>;
details?: Maybe<Array<Maybe<UpgradeInsightDetail>>>;
id: Scalars['ID']['output'];
insertedAt?: Maybe<Scalars['DateTime']['output']>;
name: Scalars['String']['output'];
refreshedAt?: Maybe<Scalars['DateTime']['output']>;
status?: Maybe<UpgradeInsightStatus>;
transitionedAt?: Maybe<Scalars['DateTime']['output']>;
updatedAt?: Maybe<Scalars['DateTime']['output']>;
/** the k8s version this insight applies to */
version?: Maybe<Scalars['String']['output']>;
};

export type UpgradeInsightAttributes = {
/** longform description of this insight */
description?: InputMaybe<Scalars['String']['input']>;
details?: InputMaybe<Array<InputMaybe<UpgradeInsightDetailAttributes>>>;
name: Scalars['String']['input'];
refreshedAt?: InputMaybe<Scalars['DateTime']['input']>;
status?: InputMaybe<UpgradeInsightStatus>;
transitionedAt?: InputMaybe<Scalars['DateTime']['input']>;
/** the k8s version this insight applies to */
version?: InputMaybe<Scalars['String']['input']>;
};

export type UpgradeInsightDetail = {
__typename?: 'UpgradeInsightDetail';
id: Scalars['ID']['output'];
insertedAt?: Maybe<Scalars['DateTime']['output']>;
removedIn?: Maybe<Scalars['String']['output']>;
replacedIn?: Maybe<Scalars['String']['output']>;
/** the replacement for this API */
replacement?: Maybe<Scalars['String']['output']>;
status?: Maybe<UpgradeInsightStatus>;
updatedAt?: Maybe<Scalars['DateTime']['output']>;
/** a possibly deprecated API */
used?: Maybe<Scalars['String']['output']>;
};

export type UpgradeInsightDetailAttributes = {
removedIn?: InputMaybe<Scalars['String']['input']>;
replacedIn?: InputMaybe<Scalars['String']['input']>;
/** the replacement for this API */
replacement?: InputMaybe<Scalars['String']['input']>;
status?: InputMaybe<UpgradeInsightStatus>;
/** a possibly deprecated API */
used?: InputMaybe<Scalars['String']['input']>;
};

export enum UpgradeInsightStatus {
Failed = 'FAILED',
Passing = 'PASSING',
Unknown = 'UNKNOWN'
}

export type UpgradePlan = {
__typename?: 'UpgradePlan';
events?: Maybe<Array<Maybe<Event>>>;
Expand Down
122 changes: 109 additions & 13 deletions go/client/models_gen.go

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

41 changes: 37 additions & 4 deletions lib/console/deployments/clusters.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ defmodule Console.Deployments.Clusters do
ProviderCredential,
RuntimeService,
AgentMigration,
PinnedCustomResource
PinnedCustomResource,
UpgradeInsight
}
alias Console.Deployments.Compatibilities
require Logger
Expand Down Expand Up @@ -443,13 +444,16 @@ defmodule Console.Deployments.Clusters do
"""
@spec update_upgrade_plan(Cluster.t) :: cluster_resp
def update_upgrade_plan(%Cluster{} = cluster) do
%{api_deprecations: deps} = cluster = Repo.preload(cluster, [:api_deprecations])
%{api_deprecations: deps, upgrade_insights: insights} = cluster =
Repo.preload(cluster, [:api_deprecations, :upgrade_insights])

addons = runtime_services(cluster)
Cluster.changeset(cluster, %{
upgrade_plan: %{
deprecations: length(deps) == 0,
deprecations: length(deps) == 0 && Enum.all?(insights, & &1.status == :passing),
compatibilities: !Enum.any?(addons, fn
%{addon_version: %Version{} = vsn} -> Version.blocking?(vsn, cluster.current_version)
%{addon_version: %Version{} = vsn} ->
Version.blocking?(vsn, cluster.current_version)
_ -> false
end),
incompatibilities: true
Expand Down Expand Up @@ -891,6 +895,35 @@ defmodule Console.Deployments.Clusters do
|> when_ok(:delete)
end

@doc """
Saves upgrade insights for a cluster
"""
@spec save_upgrade_insights([map], Cluster.t) :: {:ok, [UpgradeInsight.t]} | Console.error
def save_upgrade_insights(insights, %Cluster{id: id}) do
xact = add_operation(start_transaction(), :prune, fn _ ->
UpgradeInsight.for_cluster(id)
|> Repo.delete_all()
|> ok()
end)

Enum.with_index(insights)
|> Enum.reduce(xact, fn {insight, ind}, xact ->
add_operation(xact, {:insight, ind}, fn _ ->
%UpgradeInsight{cluster_id: id}
|> UpgradeInsight.changeset(insight)
|> Repo.insert()
end)
end)
|> execute()
|> when_ok(fn res ->
Enum.filter(res, fn
{{:insight, _}, _} -> true
_ -> false
end)
|> Enum.map(fn {_, v} -> v end)
end)
end

def kas_url() do
kas_dns()
|> URI.parse()
Expand Down
2 changes: 1 addition & 1 deletion lib/console/deployments/pr/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Console.Deployments.Pr.Config do
end

defp structure(pr, branch, ctx) do
spec = Map.take(pr, ~w(identifier creates updates message)a)
spec = Map.take(pr, ~w(identifier deletes creates updates message)a)
|> Map.put(:branch, branch)
%{
apiVersion: "pr.plural.sh/v1alpha1",
Expand Down
4 changes: 3 additions & 1 deletion lib/console/graphql/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ defmodule Console.GraphQl.Configuration do
field :is_sandbox, :boolean
field :plural_login, :boolean
field :vpn_enabled, :boolean
field :installed, :boolean, resolve: fn _, _, _ -> {:ok, Console.Deployments.Clusters.installed?()} end
field :installed, :boolean,
resolve: fn _, _, _ -> {:ok, Console.Deployments.Clusters.installed?()} end,
description: "whether at least one cluster has been installed, false if a user hasn't fully onboarded"
field :cloud, :boolean, resolve: fn _, _, _ -> {:ok, Console.cloud?()} end
field :byok, :boolean, resolve: fn _, _, _ -> {:ok, Console.byok?()} end
field :external_oidc, :boolean, resolve: fn _, _, _ -> {:ok, !!Console.conf(:oidc_login)} end
Expand Down
Loading

0 comments on commit 311cda6

Please sign in to comment.