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

Environment check fixes #2909

Merged
merged 3 commits into from
Nov 4, 2021
Merged
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
12 changes: 10 additions & 2 deletions node-packages/commons/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,12 @@ export async function getActiveSystemForProject(

export async function getEnvironmentByName(
name: string,
projectId: number
projectId: number,
includeDeleted: boolean = true
): Promise<any> {
const result = await graphqlapi.query(`
{
environmentByName(name: "${name}", project:${projectId}) {
environmentByName(name: "${name}", project:${projectId}, includeDeleted:${includeDeleted}) {
id,
name,
route,
Expand Down Expand Up @@ -1143,6 +1144,13 @@ export const getOpenShiftInfoForEnvironment = (environment: number): Promise<any
routerPattern
monitoringConfig
}
project {
envVariables {
name
value
scope
}
}
}
}
`);
Expand Down
4 changes: 2 additions & 2 deletions node-packages/commons/src/deploy-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const deployTargetBranches = async function(data: any) {

// see if the environment has already been created/deployed and get the openshift and projectpattern out of it
try {
const apiEnvironment = await getEnvironmentByName(branchName, projectId);
const apiEnvironment = await getEnvironmentByName(branchName, projectId, false);
let envId = apiEnvironment.environmentByName.id
const environmentOpenshift = await getOpenShiftInfoForEnvironment(envId);
deployTarget = {
Expand Down Expand Up @@ -310,7 +310,7 @@ export const deployTargetPullrequest = async function(data: any) {
let deployTarget
// see if the environment has already been created/deployed and get the openshift and projectpattern out of it
try {
const apiEnvironment = await getEnvironmentByName(branchName, projectId);
const apiEnvironment = await getEnvironmentByName(branchName, projectId, false);
let envId = apiEnvironment.environmentByName.id
const environmentOpenshift = await getOpenShiftInfoForEnvironment(envId);
deployTarget = {
Expand Down
22 changes: 11 additions & 11 deletions node-packages/commons/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export const getControllerBuildData = async function(deployData: any) {
// check if this environment already exists in the API so we can get the openshift target it is using
// this is even valid for promotes if it isn't the first time time it is being deployed
try {
const apiEnvironment = await getEnvironmentByName(branchName, lagoonProjectData.id);
const apiEnvironment = await getEnvironmentByName(branchName, lagoonProjectData.id, false);
let envId = apiEnvironment.environmentByName.id
const environmentOpenshift = await getOpenShiftInfoForEnvironment(envId);
deployTarget.openshift = environmentOpenshift.environment.openshift
Expand Down Expand Up @@ -448,7 +448,7 @@ export const getControllerBuildData = async function(deployData: any) {
let environmentId;
try {
const now = moment.utc();
const apiEnvironment = await getEnvironmentByName(branchName, lagoonProjectData.id);
const apiEnvironment = await getEnvironmentByName(branchName, lagoonProjectData.id, false);
environmentId = apiEnvironment.environmentByName.id
deployment = await addDeployment(buildName, "NEW", now.format('YYYY-MM-DDTHH:mm:ss'), apiEnvironment.environmentByName.id);
} catch (error) {
Expand Down Expand Up @@ -910,33 +910,33 @@ export const createMiscTask = async function(taskData: any) {
const randRestoreId = Math.random().toString(36).substring(7);
const restoreName = `restore-${R.slice(0, 7, taskData.data.backup.backupId)}-${randRestoreId}`;
// Parse out the baasBucketName for any migrated projects
let baasBucketName = result.project.envVariables.find(obj => {
let baasBucketName = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_BUCKET_NAME"
})
if (baasBucketName) {
baasBucketName = baasBucketName.value
}

// Handle custom backup configurations
let lagoonBaasCustomBackupEndpoint = result.project.envVariables.find(obj => {
let lagoonBaasCustomBackupEndpoint = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_BACKUP_ENDPOINT"
})
if (lagoonBaasCustomBackupEndpoint) {
lagoonBaasCustomBackupEndpoint = lagoonBaasCustomBackupEndpoint.value
}
let lagoonBaasCustomBackupBucket = result.project.envVariables.find(obj => {
let lagoonBaasCustomBackupBucket = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_BACKUP_BUCKET"
})
if (lagoonBaasCustomBackupBucket) {
lagoonBaasCustomBackupBucket = lagoonBaasCustomBackupBucket.value
}
let lagoonBaasCustomBackupAccessKey = result.project.envVariables.find(obj => {
let lagoonBaasCustomBackupAccessKey = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_BACKUP_ACCESS_KEY"
})
if (lagoonBaasCustomBackupAccessKey) {
lagoonBaasCustomBackupAccessKey = lagoonBaasCustomBackupAccessKey.value
}
let lagoonBaasCustomBackupSecretKey = result.project.envVariables.find(obj => {
let lagoonBaasCustomBackupSecretKey = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_BACKUP_SECRET_KEY"
})
if (lagoonBaasCustomBackupSecretKey) {
Expand All @@ -960,25 +960,25 @@ export const createMiscTask = async function(taskData: any) {
}

// Handle custom restore configurations
let lagoonBaasCustomRestoreEndpoint = result.project.envVariables.find(obj => {
let lagoonBaasCustomRestoreEndpoint = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_RESTORE_ENDPOINT"
})
if (lagoonBaasCustomRestoreEndpoint) {
lagoonBaasCustomRestoreEndpoint = lagoonBaasCustomRestoreEndpoint.value
}
let lagoonBaasCustomRestoreBucket = result.project.envVariables.find(obj => {
let lagoonBaasCustomRestoreBucket = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_RESTORE_BUCKET"
})
if (lagoonBaasCustomRestoreBucket) {
lagoonBaasCustomRestoreBucket = lagoonBaasCustomRestoreBucket.value
}
let lagoonBaasCustomRestoreAccessKey = result.project.envVariables.find(obj => {
let lagoonBaasCustomRestoreAccessKey = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_RESTORE_ACCESS_KEY"
})
if (lagoonBaasCustomRestoreAccessKey) {
lagoonBaasCustomRestoreAccessKey = lagoonBaasCustomRestoreAccessKey.value
}
let lagoonBaasCustomRestoreSecretKey = result.project.envVariables.find(obj => {
let lagoonBaasCustomRestoreSecretKey = result.environment.project.envVariables.find(obj => {
return obj.name === "LAGOON_BAAS_CUSTOM_RESTORE_SECRET_KEY"
})
if (lagoonBaasCustomRestoreSecretKey) {
Expand Down
9 changes: 7 additions & 2 deletions services/api/src/resources/environment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ export const getEnvironmentByName: ResolverFn = async (
args,
{ sqlClientPool, hasPermission }
) => {

if (args.includeDeleted == undefined) {
args.includeDeleted = true
}
const rows = await query(
sqlClientPool,
`SELECT *
FROM environment
WHERE name = :name AND
project = :project`,
args
project = :project
${args.includeDeleted ? '' : 'AND deleted = "0000-00-00 00:00:00"'}`,
args,
);
const withK8s = Helpers(sqlClientPool).aliasOpenshiftToK8s(rows);
const environment = withK8s[0];
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ const typeDefs = gql`
Returns Project Object by a given gitUrl (only the first one if there are multiple)
"""
projectByGitUrl(gitUrl: String!): Project
environmentByName(name: String!, project: Int!): Environment
environmentByName(name: String!, project: Int!, includeDeleted: Boolean): Environment
environmentById(id: Int!): Environment
"""
Returns Environment Object by a given openshiftProjectName
Expand Down