Skip to content

Commit

Permalink
Add src and image to envs (#1050)
Browse files Browse the repository at this point in the history
* Added to environment confir image and dockerfilename

* Build images individually for each env

* Added build job go routine

* Build each env and component in own job, when build-kit used

* Corrected log messages

* Added env to build job component annotation

* Fixing unit-tests

* Fixing unit-tests

* Fixing unit-tests

* Extending unit-tests

* Extending unit-tests

* Extending unit-tests

* Extending unit-tests

* Show component names in pipeline steps

* Limited container and image name for environments

* Corrected log text for failed pipeline job

* Added buildContext to the pipeline job result configMap

* Added buildContext to the pipeline job result configMap

* Removed buildContext from the pipeline job result configMap

* Fixed commit-id logic

* Repaired componentsToDeploy condition

* Corrected componentsToDeploy condition

* Corrected componentsToDeploy condition

* Corrected reported lint issues

* Added error for getComponentSources, renamed methods

* Corrected getComponentSources

* Corrected getComponentSources

* Set new version
  • Loading branch information
satr authored Mar 4, 2024
1 parent 8e7bfcd commit 5d0e055
Show file tree
Hide file tree
Showing 27 changed files with 1,187 additions and 561 deletions.
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.30.1
appVersion: 1.50.1
version: 1.30.2
appVersion: 1.50.2
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
24 changes: 24 additions & 0 deletions charts/radix-operator/templates/radixapplication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ spec:
type: boolean
type: object
type: object
dockerfileName:
description: 'Name of the Dockerfile that builds the component.
More info: https://www.radix.equinor.com/references/reference-radix-config/#dockerfilename'
type: string
enabled:
description: 'Controls if the component shall be deployed
to this environment. More info: https://www.radix.equinor.com/references/reference-radix-config/#enabled'
Expand Down Expand Up @@ -442,6 +446,10 @@ spec:
- clientId
type: object
type: object
image:
description: 'Name of an existing container image to use
when running the component. More info: https://www.radix.equinor.com/references/reference-radix-config/#image'
type: string
imageTagName:
description: 'The imageTagName allows for flexible configuration
of fixed images, built outside of Radix, to be configured
Expand Down Expand Up @@ -595,6 +603,10 @@ spec:
type: object
type: array
type: object
src:
description: 'Path to the Dockerfile that builds the component.
More info: https://www.radix.equinor.com/references/reference-radix-config/#src'
type: string
variables:
additionalProperties:
type: string
Expand Down Expand Up @@ -1322,6 +1334,10 @@ spec:
format: int32
minimum: 0
type: integer
dockerfileName:
description: 'Name of the Dockerfile that builds the component.
More info: https://www.radix.equinor.com/references/reference-radix-config/#dockerfilename'
type: string
enabled:
description: Controls if the job shall be deployed to
this environment.
Expand Down Expand Up @@ -1349,6 +1365,10 @@ spec:
- clientId
type: object
type: object
image:
description: 'Name of an existing container image to use
when running the job. More info: https://www.radix.equinor.com/references/reference-radix-config/#image-2'
type: string
imageTagName:
description: 'The imageTagName allows for flexible configuration
of fixed images, built outside of Radix, to be configured
Expand Down Expand Up @@ -1510,6 +1530,10 @@ spec:
type: object
type: array
type: object
src:
description: 'Path to the Dockerfile that builds the component.
More info: https://www.radix.equinor.com/references/reference-radix-config/#src'
type: string
timeLimitSeconds:
description: 'Environment specific value for the maximum
number of seconds the job can run. More info: https://www.radix.equinor.com/references/reference-radix-config/#timelimitseconds-2'
Expand Down
24 changes: 24 additions & 0 deletions json-schema/radixapplication.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@
},
"type": "object"
},
"dockerfileName": {
"description": "Name of the Dockerfile that builds the component. More info: https://www.radix.equinor.com/references/reference-radix-config/#dockerfilename",
"type": "string"
},
"enabled": {
"description": "Controls if the component shall be deployed to this environment. More info: https://www.radix.equinor.com/references/reference-radix-config/#enabled",
"type": "boolean"
Expand Down Expand Up @@ -440,6 +444,10 @@
},
"type": "object"
},
"image": {
"description": "Name of an existing container image to use when running the component. More info: https://www.radix.equinor.com/references/reference-radix-config/#image",
"type": "string"
},
"imageTagName": {
"description": "The imageTagName allows for flexible configuration of fixed images, built outside of Radix, to be configured with separate tag for each environment. More info: https://www.radix.equinor.com/references/reference-radix-config/#imagetagname",
"type": "string"
Expand Down Expand Up @@ -591,6 +599,10 @@
},
"type": "object"
},
"src": {
"description": "Path to the Dockerfile that builds the component. More info: https://www.radix.equinor.com/references/reference-radix-config/#src",
"type": "string"
},
"variables": {
"additionalProperties": {
"type": "string"
Expand Down Expand Up @@ -1369,6 +1381,10 @@
"minimum": 0,
"type": "integer"
},
"dockerfileName": {
"description": "Name of the Dockerfile that builds the component. More info: https://www.radix.equinor.com/references/reference-radix-config/#dockerfilename",
"type": "string"
},
"enabled": {
"description": "Controls if the job shall be deployed to this environment.",
"type": "boolean"
Expand Down Expand Up @@ -1399,6 +1415,10 @@
},
"type": "object"
},
"image": {
"description": "Name of an existing container image to use when running the job. More info: https://www.radix.equinor.com/references/reference-radix-config/#image-2",
"type": "string"
},
"imageTagName": {
"description": "The imageTagName allows for flexible configuration of fixed images, built outside of Radix, to be configured with separate tag for each environment. More info: https://www.radix.equinor.com/references/reference-radix-config/#imagetagname-2",
"type": "string"
Expand Down Expand Up @@ -1557,6 +1577,10 @@
},
"type": "object"
},
"src": {
"description": "Path to the Dockerfile that builds the component. More info: https://www.radix.equinor.com/references/reference-radix-config/#src",
"type": "string"
},
"timeLimitSeconds": {
"description": "Environment specific value for the maximum number of seconds the job can run. More info: https://www.radix.equinor.com/references/reference-radix-config/#timelimitseconds-2",
"format": "int64",
Expand Down
6 changes: 3 additions & 3 deletions pipeline-runner/internal/tekton/tekton.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const (
// CreateActionPipelineJob Create action pipeline job
func CreateActionPipelineJob(containerName string, action string, pipelineInfo *model.PipelineInfo, appName string, initContainers []corev1.Container, envVars *[]corev1.EnvVar) *batchv1.Job {
imageTag := pipelineInfo.PipelineArguments.ImageTag
jobName := pipelineInfo.PipelineArguments.JobName
pipelineJobName := pipelineInfo.PipelineArguments.JobName
timestamp := time.Now().Format("20060102150405")
hash := strings.ToLower(utils.RandStringStrSeed(5, pipelineInfo.PipelineArguments.JobName))
backOffLimit := int32(0)
job := batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("radix-%s-pipelines-%s-%s-%s", action, timestamp, imageTag, hash),
Labels: map[string]string{
kube.RadixJobNameLabel: jobName,
kube.RadixJobNameLabel: pipelineJobName,
kube.RadixAppLabel: appName,
kube.RadixImageTagLabel: imageTag,
kube.RadixJobTypeLabel: getActionPipelineJobTypeLabelByPipelinesAction(action),
Expand All @@ -44,7 +44,7 @@ func CreateActionPipelineJob(containerName string, action string, pipelineInfo *
BackoffLimit: &backOffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: radixlabels.ForPipelineJobName(jobName),
Labels: radixlabels.ForPipelineJobName(pipelineJobName),
Annotations: annotations.ForClusterAutoscalerSafeToEvict(false),
},
Spec: corev1.PodSpec{
Expand Down
18 changes: 17 additions & 1 deletion pipeline-runner/internal/wait/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package wait
import (
"errors"
"fmt"
"strings"

"github.com/equinor/radix-operator/pkg/apis/kube"
logger "github.com/sirupsen/logrus"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -51,7 +53,7 @@ func waitForCompletionOf(kubeClient kubernetes.Interface, job *batchv1.Job) erro
case currJob.Status.Succeeded == 1:
errChan <- nil
case currJob.Status.Failed == 1:
errChan <- fmt.Errorf("job failed. See log for more details")
errChan <- fmt.Errorf("job failed. See more details in the log of the job %s", getJobDescription(currJob))
}
}
},
Expand Down Expand Up @@ -106,6 +108,20 @@ func waitForCompletionOf(kubeClient kubernetes.Interface, job *batchv1.Job) erro
return err
}

func getJobDescription(job *batchv1.Job) string {
var lines []string
if jobType, ok := job.GetLabels()[kube.RadixJobTypeLabel]; ok {
lines = append(lines, jobType)
}
if componentName, ok := job.GetLabels()[kube.RadixComponentLabel]; ok {
lines = append(lines, fmt.Sprintf("for the component %s", componentName))
}
if envName, ok := job.GetLabels()[kube.RadixEnvLabel]; ok {
lines = append(lines, fmt.Sprintf("for the environment %s", envName))
}
return strings.Join(lines, " ")
}

func checkPodIsTerminatedOrFailed(containerStatuses *[]corev1.ContainerStatus) error {
for _, containerStatus := range *containerStatuses {
if containerStatus.State.Terminated != nil {
Expand Down
4 changes: 2 additions & 2 deletions pipeline-runner/model/pipelineInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type PipelineInfo struct {
GitCommitHash string
GitTags string

// Holds information about components to be built
BuildComponentImages pipeline.BuildComponentImages
// Holds information about components to be built for each environment
BuildComponentImages pipeline.EnvironmentBuildComponentImages

// Hold information about components to be deployed
DeployEnvironmentComponentImages pipeline.DeployEnvironmentComponentImages
Expand Down
7 changes: 4 additions & 3 deletions pipeline-runner/pipelines/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ func (cli *PipelineRunner) CreateResultConfigMap() error {
if err != nil {
return err
}
jobName := cli.pipelineInfo.PipelineArguments.JobName
pipelineJobName := cli.pipelineInfo.PipelineArguments.JobName

configMap := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: jobName,
Name: pipelineJobName,
Labels: map[string]string{
kube.RadixJobNameLabel: jobName,
kube.RadixJobNameLabel: pipelineJobName,
kube.RadixConfigMapTypeLabel: string(kube.RadixPipelineResultConfigMap),
},
},
Expand Down
Loading

0 comments on commit 5d0e055

Please sign in to comment.