Skip to content

Commit

Permalink
Feature: environments (#41)
Browse files Browse the repository at this point in the history
* add: environments management
  • Loading branch information
piontec authored Jun 29, 2022
1 parent f951031 commit 77bfee8
Show file tree
Hide file tree
Showing 35 changed files with 1,010 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

Based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
following [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Added
- Description and examples for environment management
- Initail release with basic fnunctionality and docs in place
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
configMapGenerator:
- behavior: replace
files:
- values=override_config_hello_world.yaml
name: ${cluster_id}-hello-world-values
generatorOptions:
disableNameSuffixHash: true
kind: Kustomization
resources:
- ../../../../app_sets/hello-web-app/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
admin_login: hello-admin-in-cluster-template
db_config:
db_port: 5433 # has to be in sync with config in default_config_simple_db.yaml
db_user: hello-web-app # has to be in sync with config in default_config_simple_db.yaml
host: simple-db.simple-web.svc # has to be in sync with 'namespace:' set in kustomization.yaml
thread_pool_size: 64
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
data:
values: |
cloudConfig: cloud-config-giantswarm-2
cloudName: openstack
externalNetworkID: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
kind: ConfigMap
metadata:
name: ${cluster_name}-user-config
namespace: org-${organization}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
commonLabels:
giantswarm.io/managed-by: flux
kind: Kustomization
patchesStrategicMerge:
- patch_user_config.yaml
resources:
- ../../../clusters/capo/>=v0.6.0
- cluster_user_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
name: ${cluster_name}
namespace: org-${organization}
spec:
userConfig:
configMap:
name: ${cluster_name}-user-config
namespace: org-${organization}
6 changes: 6 additions & 0 deletions bases/cluster_templates/hello_app_cluster/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
kind: Kustomization
resources:
- cluster/
- app_sets/hello-web-app/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: application.giantswarm.io/v1alpha1
kind: Catalog
metadata:
labels:
application.giantswarm.io/catalog-visibility: internal
name: giantswarm-catalog-oci
namespace: org-${organization}
spec:
description: giantswarm-catalog-oci
logoURL: "https://avatars.githubusercontent.com/u/7556340?s=60&v=4"
repositories:
- URL: oci://giantswarmpublic.azurecr.io/giantswarm-catalog/
type: helm
storage:
URL: oci://giantswarmpublic.azurecr.io/giantswarm-catalog/
type: helm
title: giantswarm-catalog-oci
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageUpdateAutomation
metadata:
name: ${cluster_id}-image-updates
namespace: org-${organization}
spec:
git:
checkout:
ref:
branch: main
commit:
author:
email: [email protected]
name: fluxcdbot
messageTemplate: |
automated app upgrades:
{{ range $image, $_ := .Updated.Images -}}
- {{ $image.Repository }} to {{ $image.Identifier }}
{{ end -}}
push:
branch: main
interval: 1m0s
sourceRef:
kind: GitRepository
name: YOUR_GIT_REPO
update:
path: ./management-clusters/MC_NAME
strategy: Setters
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
commonLabels:
giantswarm.io/managed-by: flux
kind: Kustomization
resources:
- catalog.yaml
- imageupdate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
thread_pool_size: 16
24 changes: 24 additions & 0 deletions bases/environments/stages/dev/hello_app_cluster/imagepolicies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: ${cluster_id}-hello-app
spec:
filterTags:
pattern: '.*-dev.*'
imageRepositoryRef:
name: ${cluster_id}-hello-app
policy:
semver:
range: '>=0.1.0'
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: ${cluster_id}-simple-db-app
spec:
imageRepositoryRef:
name: ${cluster_id}-simple-db
policy:
semver:
range: '>=0.1.0 <0.2.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: ${cluster_id}-hello-app
spec:
image: giantswarmpublic.azurecr.io/giantswarm-catalog/hello-world-app
interval: 10m0s
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: ${cluster_id}-simple-db-app
spec:
image: giantswarmpublic.azurecr.io/giantswarm-catalog/simple-db-app
interval: 10m0s
32 changes: 32 additions & 0 deletions bases/environments/stages/dev/hello_app_cluster/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
configMapGenerator:
- behavior: create
files:
- values=hello_world_app_user_config.yaml
name: ${cluster_id}-hello-world-user-config
generatorOptions:
disableNameSuffixHash: true
kind: Kustomization
# (optional) here we can enforce versions for both component of the app that we want in prod
patches:
- patch: |-
- op: replace
path: /spec/version
value: '0.1.8 # {"$imagepolicy": "org-${organization}:${cluster_id}-hello-app"}'
target:
kind: App
name: \${cluster_id}-hello-world
- patch: |-
- op: replace
path: /spec/version
value: '0.1.0 # {"$imagepolicy": "org-${organization}:${cluster_id}-simple-db-app"}'
target:
kind: App
name: \${cluster_id}-simple-db
# block end
resources:
- automatic_updates/
- imagepolicies.yaml
- imagerepositories.yaml
- ../../../../cluster_templates/hello_app_cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
values: |
cloudConfig: cloud-config-giantswarm-2
cloudName: openstack
externalNetworkID: prod-bbbb-cccc-dddd-eeeeeeeeeeee
nodeClasses:
- bootFromVolume: true
diskSize: 150
flavor: n1.large
image: dddddddd-dddd-dddd-dddd-dddddddddddd
name: default
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
thread_pool_size: 256
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
configMapGenerator:
- behavior: create
files:
- values=hello_world_app_user_config.yaml
name: ${cluster_id}-hello-world-user-config
- behavior: replace
files:
- values=cluster_user_config.yaml
name: ${cluster_name}-user-config
namespace: org-${organization}
generatorOptions:
disableNameSuffixHash: true
kind: Kustomization
# (optional) here we can enforce versions for both component of the app that we want in prod
patches:
- patch: |-
- op: replace
path: /spec/version
value: 0.1.8
target:
kind: App
name: \${cluster_id}-hello-world
- patch: |-
- op: replace
path: /spec/version
value: 0.1.0
target:
kind: App
name: \${cluster_id}-simple-db
# block end
resources:
- ../../../../cluster_templates/hello_app_cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: application.giantswarm.io/v1alpha1
kind: Catalog
metadata:
labels:
application.giantswarm.io/catalog-visibility: internal
name: giantswarm-catalog-oci
namespace: org-${organization}
spec:
description: giantswarm-catalog-oci
logoURL: "https://avatars.githubusercontent.com/u/7556340?s=60&v=4"
repositories:
- URL: oci://giantswarmpublic.azurecr.io/giantswarm-catalog/
type: helm
storage:
URL: oci://giantswarmpublic.azurecr.io/giantswarm-catalog/
type: helm
title: giantswarm-catalog-oci
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageUpdateAutomation
metadata:
name: ${cluster_id}-image-updates
namespace: org-${organization}
spec:
git:
checkout:
ref:
branch: main
commit:
author:
email: [email protected]
name: fluxcdbot
messageTemplate: |
automated app upgrades:
{{ range $image, $_ := .Updated.Images -}}
- {{ $image.Repository }} to {{ $image.Identifier }}
{{ end -}}
push:
branch: main
interval: 1m0s
sourceRef:
kind: GitRepository
name: YOUR_GIT_REPO
update:
path: ./management-clusters/MC_NAME
strategy: Setters
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
commonLabels:
giantswarm.io/managed-by: flux
kind: Kustomization
resources:
- catalog.yaml
- imageupdate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
thread_pool_size: 64
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: ${cluster_id}-hello-app
spec:
imageRepositoryRef:
name: ${cluster_id}-hello-app
policy:
semver:
range: '>=0.1.0 <1.0.0'
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: ${cluster_id}-simple-db-app
spec:
imageRepositoryRef:
name: ${cluster_id}-simple-db
policy:
semver:
range: '>=0.1.0 <0.2.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: ${cluster_id}-hello-app
spec:
image: giantswarmpublic.azurecr.io/giantswarm-catalog/hello-world-app
interval: 10m0s
---
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: ${cluster_id}-simple-db-app
spec:
image: giantswarmpublic.azurecr.io/giantswarm-catalog/simple-db-app
interval: 10m0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: kustomize.config.k8s.io/v1beta1
buildMetadata: [originAnnotations]
configMapGenerator:
- behavior: create
files:
- values=hello_world_app_user_config.yaml
name: ${cluster_id}-hello-world-user-config
generatorOptions:
disableNameSuffixHash: true
kind: Kustomization
# (optional) here we can enforce versions for both component of the app that we want in prod
patches:
- patch: |-
- op: replace
path: /spec/version
value: '0.1.8 # {"$imagepolicy": "org-${organization}:${cluster_id}-hello-app"}'
target:
kind: App
name: \${cluster_id}-hello-world
- patch: |-
- op: replace
path: /spec/version
value: '0.1.0 # {"$imagepolicy": "org-${organization}:${cluster_id}-simple-db-app"}'
target:
kind: App
name: \${cluster_id}-simple-db
# block end
resources:
- automatic_updates/
- imagepolicies.yaml
- imagerepositories.yaml
- ../../../../cluster_templates/hello_app_cluster
1 change: 1 addition & 0 deletions docs/add_wc.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ understand and follow all of them to produce a valid configuration. These steps

1. [Preparing a cluster definition template](./add_wc_template.md) you want to use for your cluster (if it
doesn't already exist).
1. [Preparing multiple environments](./add_wc_environments.md)
1. [Preparing GitOps repository structure, encryption secrets and dedicated Flux Kustomization](./add_wc_structure.md).
1. [Providing actual instance of a cluster, a definition of infrastructure required to run it](./add_wc_instance.md).
1. [Configuring Apps to be deployed in the new cluster](./apps/README.md).
Loading

0 comments on commit 77bfee8

Please sign in to comment.