From d9cad0144d374c6b736fa7c4bf40ba189c5fe308 Mon Sep 17 00:00:00 2001 From: Bryan Oliver Date: Sat, 24 Jun 2023 12:54:11 -0400 Subject: [PATCH] [olivercodes] feat(gh-2): Teams, Namespace, and Gateway types/struct definitions ThoughtWorks-DPS/lab-api-teams/#2 Signed-off-by: Bryan Oliver --- README.md | 1 + cmd/teams-api-server/main.go | 0 go.mod | 3 ++ pkg/domain/gateways.go | 18 ++++++++ pkg/domain/namespaces.go | 39 ++++++++++++++++ pkg/domain/teams.go | 46 +++++++++++++++++++ pkg/handler/handler.go | 0 pkg/repository/mock/mock_repository.go | 0 .../mock/teams_api_repository_test.go | 0 pkg/repository/redis_teams_api_repository.go | 0 pkg/service/service.go | 0 11 files changed, 107 insertions(+) create mode 100644 README.md create mode 100644 cmd/teams-api-server/main.go create mode 100644 go.mod create mode 100644 pkg/domain/gateways.go create mode 100644 pkg/domain/namespaces.go create mode 100644 pkg/domain/teams.go create mode 100644 pkg/handler/handler.go create mode 100644 pkg/repository/mock/mock_repository.go create mode 100644 pkg/repository/mock/teams_api_repository_test.go create mode 100644 pkg/repository/redis_teams_api_repository.go create mode 100644 pkg/service/service.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..7413837 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# lab-api-teams diff --git a/cmd/teams-api-server/main.go b/cmd/teams-api-server/main.go new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d34bc48 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module twdps.io/lab-api-teams + +go 1.20 diff --git a/pkg/domain/gateways.go b/pkg/domain/gateways.go new file mode 100644 index 0000000..93ccb15 --- /dev/null +++ b/pkg/domain/gateways.go @@ -0,0 +1,18 @@ +package domain + +// gw-id: subdomain of gateway, e.g., dev.api.twdps.io +// gw-cert-managed: is this a supported gateway, cert-manager to manage? +// gw-custom-cert: where the customer supplies the cert? +// gw-ingress: ingress-gateway to attach + +type Gateway struct { + GatewayID string `json:"gatewayID"` + GatewayCertManaged bool `json:"gatewayCertManaged"` + GatewayCustomCert string `json:"gatewayCustomCert"` + GatewayIngress string `json:"gatewayIngress"` +} + +type GatewayRepository interface { + GetGateways() ([]Gateway, error) + GetGatewayByID(id string) (Gateway, error) +} diff --git a/pkg/domain/namespaces.go b/pkg/domain/namespaces.go new file mode 100644 index 0000000..33323ea --- /dev/null +++ b/pkg/domain/namespaces.go @@ -0,0 +1,39 @@ +package domain + +// ns-type: [ normal | master | standard | custom ] +// normal:     the ns definition is a normal, team ns desired state definition. Normal +//                        namespaces are subject of the sync action. +//      master:     ns definition not associated with any team. The master record contains +//                       the default values used for ram, cpu, in-or-out of mesh. +//      standard: The standard ns records represent the default namespaces provisioned +//                       for a new team at creation. +//      custom:    Teams my define custom namespace. By convention this is the equivalent +//                        of creating an 'optional' standard entry. All teams can view the list of custom +//                        ns and choose to adopt it as well as define a new one. +// ns-team: team-id used by normal ns entries +// ns-id: name to append to team-id [dev | qa | etc] +// ns-ram: k8s resource +//      [pool resource] In the master record, define the default amount of ram/cpu to assign +//      to new ns (typically a number like 1/5 of the amount of the teams pool from the team +//      record +// ns-cpu: k8s resource [pool resource like ram] +// ns-in-mesh: istio managed? boolean, true by default +// ns-cluster-location: name of cluster where the ns resides TODO - discuss if this is needed +// ns-from-default: was this created at onboarding from defaults? + +type Namespace struct { + NamespaceType string `json:"namespaceType"` // normal, master, standard, custom + NamespaceTeamID string `json:"namespaceTeamID"` // ID from teams API + NamespaceID string `json:"namesapceID"` // Dev, QA, etc + NamespaceRam int `json:"namespaceRam"` + NamespaceCpu int `json:"namespaceCpu"` + NamespaceInMesh bool `json:"namespaceInMesh"` + NamespaceFromDefault bool `json:"namespaceFromDefault"` +} + +type NamespacesRepository interface { + GetNamespaces() ([]Namespace, error) + GetStandardNamespaces() ([]Namespace, error) + GetCustomNamespaces() ([]Namespace, error) + GetMasterNamespaces() ([]Namespace, error) +} diff --git a/pkg/domain/teams.go b/pkg/domain/teams.go new file mode 100644 index 0000000..13e4bee --- /dev/null +++ b/pkg/domain/teams.go @@ -0,0 +1,46 @@ +package domain + +// team-type: [ normal | master | admin ] +// team-id: (team github name) +// team-description: freeform +// team-ram: integer +//      In the master record this +//      represents the default pool +//      size to assign to teams. +// team-cpu: integer +// team-integrations: json +//      list of the supported integrations the +//      team wants the platform to maintain on their +//      behalf. +// team-ram-limit: only admin edit. +//      in master this is the max +//      self-managed resource limit +// team-cpu-limit: only admin edit. +//      in master this is the max +//      self-managed resource limit +// team-marked-for-deletion: +//      [ requested | pending | done ] + +type Team struct { + TeamType string `json:"teamType"` + TeamID string `json:"teamID"` + TeamDescription string `json:"teamDescription"` + TeamRAM int `json:"teamRAM"` + TeamCPU int `json:"teamCPU"` + TeamRamLimit int `json:"teamRamLimit"` + TeamCpuLimit int `json:"teamCPULimit"` + TeamMarkedForDeletion string `json:"teamMarkedForDeletion"` + TeamIntegrations []TeamIntegration `json:"teamIntegrations"` +} + +type TeamIntegration struct { + IntegrationName string `json:"integrationName"` +} + +type TeamsRepository interface { + GetTeams() ([]Team, error) + GetTeam(id string) (Team, error) + AddTeam(newTeam Team) error + UpdateTeam(team Team) error + RemoveTeam(id string) (Team, error) +} diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go new file mode 100644 index 0000000..e69de29 diff --git a/pkg/repository/mock/mock_repository.go b/pkg/repository/mock/mock_repository.go new file mode 100644 index 0000000..e69de29 diff --git a/pkg/repository/mock/teams_api_repository_test.go b/pkg/repository/mock/teams_api_repository_test.go new file mode 100644 index 0000000..e69de29 diff --git a/pkg/repository/redis_teams_api_repository.go b/pkg/repository/redis_teams_api_repository.go new file mode 100644 index 0000000..e69de29 diff --git a/pkg/service/service.go b/pkg/service/service.go new file mode 100644 index 0000000..e69de29