From b01122791e5359894bf6eab088c12dfdaa5f698f Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 31 Aug 2023 10:31:36 +1000 Subject: [PATCH] refactor: use injection from the task data from the lagoon api --- apis/lagoon/v1beta1/lagoontask_types.go | 18 +++++++++-------- .../crd/bases/crd.lagoon.sh_lagoonbuilds.yaml | 16 +++++++++++++++ .../crd/bases/crd.lagoon.sh_lagoontasks.yaml | 20 +++++++++++++++++++ internal/messenger/tasks_handler.go | 8 ++++---- main.go | 5 +++-- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/apis/lagoon/v1beta1/lagoontask_types.go b/apis/lagoon/v1beta1/lagoontask_types.go index db4b1770..d7739fb5 100644 --- a/apis/lagoon/v1beta1/lagoontask_types.go +++ b/apis/lagoon/v1beta1/lagoontask_types.go @@ -81,14 +81,16 @@ type LagoonTaskSpec struct { // LagoonTaskInfo defines what a task can use to communicate with Lagoon via SSH/API. type LagoonTaskInfo struct { - ID string `json:"id"` // should be int, but the api sends it as a string :\ - Name string `json:"name,omitempty"` - TaskName string `json:"taskName,omitempty"` - Service string `json:"service,omitempty"` - Command string `json:"command,omitempty"` - SSHHost string `json:"sshHost,omitempty"` - SSHPort string `json:"sshPort,omitempty"` - APIHost string `json:"apiHost,omitempty"` + ID string `json:"id"` // should be int, but the api sends it as a string :\ + Name string `json:"name,omitempty"` + TaskName string `json:"taskName,omitempty"` + Service string `json:"service,omitempty"` + Command string `json:"command,omitempty"` + SSHHost string `json:"sshHost,omitempty"` + SSHPort string `json:"sshPort,omitempty"` + APIHost string `json:"apiHost,omitempty"` + DeployTokenInjection bool `json:"deployTokenInjection,omitempty"` + ProjectKeyInjection bool `json:"projectKeyInjection,omitempty"` } // LagoonAdvancedTaskInfo defines what an advanced task can use for the creation of the pod. diff --git a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml index e3b5946d..7ca5f781 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoonbuilds.yaml @@ -268,10 +268,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -357,10 +361,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -448,10 +456,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -541,10 +553,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: diff --git a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml index 180051c3..c4149f44 100644 --- a/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml +++ b/config/crd/bases/crd.lagoon.sh_lagoontasks.yaml @@ -132,10 +132,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -250,10 +254,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -339,10 +347,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -430,10 +442,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: @@ -523,10 +539,14 @@ spec: type: string command: type: string + deployTokenInjection: + type: boolean id: type: string name: type: string + projectKeyInjection: + type: boolean service: type: string sshHost: diff --git a/internal/messenger/tasks_handler.go b/internal/messenger/tasks_handler.go index 4dc6a031..eed0c437 100644 --- a/internal/messenger/tasks_handler.go +++ b/internal/messenger/tasks_handler.go @@ -264,11 +264,11 @@ func (m *Messenger) ActiveStandbySwitch(namespace string, jobSpec *lagoonv1beta1 // AdvancedTask handles running the ingress migrations. func (m *Messenger) AdvancedTask(namespace string, jobSpec *lagoonv1beta1.LagoonTaskSpec) error { - if m.AdvancedTaskSSHKeyInjection { - jobSpec.AdvancedTask.SSHKey = true + if jobSpec.Task.DeployTokenInjection { + jobSpec.AdvancedTask.DeployerToken = jobSpec.Task.DeployTokenInjection } - if m.AdvancedTaskDeployTokenInjection { - jobSpec.AdvancedTask.DeployerToken = true + if jobSpec.Task.ProjectKeyInjection { + jobSpec.AdvancedTask.SSHKey = jobSpec.Task.ProjectKeyInjection } return m.createAdvancedTask(namespace, jobSpec, nil) } diff --git a/main.go b/main.go index e3a6fd6b..8958525c 100644 --- a/main.go +++ b/main.go @@ -284,10 +284,11 @@ func main() { flag.BoolVar(&tlsSkipVerify, "skip-tls-verify", false, "Flag to skip tls verification for http clients (harbor).") // default the sshkey injection to true for now, eventually Lagoon should handle this for tasks that require it + // these are deprecated now and do nothing as the values are sourced from the lagoon task now flag.BoolVar(&advancedTaskSSHKeyInjection, "advanced-task-sshkey-injection", true, - "Flag to specify injecting the sshkey for the environment into any advanced tasks.") + "DEPRECATED: Flag to specify injecting the sshkey for the environment into any advanced tasks.") flag.BoolVar(&advancedTaskDeployToken, "advanced-task-deploytoken-injection", false, - "Flag to specify injecting the deploy token for the environment into any advanced tasks.") + "DEPRECATED: Flag to specify injecting the deploy token for the environment into any advanced tasks.") flag.BoolVar(&cleanupHarborRepositoryOnDelete, "cleanup-harbor-repository-on-delete", false, "Flag to specify if when deleting an environment, the associated harbor repository/images should be removed too.")