Skip to content

Commit

Permalink
Adjust Python image building
Browse files Browse the repository at this point in the history
  • Loading branch information
halamix2 committed Mar 1, 2024
1 parent 69f8b14 commit eebc8a3
Show file tree
Hide file tree
Showing 39 changed files with 250 additions and 30 deletions.
16 changes: 15 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ updates:
include: "scope"

- package-ecosystem: "pip"
directory: "/components/runtimes/python39/kubeless"
directory: "/components/runtimes/python/python39"
labels:
- "area/dependency"
- "kind/chore"
Expand All @@ -82,6 +82,20 @@ updates:
opentelemetry:
patterns:
- "opentelemetry-*"
- package-ecosystem: "pip"
directory: "/components/runtimes/python/python312"
labels:
- "area/dependency"
- "kind/chore"
schedule:
interval: "weekly"
commit-message:
prefix: "pip-python312"
include: "scope"
groups:
opentelemetry:
patterns:
- "opentelemetry-*"

- package-ecosystem: "npm"
directory: "/components/runtimes/nodejs/nodejs16"
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions components/runtimes/python/python312/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.12.2-alpine3.19

# Serverless
LABEL source = git@github.com:kyma-project/kyma.git

# build-base and linux-headers are needed to install all requirements
RUN apk add --no-cache --virtual .build-deps build-base linux-headers

COPY ./python312/requirements.txt /kubeless/requirements.txt

RUN pip install --no-cache-dir -r /kubeless/requirements.txt

COPY ./kubeless/ /

WORKDIR /

USER 1000
# Tracing propagators are configured based on OTEL_PROPAGATORS env variable https://opentelemetry.io/docs/instrumentation/python/manual/#using-environment-variables
ENV OTEL_PROPAGATORS=tracecontext,baggage,b3multi
ENV OTEL_PYTHON_REQUESTS_EXCLUDED_URLS="healthz,favicon.ico,metrics"

CMD ["python", "/kubeless.py"]
1 change: 1 addition & 0 deletions components/runtimes/python/python39/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kubeless/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ LABEL source = git@github.com:kyma-project/kyma.git
# build-base and linux-headers are needed to install all requirements
RUN apk add --no-cache --virtual .build-deps build-base linux-headers

COPY kubeless/requirements.txt /kubeless/requirements.txt
COPY ./python39/requirements.txt /kubeless/requirements.txt

RUN pip install --no-cache-dir -r /kubeless/requirements.txt

COPY kubeless/ /
COPY ./kubeless/ /

WORKDIR /

Expand Down
12 changes: 12 additions & 0 deletions components/runtimes/python/python39/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
setuptools==69.1.1
requests>=2.31.0
bottle==0.12.25
cheroot==10.0.0
wsgi-request-logger==0.4.6
prometheus_client==0.20.0
opentelemetry-api==1.23.0
opentelemetry-sdk==1.23.0
opentelemetry-exporter-otlp-proto-http==1.23.0
opentelemetry-propagator-b3==1.23.0
opentelemetry-instrumentation-requests==0.44b0
cloudevents
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,13 @@ spec:
type: object
runtime:
description: Specifies the runtime of the Function. The available
values are `nodejs16` - deprecated, `nodejs18`, and `python39`.
values are `nodejs16` - deprecated, `nodejs18`, `python39`, and
`python312`.
enum:
- nodejs16
- nodejs18
- python39
- python312
type: string
runtimeImageOverride:
description: Specifies the runtime image used instead of the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
rtmNodeJS16 = fnRuntime.GetRuntimeConfig(serverlessv1alpha2.NodeJs16)
rtmNodeJS18 = fnRuntime.GetRuntimeConfig(serverlessv1alpha2.NodeJs18)
rtmPython39 = fnRuntime.GetRuntimeConfig(serverlessv1alpha2.Python39)
rtmPython312 = fnRuntime.GetRuntimeConfig(serverlessv1alpha2.Python312)

Check failure on line 22 in components/serverless/internal/controllers/serverless/build_resources_test.go

View workflow job for this annotation

GitHub Actions / lint

var `rtmPython312` is unused (unused)
)

func TestFunctionReconciler_buildConfigMap(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ func fillConfigEnvVars(runtime serverlessv1alpha2.Runtime, config *Config) {
{Name: "PYTHONPATH", Value: "$(KUBELESS_INSTALL_VOLUME)/lib.python3.9/site-packages:$(KUBELESS_INSTALL_VOLUME)"},
{Name: "PYTHONUNBUFFERED", Value: "TRUE"}}...)
return
case serverlessv1alpha2.Python312:
config.RuntimeEnvs = append(config.RuntimeEnvs,
[]corev1.EnvVar{
// https://github.com/kubeless/runtimes/blob/master/stable/python/python.jsonnet#L45
{Name: "PYTHONPATH", Value: "$(KUBELESS_INSTALL_VOLUME)/lib.python3.12/site-packages:$(KUBELESS_INSTALL_VOLUME)"},
{Name: "PYTHONUNBUFFERED", Value: "TRUE"}}...)
return
}
}

Expand All @@ -50,7 +57,7 @@ func fillConfigFileNames(runtime serverlessv1alpha2.Runtime, config *Config) {
config.DependencyFile = "package.json"
config.FunctionFile = "handler.js"
return
case serverlessv1alpha2.Python39:
case serverlessv1alpha2.Python39, serverlessv1alpha2.Python312:
config.DependencyFile = "requirements.txt"
config.FunctionFile = "handler.py"
return
Expand All @@ -59,7 +66,7 @@ func fillConfigFileNames(runtime serverlessv1alpha2.Runtime, config *Config) {

func GetRuntime(r serverlessv1alpha2.Runtime) Runtime {
switch r {
case serverlessv1alpha2.Python39:
case serverlessv1alpha2.Python39, serverlessv1alpha2.Python312:
return python{}
default:
return nodejs{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ func TestGetRuntimeConfig(t *testing.T) {
{Name: "PYTHONUNBUFFERED", Value: "TRUE"}},
},
},
"python312": {
name: "python312",
runtime: serverlessv1alpha2.Python312,
want: runtime.Config{
Runtime: serverlessv1alpha2.Python312,
DependencyFile: "requirements.txt",
FunctionFile: "handler.py",
DockerfileConfigMapName: "dockerfile-python312",
RuntimeEnvs: []corev1.EnvVar{{Name: "PYTHONPATH", Value: "$(KUBELESS_INSTALL_VOLUME)/lib.python3.12/site-packages:$(KUBELESS_INSTALL_VOLUME)"},
{Name: "FUNC_RUNTIME", Value: "python312"},
{Name: "PYTHONUNBUFFERED", Value: "TRUE"}},
},
},
"nodej16": {
name: "nodejs16 config",
runtime: serverlessv1alpha2.NodeJs16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func getPackageConfigVolumeMountsForRuntime(rtm serverlessv1alpha2.Runtime) []co
SubPath: ".npmrc",
},
}
case serverlessv1alpha2.Python39:
case serverlessv1alpha2.Python39, serverlessv1alpha2.Python312:
return []corev1.VolumeMount{
{
Name: "registry-config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Runtime string

const (
Python39 Runtime = "python39"
Python312 Runtime = "python312"
// Deprecated: Nodejs16 will be removed soon
NodeJs16 Runtime = "nodejs16"
NodeJs18 Runtime = "nodejs18"
Expand Down Expand Up @@ -167,8 +168,8 @@ const (

// Defines the desired state of the Function
type FunctionSpec struct {
// Specifies the runtime of the Function. The available values are `nodejs16` - deprecated, `nodejs18`, and `python39`.
// +kubebuilder:validation:Enum=nodejs16;nodejs18;python39;
// Specifies the runtime of the Function. The available values are `nodejs16` - deprecated, `nodejs18`, `python39`, and `python312`.
// +kubebuilder:validation:Enum=nodejs16;nodejs18;python39;python312;
Runtime Runtime `json:"runtime"`

// Specifies the runtime image used instead of the default one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ func Test_XKubernetesValidations_Valid(t *testing.T) {
},
},
},
"allowed runtime: python312": {
fn: &serverlessv1alpha2.Function{
ObjectMeta: fixMetadata,
Spec: serverlessv1alpha2.FunctionSpec{
Runtime: serverlessv1alpha2.Python312,
Source: serverlessv1alpha2.Source{
Inline: &serverlessv1alpha2.InlineSource{Source: "a"}},
},
},
},
"allowed envs": {
fn: &serverlessv1alpha2.Function{
ObjectMeta: fixMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func ValidateDependencies(runtime Runtime, dependencies string) error {
switch runtime {
case NodeJs16, NodeJs18:
return validateNodeJSDependencies(dependencies)
case Python39:
case Python39, Python312:
return nil
}
return fmt.Errorf("cannot find runtime: %s", runtime)
Expand Down
11 changes: 6 additions & 5 deletions config/serverless/templates/busola-serverless-extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ data:
source: 'spec.source.gitRepository ? "Git Repository" : "Inline Editor"'
- name: header.runtime
source: >-
spec.runtime = 'nodejs16' ? 'Node.js 16 - deprecated' : (spec.runtime = 'python39' ? 'Python 3.9' : (spec.runtime = 'nodejs18' ? 'Node.js 18' : spec.runtime))
spec.runtime = 'nodejs16' ? 'Node.js 16 - deprecated' : (spec.runtime = 'python39' ? 'Python 3.9' : (spec.runtime = 'nodejs18' ? 'Node.js 18' : (spec.runtime = 'python312' ? 'Python 3.12' : spec.runtime)))
body:
- widget: Tabs
children:
Expand Down Expand Up @@ -213,14 +213,14 @@ data:
trigger: [language]
dynamicValue: |
spec.runtime in ['nodejs16', 'nodejs18'] ? 'JavaScript' :
spec.runtime in ['python39'] ? 'Python' :
spec.runtime in ['python39', 'python312'] ? 'Python' :
''
- simple: true
path: spec.runtime
placeholder: placeholders.spec.runtime
enum: |
$language = 'JavaScript' ? ['nodejs16', 'nodejs18'] :
$language = 'Python' ? ['python39'] :
$language = 'Python' ? ['python39', 'python312'] :
[]
subscribe:
language: |
Expand Down Expand Up @@ -422,7 +422,7 @@ data:
list: |-
- name: header.runtime
source: >-
spec.runtime = 'nodejs16' ? 'Node.js 16 - deprecated' : (spec.runtime = 'python39' ? 'Python 3.9' : (spec.runtime = 'nodejs18' ? 'Node.js 18' : spec.runtime))
spec.runtime = 'nodejs16' ? 'Node.js 16 - deprecated' : (spec.runtime = 'python39' ? 'Python 3.9' : (spec.runtime = 'nodejs18' ? 'Node.js 18' : (spec.runtime = 'python312' ? 'Python 3.12' : spec.runtime)))
- name: header.sourceType
source: 'spec.source.gitRepository ? "Git Repository" : "Inline Editor"'
- name: header.status
Expand Down Expand Up @@ -536,6 +536,7 @@ data:
spec.runtime.nodejs16: Node.js 16 - deprecated
spec.runtime.nodejs18: Node.js 18
spec.runtime.python39: Python 3.9
spec.runtime.python312: Python 3.12
spec.resourceConfiguration.build: Build
spec.resourceConfiguration.function: Function
spec.resourceConfiguration.function.profile: Function profile
Expand Down Expand Up @@ -583,4 +584,4 @@ data:
def main(event, context):
message = "Hello World from the Kyma Function "+context['function-name']+" running on "+context['runtime']+ "!";
print(message)
return message
return message
4 changes: 3 additions & 1 deletion config/serverless/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,13 @@ spec:
type: object
runtime:
description: Specifies the runtime of the Function. The available
values are `nodejs16` - deprecated, `nodejs18`, and `python39`.
values are `nodejs16` - deprecated, `nodejs18`, `python39`, and
`python312`.
enum:
- nodejs16
- nodejs18
- python39
- python312
type: string
runtimeImageOverride:
description: Specifies the runtime image used instead of the default
Expand Down
24 changes: 24 additions & 0 deletions config/serverless/templates/runtimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,28 @@ data:
RUN rm -rf /etc/pip.conf
USER 1000
---
apiVersion: v1
kind: ConfigMap
metadata:
name: dockerfile-python312
namespace: {{ .Release.Namespace }}
labels:
serverless.kyma-project.io/config: runtime
serverless.kyma-project.io/runtime: python312
data:
Dockerfile: |-
ARG base_image={{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.function_runtime_python312) }}
FROM ${base_image}
USER root
ENV KUBELESS_INSTALL_VOLUME=/kubeless
COPY /src/requirements.txt $KUBELESS_INSTALL_VOLUME/requirements.txt
COPY /registry-config/* /etc/
RUN pip install --no-cache-dir -r $KUBELESS_INSTALL_VOLUME/requirements.txt
COPY /src $KUBELESS_INSTALL_VOLUME
RUN rm -rf /etc/pip.conf
USER 1000
4 changes: 4 additions & 0 deletions config/serverless/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ global:
name: "function-runtime-python39"
version: "main"
directory: "prod"
function_runtime_python312:
name: "function-runtime-python312"
version: "main"
directory: "prod"
kaniko_executor:
name: "tpi/kaniko-executor"
version: "1.9.2-ea54c1c7"
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ services:
image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python39:local
platform: "linux/amd64"
build:
context: components/runtimes/python39
dockerfile: Dockerfile
context: components/runtimes/python/python39
dockerfile: Dockerfile
function_runtime_python312:
image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python312:local
platform: "linux/amd64"
build:
context: components/runtimes/python/python312
dockerfile: Dockerfile
4 changes: 2 additions & 2 deletions docs/user/resources/06-10-function-cr.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ spec:
| **resourceConfiguration.​function** | object | Specifies resources requested by the Function's Pod. |
| **resourceConfiguration.​function.​profile** | string | Defines the name of the predefined set of values of the resource. Can't be used together with **Resources**. |
| **resourceConfiguration.​function.​resources** | object | Defines the amount of resources available for the Pod. Can't be used together with **Profile**. For configuration details, see the [official Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/). |
| **runtime** (required) | string | Specifies the runtime of the Function. The available values are `nodejs16` - deprecated, `nodejs18`, and `python39`. |
| **runtime** (required) | string | Specifies the runtime of the Function. The available values are `nodejs16` - deprecated, `nodejs18`, `python39`, and `python312`. |
| **runtimeImageOverride** | string | Specifies the runtime image used instead of the default one. |
| **scaleConfig** | object | Defines the minimum and maximum number of Function's Pods to run at a time. When it is configured, a HorizontalPodAutoscaler will be deployed and will control the **Replicas** field to scale the Function based on the CPU utilisation. |
| **scaleConfig.​maxReplicas** (required) | integer | Defines the maximum number of Function's Pods to run at a time. |
Expand Down Expand Up @@ -207,4 +207,4 @@ These components use this CR:

| Component | Description |
| ------------------- | ------------------------------------------------------------------------------------------------------------ |
| Function Controller | Uses the Function CR for the detailed Function definition, including the environment on which it should run. |
| Function Controller | Uses the Function CR for the detailed Function definition, including the environment on which it should run. |
4 changes: 2 additions & 2 deletions docs/user/technical-reference/05-20-env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Every runtime provides its own unique environment configuration which can be rea
| **FUNC_PORT** | `8080` | The right port a server listens to. |
| **SERVICE_NAMESPACE** | None | The namespace where the right Function exists in a cluster. |
| **KUBELESS_INSTALL_VOLUME** | `/kubeless` | Full path to volume mount with users source code. |
| **FUNC_RUNTIME** | None | The name of the actual runtime. Possible values: `nodejs16` - deprecated, `nodejs18`, `python39`. |
| **FUNC_RUNTIME** | None | The name of the actual runtime. Possible values: `nodejs16` - deprecated, `nodejs18`, `python39`, and `python312`. |
| **TRACE_COLLECTOR_ENDPOINT** | None | Full address of OpenTelemetry Trace Collector is exported if the trace collector's endpoint is present. |
| **PUBLISHER_PROXY_ADDRESS** | `http://eventing-publisher-proxy.kyma-system.svc .cluster.local/publish` | Full address of the Publisher Proxy service. |

Expand Down Expand Up @@ -126,4 +126,4 @@ spec:
source: |
def main(event. context):
return "Hello World!"
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ See all parameter descriptions.
|----------------------------------------------------------------|:--------:| ---------| ---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **name** | Yes | Function | | Specifies the name of your Function. |
| **namespace** | No | Function | `default` | Defines the namespace in which the Function is created. |
| **runtime** | Yes | Function | | Specifies the execution environment for your Function. The available values are `nodejs16` - deprecated, `nodejs18`, and `python39`. |
| **runtime** | Yes | Function | | Specifies the execution environment for your Function. The available values are `nodejs16` - deprecated, `nodejs18`, `python39`, and `python312`. |
| **runtimeImageOverride** | No | Function | | Specifies the runtimes image which must be used instead of default one. |
| **labels** | No | Function | | Specifies the Function's Pod labels. |
| **source** | Yes | Function | | Provides details on the type and location of your Function's source code and dependencies. |
Expand Down Expand Up @@ -175,4 +175,4 @@ See the detailed descriptions of all related custom resources referred to in the

- [Function](../resources/06-10-function-cr.md)
- [Subscription](https://kyma-project.io/docs/kyma/latest/05-technical-reference/00-custom-resources/evnt-01-subscription/)
- [API Rule](https://kyma-project.io/docs/kyma/latest/05-technical-reference/00-custom-resources/apix-01-apirule/)
- [API Rule](https://kyma-project.io/docs/kyma/latest/05-technical-reference/00-custom-resources/apix-01-apirule/)
Loading

0 comments on commit eebc8a3

Please sign in to comment.