Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes pre-release #1658

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assets/src/components/cd/clusters/ClusterHealthChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ export function ClusterHealth({

return (
<ClusterHealthChip
cluster={cluster}
pingedAt={cluster.pingedAt}
size={size}
/>
)
}

function ClusterHealthChip({
cluster,
pingedAt,
size = 'medium',
}: {
cluster?: ClustersRowFragment
pingedAt?: string | null
size?: 'small' | 'medium' | 'large'
}) {
Expand All @@ -49,7 +52,8 @@ function ClusterHealthChip({

const pinged = pingedAt !== null
const healthy =
pingedAt && now.clone().subtract(10, 'minutes').isBefore(pingedAt)
cluster?.healthy ||
(pingedAt && now.clone().subtract(10, 'minutes').isBefore(pingedAt))

return (
<TooltipTime
Expand Down
13 changes: 12 additions & 1 deletion assets/src/components/cd/globalServices/details/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import DecoratedName from '../../services/DecoratedName.tsx'
import {
ColCluster,
ColLastActivity,
ColRef,
ColRepo,
ColErrors,
ColStatus,
} from '../../services/ServicesColumns.tsx'

Expand All @@ -31,4 +34,12 @@ const ColDeployment = columnHelper.accessor(({ node }) => node, {
},
})

export const columns = [ColDeployment, ColCluster, ColLastActivity, ColStatus]
export const columns = [
ColDeployment,
ColCluster,
ColRepo,
ColRef,
ColLastActivity,
ColStatus,
ColErrors,
]
27 changes: 15 additions & 12 deletions assets/src/generated/graphql.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/src/graph/cdClusters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ fragment ClustersRow on Cluster {
currentVersion
id
self
healthy
protect
name
handle
Expand Down
2 changes: 2 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.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pluralsh/console/go/controller/internal/utils"
)

func (in *PrAutomationReconciler) attributes(ctx context.Context, pra *v1alpha1.PrAutomation) (*console.PrAutomationAttributes, error) {
func (in *PrAutomationReconciler) Attributes(ctx context.Context, pra *v1alpha1.PrAutomation) (*console.PrAutomationAttributes, error) {
helper := utils.NewConsoleHelper(ctx, in.ConsoleClient, in.Client)

clusterID, err := helper.IDFromRef(pra.Spec.ClusterRef, &v1alpha1.Cluster{})
Expand Down
45 changes: 25 additions & 20 deletions go/controller/internal/controller/prautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,8 @@ func (in *PrAutomationReconciler) Reconcile(ctx context.Context, req reconcile.R
return *result, err
}

// Get PrAutomation SHA that can be saved back in the status to check for changes
changed, sha, err := prAutomation.Diff(utils.HashObject)
if err != nil {
logger.Error(err, "unable to calculate prAutomation SHA")
utils.MarkFalse(prAutomation.SetCondition, v1alpha1.SynchronizedConditionType, v1alpha1.SynchronizedConditionReasonError, err.Error())
return ctrl.Result{}, err
}

// Sync PrAutomation CRD with the Console API
apiPrAutomation, err := in.sync(ctx, prAutomation, changed)
apiPrAutomation, sha, err := in.sync(ctx, prAutomation)
if err != nil {
if errors.IsNotFound(err) {
utils.MarkCondition(prAutomation.SetCondition, v1alpha1.SynchronizedConditionType, metav1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, notFoundOrReadyError)
Expand Down Expand Up @@ -150,37 +142,50 @@ func (in *PrAutomationReconciler) addOrRemoveFinalizer(ctx context.Context, prAu
return nil, nil
}

func (in *PrAutomationReconciler) sync(ctx context.Context, prAutomation *v1alpha1.PrAutomation, changed bool) (*console.PrAutomationFragment, error) {
func (in *PrAutomationReconciler) sync(ctx context.Context, prAutomation *v1alpha1.PrAutomation) (pra *console.PrAutomationFragment, sha string, err error) {
logger := log.FromContext(ctx)
exists, err := in.ConsoleClient.IsPrAutomationExistsByName(ctx, prAutomation.ConsoleName())
if err != nil {
return nil, err
return pra, sha, err
}

if exists && !prAutomation.Status.HasID() {
return nil, nil
return pra, sha, err
}
if err := in.ensure(prAutomation); err != nil {
return nil, err

if err = in.ensure(prAutomation); err != nil {
return pra, sha, err
}
attributes, err := in.attributes(ctx, prAutomation)

attributes, err := in.Attributes(ctx, prAutomation)
if err != nil {
return nil, err
return pra, sha, err
}

// Get PrAutomation SHA that can be saved back in the status to check for changes
sha, err = utils.HashObject(attributes)
if err != nil {
logger.Error(err, "unable to calculate prAutomation SHA")
utils.MarkFalse(prAutomation.SetCondition, v1alpha1.SynchronizedConditionType, v1alpha1.SynchronizedConditionReasonError, err.Error())
return pra, sha, err
}

// Update only if PrAutomation has changed
if changed && exists {
if prAutomation.Status.SHA != nil && *prAutomation.Status.SHA != sha && exists {
logger.Info("Updating PR automation")
return in.ConsoleClient.UpdatePrAutomation(ctx, prAutomation.Status.GetID(), *attributes)
pra, err = in.ConsoleClient.UpdatePrAutomation(ctx, prAutomation.Status.GetID(), *attributes)
return pra, sha, err
}

// Read the PrAutomation from Console API if it already exists
if exists {
return in.ConsoleClient.GetPrAutomation(ctx, prAutomation.Status.GetID())
pra, err = in.ConsoleClient.GetPrAutomation(ctx, prAutomation.Status.GetID())
return pra, sha, err
}

logger.Info("Creating PR automation")
return in.ConsoleClient.CreatePrAutomation(ctx, *attributes)
pra, err = in.ConsoleClient.CreatePrAutomation(ctx, *attributes)
return pra, sha, err
}

func (in *PrAutomationReconciler) updateReadyCondition(prAutomation *v1alpha1.PrAutomation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ var _ = Describe("PR Automation Controller", func() {
Name: scmConnectionName,
},
})
_, prAutomationHash, _ = generatedPrAutomation.Diff(utils.HashObject)

prAutomationObjectKey = types.NamespacedName{Name: prAutomationName}
)
Expand Down Expand Up @@ -104,10 +103,13 @@ var _ = Describe("PR Automation Controller", func() {

prAutomation := &v1alpha1.PrAutomation{}
err = k8sClient.Get(ctx, prAutomationObjectKey, prAutomation)
attrs, _ := controllerReconciler.Attributes(ctx, prAutomation)
sha, _ := utils.HashObject(attrs)

Expect(err).NotTo(HaveOccurred())
Expect(common.SanitizeStatusConditions(prAutomation.Status)).To(Equal(common.SanitizeStatusConditions(v1alpha1.Status{
ID: lo.ToPtr(prAutomationConsoleID),
SHA: lo.ToPtr(prAutomationHash),
SHA: lo.ToPtr(sha),
Conditions: []metav1.Condition{
{
Type: v1alpha1.ReadyConditionType.String(),
Expand Down Expand Up @@ -181,7 +183,6 @@ var _ = Describe("PR Automation Controller", func() {
Namespace: clusterNamespace,
},
})
_, prAutomationHash, _ = generatedPrAutomation.Diff(utils.HashObject)

prAutomationObjectKey = types.NamespacedName{Name: prAutomationName}
)
Expand Down Expand Up @@ -239,10 +240,14 @@ var _ = Describe("PR Automation Controller", func() {

prAutomation := &v1alpha1.PrAutomation{}
err = k8sClient.Get(ctx, prAutomationObjectKey, prAutomation)

attrs, _ := controllerReconciler.Attributes(ctx, prAutomation)
sha, _ := utils.HashObject(attrs)

Expect(err).NotTo(HaveOccurred())
Expect(common.SanitizeStatusConditions(prAutomation.Status)).To(Equal(common.SanitizeStatusConditions(v1alpha1.Status{
ID: lo.ToPtr(prAutomationConsoleID),
SHA: lo.ToPtr(prAutomationHash),
SHA: lo.ToPtr(sha),
Conditions: []metav1.Condition{
{
Type: v1alpha1.ReadyConditionType.String(),
Expand Down
4 changes: 4 additions & 0 deletions lib/console/graphql/deployments/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ defmodule Console.GraphQl.Deployments.Cluster do
field :settings, :cloud_settings, description: "the cloud settings for this cluster (for instance its aws region)"
field :upgrade_plan, :cluster_upgrade_plan, description: "Checklist of tasks to complete to safely upgrade this cluster"

field :healthy, :boolean, description: "Whether this cluster was recently pinged", resolve: fn
cluster, _, _ -> {:ok, Cluster.healthy?(cluster)}
end

field :kas_url, :string, description: "the url of the kas server you can access this cluster from", resolve: fn
_, _, _ -> {:ok, Console.Deployments.Clusters.kas_proxy_url()}
end
Expand Down
7 changes: 7 additions & 0 deletions lib/console/schema/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ defmodule Console.Schema.Cluster do
timestamps()
end

def healthy?(%__MODULE__{pinged_at: nil}), do: false
def healthy?(%__MODULE__{pinged_at: pinged}) do
Timex.now()
|> Timex.shift(minutes: -20)
|> Timex.before?(pinged)
end

defp upgrade_plan_fields(), do: __MODULE__.UpgradePlan.__schema__(:fields) -- [:id]

def search(query \\ __MODULE__, sq) do
Expand Down
2 changes: 1 addition & 1 deletion lib/console/schema/pr_automation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ defmodule Console.Schema.PrAutomation do
|> cast_assoc(:create_bindings)
|> put_new_change(:write_policy_id, &Ecto.UUID.generate/0)
|> put_new_change(:create_policy_id, &Ecto.UUID.generate/0)
|> validate_required([:name, :title, :message, :connection_id])
|> unique_constraint(:name)
|> foreign_key_constraint(:promotion_criteria,
name: :promotion_criteria,
Expand All @@ -138,6 +137,7 @@ defmodule Console.Schema.PrAutomation do
|> foreign_key_constraint(:connection_id)
|> foreign_key_constraint(:project_id)
|> foreign_key_constraint(:catalog_id)
|> validate_required([:name, :title, :message, :connection_id])
end

defp update_changeset(model, attrs) do
Expand Down
3 changes: 3 additions & 0 deletions schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4622,6 +4622,9 @@ type Cluster {
"Checklist of tasks to complete to safely upgrade this cluster"
upgradePlan: ClusterUpgradePlan

"Whether this cluster was recently pinged"
healthy: Boolean

"the url of the kas server you can access this cluster from"
kasUrl: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,24 @@ defmodule Console.GraphQl.Deployments.GitMutationsTest do
describe "updatePrAutomation" do
test "it will create a new scm connection" do
pr = insert(:pr_automation)
catalog = insert(:catalog)

{:ok, %{data: %{"updatePrAutomation" => updated}}} = run_query("""
mutation Create($id: ID!, $attrs: PrAutomationAttributes!) {
updatePrAutomation(id: $id, attributes: $attrs) {
id
name
catalog { id }
}
}
""", %{"attrs" => %{"name" => "test"}, "id" => pr.id}, %{current_user: admin_user()})
""", %{"id" => pr.id, "attrs" => %{
"name" => "test",
"catalogId" => catalog.id
}}, %{current_user: admin_user()})

assert updated["id"] == pr.id
assert updated["name"] == "test"
assert updated["catalog"]["id"] == catalog.id
end
end

Expand Down
Loading