Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
trying to get execution-status working...
Browse files Browse the repository at this point in the history
[cloudfoundry/eirini-release#190]

Co-authored-by: Danail Branekov <[email protected]>
  • Loading branch information
Kieron Browne and danail-branekov committed May 10, 2021
1 parent c4f19bf commit a849d05
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 12 deletions.
6 changes: 6 additions & 0 deletions k8s/reconciler/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func (t *Task) Reconcile(ctx context.Context, request reconcile.Request) (reconc
return reconcile.Result{}, exterrors.Wrap(err, "failed to desire task")
}

newTask := task.DeepCopy()
newTask.Status.ExecutionStatus = "starting"
if err := t.client.Status().Patch(ctx, newTask, client.MergeFrom(task)); err != nil {
logger.Error("patch-status-failed", err)
}

logger.Debug("task-desired-successfully")

return reconcile.Result{}, nil
Expand Down
16 changes: 15 additions & 1 deletion k8s/reconciler/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var _ = Describe("Task", func() {
namespacedName types.NamespacedName
taskDesirer *reconcilerfakes.FakeTaskDesirer
scheme *runtime.Scheme
statusWriter *reconcilerfakes.FakeStatusWriter
)

BeforeEach(func() {
Expand All @@ -44,6 +45,8 @@ var _ = Describe("Task", func() {
scheme = eiriniv1scheme.Scheme
logger := lagertest.NewTestLogger("task-reconciler")
taskReconciler = reconciler.NewTask(logger, controllerClient, taskDesirer, scheme)
statusWriter = new(reconcilerfakes.FakeStatusWriter)
controllerClient.StatusReturns(statusWriter)
})

JustBeforeEach(func() {
Expand Down Expand Up @@ -120,7 +123,18 @@ var _ = Describe("Task", func() {
Expect(task.CPUWeight).To(BeNumerically("==", 14))
})

By("sets an owner reference in the statefulset", func() {
By("updating the task execution status", func() {
Expect(statusWriter.PatchCallCount()).To(Equal(1))
_, patchedObject, patch, patchOpts := statusWriter.PatchArgsForCall(0)
Expect(patchedObject.GetName()).To(Equal(namespacedName.Name))
eiriniTask, ok := patchedObject.(*eiriniv1.Task)
Expect(ok).To(BeTrue())
Expect(eiriniTask.Status.ExecutionStatus).To(Equal("starting"))
Expect(patch.Type()).To(Equal(types.MergePatchType))
Expect(patchOpts).To(BeEmpty())
})

By("sets an owner reference in the job", func() {
Expect(taskDesirer.DesireCallCount()).To(Equal(1))
_, _, _, setOwnerFns := taskDesirer.DesireArgsForCall(0)
Expect(setOwnerFns).To(HaveLen(1))
Expand Down
9 changes: 9 additions & 0 deletions lrp-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: eirini.cloudfoundry.org/v1
kind: LRP
metadata:
name: test-lrp
spec:
GUID: asdf123
diskMB: 1024
status:
replicas: 99
11 changes: 9 additions & 2 deletions pkg/apis/eirini/v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status

// Task describes a short-lived job running alongside an LRP
type Task struct {
meta_v1.TypeMeta `json:",inline"`
meta_v1.ObjectMeta `json:"metadata,omitempty"`

Spec TaskSpec `json:"spec"`
Spec TaskSpec `json:"spec"`
Status TaskStatus `json:"status"`
}

type TaskSpec struct {
Expand Down Expand Up @@ -43,3 +44,9 @@ type TaskList struct {

Items []Task `json:"items"`
}

type TaskStatus struct {
StartTime meta_v1.Time `json:"start_time"`
EndTime meta_v1.Time `json:"end_time"`
ExecutionStatus string `json:"execution_status"`
}
19 changes: 19 additions & 0 deletions pkg/apis/eirini/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/generated/clientset/versioned/typed/eirini/v1/task.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions scripts/check-everything.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ run_eats() {
echo

if [[ "$redeploy" == "true" ]]; then
regenerate_secrets
redeploy_wiremock
redeploy_prometheus
redeploy_eirini
regenerate_secrets "$redeploy"
fi
redeploy_wiremock "$redeploy"
redeploy_prometheus "$redeploy"
redeploy_eirini "$redeploy"

local service_name
service_name=telepresence-$(uuidgen)
Expand Down Expand Up @@ -136,12 +136,16 @@ regenerate_secrets() {
}

redeploy_wiremock() {
kapp -y delete -a wiremock
if [[ "$1" == "true" ]]; then
kapp -y delete -a wiremock
fi
kapp -y deploy -a wiremock -f "$EIRINI_RELEASE_BASEDIR/scripts/assets/wiremock.yml"
}

redeploy_prometheus() {
kapp -y delete -a prometheus
if [[ "$1" == "true" ]]; then
kapp -y delete -a prometheus
fi
helm -n eirini-core template prometheus prometheus-community/prometheus | kapp -y deploy -a prometheus -f -
}

Expand All @@ -156,7 +160,9 @@ redeploy_eirini() {
for img in $(grep -oh "kbld:.*" "$render_dir/rendered.yml"); do
kind load docker-image --name eats "$img"
done
kapp -y delete -a eirini
if [[ "$1" == "true" ]]; then
kapp -y delete -a eirini
fi
kapp -y deploy -a eirini -f "$render_dir/rendered.yml"
}

Expand Down
2 changes: 1 addition & 1 deletion tests/eats/eats_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func TestEats(t *testing.T) {
SetDefaultEventuallyTimeout(4 * time.Minute)
SetDefaultEventuallyTimeout(2 * time.Minute)
RegisterFailHandler(tests.EatsFailHandler)
RunSpecs(t, "Eats Suite")
}
Expand Down
28 changes: 27 additions & 1 deletion tests/eats/tasks_crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var _ = Describe("Tasks CRD [needs-logs-for: eirini-controller]", func() {
taskDeleteOpts metav1.DeleteOptions
taskServiceName string
port int32
ctx context.Context
)

BeforeEach(func() {
Expand All @@ -44,22 +45,47 @@ var _ = Describe("Tasks CRD [needs-logs-for: eirini-controller]", func() {
Command: []string{"/notdora"},
},
}

ctx = context.Background()
})

getExecutionStatus := func() (string, error) {
runningTask, err := fixture.EiriniClientset.
EiriniV1().
Tasks(fixture.Namespace).
Get(ctx, taskName, metav1.GetOptions{})
if err != nil {
return "", err
}

return runningTask.Status.ExecutionStatus, nil
}

Describe("Creating a Task CRD", func() {
JustBeforeEach(func() {
_, err := fixture.EiriniClientset.
EiriniV1().
Tasks(fixture.Namespace).
Create(context.Background(), task, metav1.CreateOptions{})
Create(ctx, task, metav1.CreateOptions{})

Expect(err).NotTo(HaveOccurred())

taskServiceName = tests.ExposeAsService(fixture.Clientset, fixture.Namespace, taskGUID, port)
})

FWhen("the job is starting", func() {
BeforeEach(func() {
task.Spec.Image = "eirini/does-not-exist"
})

It("sets the task execution status to starting", func() {
Eventually(getExecutionStatus).Should(Equal("starting"))
})
})

It("runs the task", func() {
Eventually(tests.RequestServiceFn(fixture.Namespace, taskServiceName, port, "/")).Should(ContainSubstring("Dora!"))
Eventually(getExecutionStatus).Should(Equal("running"))
})

When("the task image lives in a private registry", func() {
Expand Down

0 comments on commit a849d05

Please sign in to comment.