Skip to content

Commit

Permalink
simple e2e test for appwrapper integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrove-oss committed Jan 13, 2025
1 parent 88bb3a2 commit fd21974
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 6 deletions.
18 changes: 15 additions & 3 deletions Makefile-deps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,25 @@ cluster-autoscaler-crd: ## Copy the CRDs from the cluster-autoscaler to the dep-
cp -f $(CLUSTER_AUTOSCALER_ROOT)/config/crd/* $(EXTERNAL_CRDS_DIR)/cluster-autoscaler/

APPWRAPPER_ROOT = $(shell $(GO_CMD) list -m -mod=readonly -f "{{.Dir}}" github.com/project-codeflare/appwrapper)
APPWRAPPER_VERSION = $(shell $(GO_CMD) list -m -f "{{.Version}}" github.com/project-codeflare/appwrapper)
.PHONY: appwrapper-crd
appwrapper-crd: ## Copy the CRDs from the appwrapper to the dep-crds directory.
mkdir -p $(EXTERNAL_CRDS_DIR)/appwrapper/
cp -f $(APPWRAPPER_ROOT)/config/crd/bases/* $(EXTERNAL_CRDS_DIR)/appwrapper/
mkdir -p $(EXTERNAL_CRDS_DIR)/appwrapper-crds/
cp -f $(APPWRAPPER_ROOT)/config/crd/bases/* $(EXTERNAL_CRDS_DIR)/appwrapper-crds/

.PHONY: appwrapper-manifests
appwrapper-manifests: ## Copy whole manifests folder from the appwrapper controller to the dep-crds directory.
## Full version of the manifest required for e2e tests.
if [ -d "$(EXTERNAL_CRDS_DIR)/appwrapper" ]; then \
chmod -R u+w "$(EXTERNAL_CRDS_DIR)/appwrapper" && \
rm -rf "$(EXTERNAL_CRDS_DIR)/appwrapper"; \
fi
mkdir -p "$(EXTERNAL_CRDS_DIR)/appwrapper"
cp -rf "$(APPWRAPPER_ROOT)/config" "$(EXTERNAL_CRDS_DIR)/appwrapper"
cd "$(EXTERNAL_CRDS_DIR)/appwrapper/config/manager" && chmod u+w kustomization.yaml && $(KUSTOMIZE) edit set image controller=quay.io/ibm/appwrapper:${APPWRAPPER_VERSION} && chmod u-w kustomization.yaml

.PHONY: dep-crds
dep-crds: mpi-operator-crd kf-training-operator-crd ray-operator-crd jobset-operator-crd cluster-autoscaler-crd appwrapper-crd kf-training-operator-manifests ## Copy the CRDs from the external operators to the dep-crds directory.
dep-crds: mpi-operator-crd kf-training-operator-crd ray-operator-crd jobset-operator-crd cluster-autoscaler-crd appwrapper-crd appwrapper-manifests kf-training-operator-manifests ## Copy the CRDs from the external operators to the dep-crds directory.
@echo "Copying CRDs from external operators to dep-crds directory"

.PHONY: kueuectl-docs
Expand Down
4 changes: 3 additions & 1 deletion Makefile-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ IMAGE_NAME := kueue
IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG)

# JobSet Version
# Versions for external controllers
APPWRAPPER_VERSION = $(shell $(GO_CMD) list -m -f "{{.Version}}" github.com/project-codeflare/appwrapper)
JOBSET_VERSION = $(shell $(GO_CMD) list -m -f "{{.Version}}" sigs.k8s.io/jobset)
KUBEFLOW_VERSION = $(shell $(GO_CMD) list -m -f "{{.Version}}" github.com/kubeflow/training-operator)
KUBEFLOW_MPI_VERSION = $(shell $(GO_CMD) list -m -f "{{.Version}}" github.com/kubeflow/mpi-operator)
Expand Down Expand Up @@ -108,6 +109,7 @@ run-test-e2e-%: FORCE
@echo Running e2e for k8s ${K8S_VERSION}
E2E_KIND_VERSION="kindest/node:v$(K8S_VERSION)" KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) CREATE_KIND_CLUSTER=$(CREATE_KIND_CLUSTER) \
ARTIFACTS="$(ARTIFACTS)/$@" IMAGE_TAG=$(IMAGE_TAG) GINKGO_ARGS="$(GINKGO_ARGS)" \
APPWRAPPER_VERSION=$(APPWRAPER_VERSION) \
JOBSET_VERSION=$(JOBSET_VERSION) \
KIND_CLUSTER_FILE="kind-cluster.yaml" E2E_TARGET_FOLDER="singlecluster" \
./hack/e2e-test.sh
Expand Down
15 changes: 15 additions & 0 deletions hack/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export YQ="$ROOT_DIR"/bin/yq

export KIND_VERSION="${E2E_KIND_VERSION/"kindest/node:v"/}"

if [[ -n ${APPWRAPPER_VERSION:-} ]]; then
export APPWRAPPER_MANIFEST=${ROOT_DIR}/dep-crds/appwrapper/config/standalone
APPWRAPPER_IMAGE=quay.io/ibm/appwrapper:${APPWRAPPER_VERSION}
fi

if [[ -n ${JOBSET_VERSION:-} ]]; then
export JOBSET_MANIFEST="https://github.com/kubernetes-sigs/jobset/releases/download/${JOBSET_VERSION}/manifests.yaml"
export JOBSET_IMAGE=registry.k8s.io/jobset/jobset:${JOBSET_VERSION}
Expand Down Expand Up @@ -80,6 +85,9 @@ function prepare_docker_images {
docker tag $E2E_TEST_SLEEP_IMAGE "$E2E_TEST_SLEEP_IMAGE_WITHOUT_SHA"
docker tag $E2E_TEST_CURL_IMAGE "$E2E_TEST_CURL_IMAGE_WITHOUT_SHA"

if [[ -n ${APPWRAPPER_VERSION:-} ]]; then
docker pull "${APPWRAPPER_IMAGE}"
fi
if [[ -n ${JOBSET_VERSION:-} ]]; then
docker pull "${JOBSET_IMAGE}"
fi
Expand Down Expand Up @@ -115,6 +123,13 @@ function cluster_kueue_deploy {
fi
}

#$1 - cluster name
function install_appwrapper {
cluster_kind_load_image "${1}" "${APPWRAPPER_IMAGE}"
kubectl config use-context "kind-${1}"
kubectl apply -k "${APPWRAPPER_MANIFEST}"
}

#$1 - cluster name
function install_jobset {
cluster_kind_load_image "${1}" "${JOBSET_IMAGE}"
Expand Down
3 changes: 3 additions & 0 deletions hack/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function kind_load {
cluster_kind_load "$KIND_CLUSTER_NAME"
fi

if [[ -n ${APPWRAPPER_VERSION:-} ]]; then
install_appwrapper "$KIND_CLUSTER_NAME"
fi
if [[ -n ${JOBSET_VERSION:-} ]]; then
install_jobset "$KIND_CLUSTER_NAME"
fi
Expand Down
115 changes: 115 additions & 0 deletions test/e2e/singlecluster/appwrapper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright 2024 The Kubernetes 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 e2e

import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
"sigs.k8s.io/kueue/pkg/util/testing"
awtesting "sigs.k8s.io/kueue/pkg/util/testingjobs/appwrapper"
utiltestingjob "sigs.k8s.io/kueue/pkg/util/testingjobs/job"
"sigs.k8s.io/kueue/test/util"
)

var _ = ginkgo.Describe("AppWrapper", func() {
const (
resourceFlavorName = "appwrapper-rf"
clusterQueueName = "appwrapper-cq"
localQueueName = "appwrapper-lq"
)

var (
ns *corev1.Namespace
rf *kueue.ResourceFlavor
cq *kueue.ClusterQueue
lq *kueue.LocalQueue
)

ginkgo.BeforeEach(func() {
ns = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "appwrapper-e2e-",
},
}
gomega.Expect(k8sClient.Create(ctx, ns)).To(gomega.Succeed())

rf = testing.MakeResourceFlavor(resourceFlavorName).
NodeLabel("instance-type", "on-demand").
Obj()
gomega.Expect(k8sClient.Create(ctx, rf)).To(gomega.Succeed())

cq = testing.MakeClusterQueue(clusterQueueName).
ResourceGroup(
*testing.MakeFlavorQuotas(resourceFlavorName).
Resource(corev1.ResourceCPU, "5").
Obj(),
).
Preemption(kueue.ClusterQueuePreemption{
WithinClusterQueue: kueue.PreemptionPolicyLowerPriority,
}).
Obj()
gomega.Expect(k8sClient.Create(ctx, cq)).To(gomega.Succeed())

lq = testing.MakeLocalQueue(localQueueName, ns.Name).ClusterQueue(cq.Name).Obj()
gomega.Expect(k8sClient.Create(ctx, lq)).To(gomega.Succeed())
})
ginkgo.AfterEach(func() {
gomega.Expect(util.DeleteNamespace(ctx, k8sClient, ns)).To(gomega.Succeed())
util.ExpectObjectToBeDeleted(ctx, k8sClient, cq, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, rf, true)
})

ginkgo.It("Should admit workloads that fit", func() {
aw := awtesting.MakeAppWrapper("appwrapper", ns.Name).
Component(utiltestingjob.MakeJob("job-0", ns.Name).
Request("cpu", "1").
Image(util.E2eTestSleepImage, []string{"10s"}).
SetTypeMeta().Obj()).
Queue(localQueueName).
Obj()

ginkgo.By("Create an appwrapper", func() {
gomega.Expect(k8sClient.Create(ctx, aw)).To(gomega.Succeed())
})

ginkgo.By("Wait for appwrapper reach running state", func() {
createdAppWrapper := &awv1beta2.AppWrapper{}
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(aw), createdAppWrapper)).To(gomega.Succeed())
g.Expect(createdAppWrapper.Status.Phase).To(gomega.Equal(awv1beta2.AppWrapperRunning))
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
})

ginkgo.By("Wait for the wrapped Job to successfully complete", func() {
createdAppWrapper := &awv1beta2.AppWrapper{}
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(aw), createdAppWrapper)).To(gomega.Succeed())
g.Expect(createdAppWrapper.Status.Phase).To(gomega.Equal(awv1beta2.AppWrapperSucceeded))
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
})

ginkgo.By("Delete the appwrapper", func() {
util.ExpectObjectToBeDeleted(ctx, k8sClient, aw, true)
})
})
})
3 changes: 2 additions & 1 deletion test/e2e/singlecluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ var _ = ginkgo.BeforeSuite(func() {
waitForAvailableStart := time.Now()
util.WaitForKueueAvailability(ctx, k8sClient)
util.WaitForJobSetAvailability(ctx, k8sClient)
ginkgo.GinkgoLogr.Info("Kueue and JobSet oprators are available in the cluster", "waitingTime", time.Since(waitForAvailableStart))
util.WaitForAppWrapperAvailability(ctx, k8sClient)
ginkgo.GinkgoLogr.Info("Kueue, JobSet and AppWrapper operators are available in the cluster", "waitingTime", time.Since(waitForAvailableStart))
})
2 changes: 1 addition & 1 deletion test/integration/controller/jobs/appwrapper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
ctx context.Context
fwk *framework.Framework
crdPath = filepath.Join("..", "..", "..", "..", "..", "config", "components", "crd", "bases")
appwrapperCrdPath = filepath.Join("..", "..", "..", "..", "..", "dep-crds", "appwrapper")
appwrapperCrdPath = filepath.Join("..", "..", "..", "..", "..", "dep-crds", "appwrapper-crds")
)

func TestAPIs(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions test/util/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func WaitForKueueAvailability(ctx context.Context, k8sClient client.Client) {
waitForOperatorAvailability(ctx, k8sClient, kcmKey)
}

func WaitForAppWrapperAvailability(ctx context.Context, k8sClient client.Client) {
jcmKey := types.NamespacedName{Namespace: "appwrapper-system", Name: "appwrapper-controller-manager"}
waitForOperatorAvailability(ctx, k8sClient, jcmKey)
}

func WaitForJobSetAvailability(ctx context.Context, k8sClient client.Client) {
jcmKey := types.NamespacedName{Namespace: "jobset-system", Name: "jobset-controller-manager"}
waitForOperatorAvailability(ctx, k8sClient, jcmKey)
Expand Down

0 comments on commit fd21974

Please sign in to comment.