Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Fixes #243 - Add initial kustomize templates for this project #244

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Secrets
**/*.env*
**/secret

# Node dev
**/node_modules/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ webpack-stats.json
# MySQL data files
.data
ngrok.yml
**/secret

# Temp files
*.swp
Expand Down
44 changes: 44 additions & 0 deletions kustomize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# OpenShift configuration with Kustomize

Resource configuration and secret consumption for OpenShift projects are managed
using [`kustomize`](https://kubectl.docs.kubernetes.io/guides/introduction/kustomize/).
Comment on lines +1 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could link to this file from the main README.


## Setup

1. Populate secrets.

Sensitive values and files are located in Dropbox in the
`TL Security files -> Canvas App Explorer -> secrets`
Dropbox folder. Merge the `base` and `overlays` directories with their equivalents in the `service`
jonespm marked this conversation as resolved.
Show resolved Hide resolved
directory in your local repository.

2. Install `kustomize`.

You can install Kustomize using the command from the
[website](https://kubectl.docs.kubernetes.io/installation/kustomize/binaries/),
and adding version 4.5.5 (what is supported for now) as an argument.
```
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s 4.5.5`
jonespm marked this conversation as resolved.
Show resolved Hide resolved
```

This will download the binary to the local directory. Ideally you'd move this somewhere on your path.

## Updating a project

1. Login and select the desired project using `oc`.
```
oc login ...
oc project canvas-app-explorer-dev
```

2. Fron the `service` directory, use `kustomize build` on an overlay directory
and pipe the result to `oc apply`.
```
kustomize build overlays/dev | oc apply -f - --validate
```

To make changes to a project's ingress (e.g. updating certificates),
you may need to first delete the ingress before running `kustomize build`.
```
oc delete ingress some-ingress-name
```
29 changes: 29 additions & 0 deletions kustomize/base/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: BuildConfig
metadata:
name: web
spec:
output:
to:
kind: DockerImage
name: docker-registry.default.svc:5000/canvas-app-explorer-dev/canvas-app-explorer:latest
runPolicy: Serial
source:
git:
uri: https://github.com/tl-its-umich-edu/canvas-app-explorer.git
ref: "main"
type: Git
strategy:
type: Docker
dockerStrategy:
dockerfilePath: dockerfiles/Dockerfile.openshift
noCache: true
forcePull: true
triggers:
- type: "GitHub"
github:
secretReference:
name: github
nodeSelector: {}
status:
lastVersion: 0
18 changes: 18 additions & 0 deletions kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
org: umich
project: canvas-app-explorer
resources:
- web-autoscaler.yaml
- web-deployment.yaml
- web-service.yaml
# - web-ingress.yaml
- build.yaml
namePrefix: canvas-app-explorer-
configMapGenerator:
- name: canvas-app-explorer
crds: # Use CRDs to support OpenShift resource kinds
- openshift-buildconfig.json
- openshift-deploymentconfig.json
- openshift-route.json
52 changes: 52 additions & 0 deletions kustomize/base/openshift-buildconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"github.com/adnovum/kustomize-openshift/dc.openshift.io.v1.BuildConfig": {
"Schema": {
"description": "This is a fake CRD description to make kustomize fix OpenShift DeploymentConfig resources. See: https://github.com/adnovum/kustomize-openshift",
"properties": {
"apiVersion": {
"type": "string"
},
"kind": {
"type": "string"
},
"metadata": {
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
},
"spec": {
"$ref": "github.com/adnovum/kustomize-openshift/dc.openshift.io.v1.BuildConfigSpec"
}
}
}
},
"github.com/adnovum/kustomize-openshift/dc.openshift.io.v1.BuildConfigSpec": {
"Schema": {
"properties": {
"source/sourceSecret": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",
"x-kubernetes-object-ref-name-key": "name"
},
"source/secrets/secret": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",
"x-kubernetes-object-ref-name-key": "name"
},
"triggers/gitlab/secretReference": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",
"x-kubernetes-object-ref-name-key": "name"
},
"triggers/github/secretReference": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",
"x-kubernetes-object-ref-name-key": "name"
},
"triggers/generic/secretReference": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",
"x-kubernetes-object-ref-name-key": "name"
}
}
}
}
}
43 changes: 43 additions & 0 deletions kustomize/base/openshift-deploymentconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"github.com/adnovum/kustomize-openshift/dc.openshift.io.v1.DeploymentConfig": {
"Schema": {
"description": "This is a fake CRD description to make kustomize fix OpenShift DeploymentConfig resources. See: https://github.com/adnovum/kustomize-openshift",
"properties": {
"apiVersion": {
"type": "string"
},
"kind": {
"type": "string"
},
"metadata": {
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
},
"spec": {
"$ref": "github.com/adnovum/kustomize-openshift/dc.openshift.io.v1.DeploymentConfigSpec"
}
}
}
},
"github.com/adnovum/kustomize-openshift/dc.openshift.io.v1.DeploymentConfigSpec": {
"Schema": {
"properties": {
"template/metadata": {
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
},
"template/spec/volumes/configMap": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "ConfigMap"
},
"template/spec/containers/envFrom/configMapRef": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "ConfigMap"
},
"template/spec/containers/envFrom/secretRef": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",
"x-kubernetes-object-ref-name-key": "name"
}
}
}
}
}
31 changes: 31 additions & 0 deletions kustomize/base/openshift-route.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"github.com/adnovum/kustomize-openshift/route.openshift.io.v1.Route": {
"Schema": {
"description": "This is a fake CRD description to make kustomize fix OpenShift route resources. See: https://github.com/adnovum/kustomize-openshift",
"properties": {
"apiVersion": {
"type": "string"
},
"kind": {
"type": "string"
},
"metadata": {
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
},
"spec": {
"$ref": "github.com/adnovum/kustomize-openshift/route.openshift.io.v1.RouteSpec"
}
}
}
},
"github.com/adnovum/kustomize-openshift/route.openshift.io.v1.RouteSpec": {
"Schema": {
"properties": {
"to": {
"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Service"
}
}
}
}
}
11 changes: 11 additions & 0 deletions kustomize/base/web-autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: web
spec:
scaleTargetRef:
apiVersion: v1
kind: DeploymentConfig
name: canvas-app-explorer-web-dev
minReplicas: 1
maxReplicas: 1
jonespm marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 46 additions & 0 deletions kustomize/base/web-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: v1
kind: DeploymentConfig
metadata:
name: web
labels:
app: web
spec:
replicas: 1
selector:
app: web
org: umich
project: canvas-app-explorer
variant: dev
strategy:
type: Recreate
template:
metadata:
labels:
app: web
org: umich
project: canvas-app-explorer
variant: dev
spec:
containers:
- name: web
image: docker-registry.default.svc:5000/canvas-app-explorer-dev/canvas-app-explorer:latest
ports:
- containerPort: 5000
protocol: TCP
envFrom:
- configMapRef:
name: canvas-app-explorer
resources:
limits:
cpu: "1"
memory: 4Gi
triggers:
- type: "ImageChange"
imageChangeParams:
automatic: true
from:
kind: "ImageStreamTag"
name: "canvas-app-explorer:latest"
namespace: "canvas-app-explorer-dev"
containerNames:
- "web"
20 changes: 20 additions & 0 deletions kustomize/base/web-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web
labels:
app: web
spec:
rules:
- host: dev-canvas-app-explorer-dev.webplatformsunpublished.umich.edu
http:
paths:
- path: /
backend:
serviceName: web
servicePort: 5000
tls:
- hosts:
- dev-canvas-app-explorer-dev.webplatformsunpublished.umich.edu
secret:
optional: true
11 changes: 11 additions & 0 deletions kustomize/base/web-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 5000
targetPort: 5000
protocol: TCP
13 changes: 13 additions & 0 deletions kustomize/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
variant: dev
org: umich
nameSuffix: -dev
bases:
- ../../base
configMapGenerator:
- name: canvas-app-explorer
behavior: replace
envs:
- secret/configmap-dev.properties
3 changes: 3 additions & 0 deletions kustomize/overlays/prod/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- op: replace
path: /spec/output/to/name
value: docker-registry.default.svc:5000/canvas-app-explorer-test/canvas-app-explorer:latest
11 changes: 11 additions & 0 deletions kustomize/overlays/prod/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- op: replace
path: /spec/template/spec/containers/0/image
value: docker-registry.default.svc:5000/canvas-app-explorer-test/canvas-app-explorer:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to parameterize this if we plan to run this on all releases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe it makes more sense to just update the value with the release tag on each release. I'm not sure.

- op: replace
path: /spec/selector/variant
value: prod
- op: replace
path: /spec/template/metadata/labels/variant
value: prod
- op: remove
path: /spec/triggers
6 changes: 6 additions & 0 deletions kustomize/overlays/prod/hostname.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- op: add
path: /spec/rules/0/host
value: cae.tl.it.umich.edu
- op: replace
path: /spec/tls/0/hosts/0
value: cae.tl.it.umich.edu
Loading