Skip to content

Commit

Permalink
Merge pull request #263 from uselagoon/v1beta2-env-project-ids
Browse files Browse the repository at this point in the history
chore: add project/environment ids as envvars to builds and tasks
  • Loading branch information
shreddedbacon authored Sep 16, 2024
2 parents 56a2e9e + 9c569f2 commit 1f2279d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 13 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
4 changes: 2 additions & 2 deletions test-resources/dynamic-secret-in-task-project1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ spec:
sshKey: false
environment:
environmentType: ''
id: ''
id: 1
name: main
project: ngnix-example
key: kubernetes:route:migrate
misc:
id: ''
project:
id: ''
id: 1
name: nginx-example
task:
id: '1'
Expand Down

0 comments on commit 1f2279d

Please sign in to comment.