From c8689dc5f9b3548ada6df65f968435f6e19c70b5 Mon Sep 17 00:00:00 2001 From: Andrey Velichkevich Date: Thu, 15 Aug 2024 16:23:20 +0100 Subject: [PATCH 1/3] KEP-2170: Add directories for the V2 APIs Signed-off-by: Andrey Velichkevich --- .../workflows/build-and-publish-images.yaml | 6 ++++++ .github/workflows/publish-core-images.yaml | 5 +++++ .../template-publish-image/action.yaml | 5 ++++- cmd/training-operator.v2alpha1/Dockerfile | 13 ++++++++++++ cmd/training-operator.v2alpha1/main.go | 21 +++++++++++++++++++ .../v2alpha1/trainingruntime_types.go | 17 +++++++++++++++ .../kubeflow.org/v2alpha1/trainjob_types.go | 17 +++++++++++++++ pkg/controller.v2/trainjob_controller.go | 17 +++++++++++++++ pkg/webhook.v2/trainjob_webhook.go | 17 +++++++++++++++ 9 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 cmd/training-operator.v2alpha1/Dockerfile create mode 100644 cmd/training-operator.v2alpha1/main.go create mode 100644 pkg/apis/kubeflow.org/v2alpha1/trainingruntime_types.go create mode 100644 pkg/apis/kubeflow.org/v2alpha1/trainjob_types.go create mode 100644 pkg/controller.v2/trainjob_controller.go create mode 100644 pkg/webhook.v2/trainjob_webhook.go diff --git a/.github/workflows/build-and-publish-images.yaml b/.github/workflows/build-and-publish-images.yaml index 9d551a1ecb..dbb8ce37a9 100644 --- a/.github/workflows/build-and-publish-images.yaml +++ b/.github/workflows/build-and-publish-images.yaml @@ -17,6 +17,10 @@ on: required: false type: string default: . + prefix: + required: true + type: string + default: v1 secrets: DOCKERHUB_USERNAME: required: false @@ -57,6 +61,7 @@ jobs: platforms: ${{ inputs.platforms }} context: ${{ inputs.context }} push: true + prefix: ${{ inputs.prefix }} - name: Test Build For Component ${{ inputs.component-name }} if: steps.publish.outcome == 'skipped' @@ -67,3 +72,4 @@ jobs: platforms: ${{ inputs.platforms }} context: ${{ inputs.context }} push: false + prefix: ${{ inputs.prefix }} diff --git a/.github/workflows/publish-core-images.yaml b/.github/workflows/publish-core-images.yaml index 3068f901a4..f232d54815 100644 --- a/.github/workflows/publish-core-images.yaml +++ b/.github/workflows/publish-core-images.yaml @@ -13,6 +13,7 @@ jobs: platforms: ${{ matrix.platforms }} dockerfile: ${{ matrix.dockerfile }} context: ${{ matrix.context }} + prefix: ${{matrix.prefix}} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -24,6 +25,10 @@ jobs: - component-name: training-operator dockerfile: build/images/training-operator/Dockerfile platforms: linux/amd64,linux/arm64,linux/ppc64le + - component-name: training-operator + dockerfile: cmd/training-operator.v2alpha1/Dockerfile + platforms: linux/amd64,linux/arm64,linux/ppc64le + prefix: v2alpha1 - component-name: kubectl-delivery dockerfile: build/images/kubectl-delivery/Dockerfile platforms: linux/amd64,linux/arm64,linux/ppc64le diff --git a/.github/workflows/template-publish-image/action.yaml b/.github/workflows/template-publish-image/action.yaml index bbde5d1b76..8f73fb30e2 100644 --- a/.github/workflows/template-publish-image/action.yaml +++ b/.github/workflows/template-publish-image/action.yaml @@ -19,6 +19,9 @@ inputs: push: required: true description: whether to push container images or not + prefix: + required: true + description: Prefix for image tag, e.g. v1 or v2alpha1 runs: using: composite @@ -38,7 +41,7 @@ runs: images: ${{ inputs.image }} tags: | type=raw,latest - type=sha,prefix=v1- + type=sha,prefix=${{ inputs.prefix }}- - name: Build and Push uses: docker/build-push-action@v5 diff --git a/cmd/training-operator.v2alpha1/Dockerfile b/cmd/training-operator.v2alpha1/Dockerfile new file mode 100644 index 0000000000..898cff8bf2 --- /dev/null +++ b/cmd/training-operator.v2alpha1/Dockerfile @@ -0,0 +1,13 @@ +# Build the manager binary +FROM golang:1.22 as builder + +WORKDIR /workspace +# Build +RUN --mount=type=bind,target=. CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager cmd/training-operator.v2alpha1/main.go + +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/static:nonroot +WORKDIR / +COPY --from=builder /workspace/manager . +ENTRYPOINT ["/manager"] diff --git a/cmd/training-operator.v2alpha1/main.go b/cmd/training-operator.v2alpha1/main.go new file mode 100644 index 0000000000..da96f6f2c2 --- /dev/null +++ b/cmd/training-operator.v2alpha1/main.go @@ -0,0 +1,21 @@ +/* +Copyright 2024 The Kubeflow Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +func main() { + +} diff --git a/pkg/apis/kubeflow.org/v2alpha1/trainingruntime_types.go b/pkg/apis/kubeflow.org/v2alpha1/trainingruntime_types.go new file mode 100644 index 0000000000..ab0377d028 --- /dev/null +++ b/pkg/apis/kubeflow.org/v2alpha1/trainingruntime_types.go @@ -0,0 +1,17 @@ +/* +Copyright 2024 The Kubeflow Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2alpha1 diff --git a/pkg/apis/kubeflow.org/v2alpha1/trainjob_types.go b/pkg/apis/kubeflow.org/v2alpha1/trainjob_types.go new file mode 100644 index 0000000000..ab0377d028 --- /dev/null +++ b/pkg/apis/kubeflow.org/v2alpha1/trainjob_types.go @@ -0,0 +1,17 @@ +/* +Copyright 2024 The Kubeflow Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2alpha1 diff --git a/pkg/controller.v2/trainjob_controller.go b/pkg/controller.v2/trainjob_controller.go new file mode 100644 index 0000000000..d10f548225 --- /dev/null +++ b/pkg/controller.v2/trainjob_controller.go @@ -0,0 +1,17 @@ +/* +Copyright 2024 The Kubeflow Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controllerv2 diff --git a/pkg/webhook.v2/trainjob_webhook.go b/pkg/webhook.v2/trainjob_webhook.go new file mode 100644 index 0000000000..f228441857 --- /dev/null +++ b/pkg/webhook.v2/trainjob_webhook.go @@ -0,0 +1,17 @@ +/* +Copyright 2024 The Kubeflow Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package webhookv2 From a4d2d3b84b585cda73df80ba7f4c4b7caf678920 Mon Sep 17 00:00:00 2001 From: Andrey Velichkevich Date: Thu, 15 Aug 2024 16:31:09 +0100 Subject: [PATCH 2/3] Fix default value for prefix in build Signed-off-by: Andrey Velichkevich --- .github/workflows/publish-core-images.yaml | 2 +- .github/workflows/template-publish-image/action.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-core-images.yaml b/.github/workflows/publish-core-images.yaml index f232d54815..692283bcaf 100644 --- a/.github/workflows/publish-core-images.yaml +++ b/.github/workflows/publish-core-images.yaml @@ -13,7 +13,7 @@ jobs: platforms: ${{ matrix.platforms }} dockerfile: ${{ matrix.dockerfile }} context: ${{ matrix.context }} - prefix: ${{matrix.prefix}} + prefix: ${{ matrix.prefix }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/template-publish-image/action.yaml b/.github/workflows/template-publish-image/action.yaml index 8f73fb30e2..9759e5422a 100644 --- a/.github/workflows/template-publish-image/action.yaml +++ b/.github/workflows/template-publish-image/action.yaml @@ -21,6 +21,7 @@ inputs: description: whether to push container images or not prefix: required: true + default: v1 description: Prefix for image tag, e.g. v1 or v2alpha1 runs: From e28303f9e573979e235e29272ceda6588e227e9d Mon Sep 17 00:00:00 2001 From: Andrey Velichkevich Date: Thu, 15 Aug 2024 17:59:58 +0100 Subject: [PATCH 3/3] Fix Docker image Signed-off-by: Andrey Velichkevich --- .github/workflows/build-and-publish-images.yaml | 8 ++++---- .github/workflows/publish-core-images.yaml | 8 ++++++-- .github/workflows/template-publish-image/action.yaml | 8 ++++---- cmd/training-operator.v2alpha1/Dockerfile | 12 +++++++++++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-publish-images.yaml b/.github/workflows/build-and-publish-images.yaml index dbb8ce37a9..41efe05a4b 100644 --- a/.github/workflows/build-and-publish-images.yaml +++ b/.github/workflows/build-and-publish-images.yaml @@ -17,8 +17,8 @@ on: required: false type: string default: . - prefix: - required: true + tag-prefix: + required: false type: string default: v1 secrets: @@ -61,7 +61,7 @@ jobs: platforms: ${{ inputs.platforms }} context: ${{ inputs.context }} push: true - prefix: ${{ inputs.prefix }} + tag-prefix: ${{ inputs.tag-prefix }} - name: Test Build For Component ${{ inputs.component-name }} if: steps.publish.outcome == 'skipped' @@ -72,4 +72,4 @@ jobs: platforms: ${{ inputs.platforms }} context: ${{ inputs.context }} push: false - prefix: ${{ inputs.prefix }} + tag-prefix: ${{ inputs.tag-prefix }} diff --git a/.github/workflows/publish-core-images.yaml b/.github/workflows/publish-core-images.yaml index 692283bcaf..86b887833c 100644 --- a/.github/workflows/publish-core-images.yaml +++ b/.github/workflows/publish-core-images.yaml @@ -13,7 +13,7 @@ jobs: platforms: ${{ matrix.platforms }} dockerfile: ${{ matrix.dockerfile }} context: ${{ matrix.context }} - prefix: ${{ matrix.prefix }} + tag-prefix: ${{ matrix.tag-prefix }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -25,18 +25,22 @@ jobs: - component-name: training-operator dockerfile: build/images/training-operator/Dockerfile platforms: linux/amd64,linux/arm64,linux/ppc64le + tag-prefix: v1 - component-name: training-operator dockerfile: cmd/training-operator.v2alpha1/Dockerfile platforms: linux/amd64,linux/arm64,linux/ppc64le - prefix: v2alpha1 + tag-prefix: v2alpha1 - component-name: kubectl-delivery dockerfile: build/images/kubectl-delivery/Dockerfile platforms: linux/amd64,linux/arm64,linux/ppc64le + tag-prefix: v1 - component-name: storage-initializer dockerfile: sdk/python/kubeflow/storage_initializer/Dockerfile context: sdk/python/kubeflow/storage_initializer platforms: linux/amd64,linux/arm64 + tag-prefix: v1 - component-name: trainer-huggingface dockerfile: sdk/python/kubeflow/trainer/Dockerfile context: sdk/python/kubeflow/trainer platforms: linux/amd64,linux/arm64 + tag-prefix: v1 diff --git a/.github/workflows/template-publish-image/action.yaml b/.github/workflows/template-publish-image/action.yaml index 9759e5422a..03fbd3caee 100644 --- a/.github/workflows/template-publish-image/action.yaml +++ b/.github/workflows/template-publish-image/action.yaml @@ -19,10 +19,10 @@ inputs: push: required: true description: whether to push container images or not - prefix: - required: true + tag-prefix: + required: false default: v1 - description: Prefix for image tag, e.g. v1 or v2alpha1 + description: Prefix for the image tag, e.g. v1 or v2alpha1 runs: using: composite @@ -42,7 +42,7 @@ runs: images: ${{ inputs.image }} tags: | type=raw,latest - type=sha,prefix=${{ inputs.prefix }}- + type=sha,prefix=${{ inputs.tag-prefix }}- - name: Build and Push uses: docker/build-push-action@v5 diff --git a/cmd/training-operator.v2alpha1/Dockerfile b/cmd/training-operator.v2alpha1/Dockerfile index 898cff8bf2..6c98c27964 100644 --- a/cmd/training-operator.v2alpha1/Dockerfile +++ b/cmd/training-operator.v2alpha1/Dockerfile @@ -2,8 +2,18 @@ FROM golang:1.22 as builder WORKDIR /workspace +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download + +# Copy the go source +COPY . . + # Build -RUN --mount=type=bind,target=. CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager cmd/training-operator.v2alpha1/main.go +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager cmd/training-operator.v2alpha1/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details