Skip to content

Commit

Permalink
Ensure run completion events with no artifacts return an empty slice …
Browse files Browse the repository at this point in the history
…rather than nil (#403)

Co-authored-by: Ian <[email protected]>
  • Loading branch information
aidandunlop and grahamia authored Nov 28, 2024
1 parent d2513a9 commit 5fd91a2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion argo/common/run_completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RunCompletionEvent struct {
RunName *NamespacedName `json:"runName,omitempty"`
RunId string `json:"runId"`
ServingModelArtifacts []Artifact `json:"servingModelArtifacts"`
Artifacts []Artifact `json:"artifacts,omitempty"`
Artifacts []Artifact `json:"artifacts"`
Provider string `json:"provider"`
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/webhook/runcompletion_event_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webhook
import (
"context"
"fmt"

"github.com/sky-uk/kfp-operator/argo/common"
"google.golang.org/grpc/credentials/insecure"

Expand Down Expand Up @@ -85,7 +86,7 @@ func RunCompletionEventToProto(event common.RunCompletionEvent) (*pb.RunCompleti
}

func artifactToProto(commonArtifacts []common.Artifact) []*pb.Artifact {
var pbArtifacts []*pb.Artifact
pbArtifacts := []*pb.Artifact{}
for _, commonArtifact := range commonArtifacts {
pbArtifacts = append(pbArtifacts, &pb.Artifact{
Location: commonArtifact.Location,
Expand Down
19 changes: 18 additions & 1 deletion controllers/webhook/runcompletion_event_trigger_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package webhook
import (
"context"
"errors"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -97,6 +98,8 @@ var _ = Context("EventDataToPbRunCompletion", func() {

It("returns no error when event data is converted to proto runcompletion event", func() {
protoRce, err := RunCompletionEventToProto(rce)
Expect(err).NotTo(HaveOccurred())

expectedArtifacts := []*pb.Artifact{
{
Name: "some-artifact",
Expand All @@ -114,12 +117,27 @@ var _ = Context("EventDataToPbRunCompletion", func() {
Provider: "some-provider",
}
Expect(protoRce).To(Equal(expectedResult))
})

It("returns empty slices when there are no artifacts", func() {
rceWithoutArtifacts := rce
rceWithoutArtifacts.Artifacts = []common.Artifact{}
rceWithoutArtifacts.ServingModelArtifacts = []common.Artifact{}

protoRce, err := RunCompletionEventToProto(rceWithoutArtifacts)
Expect(err).NotTo(HaveOccurred())

emptySliceOfArtifacts := []*pb.Artifact{}

Expect(protoRce.Artifacts).To(Equal(emptySliceOfArtifacts))
Expect(protoRce.ServingModelArtifacts).To(Equal(emptySliceOfArtifacts))
})

It("returns no error when event data with no RunName provided is converted to proto runcompletion event", func() {
rce.RunName = nil
protoRce, err := RunCompletionEventToProto(rce)
Expect(err).NotTo(HaveOccurred())

expectedArtifacts := []*pb.Artifact{
{
Name: "some-artifact",
Expand All @@ -137,7 +155,6 @@ var _ = Context("EventDataToPbRunCompletion", func() {
Provider: "some-provider",
}
Expect(protoRce).To(Equal(expectedResult))
Expect(err).NotTo(HaveOccurred())
})

It("returns error when namespaced name fields cannot be marshalled", func() {
Expand Down
9 changes: 6 additions & 3 deletions triggers/run-completion-event-trigger/cmd/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/sky-uk/kfp-operator/argo/common"
"github.com/sky-uk/kfp-operator/triggers/run-completion-event-trigger/internal/publisher"
"log"
"testing"
"time"

"github.com/sky-uk/kfp-operator/argo/common"
"github.com/sky-uk/kfp-operator/triggers/run-completion-event-trigger/internal/publisher"

"google.golang.org/grpc/credentials/insecure"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -83,6 +84,8 @@ var _ = Context("RunCompletionEventTriggerService", Ordered, func() {
},
}

emptyArtifacts := []*pb.Artifact{}

runCompletionEvent := &pb.RunCompletionEvent{
PipelineName: "some-pipeline-name",
Provider: "some-provider",
Expand All @@ -91,7 +94,7 @@ var _ = Context("RunCompletionEventTriggerService", Ordered, func() {
RunName: "some-run-name",
Status: pb.Status_SUCCEEDED,
ServingModelArtifacts: artifacts,
Artifacts: artifacts,
Artifacts: emptyArtifacts,
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func ProtoRunCompletionToCommon(protoRunCompletion *pb.RunCompletionEvent) (comm
RunConfigurationName: &runConfigurationName,
RunName: &runName,
RunId: protoRunCompletion.RunId,
ServingModelArtifacts: artifactsConverter(protoRunCompletion.ServingModelArtifacts),
Artifacts: artifactsConverter(protoRunCompletion.Artifacts),
ServingModelArtifacts: protoToArtifacts(protoRunCompletion.ServingModelArtifacts),
Artifacts: protoToArtifacts(protoRunCompletion.Artifacts),
Provider: protoRunCompletion.Provider,
}, nil
}

func artifactsConverter(artifacts []*pb.Artifact) []common.Artifact {
var commonArtifacts []common.Artifact
func protoToArtifacts(artifacts []*pb.Artifact) []common.Artifact {
commonArtifacts := []common.Artifact{}

for _, pbArtifact := range artifacts {
commonArtifact := common.Artifact{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package converters

import (
"testing"

"github.com/sky-uk/kfp-operator/argo/common"
pb "github.com/sky-uk/kfp-operator/triggers/run-completion-event-trigger/proto"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -67,7 +68,7 @@ var _ = Context("ProtoRunCompletionToCommon", func() {
})
})

var _ = Context("artifactsConverter", func() {
var _ = Context("protoToArtifacts", func() {

When("given a list of proto `Artifacts`", func() {
It("returns a list of artifacts in the common struct", func() {
Expand All @@ -82,7 +83,7 @@ var _ = Context("artifactsConverter", func() {
},
}

Expect(artifactsConverter(artifacts)).To(Equal(
Expect(protoToArtifacts(artifacts)).To(Equal(
[]common.Artifact{
{
Location: "some-location",
Expand Down

0 comments on commit 5fd91a2

Please sign in to comment.