Code Monkey home page Code Monkey logo

cloud-platform-environments's Introduction

cloud-platform-environments

Intro

This repository is where kubernetes namespaces are managed, across all the clusters. Kubernetes namespaces and resources are defined in the namespaces directory in this repository under the corresponding cluster name.

Functionality

The pipeline will for each defined cluster:

  1. Create a namespace as defined in the namespaces/cluster directory. If the namespace already exists on the cluster it will be ignored.
  2. Delete any namespaces that exist in the cluster but are not defined in the repository.
  3. Create any kubernetes resource that is defined under namespaces/cluster/namespace

Namespaces

The namespaces/ directory contains sub directories named after the existing cluster names, and inside, sub directories named after each of the desired namespaces you want to create for each cluster. Placed inside are the kubernetes resource files you want to create in the kubernetes format. Those will be created automatically after a push is made to the Repositories master branch by the AWS code pipeline.

AWS resources

In a similar fashion as namespaces, you can create AWS resources in your desired namespace. The file structure for that is namespaces/cluster/namespace/terraform/ and Terraform files should be placed in that route for the pipeline to be triggered and create those AWS resources. Different terraform modules exist, for example: ECR credentials, S3 bucket, and should be used to create these resources as follows:

Changes within namespaces

Changes within namespaces directory are managed by the build-environments concourse job configured here. GitHub triggers the build process using webhook. Build itself runs script whichNamespace.sh checking for last commit changes, and if it detects any within namespace folder it executes namespace.py with appropriate cluster(s) parameter.

Example terraform file

module "my_S3_bucket" {
  source = "github.com/ministryofjustice/cloud-platform-terraform-s3-bucket?ref=1.0"

  team_name = "my-team"
  bucket_id = "my-bucket"
}

resource "kubernetes_secret" "my_S3_bucket_creeds" {
  metadata {
    name = "my-S3-bucket-creeds"
  }

  data {
    access_key_id     = "${module.my_s3_bucket.access_key_id}"
    Secret_access_key = "${module.my_s3_bucket.secret_access_key}"
    Bucket_name       = "${module.my_s3_bucket.bucket_name}"
  }
}

concourse-ci/status Check

There are occasions where Terraform in the code/pipeline plan will return something like the following which appears to remove policy config. However examination of the plan will reveal that it has been re-added by terraform

      ~ policy = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = "dynamodb:*"
                      - Effect   = "Allow"
                      - Resource = "arn:aws:dynamodb:eu-west-2:1234567898:table/cp-abcdefghij123"
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
        user   = "cp-dynamo-"cp-abcdefghij123

cloud-platform-environments's People

Contributors

andrewrlee avatar andymarke avatar anthony-britton-moj avatar carlov20 avatar danbenton-mojdt avatar digitalali-moj avatar digitalronin avatar github-actions[bot] avatar ivanelec avatar jakemulley avatar jaskaransarkaria avatar jasonbirchall avatar jsugarman avatar karenmillermoj avatar marcus-bcl avatar mattops avatar mjwillis avatar neilmendum avatar petergphillips avatar poornima-krishnasamy avatar psoleckimoj avatar said-moj avatar simonmitchellmoj avatar sj-williams avatar stevenleighton21 avatar thedustroom avatar ushkarev avatar vijay-veeranki avatar willc-work avatar zheileman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloud-platform-environments's Issues

Add a `git-crypt unlock` step to the plan script

Our plan pipeline fails whenever a namespace folder includes any git-crypted files, because it works with the encrypted file, and so it fails to parse as valid yaml. This means we have to manually edit branch protection rules whenever we want to merge a PR for any namespace which includes secrets.

The apply script has a step to git-crypt unlock its working copy so that it can apply the source code. Add this step to the plan script, so that we don't have this problem anymore.

Apply (some) yaml files from the env. repo when building test clusters

We extensively tested a change to prometheus, but then found that the change failed in live-1 because the network policies were different, because the policies defined in the environments repo are not applied to test clusters.

To try and avoid similar problems in future, apply as much as possible of the kubernetes yaml files in the environments repo when we build test clusters.

Some things like deployments and ingress definitions should not be applied. Deployments because they use up time and resources, and ingress definitions because of domain name conflicts. We use consistent naming conventions, so it should be possible to create a whitelist of filenames we feel are sensible to apply to test clusters.

HMPPS EMS GitHub Actions Service Accounts Cannot Deploy ConfigMaps

[INFO] 2020/09/16 16:50:57 main.go:637: deploying configmap/grafana-dev
[ERROR] 2020/09/16 16:50:58 main.go:256: Error from server (Forbidden): error when retrieving current configuration of:
Resource: "/v1, Resource=configmaps", GroupVersionKind: "/v1, Kind=ConfigMap"
Name: "grafana-dev", Namespace: "hmpps-ems-dev"
from server for: "STDIN": configmaps "grafana-dev" is forbidden: User "system:serviceaccount:hmpps-ems-dev:github-actions" cannot get resource "configmaps" in API group "" in the namespace "hmpps-ems-dev"
##[error]Process completed with exit code 1.

Clean up old developer sandbox namespaces & ECRs

We probably have several namespaces in the cluster which developers created while learning how to use the cluster, but which are no longer required.

If we can identify namespaces which are no longer required, we could ask the relevant developer if they still need the namespace and, if they don't, we can delete it and any associated ECRs.

This will help to keep our concourse running time down, and this repo clean.

This gist might be useful as a way to quickly identify candidate namespaces to investigae.

Duplicate Target Scrapes on Prometheus - laa-apply-for-legal-aid-uat

We are getting a number of errors on Prometheus for Target duplicate scraps for laa-apply-for-legal-aid-uat.

level=warn ts=2019-08-14T12:09:16.705297979Z caller=scrape.go:1088 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-831-prevent-changes-to-appl-monitor/0 target=http://100.96.14.252:9394/metrics msg="Error on ingesting out-of-order samples" num_dropped=47
level=warn ts=2019-08-14T12:09:18.811106275Z caller=scrape.go:1088 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-804-print-application-monitor/0 target=http://100.96.37.230:9394/metrics msg="Error on ingesting out-of-order samples" num_dropped=94
level=warn ts=2019-08-14T12:09:18.814380824Z caller=scrape.go:1088 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-831-prevent-changes-to-appl-monitor/0 target=http://100.96.37.230:9394/metrics msg="Error on ingesting out-of-order samples" num_dropped=94
level=warn ts=2019-08-14T12:09:18.815666397Z caller=scrape.go:1091 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-707-html-errors-monitor/0 target=http://100.96.37.230:9394/metrics msg="Error on ingesting samples with different value but same timestamp" num_dropped=1
level=warn ts=2019-08-14T12:09:26.482296787Z caller=scrape.go:1088 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-799-domain-name-monitor/0 target=http://100.96.15.108:9394/metrics msg="Error on ingesting out-of-order samples" num_dropped=502
level=warn ts=2019-08-14T12:09:30.162576047Z caller=scrape.go:1091 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-707-webhint-monitor/0 target=http://100.96.37.12:9394/metrics msg="Error on ingesting samples with different value but same timestamp" num_dropped=1
level=warn ts=2019-08-14T12:09:33.858953135Z caller=scrape.go:1088 component="scrape manager" scrape_pool=laa-apply-for-legalaid-uat/apply-ap-799-domain-name-monitor/0 target=http://100.96.37.230:9394/metrics msg="Error on ingesting out-of-order samples" num_dropped=94

Looking at the Status > Targets tab on Prometheus, we can see 5 Targets setup for the UAT namespace, but they are all scraping the same 5 endpoints with the same labels causing the errors above. Prod and Staging do not have this issue as they have the one target scraping one endpoint.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.