Skip to content

Commit

Permalink
feat: route k8s requests with enqueueOne strategy to /pipelines endpo…
Browse files Browse the repository at this point in the history
…int (#195)

* feat: route k8s requests with enqueueOne strategy to /pipelines endpoint

* added cue property for extra deploymentConfig fields
  • Loading branch information
Greg-At-Armory authored Oct 16, 2023
1 parent 71190ce commit 4812ee4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/validate/resources/pipelineRequest.cue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import "struct"
#DeploymentConfig: {
timeout?: #Timeout
keepDeploymentObject?: bool
ifDeploymentInProgress?: #IfDeploymentInProgress
}

#IfDeploymentInProgress: {
strategy: "reject" | "enqueueOne"
}

#Timeout: {
Expand Down
9 changes: 8 additions & 1 deletion pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type (

const (
mediaTypeKubernetesPipelineV2 = "application/vnd.start.kubernetes.pipeline.v2+json"
kubernetesKind = "kubernetes"
)

func NewClient(configuration *config.Configuration) *Client {
Expand Down Expand Up @@ -173,7 +174,13 @@ func getPipelinePathAndHeaders(options StartPipelineOptions) (string, map[string
if err != nil {
return "", nil, err
}
if structured.Kind == "kubernetes" || structured.Kind == "" {
if structured.Kind == kubernetesKind &&
structured.DeploymentConfig != nil &&
structured.DeploymentConfig.IfDeploymentInProgress != nil &&
structured.DeploymentConfig.IfDeploymentInProgress.Strategy == enqueueOne {
return "/pipelines", nil, nil
}
if structured.Kind == kubernetesKind || structured.Kind == "" {
return "/pipelines/kubernetes", map[string]string{
"Content-Type": mediaTypeKubernetesPipelineV2,
"Accept": mediaTypeKubernetesPipelineV2,
Expand Down
14 changes: 14 additions & 0 deletions pkg/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ application: lambda-application
yaml: `
kind: banana cloud
application: lambda-application
`,
expectedPath: "/pipelines",
expectedHeaders: map[string]string{
"Content-Type": "application/json",
},
},
{
name: "k8s with enqueueOne strategy",
yaml: `
kind: kubernetes
application: classic-k8s-app
deploymentConfig:
ifDeploymentInProgress:
strategy: enqueueOne
`,
expectedPath: "/pipelines",
expectedHeaders: map[string]string{
Expand Down
20 changes: 17 additions & 3 deletions pkg/deploy/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@ type (
}

structuredConfig struct {
Kind string `yaml:"kind"`
Application string `yaml:"application"`
Manifests []manifest `yaml:"manifests"`
Kind string `yaml:"kind"`
Application string `yaml:"application"`
Manifests []manifest `yaml:"manifests"`
DeploymentConfig *deploymentConfig `yaml:"deploymentConfig"`
}

manifest struct {
Path string `yaml:"path"`
Targets []string `yaml:"targets"`
Inline string `yaml:"inline"`
}

deploymentConfig struct {
IfDeploymentInProgress *ifDeploymentInProgress `yaml:"ifDeploymentInProgress"`
}

ifDeploymentInProgress struct {
Strategy strategy `yaml:"strategy"`
}

strategy string
)

const (
Expand All @@ -41,6 +52,9 @@ const (
contextKey = "context"
scmcKey = "sourceControl"
envVarGithubWorkspace = "GITHUB_WORKSPACE"

enqueueOne strategy = "enqueueOne"
reject strategy = "reject"
)

func (s *StartPipelineOptions) structuredConfig() (*structuredConfig, error) {
Expand Down

0 comments on commit 4812ee4

Please sign in to comment.