microsoft / AutoCrane

MIT License
6 stars 5 forks source link

Add janitor/ttl feature #27

Closed timmydo closed 3 years ago

timmydo commented 3 years ago

This janitor/ttl feature lets you set an annotation on deployments or services to have them cleaned up after a certain amount of time. The amount of time is calculated from the creationDate of a resource. the TTL value specified similar to golang duration values.

Sample:

          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: xyz
            namespace: abc
            annotations:
              janitor/ttl: "4h"

Autocrane will delete the above deployment after 4 hours. You'll need to give the orchestrator permissions:

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: autocrane-deployment-reader-writer
  labels:
    app.kubernetes.io/name: autocrane
    app.kubernetes.io/part-of: autocrane
rules:
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["list", "delete"]
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: autocrane-service-reader-writer
  labels:
    app.kubernetes.io/name: autocrane
    app.kubernetes.io/part-of: autocrane
rules:
- apiGroups: [""]
  resources: ["services"]
  verbs: ["list", "delete"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: autocrane-deployment-reader-writer-binding-autocrane
  labels:
    app.kubernetes.io/name: autocrane
    app.kubernetes.io/part-of: autocrane
subjects:
- kind: ServiceAccount
  name: autocrane
roleRef:
  kind: Role
  name: autocrane-deployment-reader-writer
  apiGroup: rbac.authorization.k8s.io
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: autocrane-service-reader-writer-binding-autocrane
  labels:
    app.kubernetes.io/name: autocrane
    app.kubernetes.io/part-of: autocrane
subjects:
- kind: ServiceAccount
  name: autocrane
roleRef:
  kind: Role
  name: autocrane-service-reader-writer
  apiGroup: rbac.authorization.k8s.io