Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for organization environment variables #275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions api/lagoon/v1beta1/lagoonbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ type Organization struct {

// Variables contains the project and environment variables from lagoon.
type LagoonVariables struct {
Project []byte `json:"project,omitempty"`
Environment []byte `json:"environment,omitempty"`
Organization []byte `json:"organization,omitempty"`
Project []byte `json:"project,omitempty"`
Environment []byte `json:"environment,omitempty"`
}

// Branch contains the branch name used for a branch deployment.
Expand Down
5 changes: 3 additions & 2 deletions api/lagoon/v1beta2/lagoonbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ type Organization struct {

// Variables contains the project and environment variables from lagoon.
type LagoonVariables struct {
Project []byte `json:"project,omitempty"`
Environment []byte `json:"environment,omitempty"`
Organization []byte `json:"organization,omitempty"`
Project []byte `json:"project,omitempty"`
Environment []byte `json:"environment,omitempty"`
}

// Branch contains the branch name used for a branch deployment.
Expand Down
14 changes: 10 additions & 4 deletions config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,18 @@ spec:
uiLink:
type: string
variables:
description: Variables contains the project and environment variables
from lagoon.
description: Variables contains the organization, project,
and environment variables from lagoon.
properties:
environment:
format: byte
type: string
project:
format: byte
type: string
organization:
format: byte
type: string
type: object
required:
- deployTarget
Expand Down Expand Up @@ -812,15 +815,18 @@ spec:
uiLink:
type: string
variables:
description: Variables contains the project and environment variables
from lagoon.
description: Variables contains the organization, project,
and environment variables from lagoon.
properties:
environment:
format: byte
type: string
project:
format: byte
type: string
organization:
format: byte
type: string
type: object
required:
- deployTarget
Expand Down
14 changes: 10 additions & 4 deletions config/crd/bases/crd.lagoon.sh_lagoontasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ spec:
type: string
type: object
variables:
description: Variables contains the project and environment variables
from lagoon.
description: Variables contains the organization, project,
and environment variables from lagoon.
properties:
environment:
format: byte
type: string
project:
format: byte
type: string
organization:
format: byte
type: string
type: object
required:
- id
Expand Down Expand Up @@ -788,15 +791,18 @@ spec:
type: string
type: object
variables:
description: Variables contains the project and environment variables
from lagoon.
description: Variables contains the organization, project,
and environment variables from lagoon.
properties:
environment:
format: byte
type: string
project:
format: byte
type: string
organization:
format: byte
type: string
type: object
required:
- name
Expand Down
15 changes: 14 additions & 1 deletion internal/controllers/v1beta1/build_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,16 +571,19 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log
// if local/regional harbor is enabled
if r.LFFHarborEnabled {
// unmarshal the project variables
lagoonOrganizationVariables := &[]helpers.LagoonEnvironmentVariable{}
lagoonProjectVariables := &[]helpers.LagoonEnvironmentVariable{}
lagoonEnvironmentVariables := &[]helpers.LagoonEnvironmentVariable{}
json.Unmarshal(lagoonBuild.Spec.Project.Variables.Organization, lagoonOrganizationVariables)
json.Unmarshal(lagoonBuild.Spec.Project.Variables.Project, lagoonProjectVariables)
json.Unmarshal(lagoonBuild.Spec.Project.Variables.Environment, lagoonEnvironmentVariables)
// check if INTERNAL_REGISTRY_SOURCE_LAGOON is defined, and if it isn't true
// if this value is true, then we want to use what is provided by Lagoon
// if it is false, or not set, then we use what is provided by this controller
// this allows us to make it so a specific environment or the project entirely
// can still use whats provided by lagoon
if !helpers.VariableExists(lagoonProjectVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") ||
if !helpers.VariableExists(lagoonOrganizationVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") ||
!helpers.VariableExists(lagoonProjectVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") ||
!helpers.VariableExists(lagoonEnvironmentVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") {
// source the robot credential, and inject it into the lagoon project variables
// this will overwrite what is provided by lagoon (if lagoon has provided them)
Expand Down Expand Up @@ -617,6 +620,16 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log
lagoonBuild.Spec.Project.Variables.Project, _ = json.Marshal(lagoonProjectVariables)
}
}
if lagoonBuild.Spec.Project.Variables.Organization != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
if len(lagoonBuild.Spec.Project.Variables.Organization) > 2 {
podEnvs = append(podEnvs, corev1.EnvVar{
Name: "LAGOON_ORGANIZATION_VARIABLES",
Value: string(lagoonBuild.Spec.Project.Variables.Organization),
})
}
}
if lagoonBuild.Spec.Project.Variables.Project != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
Expand Down
20 changes: 20 additions & 0 deletions internal/controllers/v1beta1/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ func (r *LagoonTaskReconciler) getTaskPodDeployment(ctx context.Context, lagoonT
Value: r.ProxyConfig.NoProxy,
})
}
if lagoonTask.Spec.Project.Variables.Organization != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
if len(lagoonTask.Spec.Project.Variables.Organization) > 2 {
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_ORGANIZATION_VARIABLES",
Value: string(lagoonTask.Spec.Project.Variables.Organization),
})
}
}
if lagoonTask.Spec.Project.Variables.Project != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
Expand Down Expand Up @@ -512,6 +522,16 @@ func (r *LagoonTaskReconciler) createAdvancedTask(ctx context.Context, lagoonTas
Value: lagoonTask.Spec.Task.ID,
},
}
if lagoonTask.Spec.Project.Variables.Organization != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
if len(lagoonTask.Spec.Project.Variables.Organization) > 2 {
podEnvs = append(podEnvs, corev1.EnvVar{
Name: "LAGOON_ORGANIZATION_VARIABLES",
Value: string(lagoonTask.Spec.Project.Variables.Organization),
})
}
}
if lagoonTask.Spec.Project.Variables.Project != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
Expand Down
15 changes: 14 additions & 1 deletion internal/controllers/v1beta2/build_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,19 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log
// if local/regional harbor is enabled
if r.LFFHarborEnabled {
// unmarshal the project variables
lagoonOrganizationVariables := &[]helpers.LagoonEnvironmentVariable{}
lagoonProjectVariables := &[]helpers.LagoonEnvironmentVariable{}
lagoonEnvironmentVariables := &[]helpers.LagoonEnvironmentVariable{}
json.Unmarshal(lagoonBuild.Spec.Project.Variables.Organization, lagoonOrganizationVariables)
json.Unmarshal(lagoonBuild.Spec.Project.Variables.Project, lagoonProjectVariables)
json.Unmarshal(lagoonBuild.Spec.Project.Variables.Environment, lagoonEnvironmentVariables)
// check if INTERNAL_REGISTRY_SOURCE_LAGOON is defined, and if it isn't true
// if this value is true, then we want to use what is provided by Lagoon
// if it is false, or not set, then we use what is provided by this controller
// this allows us to make it so a specific environment or the project entirely
// can still use whats provided by lagoon
if !helpers.VariableExists(lagoonProjectVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") ||
if !helpers.VariableExists(lagoonOrganizationVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") ||
!helpers.VariableExists(lagoonProjectVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") ||
!helpers.VariableExists(lagoonEnvironmentVariables, "INTERNAL_REGISTRY_SOURCE_LAGOON", "true") {
// source the robot credential, and inject it into the lagoon project variables
// this will overwrite what is provided by lagoon (if lagoon has provided them)
Expand Down Expand Up @@ -634,6 +637,16 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log
lagoonBuild.Spec.Project.Variables.Project, _ = json.Marshal(lagoonProjectVariables)
}
}
if lagoonBuild.Spec.Project.Variables.Organization != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
if len(lagoonBuild.Spec.Project.Variables.Organization) > 2 {
podEnvs = append(podEnvs, corev1.EnvVar{
Name: "LAGOON_ORGANIZATION_VARIABLES",
Value: string(lagoonBuild.Spec.Project.Variables.Organization),
})
}
}
if lagoonBuild.Spec.Project.Variables.Project != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
Expand Down
20 changes: 20 additions & 0 deletions internal/controllers/v1beta2/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ func (r *LagoonTaskReconciler) getTaskPodDeployment(ctx context.Context, lagoonT
Value: r.ProxyConfig.NoProxy,
})
}
if lagoonTask.Spec.Project.Variables.Organization != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
if len(lagoonTask.Spec.Project.Variables.Organization) > 2 {
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_ORGANIZATION_VARIABLES",
Value: string(lagoonTask.Spec.Project.Variables.Organization),
})
}
}
if lagoonTask.Spec.Project.Variables.Project != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
Expand Down Expand Up @@ -515,6 +525,16 @@ func (r *LagoonTaskReconciler) createAdvancedTask(ctx context.Context, lagoonTas
Value: lagoonTask.Spec.Task.ID,
},
}
if lagoonTask.Spec.Project.Variables.Organization != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
if len(lagoonTask.Spec.Project.Variables.Organization) > 2 {
podEnvs = append(podEnvs, corev1.EnvVar{
Name: "LAGOON_ORGANIZATION_VARIABLES",
Value: string(lagoonTask.Spec.Project.Variables.Organization),
})
}
}
if lagoonTask.Spec.Project.Variables.Project != nil {
// if this is 2 bytes long, then it means its just an empty json array
// we only want to add it if it is more than 2 bytes
Expand Down
Loading