Skip to content

Commit

Permalink
Add repository field to promotion criteria (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Jun 28, 2024
1 parent 7cb94a9 commit 15c825b
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 25 deletions.
2 changes: 1 addition & 1 deletion AGENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.36
v0.4.37
54 changes: 46 additions & 8 deletions assets/src/components/cd/pipelines/nodes/StageNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import styled, { useTheme } from 'styled-components'
import {
Button,
Chip,
ClusterIcon,
CodeEditor,
FormField,
GitPullIcon,
IconFrame,
Modal,
PrOpenIcon,
Expand Down Expand Up @@ -42,6 +42,11 @@ import { ModalMountTransition } from 'components/utils/ModalMountTransition'
import { GqlError } from 'components/utils/Alert'
import { CountBadge } from 'components/help/CountBadge'

import {
ServiceErrorsChip,
ServiceErrorsModal,
} from 'components/cd/services/ServicesTableErrors'

import { PIPELINE_GRID_GAP } from '../PipelineGraph'
import { PipelinePullRequestsModal } from '../PipelinePullRequests'

Expand Down Expand Up @@ -186,6 +191,38 @@ function PrsButton({
)
}

function HeaderChip({ stage, isOpen, setIsOpen, status }) {
if ((stage.errors || []).length > 0) {
return (
<>
<ServiceErrorsChip
clickable
onClick={(e) => {
setIsOpen(true)
e.target?.blur()
}}
errors={stage.errors}
/>
<ServiceErrorsModal
header={`Errors applying stage ${stage.name}`}
isOpen={isOpen}
setIsOpen={setIsOpen}
errors={stage.errors}
/>
</>
)
}

return (
<Chip
size="small"
severity={stageStatusToSeverity[status]}
>
{status}
</Chip>
)
}

export function StageNode(
props: NodeProps<
PipelineStageFragment &
Expand All @@ -195,6 +232,7 @@ export function StageNode(
const navigate = useNavigate()
const { incomers, outgoers } = useNodeEdges(props.id)
const pipelineId = useParams().pipelineId!
const [isOpen, setIsOpen] = useState(false)

const {
data: { meta, ...stage },
Expand All @@ -219,14 +257,14 @@ export function StageNode(
<StageNodeSC {...props}>
<div className="headerArea">
<h2 className="heading">STAGE</h2>
<Chip
size="small"
severity={stageStatusToSeverity[status]}
>
{status}
</Chip>
<HeaderChip
stage={stage}
status={status}
isOpen={isOpen}
setIsOpen={setIsOpen}
/>
</div>
<IconHeading icon={<ClusterIcon />}>
<IconHeading icon={<GitPullIcon />}>
<IconHeadingInnerSC>Deploy to {stage.name}</IconHeadingInnerSC>
</IconHeading>

Expand Down
16 changes: 16 additions & 0 deletions assets/src/components/cd/services/ServicesTableErrors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ export function ServiceErrorsChip({
)
}

export function ServiceErrorsModal({ isOpen, setIsOpen, header, errors }) {
return (
<ModalMountTransition open={isOpen}>
<Modal
portal
size="large"
header={header}
open={isOpen}
onClose={() => setIsOpen(false)}
>
<ServiceErrorsTable errors={errors} />
</Modal>
</ModalMountTransition>
)
}

export function ServicesTableErrors({
service,
}: {
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/stacks/customrun/StackCustomRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function StackCustomRun({ stack }: { stack: StackFragment }) {

return (
<>
<Button onClick={() => setIsOpen(true)}>Create custom run</Button>
<Button onClick={() => setIsOpen(true)}>Create manual run</Button>
<ModalMountTransition open={isOpen}>
<StackCustomRunModal
open={isOpen}
Expand Down
18 changes: 11 additions & 7 deletions assets/src/generated/graphql.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/src/graph/cdPipelines.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ fragment PipelineStage on PipelineStage {
context {
...PipelineContext
}
errors {
message
source
}
}

fragment PipelineStageEdge on PipelineStageEdge {
Expand Down
5 changes: 5 additions & 0 deletions charts/controller/crds/deployments.plural.sh_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8925,6 +8925,11 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
repository:
description: The repository slug the pr automation
will use (eg pluralsh/console if you will pr against
https://github.com/pluralsh/console)
type: string
secrets:
description: Secrets to copy over in a promotion.
items:
Expand Down
4 changes: 4 additions & 0 deletions controller/api/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type PipelineStageServicePromotionCriteria struct {
// +kubebuilder:validation:Optional
PrAutomationRef *v1.ObjectReference `json:"prAutomationRef,omitempty"`

// The repository slug the pr automation will use (eg pluralsh/console if you will pr against https://github.com/pluralsh/console)
// +kubebuilder:validation:Optional
Repository *string `json:"repository,omitempty"`

// Secrets to copy over in a promotion.
// +kubebuilder:validation:Optional
Secrets []*string `json:"secrets,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion controller/api/v1alpha1/prautomation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type PrAutomationSpec struct {
// +kubebuilder:validation:Optional
Addon *string `json:"addon,omitempty"`

// Branch ...
// The base branch this pr will be based on (defaults to the repo's main branch)
// +kubebuilder:validation:Optional
Branch *string `json:"branch,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions 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 @@ -8925,6 +8925,11 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
repository:
description: The repository slug the pr automation
will use (eg pluralsh/console if you will pr against
https://github.com/pluralsh/console)
type: string
secrets:
description: Secrets to copy over in a promotion.
items:
Expand Down
20 changes: 19 additions & 1 deletion controller/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `serviceRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | ServiceRef pointing to source service to promote from. | | Optional: {} <br /> |
| `prAutomationRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | PrAutomationRef pointing to source PR automation to promote from. | | Optional: {} <br /> |
| `repository` _string_ | The repository slug the pr automation will use (eg pluralsh/console if you will pr against https://github.com/pluralsh/console) | | Optional: {} <br /> |
| `secrets` _string array_ | Secrets to copy over in a promotion. | | Optional: {} <br /> |


Expand Down Expand Up @@ -1199,7 +1200,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `role` _[PrRole](#prrole)_ | | | Enum: [CLUSTER SERVICE PIPELINE UPDATE UPGRADE] <br />Optional: {} <br /> |
| `addon` _string_ | Addon is a link to an addon name | | Optional: {} <br /> |
| `branch` _string_ | Branch ... | | Optional: {} <br /> |
| `branch` _string_ | The base branch this pr will be based on (defaults to the repo's main branch) | | Optional: {} <br /> |
| `documentation` _string_ | Documentation ... | | Optional: {} <br /> |
| `identifier` _string_ | Identifier is a string referencing the repository, i.e. for GitHub it would be "<organization>/<repositoryName>" | | Optional: {} <br /> |
| `message` _string_ | Message ... | | Optional: {} <br /> |
Expand Down Expand Up @@ -1559,6 +1560,22 @@ _Appears in:_
| `repository` _[NamespacedName](#namespacedname)_ | pointer to the FluxCD helm repository to use | | Optional: {} <br /> |


#### ServiceImport







_Appears in:_
- [ServiceSpec](#servicespec)

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `stackRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#objectreference-v1-core)_ | | | Required: {} <br /> |


#### ServiceKustomize


Expand Down Expand Up @@ -1605,6 +1622,7 @@ _Appears in:_
| `dependencies` _[ServiceDependency](#servicedependency) array_ | Dependencies contain dependent services | | Optional: {} <br /> |
| `contexts` _string array_ | Contexts contain dependent service context names | | Optional: {} <br /> |
| `templated` _boolean_ | Templated should apply liquid templating to raw yaml files, defaults to true | | Optional: {} <br /> |
| `imports` _[ServiceImport](#serviceimport) array_ | | | Optional: {} <br /> |
| `detach` _boolean_ | Detach determined if user want to delete or detach service | | Optional: {} <br /> |


Expand Down
2 changes: 1 addition & 1 deletion controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.1
// Dependencies
require (
github.com/Yamashou/gqlgenc v0.18.1
github.com/pluralsh/console-client-go v0.8.2
github.com/pluralsh/console-client-go v0.9.2
github.com/pluralsh/polly v0.1.7
github.com/samber/lo v1.39.0
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ github.com/pluralsh/console-client-go v0.8.1 h1:FuQMMts09IBzlbcjADYb2RRVkEMKunOK
github.com/pluralsh/console-client-go v0.8.1/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.8.2 h1:XxvOnitrpab8GRFjrtETREdynQ/AxJp4rZcQRuyviEE=
github.com/pluralsh/console-client-go v0.8.2/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.9.2 h1:m3rEshxsq6nTWVQkvbp1wwzXw8hVArf+09GJfbTGcF8=
github.com/pluralsh/console-client-go v0.9.2/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/polly v0.1.7 h1:MUuTb6rCUV1doisaFGC+iz+33ZPU4FZHOb/kFwSDkjw=
github.com/pluralsh/polly v0.1.7/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (r *PipelineReconciler) pipelineStageServiceCriteriaAttributes(ctx context.
SourceID: sourceID,
PrAutomationID: prAutomationID,
Secrets: criteria.Secrets,
Repository: criteria.Repository,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion controller/internal/controller/prautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (in *PrAutomationReconciler) Reconcile(ctx context.Context, req reconcile.R
if err != nil {
logger.Error(err, "unable to create or update prAutomation")
utils.MarkFalse(prAutomation.SetCondition, v1alpha1.SynchronizedConditionType, v1alpha1.SynchronizedConditionReasonError, err.Error())
return ctrl.Result{}, err
return requeue, err
}
if apiPrAutomation == nil {
logger.Info("PR automation already exists in the Console API. Won't reconcile again.")
Expand Down
19 changes: 17 additions & 2 deletions lib/console/deployments/policies/rbac.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Console.Deployments.Policies.Rbac do
PipelineContext,
AgentMigration,
RuntimeService,
ManagedNamespace,
PrAutomation,
PolicyConstraint,
PinnedCustomResource,
Expand Down Expand Up @@ -68,8 +69,18 @@ defmodule Console.Deployments.Policies.Rbac do
do: recurse(pr, user, action, fn _ -> Settings.fetch() end)
def evaluate(%GitRepository{}, %User{} = user, action),
do: recurse(Settings.fetch(), user, action)
def evaluate(%GlobalService{}, %User{} = user, action),
do: recurse(Settings.fetch(), user, action)
def evaluate(%GlobalService{} = global, %User{} = user, action) do
recurse(global, user, action, fn
%{project: %Project{} = project} -> project
_ -> Settings.fetch()
end)
end
def evaluate(%ManagedNamespace{} = ns, %User{} = user, action) do
recurse(ns, user, action, fn
%{project: %Project{} = project} -> project
_ -> Settings.fetch()
end)
end
def evaluate(%DeploymentSettings{} = settings, %User{} = user, action),
do: recurse(settings, user, action)
def evaluate(%PolicyConstraint{} = constraint, %User{} = user, action),
Expand Down Expand Up @@ -121,6 +132,10 @@ defmodule Console.Deployments.Policies.Rbac do
do: Repo.preload(stack, @stack_preloads)
def preload(%StackRun{} = pcr),
do: Repo.preload(pcr, [stack: @stack_preloads])
def preload(%GlobalService{} = global),
do: Repo.preload(global, [project: @bindings])
def preload(%ManagedNamespace{} = ns),
do: Repo.preload(ns, [project: @bindings])
def preload(%CustomStackRun{} = pcr),
do: Repo.preload(pcr, [stack: @stack_preloads])
def preload(%RunStep{} = pcr),
Expand Down
2 changes: 1 addition & 1 deletion lib/console/schema/global_service.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Console.Schema.GlobalService do
use Piazza.Ecto.Schema
alias Console.Schema.{Service, Cluster, ClusterProvider, ServiceTemplate}
alias Console.Schema.{Service, Cluster, Project, ClusterProvider, ServiceTemplate}

schema "global_services" do
field :reparent, :boolean
Expand Down
5 changes: 5 additions & 0 deletions plural/helm/console/crds/deployments.plural.sh_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8925,6 +8925,11 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
repository:
description: The repository slug the pr automation
will use (eg pluralsh/console if you will pr against
https://github.com/pluralsh/console)
type: string
secrets:
description: Secrets to copy over in a promotion.
items:
Expand Down
2 changes: 1 addition & 1 deletion static/compatibilities/flux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ versions:
requirements: []
incompatibilities: []
- version: 2.2.0
kube: ['1.29', 1.28', '1.27', '1.26']
kube: ['1.29', '1.28', '1.27', '1.26']
requirements: []
incompatibilities: []
- version: 2.1.0
Expand Down
20 changes: 20 additions & 0 deletions test/console/deployments/global_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ defmodule Console.Deployments.GlobalTest do
assert_receive {:event, %PubSub.GlobalServiceCreated{item: ^global}}
end

test "project writers can create project-scoped global services" do
user = insert(:user)
svc = insert(:service)
project = insert(:project, write_bindings: [%{user_id: user.id}])

{:ok, global} = Global.create(%{
name: "test",
project_id: project.id,
tags: [%{name: "name", value: "value"}]
}, svc.id, user)

assert global.service_id == svc.id
assert global.project_id == project.id
[tag] = global.tags
assert tag.name == "name"
assert tag.value == "value"

assert_receive {:event, %PubSub.GlobalServiceCreated{item: ^global}}
end

test "it can create a template global service" do
git = insert(:git_repository)
{:ok, global} = Global.create(%{
Expand Down

0 comments on commit 15c825b

Please sign in to comment.