Skip to content

Commit

Permalink
Added apply-config pipeline job type support
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Apr 12, 2024
1 parent 405a218 commit 226efd8
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 3 deletions.
54 changes: 54 additions & 0 deletions api/applications/applications_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (ac *applicationController) GetRoutes() models.Routes {
Method: "POST",
HandlerFunc: ac.TriggerPipelineDeploy,
},
models.Route{
Path: appPath + "/pipelines/apply-config",
Method: "POST",
HandlerFunc: ac.TriggerPipelineApplyConfig,
},
models.Route{
Path: appPath + "/deploykey-valid",
Method: "GET",
Expand Down Expand Up @@ -899,6 +904,55 @@ func (ac *applicationController) TriggerPipelineDeploy(accounts models.Accounts,
ac.JSONResponse(w, r, &jobSummary)
}

// TriggerPipelineApplyConfig creates an apply config pipeline job for the application
func (ac *applicationController) TriggerPipelineApplyConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /applications/{appName}/pipelines/apply-config application triggerPipelineApplyConfig
// ---
// summary: Run a apply config pipeline for a given application and environment
// parameters:
// - name: appName
// in: path
// description: Name of application
// type: string
// required: true
// - name: PipelineParametersApplyConfig
// description: Pipeline parameters
// in: body
// required: true
// schema:
// "$ref": "#/definitions/PipelineParametersApplyConfig"
// - name: Impersonate-User
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set)
// type: string
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
// description: Successful trigger pipeline
// schema:
// "$ref": "#/definitions/JobSummary"
// "403":
// description: "Forbidden"
// "404":
// description: "Not found"
appName := mux.Vars(r)["appName"]

handler := ac.applicationHandlerFactory.Create(accounts)
jobSummary, err := handler.TriggerPipelineApplyConfig(r.Context(), appName, r)

if err != nil {
ac.ErrorResponse(w, r, err)
return
}

ac.JSONResponse(w, r, &jobSummary)
}

// TriggerPipelinePromote creates a promote pipeline job for the application
func (ac *applicationController) TriggerPipelinePromote(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /applications/{appName}/pipelines/promote application triggerPipelinePromote
Expand Down
24 changes: 24 additions & 0 deletions api/applications/applications_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,30 @@ func (ah *ApplicationHandler) TriggerPipelineDeploy(ctx context.Context, appName
return jobSummary, nil
}

// TriggerPipelineApplyConfig Triggers apply config pipeline for an application
func (ah *ApplicationHandler) TriggerPipelineApplyConfig(ctx context.Context, appName string, r *http.Request) (*jobModels.JobSummary, error) {
var pipelineParameters applicationModels.PipelineParametersApplyConfig
if err := json.NewDecoder(r.Body).Decode(&pipelineParameters); err != nil {
return nil, err
}

log.Ctx(ctx).Info().Msgf("Creating apply config pipeline job for %s", appName)

pipeline, err := jobPipeline.GetPipelineFromName("apply-config")
if err != nil {
return nil, err
}

jobParameters := pipelineParameters.MapPipelineParametersApplyConfigToJobParameter()

jobSummary, err := ah.jobHandler.HandleStartPipelineJob(ctx, appName, pipeline, jobParameters)
if err != nil {
return nil, err
}

return jobSummary, nil
}

func (ah *ApplicationHandler) triggerPipelineBuildOrBuildDeploy(ctx context.Context, appName, pipelineName string, r *http.Request) (*jobModels.JobSummary, error) {
var pipelineParameters applicationModels.PipelineParametersBuild
userAccount := ah.getUserAccount()
Expand Down
16 changes: 16 additions & 0 deletions api/applications/models/pipeline_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,19 @@ func (deployParam PipelineParametersDeploy) MapPipelineParametersDeployToJobPara
ComponentsToDeploy: deployParam.ComponentsToDeploy,
}
}

// PipelineParametersApplyConfig describes base info
// swagger:model PipelineParametersApplyConfig
type PipelineParametersApplyConfig struct {
// TriggeredBy of the job - if empty will use user token upn (user principle name)
//
// example: a_user@equinor.com
TriggeredBy string `json:"triggeredBy,omitempty"`
}

// MapPipelineParametersApplyConfigToJobParameter maps to JobParameter
func (param PipelineParametersApplyConfig) MapPipelineParametersApplyConfigToJobParameter() *jobModels.JobParameters {
return &jobModels.JobParameters{
TriggeredBy: param.TriggeredBy,
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/cert-manager/cert-manager v1.14.2
github.com/equinor/radix-common v1.9.2
github.com/equinor/radix-job-scheduler v1.9.1
github.com/equinor/radix-operator v1.50.7
github.com/equinor/radix-operator v1.51.1-0.20240412075707-9b31e4e377a8
github.com/evanphx/json-patch/v5 v5.7.0
github.com/felixge/httpsnoop v1.0.4
github.com/go-swagger/go-swagger v0.30.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/equinor/radix-common v1.9.2 h1:pOYN/mSAoPe6KO/Nvudfd5DUETbLv4nLTLzFPr
github.com/equinor/radix-common v1.9.2/go.mod h1:ekn86U68NT4ccSdt3GT+ukpiclzfuhr96a7zBJKv/jw=
github.com/equinor/radix-job-scheduler v1.9.1 h1:B71xs8ucCG0yD6Zy2z7MVwaC0RknJOXe+EHEEfAN9AU=
github.com/equinor/radix-job-scheduler v1.9.1/go.mod h1:R2c3jrcKA7cLhHBY+3UDLZ6shEeA399JI19qMS/E4xg=
github.com/equinor/radix-operator v1.50.7 h1:/dV00+u3DhRrevdLKy/Xk7051KJ0exJW86Mcq/9Io0I=
github.com/equinor/radix-operator v1.50.7/go.mod h1:bLL8hVfdEUuucNRGUit33uBjUhuunpNWO5youmZz8e8=
github.com/equinor/radix-operator v1.51.1-0.20240412075707-9b31e4e377a8 h1:zteUAePVlg39f2te4mjR8G8GY1Q1cuigKsd5xAI2X9U=
github.com/equinor/radix-operator v1.51.1-0.20240412075707-9b31e4e377a8/go.mod h1:bLL8hVfdEUuucNRGUit33uBjUhuunpNWO5youmZz8e8=
github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI=
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0nW9SYGc=
Expand Down
72 changes: 72 additions & 0 deletions swaggerui/html/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4447,6 +4447,59 @@
}
}
},
"/applications/{appName}/pipelines/apply-config": {
"post": {
"tags": [
"application"
],
"summary": "Run a apply config pipeline for a given application and environment",
"operationId": "triggerPipelineApplyConfig",
"parameters": [
{
"type": "string",
"description": "Name of application",
"name": "appName",
"in": "path",
"required": true
},
{
"description": "Pipeline parameters",
"name": "PipelineParametersApplyConfig",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PipelineParametersApplyConfig"
}
},
{
"type": "string",
"description": "Works only with custom setup of cluster. Allow impersonation of test users (Required if Impersonate-Group is set)",
"name": "Impersonate-User",
"in": "header"
},
{
"type": "string",
"description": "Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)",
"name": "Impersonate-Group",
"in": "header"
}
],
"responses": {
"200": {
"description": "Successful trigger pipeline",
"schema": {
"$ref": "#/definitions/JobSummary"
}
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not found"
}
}
}
},
"/applications/{appName}/pipelines/build": {
"post": {
"tags": [
Expand Down Expand Up @@ -6639,6 +6692,25 @@
},
"x-go-package": "github.com/equinor/radix-api/api/events/models"
},
"PipelineParametersApplyConfig": {
"description": "PipelineParametersApplyConfig describes base info",
"type": "object",
"properties": {
"commitID": {
"description": "CommitID the commit ID of the branch\nOPTIONAL for information only",
"type": "string",
"x-go-name": "CommitID",
"example": "4faca8595c5283a9d0f17a623b9255a0d9866a2e"
},
"triggeredBy": {
"description": "TriggeredBy of the job - if empty will use user token upn (user principle name)",
"type": "string",
"x-go-name": "TriggeredBy",
"example": "a_user@equinor.com"
}
},
"x-go-package": "github.com/equinor/radix-api/api/applications/models"
},
"PipelineParametersBuild": {
"description": "PipelineParametersBuild describe branch to build and its commit ID",
"type": "object",
Expand Down

0 comments on commit 226efd8

Please sign in to comment.