Skip to content

Commit

Permalink
patch promotion status with freight detail after git promote mechanis…
Browse files Browse the repository at this point in the history
…m, add conventional method to add freight to promotion status

Signed-off-by: Nguyen Duy Phuong <knowledge.phuongnguyen@gmail.com>
  • Loading branch information
phuongdnguyen committed Apr 10, 2024
1 parent b3381ff commit 63beae7
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 244 deletions.
441 changes: 220 additions & 221 deletions api/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/v1alpha1/generated.proto

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

11 changes: 9 additions & 2 deletions api/v1alpha1/promotion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ type PromotionStatus struct {
// Metadata holds arbitrary metadata set by promotion mechanisms
// (e.g. for display purposes, or internal bookkeeping)
Metadata map[string]string `json:"metadata,omitempty" protobuf:"bytes,3,rep,name=metadata" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
// PromotedFreight is the detail of the piece of freight that was referenced by this promotion.
PromotedFreight *FreightReference `json:"promotedFreight,omitempty" protobuf:"bytes,4,opt,name=promotedFreight"`
// Freight is the detail of the piece of freight that was referenced by this promotion.
Freight *FreightReference `json:"promotedFreight,omitempty" protobuf:"bytes,4,opt,name=freight"`
}

// WithPhase returns a copy of PromotionStatus with the given phase
Expand All @@ -107,6 +107,13 @@ func (p *PromotionStatus) WithPhase(phase PromotionPhase) *PromotionStatus {
return status
}

// WithFreight returns a copy of PromotionStatus with the given freight
func (p *PromotionStatus) WithFreight(freight *FreightReference) *PromotionStatus {
status := p.DeepCopy()
status.Freight = freight
return status

Check warning on line 114 in api/v1alpha1/promotion_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/promotion_types.go#L111-L114

Added lines #L111 - L114 were not covered by tests
}

// +kubebuilder:object:root=true

// PromotionList contains a list of Promotion
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions charts/kargo/resources/crds/kargo.akuity.io_promotions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ spec:
lifecycle.
type: string
promotedFreight:
description: PromotedFreight is the detail of the piece of freight
that was referenced by this promotion.
description: Freight is the detail of the piece of freight that was
referenced by this promotion.
properties:
charts:
description: Charts describes specific versions of specific Helm
Expand Down
8 changes: 4 additions & 4 deletions charts/kargo/resources/crds/kargo.akuity.io_stages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,8 @@ spec:
is in its lifecycle.
type: string
promotedFreight:
description: PromotedFreight is the detail of the piece of
freight that was referenced by this promotion.
description: Freight is the detail of the piece of freight
that was referenced by this promotion.
properties:
charts:
description: Charts describes specific versions of specific
Expand Down Expand Up @@ -1724,8 +1724,8 @@ spec:
is in its lifecycle.
type: string
promotedFreight:
description: PromotedFreight is the detail of the piece of
freight that was referenced by this promotion.
description: Freight is the detail of the piece of freight
that was referenced by this promotion.
properties:
charts:
description: Charts describes specific versions of specific
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/promotion/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (g *gitMechanism) Promote(
); err != nil {
return nil, newFreight, err
}
newStatus = aggregateGitPromoStatus(newStatus, *otherStatus)
newStatus = aggregateGitPromoStatus(newStatus, *otherStatus).WithFreight(&newFreight)
}

logger.Debugf("done executing %s", g.name)
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/promotions/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (r *reconciler) promote(
)
}
if targetFreight == nil {
return nil, fmt.Errorf("freight %q not found in namespace %q", promo.Spec.Freight, promo.Namespace)
return nil, fmt.Errorf("Freight %q not found in namespace %q", promo.Spec.Freight, promo.Namespace)
}
upstreamStages := make([]string, len(stage.Spec.Subscriptions.UpstreamStages))
for i, upstreamStage := range stage.Spec.Subscriptions.UpstreamStages {
Expand Down Expand Up @@ -423,10 +423,10 @@ func (r *reconciler) promote(
}
// record the freight reference to the promotion's status
err = kubeclient.PatchStatus(ctx, r.kargoClient, &promo, func(status *kargoapi.PromotionStatus) {
status.PromotedFreight = &targetFreightRef
status.Freight = &targetFreightRef
})
if err != nil {
return nil, err
logger.Errorf("Promotion status patch failed: %v", err)

Check warning on line 429 in internal/controller/promotions/promotions.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotions/promotions.go#L425-L429

Added lines #L425 - L429 were not covered by tests
}

newStatus, nextFreight, err := r.promoMechanisms.Promote(ctx, stage, &promo, targetFreightRef)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/gen/schema/promotions.kargo.akuity.io_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"type": "string"
},
"promotedFreight": {
"description": "PromotedFreight is the detail of the piece of freight that was referenced by this promotion.",
"description": "Freight is the detail of the piece of freight that was referenced by this promotion.",
"properties": {
"charts": {
"description": "Charts describes specific versions of specific Helm charts.",
Expand Down
4 changes: 2 additions & 2 deletions ui/src/gen/schema/stages.kargo.akuity.io_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@
"type": "string"
},
"promotedFreight": {
"description": "PromotedFreight is the detail of the piece of freight that was referenced by this promotion.",
"description": "Freight is the detail of the piece of freight that was referenced by this promotion.",
"properties": {
"charts": {
"description": "Charts describes specific versions of specific Helm charts.",
Expand Down Expand Up @@ -1568,7 +1568,7 @@
"type": "string"
},
"promotedFreight": {
"description": "PromotedFreight is the detail of the piece of freight that was referenced by this promotion.",
"description": "Freight is the detail of the piece of freight that was referenced by this promotion.",
"properties": {
"charts": {
"description": "Charts describes specific versions of specific Helm charts.",
Expand Down
8 changes: 4 additions & 4 deletions ui/src/gen/v1alpha1/generated_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2874,11 +2874,11 @@ export class PromotionStatus extends Message<PromotionStatus> {
metadata: { [key: string]: string } = {};

/**
* PromotedFreight is the detail of the piece of freight that was referenced by this promotion.
* Freight is the detail of the piece of freight that was referenced by this promotion.
*
* @generated from field: optional git.luolix.top.akuity.kargo.api.v1alpha1.FreightReference promotedFreight = 4;
* @generated from field: optional git.luolix.top.akuity.kargo.api.v1alpha1.FreightReference freight = 4;
*/
promotedFreight?: FreightReference;
freight?: FreightReference;

constructor(data?: PartialMessage<PromotionStatus>) {
super();
Expand All @@ -2891,7 +2891,7 @@ export class PromotionStatus extends Message<PromotionStatus> {
{ no: 1, name: "phase", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 2, name: "message", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 3, name: "metadata", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "scalar", T: 9 /* ScalarType.STRING */} },
{ no: 4, name: "promotedFreight", kind: "message", T: FreightReference, opt: true },
{ no: 4, name: "freight", kind: "message", T: FreightReference, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): PromotionStatus {
Expand Down

0 comments on commit 63beae7

Please sign in to comment.