Skip to content

Commit

Permalink
added freight ref to warehouse status and repo-commit mappings fetcher
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Stankevic <[email protected]>
  • Loading branch information
maksimstankevic committed Mar 5, 2024
1 parent 467a3cd commit d8aff35
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/warehouse_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ type WarehouseStatus struct {
// ObservedGeneration represents the .metadata.generation that this Warehouse
// was reconciled against.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// FreightReference refers to the last Freight produced by this Warehouse
FreightReference string `json:"freightReference,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
4 changes: 4 additions & 0 deletions charts/kargo/crds/kargo.akuity.io_warehouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ spec:
description: Error describes any errors that are preventing the Warehouse
controller from polling repositories to discover new Freight.
type: string
freightReference:
description: FreightReference refers to the last Freight produced
by this Warehouse
type: string
observedGeneration:
description: ObservedGeneration represents the .metadata.generation
that this Warehouse was reconciled against.
Expand Down
41 changes: 41 additions & 0 deletions internal/controller/warehouses/git_repos_commits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package warehouses

import (
"context"

"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
)

func (r *reconciler) getGitRepoCommitsMappings(
ctx context.Context,
freightId string,
ns string,
) (map[string][]string, error) {

freight := kargoapi.Freight{}
if err := r.client.Get(
ctx,
client.ObjectKey{
Namespace: ns,
Name: freightId,
},
&freight,
); err != nil {
return nil, errors.Wrapf(
err,
"error checking for existence of Freight with ID %q",
freightId,
)
}

result := map[string][]string{}
for _, commit := range freight.Commits {
result[commit.RepoURL] = []string{commit.ID, commit.Branch}
}

return result, nil

}
13 changes: 13 additions & 0 deletions internal/controller/warehouses/warehouses.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ type reconciler struct {

getAvailableFreightAliasFn func(context.Context) (string, error)

getGitRepoCommitsMappingsFn func(context.Context, string, string) (map[string][]string, error)

createFreightFn func(
context.Context,
client.Object,
Expand Down Expand Up @@ -162,6 +164,7 @@ func newReconciler(
r.selectChartVersionFn = helm.SelectChartVersion
r.selectCommitMetaFn = r.selectCommitMeta
r.getAvailableFreightAliasFn = r.getAvailableFreightAlias
r.getGitRepoCommitsMappingsFn = r.getGitRepoCommitsMappings
r.createFreightFn = kubeClient.Create
return r
}
Expand Down Expand Up @@ -241,10 +244,19 @@ func (r *reconciler) syncWarehouse(
) (kargoapi.WarehouseStatus, error) {
status := *warehouse.Status.DeepCopy()
status.ObservedGeneration = warehouse.Generation
status.FreightReference = warehouse.Status.FreightReference
status.Error = "" // Clear any previous error

logger := logging.LoggerFromContext(ctx)

// debug
res, err := r.getGitRepoCommitsMappingsFn(ctx, warehouse.Status.FreightReference, warehouse.Namespace)
if err != nil {
return status,
errors.Wrap(err, "error getting git repos commits mappings")
}
logger.Debug("!!!DEBUG!!!", res)

freight, err := r.getLatestFreightFromReposFn(ctx, warehouse)
if err != nil {
return status,
Expand Down Expand Up @@ -283,6 +295,7 @@ func (r *reconciler) syncWarehouse(
freight.Name,
freight.Namespace,
)
status.FreightReference = freight.ID

return status, nil
}
Expand Down
4 changes: 4 additions & 0 deletions ui/src/gen/schema/warehouses.kargo.akuity.io_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
"description": "Error describes any errors that are preventing the Warehouse controller from polling repositories to discover new Freight.",
"type": "string"
},
"freightReference": {
"description": "FreightReference refers to the last Freight produced by this Warehouse",
"type": "string"
},
"observedGeneration": {
"description": "ObservedGeneration represents the .metadata.generation that this Warehouse was reconciled against.",
"format": "int64",
Expand Down

0 comments on commit d8aff35

Please sign in to comment.