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

Work towards adding support for stacks in plural up #56

Merged
merged 4 commits into from
Jun 30, 2024
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
20 changes: 19 additions & 1 deletion apps/repositories/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,22 @@ metadata:
namespace: infra
spec:
interval: 5m0s
url: https://pluralsh.github.io/bootstrap
url: https://pluralsh.github.io/bootstrap
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: cert-manager
namespace: infra
spec:
interval: 5m0s
url: https://charts.jetstack.io
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: flux
namespace: infra
spec:
interval: 5m0s
url: https://fluxcd-community.github.io/helm-charts
44 changes: 44 additions & 0 deletions apps/services/pr-automation/cluster-creator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: deployments.plural.sh/v1alpha1
kind: PrAutomation
metadata:
name: cluster-creator
spec:
name: cluster-creator
documentation: |
Sets up a PR to provision a cluster for a fleet + stage
creates:
templates:
- source: templates/clusters/stack.yaml
destination: "apps/clusters/{{ context.cloud }}/stacks/{{ context.name }}.yaml"
external: false
- source: templates/clusters/cluster.yaml
destination: "apps/clusters/{{ context.cloud }}/clusters/{{ context.name }}.yaml"
external: false
- source: templates/clusters/clusters.yaml
destination: "apps/services/clusters.yaml"
external: false
scmConnectionRef:
name: github # you'll need to add this ScmConnection manually before this is functional
title: "Adding {{ context.cloud }} cluster: {{ context.name }}"
message: "Adding {{ context.cloud }} cluster {{ context.name }} and registering it with Plural"
identifier: [[ .Identifier ]] # REPLACEME with your own repo slug
configuration:
- name: name
type: STRING
documentation: name for this cluster
- name: cloud
type: ENUM
documentation: the cloud you'll host on
values:
- aws
- gcp
- azure
- name: fleet
type: STRING
documentation: a name for the fleet you want this cluster to belong to
- name: tier
type: ENUM
documentation: what tier to place this cluster in
values:
- dev
- prd
8 changes: 8 additions & 0 deletions apps/services/pr-automation/scm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# You will need to manually create the github scm connection this refers to
# apiVersion: deployments.plural.sh/v1alpha1
# kind: ScmConnection
# metadata:
# name: github
# spec:
# name: github
# type: GITHUB
7 changes: 5 additions & 2 deletions apps/services/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: cert-manager
namespace: infra
spec:
version: 0.0.1
namespace: cert-manager
git:
folder: helm-values
Expand All @@ -19,7 +20,7 @@ spec:
valuesFiles:
- certmanager.yaml
repository:
namespace: plural-runtime
namespace: infra
name: cert-manager
clusterRef:
kind: Cluster
Expand All @@ -32,6 +33,7 @@ metadata:
name: flux
namespace: infra
spec:
version: 0.0.1
namespace: flux
git:
folder: helm-values
Expand All @@ -46,7 +48,7 @@ spec:
valuesFiles:
- flux.yaml
repository:
namespace: plural-runtime
namespace: infra
name: flux
clusterRef:
kind: Cluster
Expand All @@ -59,6 +61,7 @@ metadata:
name: runtime
namespace: infra
spec:
version: 0.0.1
namespace: plural-runtime
git:
folder: helm-values
Expand Down
10 changes: 10 additions & 0 deletions apps/services/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: deployments.plural.sh/v1alpha1
kind: DeploymentSettings
metadata:
name: global
namespace: plrl-deploy-operator
spec:
stacks:
jobSpec:
namespace: plrl-deploy-operator
serviceAccount: stacks
2 changes: 1 addition & 1 deletion apps/services/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: infra
namespace: infra
spec:
url: {{ configuration.repoUrl }}
url: [[ .RepoUrl ]]
---
apiVersion: deployments.plural.sh/v1alpha1
kind: Cluster
Expand Down
7 changes: 7 additions & 0 deletions templates/clusters/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: deployments.plural.sh/v1alpha1
kind: Cluster
metadata:
name: {{ context.name }}
namespace: infra
spec:
handle: {{ context.name }}
17 changes: 17 additions & 0 deletions templates/clusters/clusters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: deployments.plural.sh/v1alpha1
kind: ServiceDeployment
metadata:
name: clusters
namespace: infra
spec:
namespace: infra
git:
folder: apps/clusters
ref: main
repositoryRef:
kind: GitRepository
name: infra
namespace: infra
clusterRef:
name: mgmt
namespace: infra
26 changes: 0 additions & 26 deletions templates/clusters/eks/create.tf.liquid

This file was deleted.

5 changes: 0 additions & 5 deletions templates/clusters/eks/register.tf.liquid

This file was deleted.

29 changes: 29 additions & 0 deletions templates/clusters/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: deployments.plural.sh/v1alpha1
kind: InfrastructureStack
metadata:
name: cluster-{{ context.name }}
spec:
name: cluster-{{ context.name }}
detach: false
type: TERRAFORM
approval: true
manageState: true
actor: console@plural.sh
configuration:
version: '1.8'
repositoryRef:
name: infra
namespace: infra
clusterRef:
name: mgmt
namespace: infra
git:
ref: main
folder: terraform/modules/clusters/{{ context.cloud }}
environment:
- name: TF_VAR_cluster
value: {{ context.name }}
- name: TF_VAR_fleet
value: {{ context.fleet }}
- name: TF_VAR_tier
value: {{ context.tier }}
6 changes: 5 additions & 1 deletion templates/setup/console.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ resource "helm_release" "console" {
namespace = "plrl-console"
chart = "console"
repository = "https://pluralsh.github.io/console"
version = "0.3.18"
version = "0.3.25"
create_namespace = true
timeout = 600
wait = true
Expand All @@ -86,3 +86,7 @@ resource "helm_release" "console" {

depends_on = [ module.mgmt.cluster, helm_release.runtime, module.mgmt.db_url ]
}

output "identity" {
value = module.mgmt.identity
}
2 changes: 1 addition & 1 deletion templates/setup/providers/aws.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/aws"
source = "../terraform/modules/mgmt"
cluster_name = "{{ .Cluster }}"
}
2 changes: 1 addition & 1 deletion templates/setup/providers/azure.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/azure"
source = "../terraform/modules/mgmt"
resource_group_name = "{{ .Project }}"
cluster_name = "{{ .Cluster }}"
location = "{{ .Region }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/setup/providers/gcp.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/gcp"
source = "../terraform/modules/mgmt"
project_id = "{{ .Project }}"
cluster_name = "{{ .Cluster }}"
region = "{{ .Region }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/setup/providers/linode.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/linode"
source = "../terraform/modules/mgmt"
cluster_name = "{{ .Cluster }}"
region = "{{ .Region }}"
}
7 changes: 7 additions & 0 deletions templates/setup/stacks/aws.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: stacks
namespace: plrl-deploy-operator
annotations:
eks.amazonaws.com/role-arn: {{ .StacksIdentity }}
7 changes: 7 additions & 0 deletions templates/setup/stacks/azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: stacks
namespace: plrl-deploy-operator
annotations:
azure.workload.identity/client-id: {{ .StacksIdentity }}
7 changes: 7 additions & 0 deletions templates/setup/stacks/gcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: stacks
namespace: plrl-deploy-operator
annotations:
iam.gke.io/gcp-service-account: {{ .StacksIdentity }}
2 changes: 2 additions & 0 deletions terraform/clouds/aws/eks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module "eks" {
subnet_ids = module.vpc.private_subnets
control_plane_subnet_ids = module.vpc.public_subnets

create_kms_key = false

# EKS Managed Node Group(s)
eks_managed_node_group_defaults = merge(var.node_group_defaults,
{ami_release_version = data.aws_ssm_parameter.eks_ami_release_version.value})
Expand Down
28 changes: 28 additions & 0 deletions terraform/clouds/aws/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module "assumable_role_stacks" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "5.39.1"
create_role = true
role_name = "${var.cluster_name}-plrl-stacks"
provider_url = replace(module.eks.cluster_oidc_issuer_url, "https://", "")
role_policy_arns = [aws_iam_policy.stacks.arn]
oidc_fully_qualified_subjects = [
"system:serviceaccount:plrl-deploy-operator:stacks",
]
}

resource "aws_iam_policy" "stacks" {
name_prefix = "stacks"
description = "stacks permissions for ${var.cluster_name}"
policy = <<-POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
]
}
POLICY
}
1 change: 1 addition & 0 deletions terraform/clouds/aws/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ locals {
cluster = module.eks
addons = module.eks_blueprints_addons
}
vpc_name = var.vpc_name == "" ? "${var.cluster_name}-vpc" : var.vpc_name
monitoring_role_name = var.monitoring_role == "" ? "${var.cluster_name}-PluralRDSMonitoringRole" : var.monitoring_role
}
4 changes: 4 additions & 0 deletions terraform/clouds/aws/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,8 @@ output "db_url" {

output "ready" {
value = local.cluster_ready
}

output "identity" {
value = module.assumable_role_stacks.iam_role_arn
}
2 changes: 1 addition & 1 deletion terraform/clouds/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ variable "public" {

variable "vpc_name" {
type = string
default = "plural"
default = ""
}

variable "vpc_cidr" {
Expand Down
Loading