Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency updates, drop Py 3.6 + 3.7, drop OpenJDK img, add Py 3.12 #189

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 10 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v1
- uses: actions/setup-go@v4
with:
go-version: 1.21
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
go-version: '1.21'
- uses: actions/checkout@v4
- name: Lint, test and build
run: |

# Get staticcheck
export PATH=$PATH:$(go env GOPATH)/bin
go install honnef.co/go/tools/cmd/staticcheck@v0.4.3

# Lint and test
make lint
Expand All @@ -46,19 +42,24 @@ jobs:
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
if: github.event_name != 'pull_request' && github.repository == 'jthomperoo/custom-pod-autoscaler'
run: |

# Array of images to publish
declare -a IMAGES=(python python-3-6 python-3-7 python-3-8 alpine openjdk-11)
declare -a IMAGES=(python python-3-8 python-3-12 alpine)
echo "$DOCKER_PASS" | docker login --username=$DOCKER_USER --password-stdin

if [ ${{ github.event_name }} == "release" ]; then

# This needs to be determined again, due to env vars not being shared between steps
# https://github.com/actions/starter-workflows/issues/68
VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o)

# Go through each image type and publish each one individually
for image in "${IMAGES[@]}"; do
docker tag custompodautoscaler/${image}:${VERSION} custompodautoscaler/${image}:latest
docker push custompodautoscaler/${image}:${VERSION}
docker push custompodautoscaler/${image}:latest
done

# Package binary
tar -czvf custom-pod-autoscaler.tar.gz dist/*
else
Expand All @@ -68,7 +69,7 @@ jobs:
fi
- name: Deploy binary
if: github.event_name == 'release' && github.repository == 'jthomperoo/custom-pod-autoscaler'
uses: Shopify/upload-to-release@1.0.0
uses: Shopify/upload-to-release@v2.0.0
with:
name: custom-pod-autoscaler.tar.gz
path: custom-pod-autoscaler.tar.gz
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added Python 3.12 Docker image (`custompodautoscaler/python-3-12`).
### Removed
- Dropped support for Python 3.6 and 3.7 Docker images (`custompodautoscaler/python-3-6` and
`custompodautoscaler/python-3-7`) which are EOL ([see Python version lifecycles
here](https://devguide.python.org/versions/)).
- Dropped support for OpenJDK image (`custompodautoscaler/openjdk-11`) since the base images are EOL ([see deprecation
notice here](https://hub.docker.com/_/openjdk)). Instead use a Custom Docker Image and install a JRE into it, [see
the updated simple-pod-metrics-java example for
details](https://github.com/jthomperoo/custom-pod-autoscaler/tree/master/example/simple-pod-metrics-java).
### Changed
- Updated `custompodautoscaler/python` to track Python 3.12.
- Updated package dependencies.

## [v2.9.0] - 2023-12-23
### Changed
- Switched from performing UPDATE using the K8s API to using PATCH, avoids race condition if resource is modified
Expand Down
24 changes: 6 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The Custom Pod Autoscaler Authors.
# Copyright 2023 The Custom Pod Autoscaler Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,32 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Python 3.6 build
FROM python:3.8-slim-buster AS python-3-8
WORKDIR /app
COPY dist /app/
CMD [ "/app/custom-pod-autoscaler" ]

# Python 3.7 build
FROM python:3.7-slim-buster AS python-3-7
# Python 3.12 build
FROM python:3.12-slim-bookworm AS python-3-12
WORKDIR /app
COPY dist /app/
CMD [ "/app/custom-pod-autoscaler" ]

# Python 3.6 build
FROM python:3.6-slim-buster AS python-3-6
# Python 3.8 build
FROM python:3.8-slim-buster AS python-3-8
WORKDIR /app
COPY dist /app/
CMD [ "/app/custom-pod-autoscaler" ]

# Alpine build
FROM alpine:3.10 AS alpine
WORKDIR /app
COPY dist /app/
CMD [ "/app/custom-pod-autoscaler" ]

# OpenJDK build
FROM openjdk:11-jre-slim-buster AS openjdk-11
FROM alpine:3 AS alpine
WORKDIR /app
COPY dist /app/
CMD [ "/app/custom-pod-autoscaler" ]
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test:

lint:
@echo "=============Linting============="
staticcheck ./...
go run honnef.co/go/tools/cmd/staticcheck@v0.4.6 ./...

format:
@echo "=============Formatting============="
Expand All @@ -22,12 +22,11 @@ format:

docker: default
@echo "=============Building docker images============="
docker build --target=python-3-6 -t $(REGISTRY)/python-3-6:$(VERSION) .
docker build --target=python-3-7 -t $(REGISTRY)/python-3-7:$(VERSION) .
docker ps
docker build --target=python-3-8 -t $(REGISTRY)/python-3-8:$(VERSION) .
docker build --target=python-3-12 -t $(REGISTRY)/python-3-12:$(VERSION) .
docker build --target=alpine -t $(REGISTRY)/alpine:$(VERSION) .
docker build --target=openjdk-11 -t $(REGISTRY)/openjdk-11:$(VERSION) .
docker tag $(REGISTRY)/python-3-8:$(VERSION) $(REGISTRY)/python:$(VERSION)
docker tag $(REGISTRY)/python-3-12:$(VERSION) $(REGISTRY)/python:$(VERSION)

doc:
@echo "=============Serving docs============="
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ These two pieces of logic are all the custom logic required to build a Custom Po
handle all Kubernetes API interactions for scaling/retrieving resources.

See the [examples](https://github.com/jthomperoo/custom-pod-autoscaler/tree/master/example) or the [getting started
guide](user-guide/getting-started) for more information.
guide](user-guide/getting-started.md) for more information.
11 changes: 9 additions & 2 deletions docs/reference/docker-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
The Custom Pod Autoscaler is bundled with the following Docker base images:

- `custompodautoscaler/python` tracks latest stable Python 3.x release.
- `custompodautoscaler/python-3-6` tracks latest stable Python 3.6.x release.
- `custompodautoscaler/python-3-7` tracks latest stable Python 3.7.x release.
- `custompodautoscaler/python-3-8` tracks latest stable Python 3.8.x release.
- `custompodautoscaler/python-3-8` tracks latest stable Python 3.12.x release.
- `custompodautoscaler/alpine` tracks latest stable Alpine 3.x release.

## Deprecated images

The following images are deprecated and will no longer recieve updates:

- `custompodautoscaler/python-3-6` tracks Python 3.6.x release.
- `custompodautoscaler/python-3-7` tracks Python 3.7.x release.
- `custompodautoscaler/openjdk-11` tracks OpenJDK-11 release.

See [the Docker Hub organisation here](https://hub.docker.com/u/custompodautoscaler).
9 changes: 4 additions & 5 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mkdocs==1.2.3
jinja2==3.0.0
mdx-truly-sane-lists==1.2
mkdocs-material==5.5.5
mkdocs-material-extensions==1.0
mkdocs==1.5.3
jinja2==3.1.2
mdx-truly-sane-lists==1.3
mkdocs-material==9.5.3
4 changes: 2 additions & 2 deletions example/custom-docker-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The Custom Pod Autoscaler Authors.
# Copyright 2023 The Custom Pod Autoscaler Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@ RUN apt-get update && apt-get install wget -y
# Install CPA
RUN wget \
-qO- \
https://github.com/jthomperoo/custom-pod-autoscaler/releases/download/v2.4.0/custom-pod-autoscaler.tar.gz \
https://github.com/jthomperoo/custom-pod-autoscaler/releases/download/v2.9.0/custom-pod-autoscaler.tar.gz \
| tar xvz \
&& mv dist/* /app/

Expand Down
2 changes: 1 addition & 1 deletion example/flask-metric/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Flask==2.3.2
Flask==3.0.0
6 changes: 3 additions & 3 deletions example/simple-pod-metrics-golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.16

require (
github.com/jthomperoo/custom-pod-autoscaler/v2 v2.9.0
k8s.io/api v0.21.11
k8s.io/apimachinery v0.21.11
k8s.io/client-go v0.21.11
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
)

replace github.com/jthomperoo/custom-pod-autoscaler/v2 => ../../
30 changes: 23 additions & 7 deletions example/simple-pod-metrics-java/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 The Custom Pod Autoscaler Authors.
# Copyright 2023 The Custom Pod Autoscaler Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,23 +12,39 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM gradle:jdk11 AS build
FROM gradle:jdk21 AS build
RUN apt-get update
RUN apt-get install zip -y
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build --no-daemon
RUN cd /home/gradle/src/build/distributions/ && unzip /home/gradle/src/build/distributions/simple-pod-metrics-java.zip

# Pull in OpenJDK 11 build of CPA
FROM custompodautoscaler/openjdk-11:latest
# Install dependencies for debugging
RUN apt-get update
RUN apt-get install jq curl -y
# Ubuntu base image
FROM ubuntu:latest

WORKDIR /app

# Install wget
RUN apt-get update && apt-get install wget jq curl openjdk-21-jre -y

# Install CPA
RUN wget \
-qO- \
https://github.com/jthomperoo/custom-pod-autoscaler/releases/download/v2.9.0/custom-pod-autoscaler.tar.gz \
| tar xvz \
&& mv dist/* /app/

# Remove unused dist directory
RUN rm -r dist/

# Set up aliases for easy debugging
RUN echo 'alias metrics="curl -X GET http://localhost:5000/api/v1/metrics | jq ."' >> ~/.bashrc
RUN echo 'alias evaluation="curl -X POST http://localhost:5000/api/v1/evaluation | jq ."' >> ~/.bashrc

# Add configuration file
ADD config.yaml /
# Add jar executable
COPY --from=build /home/gradle/src/build/distributions/simple-pod-metrics-java /app/simple-pod-metrics-java

CMD [ "/app/custom-pod-autoscaler" ]
14 changes: 12 additions & 2 deletions example/simple-pod-metrics-java/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Java Simple Pod Metrics Example

This example shows how to make a Custom Pod Autoscaler (CPA) using Java.
The example extends the OpenJDK 11 CPA base image (custompodautoscaler/openjdk-11) and sets up an environment to allow
Java to be used to determine metrics and evaluate how to scale.

This example builds a custom docker image with the OpenJDK 21 JRE, based on the [Custom Docker Image
example](../custom-docker-image/).

The code is verbosely commented and designed to be read and understood for building your own CPAs.

## Overview

This example contains a docker image of the example Java Custom Pod Autoscaler, alongside using the `flask-metric`
sample application ([../flask-metric/README.md](../flask-metric/README.md)) as a target to scale up and down.

Expand All @@ -21,17 +25,21 @@ The CPA exposes two endpoints:
* Aliased with `evaluation` in the example Dockerfile.

## Usage

Trying out this example requires a kubernetes cluster to try it out on, this guide will assume you are using Minikube.

### Enable CPAs

Using this CPA requires CPAs to be enabled on your kubernetes cluster, [follow this guide to set up CPAs on your
cluster](https://github.com/jthomperoo/custom-pod-autoscaler-operator#installation).

### Switch to target the Minikube registry

Target the Minikube registry for building the image:
`eval $(minikube docker-env)`

### Deploy an app for the CPA to manage

You need to deploy an app for the CPA to manage:
* Build the example app image.
`docker build -t flask-metric ../flask-metric`
Expand All @@ -40,6 +48,7 @@ You need to deploy an app for the CPA to manage:
Now you have an app running to manage scaling for.

### Build CPA image

Once CPAs have been enabled on your cluster, you need to build this example, run these commands to build the example:
* Build the example image.
`docker build -t simple-pod-metrics-java .`
Expand All @@ -48,6 +57,7 @@ Once CPAs have been enabled on your cluster, you need to build this example, run
Now the CPA should be running on your cluster, managing the app we previously deployed.

## Testing the CPA

* List pods.
`kubectl get pods -l app=flask-metric`
* Exec into a pod.
Expand Down
4 changes: 2 additions & 2 deletions example/simple-pod-metrics-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ repositories {
}

dependencies {
implementation 'commons-cli:commons-cli:1.4'
implementation 'com.google.code.gson:gson:2.8.7'
implementation 'commons-cli:commons-cli:1.6.0'
implementation 'com.google.code.gson:gson:2.10.1'
}

application {
Expand Down
Loading
Loading