diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..207faa8 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,37 @@ +name: Release +on: + push: + tags: + - '*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set tag as env var # https://stackoverflow.com/a/58178121/11757369 + id: vars + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + - name: Log in to Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:}${{ steps.vars.outputs.tag }} + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/examples/config.yaml b/examples/config.yaml index d4bb25b..7f23839 100644 --- a/examples/config.yaml +++ b/examples/config.yaml @@ -1,12 +1,8 @@ -cron: - timezone: Australia/Sydney - wake: 0 9 * * * # 9am everyday - sleep: 0 18 * * * # 6pm everyday specs: resources: deployments: - - name: smtp - namespace: apps + - name: resourceName + namespace: namespaceName statefulsets: - - name: cubestore-workers - namespace: cube + - name: resourceName + namespace: namespaceName diff --git a/examples/values.yaml b/examples/values.yaml new file mode 100644 index 0000000..305e49f --- /dev/null +++ b/examples/values.yaml @@ -0,0 +1,31 @@ +global: + namespace: hibernate + +hibernate: + + image: ghcr.io/performl/hibernate:latest + + # Environment Variables + # env: + # - name: EXAMPLE_ENV_VAR + # value: "example" + + + cron: + timezone: Australia/Sydney + sleep: 0 18 * * 1-5 # 6pm every weekday + wake: 0 9 * * 1-5 # 9am every weekday + + # for GKE spot nodes + # nodeSelector: + # iam.gke.io/gke-metadata-server-enabled: "true" + # cloud.google.com/gke-spot: "true" + + config: | + specs: + resources: + deployments: + - name: app1 + namespace: apps + + diff --git a/helm/hibernate/.helmignore b/helm/hibernate/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/hibernate/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/hibernate/Chart.yaml b/helm/hibernate/Chart.yaml new file mode 100644 index 0000000..499001d --- /dev/null +++ b/helm/hibernate/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: hibernate +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 1.0.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/helm/hibernate/README.md b/helm/hibernate/README.md new file mode 100644 index 0000000..34f86d1 --- /dev/null +++ b/helm/hibernate/README.md @@ -0,0 +1,8 @@ +# Hibernate Helm Charts + +## Installing +```bash +helm install hibernate hibernate \ + --create-namespace \ + --namespace=hibernate +``` \ No newline at end of file diff --git a/helm/hibernate/templates/configMap.yaml b/helm/hibernate/templates/configMap.yaml new file mode 100644 index 0000000..f850516 --- /dev/null +++ b/helm/hibernate/templates/configMap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: hibernate-config + namespace: {{ .Values.global.namespace }} +data: + config.yaml: {{- .Values.hibernate.config | toYaml | indent 1}} \ No newline at end of file diff --git a/helm/hibernate/templates/jobs.yaml b/helm/hibernate/templates/jobs.yaml new file mode 100644 index 0000000..11bd6e9 --- /dev/null +++ b/helm/hibernate/templates/jobs.yaml @@ -0,0 +1,77 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: hibernate-sleep + namespace: {{ .Values.global.namespace }} +spec: + timezone: {{ .Values.hibernate.cron.timezone }} + schedule: {{ .Values.hibernate.cron.sleep }} + successfulJobsHistoryLimit: 0 + failedJobsHistoryLimit: 1 + jobTemplate: + spec: + template: + spec: + restartPolicy: Never + {{- if .Values.hibernate.cron.nodeSelector }} + nodeSelector: + {{ .Values.hibernate.cron.nodeSelector | toYaml | indent 12 }} + {{- end }} + serviceAccountName: hibernate-manager + containers: + - name: hibernate-sleep + image: {{ .Values.hibernate.image }} + volumeMounts: + - name: config + mountPath: "/app/config.yaml" + subPath: "config.yaml" + readOnly: true + args: + - --action=sleep + {{- if .Values.hibernate.env }} + env: + {{ .Values.hibernate.env | toYaml | indent 12 }} + {{- end }} + volumes: + - name: config + configMap: + name: hibernate-config +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: hibernate-wake + namespace: {{ .Values.global.namespace }} +spec: + timezone: {{ .Values.hibernate.cron.timezone }} + schedule: {{ .Values.hibernate.cron.wake }} + successfulJobsHistoryLimit: 0 + failedJobsHistoryLimit: 1 + jobTemplate: + spec: + template: + spec: + restartPolicy: Never + {{- if .Values.hibernate.cron.nodeSelector }} + nodeSelector: + {{ .Values.hibernate.cron.nodeSelector | toYaml | indent 12 }} + {{- end }} + serviceAccountName: hibernate-manager + containers: + - name: hibernate-sleep + image: {{ .Values.hibernate.image }} + volumeMounts: + - name: config + mountPath: "/app/config.yaml" + subPath: "config.yaml" + readOnly: true + args: + - --action=sleep + {{- if .Values.hibernate.env }} + env: + {{ .Values.hibernate.env | toYaml | indent 12 }} + {{- end }} + volumes: + - name: config + configMap: + name: hibernate-config \ No newline at end of file diff --git a/helm/hibernate/templates/rbac.yaml b/helm/hibernate/templates/rbac.yaml new file mode 100644 index 0000000..b4caa1a --- /dev/null +++ b/helm/hibernate/templates/rbac.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: hibernate-manager + namespace: hibernate +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: hibernate-manager-role +rules: +- apiGroups: ["", "apps"] # "" indicates the core API group, "apps" indicate "AppsV1" + resources: ["deployments", "statefulsets", "configmaps"] + verbs: ["get", "watch", "list", "update", "delete"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: hibernate-manager-role-binding +subjects: +# You can specify more than one "subject" +- kind: ServiceAccount + name: hibernate-manager + namespace: hibernate +roleRef: + # "roleRef" specifies the binding to a Role / ClusterRole + kind: ClusterRole # this must be Role or ClusterRole + name: hibernate-manager-role + apiGroup: rbac.authorization.k8s.io diff --git a/version.txt b/version.txt index 51bbb66..0ec25f7 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.0.10 +v1.0.0