Skip to content

Commit

Permalink
freight finder foo
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
  • Loading branch information
krancour committed Sep 3, 2024
1 parent 03576ea commit 47cc53c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion internal/argocd/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func GetDesiredRevision(
commit, err := freight.FindCommit(
ctx,
cl,
stage,
stage.Namespace,
stage.Spec.RequestedFreight,
desiredOrigin,
frght,
app.Spec.Source.RepoURL,
Expand Down
13 changes: 7 additions & 6 deletions internal/controller/freight/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
func FindCommit(
ctx context.Context,
cl client.Client,
stage *kargoapi.Stage,
project string,
freightReqs []kargoapi.FreightRequest,
desiredOrigin *kargoapi.FreightOrigin,
freight []kargoapi.FreightReference,
repoURL string,
Expand All @@ -25,26 +26,26 @@ func FindCommit(
// for, great. If there's more than one, there's ambiguity and we need to
// return an error.
if desiredOrigin == nil {
for i := range stage.Spec.RequestedFreight {
requestedFreight := stage.Spec.RequestedFreight[i]
for i := range freightReqs {
requestedFreight := freightReqs[i]
warehouse, err := kargoapi.GetWarehouse(
ctx,
cl,
types.NamespacedName{
Name: requestedFreight.Origin.Name,
Namespace: stage.Namespace,
Namespace: project,
},
)
if err != nil {
return nil, fmt.Errorf(
"error getting Warehouse %q in namespace %q: %w",
requestedFreight.Origin.Name, stage.Namespace, err,
requestedFreight.Origin.Name, project, err,
)
}
if warehouse == nil {
return nil, fmt.Errorf(
"Warehouse %q not found in namespace %q",
requestedFreight.Origin.Name, stage.Namespace,
requestedFreight.Origin.Name, project,
)
}
for _, sub := range warehouse.Spec.Subscriptions {
Expand Down
15 changes: 9 additions & 6 deletions internal/controller/freight/finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ func TestFindCommit(t *testing.T) {
testCases := []struct {
name string
client func() client.Client
Stage *kargoapi.Stage
stage *kargoapi.Stage
desiredOrigin *kargoapi.FreightOrigin
freight []kargoapi.FreightReference
assertions func(*testing.T, *kargoapi.GitCommit, error)
}{
{
name: "desired origin specified, but commit not found",
stage: &kargoapi.Stage{},
desiredOrigin: &testOrigin1,
freight: []kargoapi.FreightReference{
{
Expand All @@ -65,6 +66,7 @@ func TestFindCommit(t *testing.T) {
},
{
name: "desired origin specified and commit is found",
stage: &kargoapi.Stage{},
desiredOrigin: &testOrigin1,
freight: []kargoapi.FreightReference{
{
Expand All @@ -88,7 +90,7 @@ func TestFindCommit(t *testing.T) {
// desired origin
return fake.NewClientBuilder().WithScheme(scheme).Build()
},
Stage: &kargoapi.Stage{
stage: &kargoapi.Stage{
Spec: kargoapi.StageSpec{
RequestedFreight: []kargoapi.FreightRequest{{Origin: testOrigin1}},
},
Expand Down Expand Up @@ -118,7 +120,7 @@ func TestFindCommit(t *testing.T) {
},
).Build()
},
Stage: &kargoapi.Stage{
stage: &kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
},
Expand Down Expand Up @@ -163,7 +165,7 @@ func TestFindCommit(t *testing.T) {
},
).Build()
},
Stage: &kargoapi.Stage{
stage: &kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
},
Expand Down Expand Up @@ -203,7 +205,7 @@ func TestFindCommit(t *testing.T) {
},
).Build()
},
Stage: &kargoapi.Stage{
stage: &kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
},
Expand Down Expand Up @@ -238,7 +240,8 @@ func TestFindCommit(t *testing.T) {
commit, err := FindCommit(
context.Background(),
cl,
testCase.Stage,
testCase.stage.Namespace,
testCase.stage.Spec.RequestedFreight,
testCase.desiredOrigin,
testCase.freight,
testRepoURL,
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/promotion/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ func (a *argoCDMechanism) applyArgoCDSourceUpdate(
commit, err := freight.FindCommit(
ctx,
a.kargoClient,
stage,
stage.Namespace,
stage.Spec.RequestedFreight,
desiredOrigin,
newFreight,
update.RepoURL,
Expand Down
10 changes: 9 additions & 1 deletion internal/controller/promotion/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,15 @@ func getReadRef(
newFreight []kargoapi.FreightReference,
) (string, *kargoapi.GitCommit, error) {
desiredOrigin := freight.GetDesiredOrigin(stage, update)
commit, err := freight.FindCommit(ctx, cli, stage, desiredOrigin, newFreight, update.RepoURL)
commit, err := freight.FindCommit(
ctx,
cli,
stage.Namespace,
stage.Spec.RequestedFreight,
desiredOrigin,
newFreight,
update.RepoURL,
)
if err != nil {
return "", nil,
fmt.Errorf("error finding commit from repo %q: %w", update.RepoURL, err)
Expand Down

0 comments on commit 47cc53c

Please sign in to comment.