Skip to content

Commit

Permalink
chore: add project/environment ids as envvars to builds and tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Sep 11, 2024
1 parent 56a2e9e commit f336100
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
4 changes: 2 additions & 2 deletions apis/lagoon/v1beta2/lagoontask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type LagoonMiscBackupInfo struct {

// LagoonTaskProject defines the lagoon project information.
type LagoonTaskProject struct {
ID string `json:"id"` // should be int, but the api sends it as a string :\
ID *uint `json:"id,omitempty"`
Name string `json:"name"`
NamespacePattern string `json:"namespacePattern,omitempty"`
Variables LagoonVariables `json:"variables,omitempty"`
Expand All @@ -139,7 +139,7 @@ type LagoonTaskProject struct {

// LagoonTaskEnvironment defines the lagoon environment information.
type LagoonTaskEnvironment struct {
ID string `json:"id"` // should be int, but the api sends it as a string :\
ID *uint `json:"id,omitempty"`
Name string `json:"name"`
Project string `json:"project"` // should be int, but the api sends it as a string :\
EnvironmentType string `json:"environmentType"`
Expand Down
12 changes: 11 additions & 1 deletion apis/lagoon/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions config/crd/bases/crd.lagoon.sh_lagoontasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -703,14 +703,13 @@ spec:
environmentType:
type: string
id:
type: string
type: integer
name:
type: string
project:
type: string
required:
- environmentType
- id
- name
- project
type: object
Expand Down Expand Up @@ -751,7 +750,7 @@ spec:
description: LagoonTaskProject defines the lagoon project information.
properties:
id:
type: string
type: integer
name:
type: string
namespacePattern:
Expand All @@ -775,7 +774,6 @@ spec:
type: string
type: object
required:
- id
- name
type: object
task:
Expand Down
12 changes: 12 additions & 0 deletions controllers/v1beta2/build_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log
Value: helpers.GetAPIValues(r.LagoonAPIConfiguration, "LAGOON_CONFIG_SSH_PORT"),
},
}
if lagoonBuild.Spec.Project.EnvironmentID != nil {
podEnvs = append(podEnvs, corev1.EnvVar{
Name: "ENVIRONMENT_ID",
Value: strconv.Itoa(int(*lagoonBuild.Spec.Project.EnvironmentID)),
})
}
if lagoonBuild.Spec.Project.ID != nil {
podEnvs = append(podEnvs, corev1.EnvVar{
Name: "PROJECT_ID",
Value: strconv.Itoa(int(*lagoonBuild.Spec.Project.ID)),
})
}
// add proxy variables to builds if they are defined
if r.ProxyConfig.HTTPProxy != "" {
podEnvs = append(podEnvs, corev1.EnvVar{
Expand Down
8 changes: 4 additions & 4 deletions controllers/v1beta2/podmonitor_taskhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (r *LagoonMonitorReconciler) updateLagoonTask(opLog logr.Logger,
Task: &lagoonTask.Spec.Task,
Environment: lagoonTask.Spec.Environment.Name,
Project: lagoonTask.Spec.Project.Name,
EnvironmentID: helpers.StringToUintPtr(lagoonTask.Spec.Environment.ID),
ProjectID: helpers.StringToUintPtr(lagoonTask.Spec.Project.ID),
EnvironmentID: lagoonTask.Spec.Environment.ID,
ProjectID: lagoonTask.Spec.Project.ID,
JobName: lagoonTask.ObjectMeta.Name,
JobStatus: condition,
RemoteID: string(jobPod.ObjectMeta.UID),
Expand Down Expand Up @@ -237,8 +237,8 @@ func (r *LagoonMonitorReconciler) taskStatusLogsToLagoonLogs(opLog logr.Logger,
Task: &lagoonTask.Spec.Task,
ProjectName: lagoonTask.Spec.Project.Name,
Environment: lagoonTask.Spec.Environment.Name,
EnvironmentID: helpers.StringToUintPtr(lagoonTask.Spec.Environment.ID),
ProjectID: helpers.StringToUintPtr(lagoonTask.Spec.Project.ID),
EnvironmentID: lagoonTask.Spec.Environment.ID,
ProjectID: lagoonTask.Spec.Project.ID,
JobName: lagoonTask.ObjectMeta.Name,
JobStatus: condition,
RemoteID: string(jobPod.ObjectMeta.UID),
Expand Down
12 changes: 12 additions & 0 deletions controllers/v1beta2/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ func (r *LagoonTaskReconciler) getTaskPodDeployment(ctx context.Context, lagoonT
Name: "TASK_DATA_ID",
Value: lagoonTask.Spec.Task.ID,
})
if lagoonTask.Spec.Project.ID != nil {
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_PROJECT_ID",
Value: strconv.Itoa(int(*lagoonTask.Spec.Project.ID)),
})
}
if lagoonTask.Spec.Environment.ID != nil {
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_ENVIRONMENT_ID",
Value: strconv.Itoa(int(*lagoonTask.Spec.Environment.ID)),
})
}
// add proxy variables to builds if they are defined
if r.ProxyConfig.HTTPProxy != "" {
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Expand Down

0 comments on commit f336100

Please sign in to comment.