From 904958250c33d6acc26a6733b37890b28dad4293 Mon Sep 17 00:00:00 2001 From: Justin Winter Date: Thu, 23 Jan 2020 12:38:39 -0600 Subject: [PATCH 1/3] Kubernetes typeDefs Revision alpha1 --- services/api/src/typeDefs.js | 71 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 3797b6941c..0e8cd7ecf2 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -1,5 +1,3 @@ -// @flow - const gql = require('./util/gql'); // TODO: Split up this file @@ -102,6 +100,11 @@ const typeDefs = gql` ZAR } + enum DeploymentTargets { + KUBERNETES + OPENSHIFT + } + type File { id: Int filename: String @@ -163,7 +166,7 @@ const typeDefs = gql` billingSoftware: String } - type Openshift { + type DeploymentTarget { id: Int name: String consoleUrl: String @@ -251,22 +254,22 @@ const typeDefs = gql` notifications(type: NotificationType): [Notification] """ Which internal Lagoon System is responsible for deploying - Currently only 'lagoon_openshiftBuildDeploy' exists + 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' """ activeSystemsDeploy: String """ Which internal Lagoon System is responsible for promoting - Currently only 'lagoon_openshiftBuildDeploy' exists + 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' """ activeSystemsPromote: String """ Which internal Lagoon System is responsible for promoting - Currently only 'lagoon_openshiftRemove' exists + 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' """ activeSystemsRemove: String """ Which internal Lagoon System is responsible for tasks - Currently only 'lagoon_openshiftJob' exists + 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' """ activeSystemsTask: String """ @@ -297,13 +300,13 @@ const typeDefs = gql` """ storageCalc: Int """ - Reference to OpenShift Object this Project should be deployed to + Reference to the Deployment Target (Kubernetes|OpenShift) Object this Project should be deployed to """ - openshift: Openshift + deploymentTarget: DeploymentTarget """ - Pattern of OpenShift Project/Namespace that should be generated, default: \`$\{project}-$\{environmentname}\` + Namespace-Environment pattern for Kubernetes (OpenShift Project) that should be generated, default: \`$\{project}-$\{environmentname}\` """ - openshiftProjectPattern: String + namespaceEnvironment: String """ How many environments can be deployed at one timeout """ @@ -376,9 +379,9 @@ const typeDefs = gql` """ environmentType: String """ - Name of the OpenShift Project/Namespace this environment is deployed into + Deployment target name to deployed into (Kubernetes Namespace | Openshift Project Name) """ - openshiftProjectName: String + targetName: String """ Unix Timestamp of the last time this environment has been updated """ @@ -524,14 +527,10 @@ const typeDefs = gql` projectByGitUrl(gitUrl: String!): Project environmentByName(name: String!, project: Int!): Environment """ - Returns Environment Object by a given openshiftProjectName + Returns Environment Object by a given namespace """ - environmentByOpenshiftProjectName( - openshiftProjectName: String! - ): Environment - userCanSshToEnvironment( - openshiftProjectName: String - ): Environment + environmentByDeploymentTargetName(name: String!): Environment + userCanSshToEnvironment(deploymentTargetName: String): Environment deploymentByRemoteId(id: String): Deployment taskByRemoteId(id: String): Task """ @@ -541,7 +540,7 @@ const typeDefs = gql` """ Returns all OpenShift Objects """ - allOpenshifts: [Openshift] + allDeploymentTargets: [Openshift | Kubernetes] """ Returns all Environments matching given filter (all if no filter defined) """ @@ -605,8 +604,8 @@ const typeDefs = gql` name: String! gitUrl: String! subfolder: String - openshift: Int! - openshiftProjectPattern: String + deploymentTarget: DeploymentTarget + namespaceEnvironment: String activeSystemsDeploy: String activeSystemsPromote: String activeSystemsRemove: String @@ -630,7 +629,7 @@ const typeDefs = gql` deployHeadRef: String deployTitle: String environmentType: EnvType! - openshiftProjectName: String! + deploymentTargetName: String! } input AddOrUpdateEnvironmentStorageInput { @@ -741,7 +740,7 @@ const typeDefs = gql` patch: UpdateTaskPatchInput! } - input AddOpenshiftInput { + input AddDeploymentTargetInput { id: Int name: String! consoleUrl: String! @@ -752,7 +751,7 @@ const typeDefs = gql` sshPort: String } - input DeleteOpenshiftInput { + input DeleteDeploymentTargetInput { name: String! } @@ -847,8 +846,8 @@ const typeDefs = gql` autoIdle: Int storageCalc: Int pullrequests: String - openshift: Int - openshiftProjectPattern: String + deploymentTarget: DeploymentTarget + namespaceEnvironment: String developmentEnvironmentsLimit: Int } @@ -857,7 +856,7 @@ const typeDefs = gql` patch: UpdateProjectPatchInput! } - input UpdateOpenshiftPatchInput { + input UpdateDeploymentTargetPatchInput { name: String consoleUrl: String token: String @@ -867,9 +866,9 @@ const typeDefs = gql` sshPort: String } - input UpdateOpenshiftInput { + input UpdateDeploymentTargetInput { id: Int! - patch: UpdateOpenshiftPatchInput! + patch: UpdateDeploymentTargetPatchInput! } input UpdateNotificationMicrosoftTeamsPatchInput { @@ -931,7 +930,7 @@ const typeDefs = gql` deployHeadRef: String deployTitle: String environmentType: EnvType - openshiftProjectName: String + deploymentTargetName: String route: String routes: String monitoringUrls: String @@ -1120,10 +1119,10 @@ const typeDefs = gql` input: RemoveNotificationFromProjectInput! ): Project removeAllNotificationsFromAllProjects: String - addOpenshift(input: AddOpenshiftInput!): Openshift - updateOpenshift(input: UpdateOpenshiftInput!): Openshift - deleteOpenshift(input: DeleteOpenshiftInput!): String - deleteAllOpenshifts: String + addDeploymentTarget(input: AddDeploymentTargetInput!): DeploymentTarget + updateDeploymentTarget(input: UpdateDeploymentTargetInput!): DeploymentTarget + deleteDeploymentTarget(input: DeleteDeploymentTargetInput!): String + deleteAllDeploymentTargets: String addProject(input: AddProjectInput!): Project updateProject(input: UpdateProjectInput!): Project deleteProject(input: DeleteProjectInput!): String From ebf9050944c64919aa1ce714e26870e9431e9fec Mon Sep 17 00:00:00 2001 From: Justin Winter Date: Fri, 24 Jan 2020 13:56:23 -0600 Subject: [PATCH 2/3] WIP --- services/api/src/typeDefs.js | 116 +++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 32 deletions(-) diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 0e8cd7ecf2..03034ae5af 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -100,7 +100,7 @@ const typeDefs = gql` ZAR } - enum DeploymentTargets { + enum ClusterType { KUBERNETES OPENSHIFT } @@ -166,9 +166,32 @@ const typeDefs = gql` billingSoftware: String } - type DeploymentTarget { + interface ClusterInterface { id: Int - name: String + name: String # Must be unique + type: ClusterType + } + + type OpenShift implements ClusterInterface { + id: Int + name: String # Must be unique + type: ClusterType + projects: [Project] #openshift calls these namespaces? + consoleUrl: String + token: String + routerPattern: String + projectUser: String + sshHost: String + sshPort: String + created: String + } + + # Alpha - Kubernetes may have different fields - Just for discussion + type Kubernetes implements ClusterInterface { + id: Int + name: String # Must be unique + type: ClusterType + projects: [Project] #namespaces based on project name? consoleUrl: String token: String routerPattern: String @@ -221,10 +244,15 @@ const typeDefs = gql` """ id: Int """ - Name of project + Name of project - Must be globally unique """ + # Internal Note - Change to require globally unique to be used for Openshift project & Kubernetes namespace name: String """ + Display Name of project + """ + displayName: String + """ Git URL, needs to be SSH Git URL in one of these two formats - git@192.168.42.1/project1.git - ssh://git@192.168.42.1:2222/project1.git @@ -252,26 +280,33 @@ const typeDefs = gql` Notifications that should be sent for this project """ notifications(type: NotificationType): [Notification] - """ - Which internal Lagoon System is responsible for deploying - 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - """ - activeSystemsDeploy: String - """ - Which internal Lagoon System is responsible for promoting - 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - """ - activeSystemsPromote: String - """ - Which internal Lagoon System is responsible for promoting - 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - """ - activeSystemsRemove: String - """ - Which internal Lagoon System is responsible for tasks - 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - """ - activeSystemsTask: String + + + # Can we derive these based on the Cluster Type, branch, name? + + # """ + # Which internal Lagoon System is responsible for deploying + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsDeploy: String + # """ + # Which internal Lagoon System is responsible for promoting + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsPromote: String + # """ + # Which internal Lagoon System is responsible for promoting + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsRemove: String + # """ + # Which internal Lagoon System is responsible for tasks + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsTask: String + + + """ Which branches should be deployed, can be one of: - \`true\` - all branches are deployed @@ -302,11 +337,16 @@ const typeDefs = gql` """ Reference to the Deployment Target (Kubernetes|OpenShift) Object this Project should be deployed to """ - deploymentTarget: DeploymentTarget - """ - Namespace-Environment pattern for Kubernetes (OpenShift Project) that should be generated, default: \`$\{project}-$\{environmentname}\` - """ - namespaceEnvironment: String + cluster: Cluster + + # Is this needed anymore? Feels a bit confusing and not super DX friendly. Can we derive this in code? + + # """ + # Namespace-Environment pattern for Kubernetes (OpenShift Project) that should be generated, default: \`$\{project}-$\{environmentname}\` + # """ + # namespaceEnvironment: String + + """ How many environments can be deployed at one timeout """ @@ -333,7 +373,7 @@ const typeDefs = gql` """ envVariables: [EnvKeyValue] """ - Which groups are directly linked to project + Which groups are directly linked to a project """ groups: [GroupInterface] } @@ -355,6 +395,10 @@ const typeDefs = gql` """ project: Project """ + Reference to the Project Object + """ + cluster: ClusterInterface + """ Which Deployment Type this environment is, can be \`branch\`, \`pullrequest\`, \`promote\` """ deployType: String @@ -518,6 +562,10 @@ const typeDefs = gql` """ projectByName(name: String!): Project """ + Returns Project Object by a display name + """ + projectByDisplayName(name: String!): Project + """ Returns Group Object by a given name """ groupByName(name: String!): Group @@ -525,11 +573,15 @@ const typeDefs = gql` Returns Project Object by a given gitUrl (only the first one if there are multiple) """ projectByGitUrl(gitUrl: String!): Project + environmentById(name: String!, project: Int!): Environment + """ + Returns Environment Object by a given names + """ environmentByName(name: String!, project: Int!): Environment """ - Returns Environment Object by a given namespace + Returns Environment Object by a Cluster Name """ - environmentByDeploymentTargetName(name: String!): Environment + environmentsByClusterName(name: String!): [Environment] userCanSshToEnvironment(deploymentTargetName: String): Environment deploymentByRemoteId(id: String): Deployment taskByRemoteId(id: String): Task From 94c6775e77708712a99058ca23980af23a8110e4 Mon Sep 17 00:00:00 2001 From: Justin Winter Date: Fri, 24 Jan 2020 15:43:12 -0600 Subject: [PATCH 3/3] More WIP after chat --- services/api/src/typeDefs.js | 153 ++++++++++++++++------------------- 1 file changed, 70 insertions(+), 83 deletions(-) diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 03034ae5af..fad502c979 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -100,10 +100,6 @@ const typeDefs = gql` ZAR } - enum ClusterType { - KUBERNETES - OPENSHIFT - } type File { id: Int @@ -166,39 +162,47 @@ const typeDefs = gql` billingSoftware: String } - interface ClusterInterface { - id: Int - name: String # Must be unique - type: ClusterType - } - - type OpenShift implements ClusterInterface { - id: Int - name: String # Must be unique - type: ClusterType - projects: [Project] #openshift calls these namespaces? - consoleUrl: String - token: String - routerPattern: String - projectUser: String - sshHost: String - sshPort: String - created: String - } - # Alpha - Kubernetes may have different fields - Just for discussion - type Kubernetes implements ClusterInterface { + type Kubernetes { id: Int name: String # Must be unique - type: ClusterType - projects: [Project] #namespaces based on project name? - consoleUrl: String + # type: ClusterType + environments: [Environment] #namespaces + api: String token: String - routerPattern: String - projectUser: String - sshHost: String - sshPort: String + autoGeneratedIngressPattern: String + remoteShellHost: String + remoteShellPort: String created: String + + #NOTES: We need to teach people to use kubernetes even though it's an openshift + + # Can we derive these based on the Cluster Type, branch, name? + + customSettings: JSON + + # """ + # Which internal Lagoon System is responsible for deploying + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + + # # TODO - TURN TO ENUMS - convert to a single field + # activeSystemsDeploy: String + # """ + # Which internal Lagoon System is responsible for promoting + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsPromote: String + # """ + # Which internal Lagoon System is responsible for promoting + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsRemove: String + # """ + # Which internal Lagoon System is responsible for tasks + # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' + # """ + # activeSystemsTask: String } type NotificationMicrosoftTeams { @@ -235,6 +239,14 @@ const typeDefs = gql` union Notification = NotificationRocketChat | NotificationSlack | NotificationMicrosoftTeams | NotificationEmail + + type KubernetesEnvironmentMap { + environmentType: EnvironmentType + kubernetes: Kubernetes + } + + # Someday... would like to suppor one project deploy in multiple places (clusters) + """ Lagoon Project (like a git repository) """ @@ -244,15 +256,10 @@ const typeDefs = gql` """ id: Int """ - Name of project - Must be globally unique + Name of project """ - # Internal Note - Change to require globally unique to be used for Openshift project & Kubernetes namespace name: String """ - Display Name of project - """ - displayName: String - """ Git URL, needs to be SSH Git URL in one of these two formats - git@192.168.42.1/project1.git - ssh://git@192.168.42.1:2222/project1.git @@ -280,33 +287,6 @@ const typeDefs = gql` Notifications that should be sent for this project """ notifications(type: NotificationType): [Notification] - - - # Can we derive these based on the Cluster Type, branch, name? - - # """ - # Which internal Lagoon System is responsible for deploying - # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - # """ - # activeSystemsDeploy: String - # """ - # Which internal Lagoon System is responsible for promoting - # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - # """ - # activeSystemsPromote: String - # """ - # Which internal Lagoon System is responsible for promoting - # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - # """ - # activeSystemsRemove: String - # """ - # Which internal Lagoon System is responsible for tasks - # 'lagoon_kubernetesBuildDeploy' | 'lagoon_openshiftBuildDeploy' - # """ - # activeSystemsTask: String - - - """ Which branches should be deployed, can be one of: - \`true\` - all branches are deployed @@ -334,19 +314,16 @@ const typeDefs = gql` Should storage for this environment be calculated (\`1\` or \`0\`) """ storageCalc: Int + """ - Reference to the Deployment Target (Kubernetes|OpenShift) Object this Project should be deployed to + Environment > Cluster """ - cluster: Cluster - - # Is this needed anymore? Feels a bit confusing and not super DX friendly. Can we derive this in code? - - # """ - # Namespace-Environment pattern for Kubernetes (OpenShift Project) that should be generated, default: \`$\{project}-$\{environmentname}\` - # """ - # namespaceEnvironment: String - + kubernetesMap: [KubernetesMap] + """ + Kubernetes Namespace pattern that should be generated, default: \`$\{project}-$\{environmentname}\` + """ + kubernetesNamespacePattern: String """ How many environments can be deployed at one timeout """ @@ -373,7 +350,7 @@ const typeDefs = gql` """ envVariables: [EnvKeyValue] """ - Which groups are directly linked to a project + Groups linked to a project """ groups: [GroupInterface] } @@ -387,17 +364,21 @@ const typeDefs = gql` """ id: Int """ - Name of this Environment + Name of this Environment (not unique) """ name: String """ + Unique Name (auto generated) environmentName.projectName.kubernetesName (ex. pr-104.drupal-example.ch1.amazee.io) + """ + uniqueName: String + """ Reference to the Project Object """ project: Project """ - Reference to the Project Object + Reference to the Kubernetes Object """ - cluster: ClusterInterface + kubernetes: Kubernetes """ Which Deployment Type this environment is, can be \`branch\`, \`pullrequest\`, \`promote\` """ @@ -421,11 +402,15 @@ const typeDefs = gql` """ Which Environment Type this environment is, can be \`production\`, \`development\` """ - environmentType: String + environmentType: EnvironmentType + """ + Kubernetes Namespace """ - Deployment target name to deployed into (Kubernetes Namespace | Openshift Project Name) + kubernetesNamespace: String """ - targetName: String + (DEPRECATED as of 2.0) Name of the OpenShift Project/Namespace this environment is deployed into + """ + openshiftProjectName: String """ Unix Timestamp of the last time this environment has been updated """ @@ -549,7 +534,9 @@ const typeDefs = gql` input DeleteEnvironmentInput { name: String! project: String! - execute: Boolean + execute: Boolean # TODO: change to two separate mutations + # Anywhere you can delete anything, change the execute thing + # Internal - deleteEnvironmentFromOpenshift } type Query {